@smartico/public-api 0.0.2 → 0.0.4
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/.nvmrc +1 -1
- package/dist/Base/ClassId.d.ts +21 -0
- package/dist/Base/ProtocolMessage.d.ts +5 -0
- package/dist/Base/ProtocolRequest.d.ts +6 -0
- package/dist/Base/ProtocolResponse.d.ts +5 -0
- package/dist/ErrorCodes.d.ts +12 -0
- package/dist/GResponse.d.ts +9 -0
- package/dist/ILogger.d.ts +7 -0
- package/dist/IntUtils.d.ts +8 -0
- package/dist/MiniGames/SAWAcknowledgeType.d.ts +5 -0
- package/dist/MiniGames/SAWBuyInType.d.ts +10 -0
- package/dist/MiniGames/SAWDoSpinRequest.d.ts +5 -0
- package/dist/MiniGames/SAWDoSpinResponse.d.ts +15 -0
- package/dist/MiniGames/SAWGameType.d.ts +10 -0
- package/dist/MiniGames/SAWGetTemplatesRequest.d.ts +3 -0
- package/dist/MiniGames/SAWGetTemplatesResponse.d.ts +5 -0
- package/dist/MiniGames/SAWPrize.d.ts +11 -0
- package/dist/MiniGames/SAWPrizeType.d.ts +8 -0
- package/dist/MiniGames/SAWPrizeUI.d.ts +13 -0
- package/dist/MiniGames/SAWTemplate.d.ts +26 -0
- package/dist/MiniGames/SAWTemplateUI.d.ts +31 -0
- package/dist/MiniGames/SAWWinSoundType.d.ts +12 -0
- package/dist/MiniGames/index.d.ts +14 -0
- package/dist/SmarticoAPI.d.ts +23 -0
- package/dist/SmarticoPublicAPI.d.ts +23 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +322 -241
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +232 -231
- package/dist/index.modern.mjs.map +1 -1
- package/dist/service/index.d.ts +3 -2
- package/dist/service/types/ErrorCodes.d.ts +13 -0
- package/dist/service/types/GRequest.d.ts +16 -0
- package/dist/service/types/GResponse.d.ts +10 -0
- package/dist/service/types/Game/GameAttemptType.d.ts +6 -0
- package/{src/service/types/Game/GameCanPlayType.ts → dist/service/types/Game/GameCanPlayType.d.ts} +10 -11
- package/dist/service/types/Game/GameExternalStatus.d.ts +6 -0
- package/{src/service/types/Game/GameInfo.ts → dist/service/types/Game/GameInfo.d.ts} +9 -11
- package/{src/service/types/Game/GamePick.ts → dist/service/types/Game/GamePick.d.ts} +90 -104
- package/dist/service/types/Game/GameUtil.d.ts +7 -0
- package/{src/service/types/SmarticoProto/GetTranslationsRequest.ts → dist/service/types/SmarticoProto/GetTranslationsRequest.d.ts} +7 -9
- package/{src/service/types/SmarticoProto/GetTranslationsResponse.ts → dist/service/types/SmarticoProto/GetTranslationsResponse.d.ts} +7 -8
- package/dist/service/types/SmarticoProto/ProtocolMessage.d.ts +5 -0
- package/dist/service/types/SmarticoProto/ProtocolRequest.d.ts +6 -0
- package/dist/service/types/SmarticoProto/ProtocolResponse.d.ts +5 -0
- package/{src/service/types/SmarticoProto/PublicLabelInfo.ts → dist/service/types/SmarticoProto/PublicLabelInfo.d.ts} +34 -39
- package/{src/service/types/SmarticoProto/PublicProperties.ts → dist/service/types/SmarticoProto/PublicProperties.d.ts} +11 -11
- package/{src/service/types/SmarticoProto/ResponseIdentify.ts → dist/service/types/SmarticoProto/ResponseIdentify.d.ts} +12 -16
- package/dist/service/types/SmarticoProto/SAW/SAWAcknowledgeType.d.ts +5 -0
- package/{src/service/types/SmarticoProto/SAW/SAWBuyInType.ts → dist/service/types/SmarticoProto/SAW/SAWBuyInType.d.ts} +5 -5
- package/{src/service/types/SmarticoProto/SAW/SAWDoSpinRequest.ts → dist/service/types/SmarticoProto/SAW/SAWDoSpinRequest.d.ts} +5 -8
- package/dist/service/types/SmarticoProto/SAW/SAWDoSpinResponse.d.ts +15 -0
- package/dist/service/types/SmarticoProto/SAW/SAWGameType.d.ts +10 -0
- package/{src/service/types/SmarticoProto/SAW/SAWGetTemplatesRequest.ts → dist/service/types/SmarticoProto/SAW/SAWGetTemplatesRequest.d.ts} +3 -5
- package/{src/service/types/SmarticoProto/SAW/SAWGetTemplatesResponse.ts → dist/service/types/SmarticoProto/SAW/SAWGetTemplatesResponse.d.ts} +5 -8
- package/dist/service/types/SmarticoProto/SAW/SAWPrize.d.ts +11 -0
- package/dist/service/types/SmarticoProto/SAW/SAWPrizeType.d.ts +8 -0
- package/dist/service/types/SmarticoProto/SAW/SAWPrizeUI.d.ts +13 -0
- package/dist/service/types/SmarticoProto/SAW/SAWTemplate.d.ts +21 -0
- package/dist/service/types/SmarticoProto/SAW/SAWTemplateUI.d.ts +31 -0
- package/dist/service/types/SmarticoProto/SAW/SAWWinSoundType.d.ts +12 -0
- package/{src/service/types/SmarticoProto/TranslationArea.ts → dist/service/types/SmarticoProto/TranslationArea.d.ts} +9 -11
- package/{src/service/types/User/UserInfo.ts → dist/service/types/User/UserInfo.d.ts} +10 -12
- package/package.json +2 -1
- package/src/Base/ClassId.ts +26 -0
- package/src/{service/types/SmarticoProto → Base}/ProtocolMessage.ts +0 -0
- package/src/{service/types/SmarticoProto → Base}/ProtocolRequest.ts +0 -0
- package/src/{service/types/SmarticoProto → Base}/ProtocolResponse.ts +0 -0
- package/src/{service/types/ErrorCodes.ts → ErrorCodes.ts} +1 -3
- package/src/{service/types/GResponse.ts → GResponse.ts} +0 -0
- package/src/ILogger.ts +11 -0
- package/src/IntUtils.ts +39 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWAcknowledgeType.ts +0 -0
- package/src/MiniGames/SAWBuyInType.ts +11 -0
- package/src/MiniGames/SAWDoSpinRequest.ts +8 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWDoSpinResponse.ts +1 -1
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWGameType.ts +2 -2
- package/src/MiniGames/SAWGetTemplatesRequest.ts +5 -0
- package/src/MiniGames/SAWGetTemplatesResponse.ts +8 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrize.ts +0 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrizeType.ts +0 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrizeUI.ts +0 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWTemplate.ts +5 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWTemplateUI.ts +0 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWWinSoundType.ts +0 -0
- package/src/MiniGames/index.ts +30 -0
- package/src/SmarticoAPI.ts +177 -0
- package/src/index.ts +11 -2
- package/tsconfig.json +17 -0
- package/src/service/index.ts +0 -12
- package/src/service/types/GRequest.ts +0 -18
- package/src/service/types/Game/GameAttemptType.ts +0 -8
- package/src/service/types/Game/GameExternalStatus.ts +0 -7
- package/src/service/types/Game/GameUtil.ts +0 -30
- package/src/util/Util.ts +0 -306
- package/test/package.json +0 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export enum SAWBuyInType {
|
|
2
|
-
Free = 1,
|
|
3
|
-
Points = 2,
|
|
4
|
-
Spins = 3
|
|
5
|
-
}
|
|
1
|
+
export declare enum SAWBuyInType {
|
|
2
|
+
Free = 1,
|
|
3
|
+
Points = 2,
|
|
4
|
+
Spins = 3
|
|
5
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ProtocolRequest } from "./ProtocolRequest";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
request_id: string; // guid
|
|
7
|
-
saw_template_id: number;
|
|
8
|
-
}
|
|
1
|
+
import { ProtocolRequest } from "./ProtocolRequest";
|
|
2
|
+
export interface SAWDoSpinRequest extends ProtocolRequest {
|
|
3
|
+
request_id: string;
|
|
4
|
+
saw_template_id: number;
|
|
5
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProtocolResponse } from "../ProtocolResponse";
|
|
2
|
+
export declare enum SAWSpinErrorCode {
|
|
3
|
+
SAW_OK = 0,
|
|
4
|
+
SAW_NO_SPINS = 40001,
|
|
5
|
+
SAW_PRIZE_POOL_EMPTY = 40002,
|
|
6
|
+
SAW_NOT_ENOUGH_POINTS = 40003,
|
|
7
|
+
SAW_FAILED_MAX_SPINS_REACHED = 40004
|
|
8
|
+
}
|
|
9
|
+
export interface SAWDoSpinResponse extends ProtocolResponse {
|
|
10
|
+
errCode: SAWSpinErrorCode;
|
|
11
|
+
errMsg?: string;
|
|
12
|
+
request_id: string;
|
|
13
|
+
saw_prize_id: number;
|
|
14
|
+
first_spin_in_period: number;
|
|
15
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ProtocolResponse } from "../ProtocolResponse";
|
|
2
|
-
import { SAWTemplate } from "./SAWTemplate";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
templates: SAWTemplate[];
|
|
8
|
-
}
|
|
1
|
+
import { ProtocolResponse } from "../ProtocolResponse";
|
|
2
|
+
import { SAWTemplate } from "./SAWTemplate";
|
|
3
|
+
export interface SAWGetTemplatesResponse extends ProtocolResponse {
|
|
4
|
+
templates: SAWTemplate[];
|
|
5
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SAWPrizeType } from "./SAWPrizeType";
|
|
2
|
+
import { SAWPrizeUI } from "./SAWPrizeUI";
|
|
3
|
+
export interface SAWPrize {
|
|
4
|
+
saw_prize_id: number;
|
|
5
|
+
saw_prize_ui_definition: SAWPrizeUI;
|
|
6
|
+
prize_value?: number;
|
|
7
|
+
prize_type_id: SAWPrizeType;
|
|
8
|
+
place_from?: number;
|
|
9
|
+
place_to?: number;
|
|
10
|
+
sawUniqueWinId?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SAWAcknowledgeType } from "./SAWAcknowledgeType";
|
|
2
|
+
import { SAWWinSoundType } from "./SAWWinSoundType";
|
|
3
|
+
export interface SAWPrizeUI {
|
|
4
|
+
position?: number;
|
|
5
|
+
name: string;
|
|
6
|
+
aknowledge_message: string;
|
|
7
|
+
sectors: number[];
|
|
8
|
+
acknowledge_type: SAWAcknowledgeType;
|
|
9
|
+
acknowledge_dp?: string;
|
|
10
|
+
font_size?: number;
|
|
11
|
+
sound_type: SAWWinSoundType;
|
|
12
|
+
icon?: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SAWBuyInType } from "./SAWBuyInType";
|
|
2
|
+
import { SAWGameType } from "./SAWGameType";
|
|
3
|
+
import { SAWPrize } from "./SAWPrize";
|
|
4
|
+
import { SAWTemplateUI } from "./SAWTemplateUI";
|
|
5
|
+
export interface SAWTemplate {
|
|
6
|
+
saw_template_id: number;
|
|
7
|
+
saw_game_type_id: SAWGameType;
|
|
8
|
+
saw_template_ui_definition: SAWTemplateUI;
|
|
9
|
+
saw_buyin_type_id: SAWBuyInType;
|
|
10
|
+
buyin_cost_points?: number;
|
|
11
|
+
visibile_when_can_spin: boolean;
|
|
12
|
+
spin_count?: number;
|
|
13
|
+
prizes: SAWPrize[];
|
|
14
|
+
is_visible: boolean;
|
|
15
|
+
jackpot_add_on_attempt: number;
|
|
16
|
+
jackpot_current: number;
|
|
17
|
+
jackpot_guaranteed: number;
|
|
18
|
+
maxActiveSpinsAllowed: number;
|
|
19
|
+
maxSpinsCount: number;
|
|
20
|
+
maxSpinsPediodMs: number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare enum AskForUsername {
|
|
2
|
+
NOASK = "no-ask",
|
|
3
|
+
ONSUMBIT = "on-submit"
|
|
4
|
+
}
|
|
5
|
+
export interface SAWTemplateUI {
|
|
6
|
+
skin: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
over_limit_message?: string;
|
|
10
|
+
no_attempts_message?: string;
|
|
11
|
+
thumbnail?: string;
|
|
12
|
+
sectors_count: number;
|
|
13
|
+
priority: number;
|
|
14
|
+
flow_builder_only: boolean;
|
|
15
|
+
background_image?: string;
|
|
16
|
+
background_image_mobile?: string;
|
|
17
|
+
background_sound?: string;
|
|
18
|
+
scratch_logo?: string;
|
|
19
|
+
scratch_cover?: string;
|
|
20
|
+
scratch_bg_desktop?: string;
|
|
21
|
+
scratch_bg_mobile?: string;
|
|
22
|
+
scratch_cursor?: string;
|
|
23
|
+
custom_css?: string;
|
|
24
|
+
custom_skin_folder?: string;
|
|
25
|
+
jackpot_symbol?: string;
|
|
26
|
+
promo_image?: string;
|
|
27
|
+
promo_text?: string;
|
|
28
|
+
ask_for_username?: AskForUsername;
|
|
29
|
+
show_prize_board?: boolean;
|
|
30
|
+
max_spins_period_ms?: number;
|
|
31
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
enum TranslationArea {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export {TranslationArea};
|
|
1
|
+
declare enum TranslationArea {
|
|
2
|
+
Casino = 1,
|
|
3
|
+
Gamification = 2,
|
|
4
|
+
Trading = 3,
|
|
5
|
+
Archived = 4,
|
|
6
|
+
Affiliation = 5,
|
|
7
|
+
RetentionGames = 6
|
|
8
|
+
}
|
|
9
|
+
export { TranslationArea };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
interface UserInfo {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { UserInfo }
|
|
1
|
+
interface UserInfo {
|
|
2
|
+
ext_user_id: string;
|
|
3
|
+
int_user_id: number;
|
|
4
|
+
public_username: string;
|
|
5
|
+
avatar_url: string;
|
|
6
|
+
last_wallet_sync_time?: Date;
|
|
7
|
+
ach_points_balance?: number;
|
|
8
|
+
pubic_username_set?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export { UserInfo };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartico/public-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Smartico public API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"md5-typescript": "^1.0.5",
|
|
18
|
+
"superagent": "^8.0.6",
|
|
18
19
|
"typescript-map": "^0.1.0"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export enum ClassId {
|
|
2
|
+
GET_LABEL_INFO = 3,
|
|
3
|
+
GET_LABEL_INFO_RESPONSE = 4,
|
|
4
|
+
IDENTIFY = 5,
|
|
5
|
+
IDENTIFY_RESPONSE = 6,
|
|
6
|
+
EVENT = 9,
|
|
7
|
+
EVENT_RESPONSE = 10,
|
|
8
|
+
|
|
9
|
+
GET_TRANSLATIONS_REQUEST = 13,
|
|
10
|
+
GET_TRANSLATIONS_RESPONSE = 14,
|
|
11
|
+
|
|
12
|
+
CHANGE_USERNAME = 159,
|
|
13
|
+
CHANGE_USERNAME_RESPONSE = 160,
|
|
14
|
+
|
|
15
|
+
SAW_GET_SPINS_REQUEST = 700,
|
|
16
|
+
SAW_GET_SPINS_RESPONSE = 701,
|
|
17
|
+
SAW_DO_SPIN_REQUEST = 702,
|
|
18
|
+
SAW_DO_SPIN_RESPONSE = 703,
|
|
19
|
+
SAW_AKNOWLEDGE_REQUEST = 704,
|
|
20
|
+
SAW_AKNOWLEDGE_RESPONSE = 705,
|
|
21
|
+
|
|
22
|
+
SAW_SPINS_COUNT_PUSH = 706,
|
|
23
|
+
SAW_SHOW_SPIN_PUSH = 707,
|
|
24
|
+
|
|
25
|
+
UNSUPPORTED_COMMAND = 99999.
|
|
26
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { SAWSpinErrorCode } from "./SmarticoProto/SAW/SAWDoSpinResponse";
|
|
2
|
-
|
|
3
1
|
export const ErrorCodes_FatalStartingRange = 100000;
|
|
4
2
|
|
|
5
3
|
export enum ErrorCodesGame {
|
|
@@ -16,4 +14,4 @@ export enum ErrorCodesGame {
|
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
|
|
19
|
-
export type ErrorCodes =
|
|
17
|
+
export type ErrorCodes = ErrorCodesGame;
|
|
File without changes
|
package/src/ILogger.ts
ADDED
package/src/IntUtils.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class IntUtils {
|
|
5
|
+
|
|
6
|
+
public static uuid(): string {
|
|
7
|
+
let a: any;
|
|
8
|
+
let b: any;
|
|
9
|
+
for (b = a = ""; a++ < 36; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : "-") {}
|
|
10
|
+
return b;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public static isNotNull(val: any): boolean {
|
|
14
|
+
return typeof val !== "undefined" && val !== null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static isNotEmpty(val: string): boolean {
|
|
18
|
+
return typeof val !== "undefined" && val !== null && val.length > 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static replaceAll(value: string, regex: string, replacement: string | number): string {
|
|
22
|
+
if (IntUtils.isNotNull(value)) {
|
|
23
|
+
return value.replace(new RegExp(IntUtils.escapeRegExp(regex), "g"), replacement?.toString());
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static escapeRegExp(v: string): string {
|
|
29
|
+
if (IntUtils.isNotEmpty(v)) {
|
|
30
|
+
return v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
31
|
+
}
|
|
32
|
+
return v;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export { IntUtils }
|
|
File without changes
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export enum SAWGameType {
|
|
2
2
|
SpinAWheel = 1,
|
|
3
3
|
ScratchCard = 2,
|
|
4
|
-
|
|
4
|
+
MatchX = 3
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export const SAWGameTypeName = {
|
|
8
8
|
[SAWGameType.SpinAWheel]: "wheel",
|
|
9
9
|
[SAWGameType.ScratchCard]: "scratch",
|
|
10
|
-
[SAWGameType.
|
|
10
|
+
[SAWGameType.MatchX]: "matchx",
|
|
11
11
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SAWAcknowledgeType } from "./SAWAcknowledgeType";
|
|
2
|
+
import { SAWBuyInType, SAWBuyInTypeName } from "./SAWBuyInType";
|
|
3
|
+
import { SAWDoSpinRequest } from "./SAWDoSpinRequest";
|
|
4
|
+
import { SAWDoSpinResponse, SAWSpinErrorCode } from "./SAWDoSpinResponse";
|
|
5
|
+
import { SAWGameType, SAWGameTypeName } from "./SAWGameType";
|
|
6
|
+
import { SAWGetTemplatesRequest } from "./SAWGetTemplatesRequest";
|
|
7
|
+
import { SAWGetTemplatesResponse } from "./SAWGetTemplatesResponse";
|
|
8
|
+
import { SAWPrize } from "./SAWPrize";
|
|
9
|
+
import { SAWPrizeType } from "./SAWPrizeType";
|
|
10
|
+
import { SAWPrizeUI } from "./SAWPrizeUI";
|
|
11
|
+
import { SAWTemplate } from "./SAWTemplate";
|
|
12
|
+
import { SAWTemplateUI } from "./SAWTemplateUI";
|
|
13
|
+
import { SAWWinSoundType, SAWWinSoundFiles } from "./SAWWinSoundType";
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
SAWAcknowledgeType,
|
|
17
|
+
SAWBuyInType, SAWBuyInTypeName,
|
|
18
|
+
SAWDoSpinRequest,
|
|
19
|
+
SAWDoSpinResponse,
|
|
20
|
+
SAWSpinErrorCode,
|
|
21
|
+
SAWGameType, SAWGameTypeName,
|
|
22
|
+
SAWGetTemplatesRequest,
|
|
23
|
+
SAWGetTemplatesResponse,
|
|
24
|
+
SAWPrize,
|
|
25
|
+
SAWPrizeType,
|
|
26
|
+
SAWPrizeUI,
|
|
27
|
+
SAWTemplate,
|
|
28
|
+
SAWTemplateUI,
|
|
29
|
+
SAWWinSoundType, SAWWinSoundFiles
|
|
30
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as superagent from 'superagent';
|
|
2
|
+
import { ClassId } from "./Base/ClassId";
|
|
3
|
+
import { ProtocolRequest } from './Base/ProtocolRequest';
|
|
4
|
+
import { ProtocolResponse } from './Base/ProtocolResponse';
|
|
5
|
+
import { SAWGetTemplatesResponse } from './MiniGames/SAWGetTemplatesResponse';
|
|
6
|
+
import { SAWGetTemplatesRequest } from './MiniGames/SAWGetTemplatesRequest';
|
|
7
|
+
import { SAWTemplate } from './MiniGames/SAWTemplate';
|
|
8
|
+
import { IntUtils } from './IntUtils';
|
|
9
|
+
import { ILogger } from './ILogger';
|
|
10
|
+
import { SAWBuyInType, SAWBuyInTypeName, SAWGameType, SAWGameTypeName } from './MiniGames';
|
|
11
|
+
|
|
12
|
+
const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
|
|
13
|
+
|
|
14
|
+
interface IOptions {
|
|
15
|
+
logger?: ILogger;
|
|
16
|
+
logCIDs?: ClassId[];
|
|
17
|
+
logHTTPTiming?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SmarticoAPI {
|
|
22
|
+
|
|
23
|
+
private publicUrl: string;
|
|
24
|
+
private logger: ILogger;
|
|
25
|
+
private logCIDs: ClassId[];
|
|
26
|
+
private logHTTPTiming: boolean;
|
|
27
|
+
|
|
28
|
+
public constructor(private label_api_key: string, private brand_api_key: string, options: IOptions = {}) {
|
|
29
|
+
|
|
30
|
+
this.logger = options.logger || (console as any);
|
|
31
|
+
|
|
32
|
+
if (this.logger.always === undefined) {
|
|
33
|
+
this.logger.always = this.logger.info;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.logCIDs = options.logCIDs || [];
|
|
37
|
+
this.logHTTPTiming = options.logHTTPTiming || false;
|
|
38
|
+
|
|
39
|
+
let ENV_ID = this.label_api_key.length === 38 ? label_api_key.substring(37, 38) : '';
|
|
40
|
+
|
|
41
|
+
if (ENV_ID === '1' || ENV_ID === '2') {
|
|
42
|
+
ENV_ID = ''
|
|
43
|
+
}
|
|
44
|
+
label_api_key = label_api_key.substring(0, 36);
|
|
45
|
+
|
|
46
|
+
this.publicUrl = PUBLIC_API_URL.replace('{ENV_ID}', ENV_ID);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private async send<T>(message: any, expectCID?: ClassId): Promise<T> {
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if (this.logCIDs.includes(message.cid)) {
|
|
53
|
+
this.logger.info('REQ', message)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
let result: any;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const timeStart = new Date().getTime();
|
|
61
|
+
const res = await superagent.post(this.publicUrl).send(message);
|
|
62
|
+
const timeEnd = new Date().getTime();
|
|
63
|
+
|
|
64
|
+
if (this.logHTTPTiming) {
|
|
65
|
+
this.logger.always('HTTP time, ms:' + (timeEnd - timeStart))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
result = JSON.parse(res.text);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
this.logger.error(`Failed to make request to smartico channel. ${e.message}`, { url: this.publicUrl, request: message, error: e.message });
|
|
71
|
+
throw(new Error(`Failed to make request to smartico channel. ${e.message}`));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (this.logCIDs.includes(message.cid)) {
|
|
75
|
+
this.logger.info('RES', result)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (expectCID) {
|
|
79
|
+
if (Array.isArray(result)) {
|
|
80
|
+
for (const str of result as string[]) {
|
|
81
|
+
const obj: ProtocolResponse = JSON.parse(str);
|
|
82
|
+
if (this.logCIDs.includes(obj.cid)) {
|
|
83
|
+
this.logger.info('RES', result)
|
|
84
|
+
}
|
|
85
|
+
if (obj.cid === expectCID) {
|
|
86
|
+
return obj as any;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
this.logger.error(`Cant find proper response in array, expected CID ${expectCID}`, { request: message, response: result });
|
|
90
|
+
} else {
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (Array.isArray(result)) {
|
|
95
|
+
if (result.length === 1) {
|
|
96
|
+
const obj = JSON.parse(result[0]);
|
|
97
|
+
if (this.logCIDs.includes(obj.cid)) {
|
|
98
|
+
this.logger.info('RES', result)
|
|
99
|
+
}
|
|
100
|
+
return obj;
|
|
101
|
+
} else {
|
|
102
|
+
this.logger.error('Expected one response, but got array', { request: message, response: result });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private buildMessage<TRequest,TResponse>(user_ext_id: string, cid: ClassId, payload: Partial<TRequest> = {}): TResponse {
|
|
110
|
+
|
|
111
|
+
const message: ProtocolRequest = {
|
|
112
|
+
api_key: this.label_api_key,
|
|
113
|
+
brand_key: this.brand_api_key,
|
|
114
|
+
ext_user_id: user_ext_id,
|
|
115
|
+
cid,
|
|
116
|
+
uuid: IntUtils.uuid(),
|
|
117
|
+
ts: new Date().getTime(),
|
|
118
|
+
...payload
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return message as any
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public async miniGamesGetTemplates(user_ext_id: string): Promise<SAWGetTemplatesResponse> {
|
|
125
|
+
|
|
126
|
+
const message = this.buildMessage<SAWGetTemplatesResponse, SAWGetTemplatesRequest>(user_ext_id, ClassId.SAW_GET_SPINS_REQUEST);
|
|
127
|
+
|
|
128
|
+
const response = await this.send<SAWGetTemplatesResponse>(message);
|
|
129
|
+
|
|
130
|
+
if (response && response.templates) {
|
|
131
|
+
response.templates.forEach(t => {
|
|
132
|
+
|
|
133
|
+
if (t.jackpot_current) {
|
|
134
|
+
t.saw_template_ui_definition.name = IntUtils.replaceAll(t.saw_template_ui_definition.name, '{{jackpot}}', t.jackpot_current);
|
|
135
|
+
t.saw_template_ui_definition.description = IntUtils.replaceAll(t.saw_template_ui_definition.description, '{{jackpot}}', t.jackpot_current);
|
|
136
|
+
t.saw_template_ui_definition.promo_text = IntUtils.replaceAll(t.saw_template_ui_definition.promo_text, '{{jackpot}}', t.jackpot_current);
|
|
137
|
+
t.prizes.forEach(p => {
|
|
138
|
+
p.saw_prize_ui_definition.name = IntUtils.replaceAll(p.saw_prize_ui_definition.name, '{{jackpot}}', t.jackpot_current);
|
|
139
|
+
p.saw_prize_ui_definition.aknowledge_message = IntUtils.replaceAll(p.saw_prize_ui_definition.aknowledge_message, '{{jackpot}}', t.jackpot_current);
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return response;
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public miniGamesFormatTemplatesForWidget(templates: SAWTemplate[], pointsBalance: number): any[] {
|
|
150
|
+
|
|
151
|
+
return templates.filter( r => r.saw_template_id >= 1).map( r => (
|
|
152
|
+
{
|
|
153
|
+
id: r.saw_template_id,
|
|
154
|
+
name: r.saw_template_ui_definition.name,
|
|
155
|
+
// description: r.saw_template_ui_definition.description,
|
|
156
|
+
game_type: SAWGameTypeName[r.saw_game_type_id] || 'unknown',
|
|
157
|
+
buyin_type: SAWBuyInTypeName[r.saw_buyin_type_id] || 'unknown',
|
|
158
|
+
jackpot: r.jackpot_current,
|
|
159
|
+
spin_count: r.spin_count,
|
|
160
|
+
buyin_cost_points: r.buyin_cost_points,
|
|
161
|
+
can_play: (
|
|
162
|
+
r.saw_buyin_type_id === SAWBuyInType.Free
|
|
163
|
+
|| (r.saw_buyin_type_id === SAWBuyInType.Points && r.buyin_cost_points <= pointsBalance)
|
|
164
|
+
|| (r.saw_buyin_type_id === SAWBuyInType.Spins && r.spin_count > 0)
|
|
165
|
+
),
|
|
166
|
+
icon:
|
|
167
|
+
r.saw_skin_ui_definition?.skin_folder
|
|
168
|
+
? r.saw_skin_ui_definition?.skin_folder + '/ico.png'
|
|
169
|
+
: `https://libs.smartico.ai/gf/images/saw/${r.saw_skin_key}/ico.png`
|
|
170
|
+
}
|
|
171
|
+
));
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { SmarticoAPI }
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ClassId } from './Base/ClassId'
|
|
2
|
+
import { ILogger } from './ILogger';
|
|
3
|
+
import { SmarticoAPI } from './SmarticoAPI'
|
|
4
|
+
|
|
5
|
+
export * from './MiniGames';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
SmarticoAPI,
|
|
9
|
+
ClassId,
|
|
10
|
+
ILogger
|
|
11
|
+
}
|