@smartico/public-api 0.0.110 → 0.0.112
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/Leaderboard/LeaderBoards.d.ts +3 -0
- package/dist/Level/LevelPublicMeta.d.ts +2 -0
- package/dist/SmarticoAPI.d.ts +2 -1
- package/dist/WSAPI/WSAPI.d.ts +6 -1
- package/dist/WSAPI/WSAPITypes.d.ts +41 -0
- package/dist/index.js +196 -93
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +105 -31
- package/dist/index.modern.mjs.map +1 -1
- package/docs/README.md +3 -0
- package/docs/classes/WSAPI.md +25 -6
- package/docs/interfaces/LeaderBoardDetailsT.md +65 -0
- package/docs/interfaces/LeaderBoardUserT.md +41 -0
- package/docs/interfaces/LeaderBoardsRewardsT.md +13 -0
- package/docs/interfaces/TAchCategory.md +1 -1
- package/docs/interfaces/TLevel.md +8 -0
- package/docs/interfaces/TMissionOrBadge.md +6 -1
- package/docs/interfaces/TStoreItem.md +9 -1
- package/package.json +1 -1
- package/src/Leaderboard/LeaderBoards.ts +51 -0
- package/src/Level/GetLevelMapResponse.ts +2 -0
- package/src/Level/LevelPublicMeta.ts +2 -0
- package/src/Missions/UserAchievement.ts +5 -3
- package/src/OCache.ts +10 -3
- package/src/SmarticoAPI.ts +18 -7
- package/src/Store/StoreItem.ts +1 -0
- package/src/WSAPI/WSAPI.ts +20 -6
- package/src/WSAPI/WSAPITypes.ts +48 -1
package/docs/README.md
CHANGED
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
- [TInboxMessage](interfaces/TInboxMessage.md)
|
|
33
33
|
- [TInboxMessageBody](interfaces/TInboxMessageBody.md)
|
|
34
34
|
- [InboxMarkMessageAction](interfaces/InboxMarkMessageAction.md)
|
|
35
|
+
- [LeaderBoardDetailsT](interfaces/LeaderBoardDetailsT.md)
|
|
36
|
+
- [LeaderBoardsRewardsT](interfaces/LeaderBoardsRewardsT.md)
|
|
37
|
+
- [LeaderBoardUserT](interfaces/LeaderBoardUserT.md)
|
|
35
38
|
|
|
36
39
|
## General API
|
|
37
40
|
|
package/docs/classes/WSAPI.md
CHANGED
|
@@ -87,29 +87,28 @@ ___
|
|
|
87
87
|
|
|
88
88
|
### getStoreCategories
|
|
89
89
|
|
|
90
|
-
▸ **getStoreCategories**(): `Promise`<[`
|
|
90
|
+
▸ **getStoreCategories**(): `Promise`<[`TStoreCategory`](../interfaces/TStoreCategory.md)[]\>
|
|
91
91
|
|
|
92
92
|
Returns store categories
|
|
93
93
|
|
|
94
94
|
#### Returns
|
|
95
95
|
|
|
96
|
-
`Promise`<[`
|
|
96
|
+
`Promise`<[`TStoreCategory`](../interfaces/TStoreCategory.md)[]\>
|
|
97
97
|
|
|
98
98
|
___
|
|
99
99
|
|
|
100
100
|
### getAchCategories
|
|
101
101
|
|
|
102
|
-
▸ **getAchCategories**(): `Promise`<[`
|
|
102
|
+
▸ **getAchCategories**(): `Promise`<[`TAchCategory`](../interfaces/TAchCategory.md)[]\>
|
|
103
103
|
|
|
104
|
-
Returns
|
|
104
|
+
Returns ach categories
|
|
105
105
|
|
|
106
106
|
#### Returns
|
|
107
107
|
|
|
108
|
-
`Promise`<[`
|
|
108
|
+
`Promise`<[`TAchCategory`](../interfaces/TAchCategory.md)[]\>
|
|
109
109
|
|
|
110
110
|
___
|
|
111
111
|
|
|
112
|
-
|
|
113
112
|
### getMiniGames
|
|
114
113
|
|
|
115
114
|
▸ **getMiniGames**(`params?`): `Promise`<[`TMiniGameTemplate`](../interfaces/TMiniGameTemplate.md)[]\>
|
|
@@ -219,6 +218,26 @@ Requests registration for the specified tournament instance. Returns the err_cod
|
|
|
219
218
|
|
|
220
219
|
___
|
|
221
220
|
|
|
221
|
+
### getLeaderBoard
|
|
222
|
+
|
|
223
|
+
▸ **getLeaderBoard**(`periodType`, `getPreviousPeriod?`): `Promise`<[`LeaderBoardDetailsT`](../interfaces/LeaderBoardDetailsT.md)\>
|
|
224
|
+
|
|
225
|
+
Returns the leaderboard for the current type (default is Daily). If getPreviousPeriod is passed as true, a leaderboard for the previous period for the current type will be returned.
|
|
226
|
+
For example, if the type is Weekly and getPreviousPeriod is true, a leaderboard for the previous week will be returned.
|
|
227
|
+
|
|
228
|
+
#### Parameters
|
|
229
|
+
|
|
230
|
+
| Name | Type |
|
|
231
|
+
| :------ | :------ |
|
|
232
|
+
| `periodType` | `LeaderBoardPeriodType` |
|
|
233
|
+
| `getPreviousPeriod?` | `boolean` |
|
|
234
|
+
|
|
235
|
+
#### Returns
|
|
236
|
+
|
|
237
|
+
`Promise`<[`LeaderBoardDetailsT`](../interfaces/LeaderBoardDetailsT.md)\>
|
|
238
|
+
|
|
239
|
+
___
|
|
240
|
+
|
|
222
241
|
### getInboxMessages
|
|
223
242
|
|
|
224
243
|
▸ **getInboxMessages**(`params?`): `Promise`<[`TInboxMessage`](../interfaces/TInboxMessage.md)[]\>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Interface: LeaderBoardDetailsT
|
|
2
|
+
|
|
3
|
+
## Properties
|
|
4
|
+
|
|
5
|
+
### board\_id
|
|
6
|
+
|
|
7
|
+
• **board\_id**: `number`
|
|
8
|
+
|
|
9
|
+
ID of the leaderboard
|
|
10
|
+
|
|
11
|
+
___
|
|
12
|
+
|
|
13
|
+
### name
|
|
14
|
+
|
|
15
|
+
• **name**: `string`
|
|
16
|
+
|
|
17
|
+
Name of the leaderboard
|
|
18
|
+
|
|
19
|
+
___
|
|
20
|
+
|
|
21
|
+
### description
|
|
22
|
+
|
|
23
|
+
• **description**: `string`
|
|
24
|
+
|
|
25
|
+
Description of the leaderboard
|
|
26
|
+
|
|
27
|
+
___
|
|
28
|
+
|
|
29
|
+
### rules
|
|
30
|
+
|
|
31
|
+
• **rules**: `string`
|
|
32
|
+
|
|
33
|
+
Rules of the leaderboard
|
|
34
|
+
|
|
35
|
+
___
|
|
36
|
+
|
|
37
|
+
### period\_type\_id
|
|
38
|
+
|
|
39
|
+
• **period\_type\_id**: `LeaderBoardPeriodType`
|
|
40
|
+
|
|
41
|
+
Leaderboard period type ID
|
|
42
|
+
|
|
43
|
+
___
|
|
44
|
+
|
|
45
|
+
### rewards
|
|
46
|
+
|
|
47
|
+
• **rewards**: [`LeaderBoardsRewardsT`](LeaderBoardsRewardsT.md)[]
|
|
48
|
+
|
|
49
|
+
Leaderboard points rewards
|
|
50
|
+
|
|
51
|
+
___
|
|
52
|
+
|
|
53
|
+
### users
|
|
54
|
+
|
|
55
|
+
• **users**: [`LeaderBoardUserT`](LeaderBoardUserT.md)[]
|
|
56
|
+
|
|
57
|
+
Leaderboard users
|
|
58
|
+
|
|
59
|
+
___
|
|
60
|
+
|
|
61
|
+
### me
|
|
62
|
+
|
|
63
|
+
• `Optional` **me**: [`LeaderBoardUserT`](LeaderBoardUserT.md)
|
|
64
|
+
|
|
65
|
+
Info about current user in leaderboard
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Interface: LeaderBoardUserT
|
|
2
|
+
|
|
3
|
+
## Properties
|
|
4
|
+
|
|
5
|
+
### public\_username
|
|
6
|
+
|
|
7
|
+
• **public\_username**: `string`
|
|
8
|
+
|
|
9
|
+
The username of the participant
|
|
10
|
+
|
|
11
|
+
___
|
|
12
|
+
|
|
13
|
+
### avatar\_url
|
|
14
|
+
|
|
15
|
+
• **avatar\_url**: `string`
|
|
16
|
+
|
|
17
|
+
The URL to the avatar of the participant
|
|
18
|
+
|
|
19
|
+
___
|
|
20
|
+
|
|
21
|
+
### position
|
|
22
|
+
|
|
23
|
+
• **position**: `number`
|
|
24
|
+
|
|
25
|
+
The position of the participant in the leaderboard
|
|
26
|
+
|
|
27
|
+
___
|
|
28
|
+
|
|
29
|
+
### points
|
|
30
|
+
|
|
31
|
+
• **points**: `number`
|
|
32
|
+
|
|
33
|
+
The points of the participant in the leaderboard
|
|
34
|
+
|
|
35
|
+
___
|
|
36
|
+
|
|
37
|
+
### is\_me
|
|
38
|
+
|
|
39
|
+
• **is\_me**: `boolean`
|
|
40
|
+
|
|
41
|
+
The indicator if the participant is current user
|
|
@@ -72,3 +72,11 @@ ___
|
|
|
72
72
|
The counter of 2nd metric used to reach the Level.
|
|
73
73
|
Relevant in case of using advanced leveling logic
|
|
74
74
|
https://help.smartico.ai/welcome/more/release-notes/september-2022#new-logic-for-leveling-users
|
|
75
|
+
|
|
76
|
+
___
|
|
77
|
+
|
|
78
|
+
### custom\_data
|
|
79
|
+
|
|
80
|
+
• **custom\_data**: `string`
|
|
81
|
+
|
|
82
|
+
The custom data of the mini-game defined by operator. Can be a JSON object, string or number
|
|
@@ -176,7 +176,6 @@ List of casino games (or other types of entities) related to the mission or badg
|
|
|
176
176
|
|
|
177
177
|
___
|
|
178
178
|
|
|
179
|
-
|
|
180
179
|
### category\_ids
|
|
181
180
|
|
|
182
181
|
• **category\_ids**: `number`[]
|
|
@@ -184,3 +183,9 @@ ___
|
|
|
184
183
|
The list of IDs of the categories where the badge item is assigned, information about categories can be retrieved with getAchCategories method
|
|
185
184
|
|
|
186
185
|
___
|
|
186
|
+
|
|
187
|
+
### hint\_text
|
|
188
|
+
|
|
189
|
+
• `Optional` **hint\_text**: `string`
|
|
190
|
+
|
|
191
|
+
The T&C text for the missions
|
|
@@ -99,7 +99,7 @@ ___
|
|
|
99
99
|
|
|
100
100
|
• **category\_ids**: `number`[]
|
|
101
101
|
|
|
102
|
-
The list of IDs of the categories where the store item is assigned, information about categories can be
|
|
102
|
+
The list of IDs of the categories where the store item is assigned, information about categories can be retrieved with getStoreCategories method
|
|
103
103
|
|
|
104
104
|
___
|
|
105
105
|
|
|
@@ -108,3 +108,11 @@ ___
|
|
|
108
108
|
• `Optional` **pool**: `number`
|
|
109
109
|
|
|
110
110
|
Number of items in the pool avaliable for the purchase.
|
|
111
|
+
|
|
112
|
+
___
|
|
113
|
+
|
|
114
|
+
### hint\_text
|
|
115
|
+
|
|
116
|
+
• `Optional` **hint\_text**: `string`
|
|
117
|
+
|
|
118
|
+
The T&C text for the store item
|
package/package.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LeaderBoardDetailsT, LeaderBoardUserT, LeaderBoardsRewardsT } from "src/WSAPI/WSAPITypes";
|
|
2
|
+
import { LeaderBoardDetails } from "./LeaderBoardDetails";
|
|
3
|
+
import { LeaderBoardPeriodType } from "./LeaderBoardPeriodType";
|
|
4
|
+
import { LeaderBoardPosition } from "./LeaderBoardPosition";
|
|
5
|
+
|
|
6
|
+
const pointsRewardTransform = (reward_points: number[]): LeaderBoardsRewardsT[] => {
|
|
7
|
+
if (reward_points && reward_points.length) {
|
|
8
|
+
return reward_points.map((r, i) => ({ place: i + 1, points: r }));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const getLeaderBoardPlayerTransformed = (user: LeaderBoardPosition, isMe?: boolean): LeaderBoardUserT => {
|
|
15
|
+
if (user) {
|
|
16
|
+
const x: LeaderBoardUserT= {
|
|
17
|
+
public_username: user?.public_username || user.user_alt_name,
|
|
18
|
+
avatar_url: user.avatar_url,
|
|
19
|
+
position: user.position_in_board,
|
|
20
|
+
points: user.points_accumulated,
|
|
21
|
+
is_me: user.is_me,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (isMe) {
|
|
25
|
+
delete x.is_me;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return x;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const getLeaderBoardTransform = (board: LeaderBoardDetails): LeaderBoardDetailsT => {
|
|
35
|
+
if (board) {
|
|
36
|
+
const x: LeaderBoardDetailsT = {
|
|
37
|
+
board_id: board.board_id,
|
|
38
|
+
name: board.board_public_meta.name,
|
|
39
|
+
description: board.board_public_meta.description,
|
|
40
|
+
rules: board.board_public_meta.rules,
|
|
41
|
+
period_type_id: board.period_type_id,
|
|
42
|
+
rewards: pointsRewardTransform(board.reward_points),
|
|
43
|
+
users: board.positions.map(p => getLeaderBoardPlayerTransformed(p)),
|
|
44
|
+
me: getLeaderBoardPlayerTransformed(board.userPosition, true),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return x;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IntUtils } from "src/IntUtils";
|
|
1
2
|
import { ProtocolResponse } from "../Base/ProtocolResponse";
|
|
2
3
|
import { TLevel } from "../WSAPI/WSAPITypes";
|
|
3
4
|
import { Level } from "./Level";
|
|
@@ -19,5 +20,6 @@ export const GetLevelMapResponseTransform = (levels: GetLevelMapResponse): TLeve
|
|
|
19
20
|
visibility_points: parseInt(l.level_public_meta.visibility_points as any),
|
|
20
21
|
required_level_counter_1: l.required_level_counter_1,
|
|
21
22
|
required_level_counter_2: l.required_level_counter_2,
|
|
23
|
+
custom_data: IntUtils.JsonOrText(l.level_public_meta?.custom_data),
|
|
22
24
|
})));
|
|
23
25
|
}
|
|
@@ -37,11 +37,12 @@ export interface UserAchievement {
|
|
|
37
37
|
|
|
38
38
|
export const UserAchievementTransform = (items: UserAchievement[]): TMissionOrBadge[] => {
|
|
39
39
|
|
|
40
|
-
return items.filter( r => r.ach_id >= 1).map( r =>
|
|
41
|
-
{
|
|
40
|
+
return items.filter( r => r.ach_id >= 1).map( r => {
|
|
41
|
+
const x: TMissionOrBadge = {
|
|
42
42
|
id: r.ach_id,
|
|
43
43
|
name: r.ach_public_meta.name,
|
|
44
44
|
description: r.ach_public_meta.description,
|
|
45
|
+
hint_text: r.ach_public_meta.hint_text,
|
|
45
46
|
unlock_mission_description: r.ach_public_meta.unlock_mission_description,
|
|
46
47
|
image: r.ach_public_meta.image_url,
|
|
47
48
|
is_completed: r.isCompleted,
|
|
@@ -80,6 +81,7 @@ export const UserAchievementTransform = (items: UserAchievement[]): TMissionOrBa
|
|
|
80
81
|
})),
|
|
81
82
|
category_ids: r.ach_categories ?? [],
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
+
return x;
|
|
85
|
+
});
|
|
84
86
|
}
|
|
85
87
|
|
package/src/OCache.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NodeCache } from "./NodeCache";
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
export enum ECacheContext {
|
|
5
4
|
Translations,
|
|
6
5
|
LabelInfo,
|
|
@@ -27,7 +26,7 @@ export class OCache {
|
|
|
27
26
|
|
|
28
27
|
this.init(cacheContext);
|
|
29
28
|
|
|
30
|
-
return this.cache[cacheContext].get(key);
|
|
29
|
+
return deepClone(this.cache[cacheContext].get(key));
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
public static set(oKey: any, o: any, cacheContext: ECacheContext, ttlSeconds: number = 60) {
|
|
@@ -36,7 +35,7 @@ export class OCache {
|
|
|
36
35
|
|
|
37
36
|
this.init(cacheContext);
|
|
38
37
|
|
|
39
|
-
this.cache[cacheContext].set(key, o, ttlSeconds);
|
|
38
|
+
this.cache[cacheContext].set(key, deepClone(o), ttlSeconds);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
public static async use<T>(oKey: any, cacheContext: ECacheContext, f: () => Promise<T>, ttlSeconds: number = 60) {
|
|
@@ -60,3 +59,11 @@ export class OCache {
|
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
}
|
|
62
|
+
|
|
63
|
+
const deepClone = (o: any) => {
|
|
64
|
+
if (o) {
|
|
65
|
+
return JSON.parse(JSON.stringify(o));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return o;
|
|
69
|
+
}
|
package/src/SmarticoAPI.ts
CHANGED
|
@@ -17,7 +17,8 @@ import { GetTournamentInfoRequest, GetTournamentInfoResponse, GetTournamentsRequ
|
|
|
17
17
|
import { GetLeaderBoardsRequest, GetLeaderBoardsResponse, LeaderBoardDetails, LeaderBoardPeriodType } from "./Leaderboard";
|
|
18
18
|
import { GetLevelMapResponse, GetLevelMapResponseTransform } from "./Level";
|
|
19
19
|
import { WSAPI } from "./WSAPI/WSAPI";
|
|
20
|
-
import { TInboxMessage, TInboxMessageBody, TLevel, TMiniGameTemplate, TMissionOrBadge, TStoreCategory, TAchCategory, TStoreItem, TTournament, TTournamentDetailed } from "./WSAPI/WSAPITypes";
|
|
20
|
+
import { TInboxMessage, TInboxMessageBody, TLevel, TMiniGameTemplate, TMissionOrBadge, TStoreCategory, TAchCategory, TStoreItem, TTournament, TTournamentDetailed, LeaderBoardDetailsT } from "./WSAPI/WSAPITypes";
|
|
21
|
+
import { getLeaderBoardTransform } from "./Leaderboard/LeaderBoards";
|
|
21
22
|
|
|
22
23
|
const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
|
|
23
24
|
const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
|
|
@@ -414,10 +415,13 @@ class SmarticoAPI {
|
|
|
414
415
|
|
|
415
416
|
const message = this.buildMessage<GetAchievementMapRequest, GetAchievementMapResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
|
|
416
417
|
const response = await this.send<GetAchievementMapResponse>(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
// we need to clone response to avoid changing original object,for cases when its called together with badgesGetItems (e.g. in Promise.all)
|
|
419
|
+
const responseClone = { ...response };
|
|
420
|
+
|
|
421
|
+
if (responseClone.achievements) {
|
|
422
|
+
responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Mission);
|
|
419
423
|
}
|
|
420
|
-
return
|
|
424
|
+
return responseClone;
|
|
421
425
|
}
|
|
422
426
|
|
|
423
427
|
public async missionsGetItemsT(user_ext_id: string): Promise<TMissionOrBadge[]> {
|
|
@@ -438,10 +442,13 @@ class SmarticoAPI {
|
|
|
438
442
|
|
|
439
443
|
const message = this.buildMessage<GetAchievementMapRequest, GetAchievementMapResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
|
|
440
444
|
const response = await this.send<GetAchievementMapResponse>(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
|
|
441
|
-
|
|
442
|
-
|
|
445
|
+
// we need to clone response to avoid changing original object,for cases when its called together with missionsGetItems (e.g. in Promise.all)
|
|
446
|
+
const responseClone = { ...response };
|
|
447
|
+
|
|
448
|
+
if (responseClone.achievements) {
|
|
449
|
+
responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Badge);
|
|
443
450
|
}
|
|
444
|
-
return
|
|
451
|
+
return responseClone;
|
|
445
452
|
}
|
|
446
453
|
|
|
447
454
|
public async badgetsGetItemsT(user_ext_id: string): Promise<TMissionOrBadge[]> {
|
|
@@ -524,6 +531,10 @@ class SmarticoAPI {
|
|
|
524
531
|
|
|
525
532
|
}
|
|
526
533
|
|
|
534
|
+
public async leaderboardsGetT(user_ext_id: string, period_type_id: LeaderBoardPeriodType = LeaderBoardPeriodType.DAILY, prevPeriod: boolean = false): Promise<LeaderBoardDetailsT> {
|
|
535
|
+
return getLeaderBoardTransform(await this.leaderboardGet(user_ext_id, period_type_id, prevPeriod));
|
|
536
|
+
}
|
|
537
|
+
|
|
527
538
|
public async levelsGet(user_ext_id: string): Promise<GetLevelMapResponse> {
|
|
528
539
|
const message = this.buildMessage<any, GetLevelMapResponse>(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
|
|
529
540
|
return await this.send<GetLevelMapResponse>(message, ClassId.GET_LEVEL_MAP_RESPONSE);
|
package/src/Store/StoreItem.ts
CHANGED
|
@@ -25,6 +25,7 @@ export const StoreItemTransform = (items: StoreItem[]): TStoreItem[] => {
|
|
|
25
25
|
limit_message: r.itemPublicMeta.limit_message,
|
|
26
26
|
priority: r.itemPublicMeta.priority,
|
|
27
27
|
related_item_ids: r.itemPublicMeta.related_items,
|
|
28
|
+
hint_text: r.itemPublicMeta.hint_text,
|
|
28
29
|
|
|
29
30
|
type: {
|
|
30
31
|
[StoreItemType.Bonus]: 'bonus',
|
package/src/WSAPI/WSAPI.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { CoreUtils } from "../Core";
|
|
|
3
3
|
import { MiniGamePrizeTypeName, SAWDoSpinResponse, SAWSpinErrorCode, SAWSpinsCountPush } from "../MiniGames";
|
|
4
4
|
import { ECacheContext, OCache } from "../OCache";
|
|
5
5
|
import { SmarticoAPI } from "../SmarticoAPI";
|
|
6
|
-
import { InboxMarkMessageAction, TAchCategory, TBuyStoreItemResult, TGetTranslations, TInboxMessage, TInboxMessageBody, TLevel, TMiniGamePlayResult, TMiniGameTemplate, TMissionOptInResult, TMissionOrBadge, TStoreCategory, TStoreItem, TTournament, TTournamentDetailed, TTournamentRegistrationResult, TUserProfile } from "./WSAPITypes";
|
|
6
|
+
import { InboxMarkMessageAction, LeaderBoardDetailsT, TAchCategory, TBuyStoreItemResult, TGetTranslations, TInboxMessage, TInboxMessageBody, TLevel, TMiniGamePlayResult, TMiniGameTemplate, TMissionOptInResult, TMissionOrBadge, TStoreCategory, TStoreItem, TTournament, TTournamentDetailed, TTournamentRegistrationResult, TUserProfile } from "./WSAPITypes";
|
|
7
|
+
import { LeaderBoardPeriodType } from "src/Leaderboard";
|
|
7
8
|
|
|
8
9
|
/** @hidden */
|
|
9
10
|
const CACHE_DATA_SEC = 30;
|
|
@@ -13,6 +14,12 @@ enum onUpdateContextKey {
|
|
|
13
14
|
Missions = 'missions',
|
|
14
15
|
TournamentList = 'tournamentList',
|
|
15
16
|
InboxMessages = 'inboxMessages',
|
|
17
|
+
Badges = 'badges',
|
|
18
|
+
Levels = 'levels',
|
|
19
|
+
StoreItems = 'storeItems',
|
|
20
|
+
StoreCategories = 'storeCategories',
|
|
21
|
+
AchCategories = 'achCategories',
|
|
22
|
+
LeaderBoards = 'leaderBoards',
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
|
|
@@ -47,7 +54,7 @@ export class WSAPI {
|
|
|
47
54
|
|
|
48
55
|
/** Returns all the levels available the current user */
|
|
49
56
|
public async getLevels(): Promise<TLevel[]> {
|
|
50
|
-
return this.api.levelsGetT(null);
|
|
57
|
+
return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(null), CACHE_DATA_SEC);
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
/** Returns all the missions available the current user.
|
|
@@ -66,12 +73,12 @@ export class WSAPI {
|
|
|
66
73
|
|
|
67
74
|
/** Returns all the badges available the current user */
|
|
68
75
|
public async getBadges(): Promise<TMissionOrBadge[]> {
|
|
69
|
-
return this.api.badgetsGetItemsT(null);
|
|
76
|
+
return OCache.use(onUpdateContextKey.Badges, ECacheContext.WSAPI, () => this.api.badgetsGetItemsT(null), CACHE_DATA_SEC);
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
/** Returns all the store items available the current user */
|
|
73
80
|
public async getStoreItems(): Promise<TStoreItem[]> {
|
|
74
|
-
return this.api.storeGetItemsT(null);
|
|
81
|
+
return OCache.use(onUpdateContextKey.StoreItems, ECacheContext.WSAPI, () => this.api.storeGetItemsT(null), CACHE_DATA_SEC);
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
/** Buy the specific shop item by item_id. Returns the err_code.*/
|
|
@@ -88,12 +95,12 @@ export class WSAPI {
|
|
|
88
95
|
|
|
89
96
|
/** Returns store categories */
|
|
90
97
|
public async getStoreCategories(): Promise<TStoreCategory[]> {
|
|
91
|
-
return this.api.storeGetCategoriesT(null);
|
|
98
|
+
return OCache.use(onUpdateContextKey.StoreCategories, ECacheContext.WSAPI, () => this.api.storeGetCategoriesT(null), CACHE_DATA_SEC);
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
/** Returns ach categories */
|
|
95
102
|
public async getAchCategories(): Promise<TAchCategory[]> {
|
|
96
|
-
return this.api.achGetCategoriesT(null);
|
|
103
|
+
return OCache.use(onUpdateContextKey.AchCategories, ECacheContext.WSAPI, () => this.api.achGetCategoriesT(null), CACHE_DATA_SEC);
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
/** Returns the list of mini-games available for user
|
|
@@ -168,6 +175,13 @@ export class WSAPI {
|
|
|
168
175
|
return o;
|
|
169
176
|
}
|
|
170
177
|
|
|
178
|
+
/** Returns the leaderboard for the current type (default is Daily). If getPreviousPeriod is passed as true, a leaderboard for the previous period for the current type will be returned.
|
|
179
|
+
For example, if the type is Weekly and getPreviousPeriod is true, a leaderboard for the previous week will be returned.
|
|
180
|
+
*/
|
|
181
|
+
public async getLeaderBoard(periodType: LeaderBoardPeriodType, getPreviousPeriod?: boolean): Promise<LeaderBoardDetailsT> {
|
|
182
|
+
return OCache.use(onUpdateContextKey.LeaderBoards, ECacheContext.WSAPI, () => this.api.leaderboardsGetT(null, periodType, getPreviousPeriod), CACHE_DATA_SEC);
|
|
183
|
+
}
|
|
184
|
+
|
|
171
185
|
/** Returns inbox messages based on the provided parameters. "From" and "to" indicate the range of messages to be fetched.
|
|
172
186
|
* The maximum number of messages per request is limited to 20. An indicator "onlyFavorite" can be passed to get only messages marked as favorites.
|
|
173
187
|
* You can leave this params empty and by default it will return list of messages ranging from 0 to 20.
|
package/src/WSAPI/WSAPITypes.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { BuyStoreItemErrorCode } from "../Store";
|
|
|
2
2
|
import { MiniGamePrizeTypeName, SAWBuyInTypeName, SAWGameTypeName, SAWSpinErrorCode } from "../MiniGames";
|
|
3
3
|
import { TournamentRegistrationError, TournamentRegistrationStatusName, TournamentRegistrationTypeName } from "../Tournaments";
|
|
4
4
|
import { AchCategory } from "../Missions";
|
|
5
|
+
import { LeaderBoardPeriodType } from "src/Leaderboard";
|
|
5
6
|
|
|
6
7
|
type TRibbon = 'sale' | 'hot' | 'new' | 'vip' | string
|
|
7
8
|
|
|
@@ -166,6 +167,9 @@ export interface TLevel {
|
|
|
166
167
|
*
|
|
167
168
|
*/
|
|
168
169
|
required_level_counter_2: number,
|
|
170
|
+
|
|
171
|
+
/** The custom data of the mini-game defined by operator. Can be a JSON object, string or number */
|
|
172
|
+
custom_data: string;
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
/**
|
|
@@ -369,6 +373,8 @@ export interface TStoreItem {
|
|
|
369
373
|
category_ids: number[];
|
|
370
374
|
/** Number of items in the pool avaliable for the purchase.*/
|
|
371
375
|
pool?: number;
|
|
376
|
+
/** The T&C text for the store item */
|
|
377
|
+
hint_text?: string;
|
|
372
378
|
}
|
|
373
379
|
|
|
374
380
|
/**
|
|
@@ -440,6 +446,9 @@ export interface TMissionOrBadge {
|
|
|
440
446
|
|
|
441
447
|
/** The list of IDs of the categories where the badge item is assigned, information about categories can be retrieved with getAchCategories method */
|
|
442
448
|
category_ids: number[];
|
|
449
|
+
|
|
450
|
+
/** The T&C text for the missions */
|
|
451
|
+
hint_text?: string;
|
|
443
452
|
}
|
|
444
453
|
|
|
445
454
|
export interface AchRelatedGame {
|
|
@@ -545,4 +554,42 @@ export interface InboxMarkMessageAction {
|
|
|
545
554
|
err_code: number;
|
|
546
555
|
/** Optional error message */
|
|
547
556
|
err_message: string;
|
|
548
|
-
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export interface LeaderBoardDetailsT {
|
|
560
|
+
/** ID of the leaderboard */
|
|
561
|
+
board_id: number;
|
|
562
|
+
/** Name of the leaderboard */
|
|
563
|
+
name: string;
|
|
564
|
+
/** Description of the leaderboard */
|
|
565
|
+
description: string;
|
|
566
|
+
/** Rules of the leaderboard */
|
|
567
|
+
rules: string;
|
|
568
|
+
/** Leaderboard period type ID */
|
|
569
|
+
period_type_id: LeaderBoardPeriodType;
|
|
570
|
+
/** Leaderboard points rewards */
|
|
571
|
+
rewards: LeaderBoardsRewardsT[];
|
|
572
|
+
/** Leaderboard users */
|
|
573
|
+
users: LeaderBoardUserT[];
|
|
574
|
+
/** Info about current user in leaderboard */
|
|
575
|
+
me?: LeaderBoardUserT;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export interface LeaderBoardsRewardsT {
|
|
579
|
+
place: number;
|
|
580
|
+
points: number;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export interface LeaderBoardUserT {
|
|
584
|
+
/** The username of the participant */
|
|
585
|
+
public_username: string;
|
|
586
|
+
/** The URL to the avatar of the participant */
|
|
587
|
+
avatar_url: string;
|
|
588
|
+
/** The position of the participant in the leaderboard */
|
|
589
|
+
position: number;
|
|
590
|
+
/** The points of the participant in the leaderboard */
|
|
591
|
+
points: number;
|
|
592
|
+
/** The indicator if the participant is current user */
|
|
593
|
+
is_me: boolean;
|
|
594
|
+
}
|
|
595
|
+
|