@smartico/public-api 0.0.3 → 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.
Files changed (96) hide show
  1. package/.nvmrc +1 -1
  2. package/dist/Base/ClassId.d.ts +21 -0
  3. package/dist/Base/ProtocolMessage.d.ts +5 -0
  4. package/dist/Base/ProtocolRequest.d.ts +6 -0
  5. package/dist/Base/ProtocolResponse.d.ts +5 -0
  6. package/dist/ErrorCodes.d.ts +12 -0
  7. package/dist/GResponse.d.ts +9 -0
  8. package/dist/ILogger.d.ts +7 -0
  9. package/dist/IntUtils.d.ts +8 -0
  10. package/dist/MiniGames/SAWAcknowledgeType.d.ts +5 -0
  11. package/dist/MiniGames/SAWBuyInType.d.ts +10 -0
  12. package/dist/MiniGames/SAWDoSpinRequest.d.ts +5 -0
  13. package/dist/MiniGames/SAWDoSpinResponse.d.ts +15 -0
  14. package/dist/MiniGames/SAWGameType.d.ts +10 -0
  15. package/dist/MiniGames/SAWGetTemplatesRequest.d.ts +3 -0
  16. package/dist/MiniGames/SAWGetTemplatesResponse.d.ts +5 -0
  17. package/dist/MiniGames/SAWPrize.d.ts +11 -0
  18. package/dist/MiniGames/SAWPrizeType.d.ts +8 -0
  19. package/dist/MiniGames/SAWPrizeUI.d.ts +13 -0
  20. package/dist/MiniGames/SAWTemplate.d.ts +26 -0
  21. package/dist/MiniGames/SAWTemplateUI.d.ts +31 -0
  22. package/dist/MiniGames/SAWWinSoundType.d.ts +12 -0
  23. package/dist/MiniGames/index.d.ts +14 -0
  24. package/dist/SmarticoAPI.d.ts +23 -0
  25. package/dist/SmarticoPublicAPI.d.ts +23 -0
  26. package/dist/index.d.ts +5 -2
  27. package/dist/index.js +322 -241
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.modern.mjs +232 -231
  30. package/dist/index.modern.mjs.map +1 -1
  31. package/dist/service/index.d.ts +3 -2
  32. package/dist/service/types/ErrorCodes.d.ts +13 -0
  33. package/dist/service/types/GRequest.d.ts +16 -0
  34. package/dist/service/types/GResponse.d.ts +10 -0
  35. package/dist/service/types/Game/GameAttemptType.d.ts +6 -0
  36. package/{src/service/types/Game/GameCanPlayType.ts → dist/service/types/Game/GameCanPlayType.d.ts} +10 -11
  37. package/dist/service/types/Game/GameExternalStatus.d.ts +6 -0
  38. package/{src/service/types/Game/GameInfo.ts → dist/service/types/Game/GameInfo.d.ts} +9 -11
  39. package/{src/service/types/Game/GamePick.ts → dist/service/types/Game/GamePick.d.ts} +90 -104
  40. package/dist/service/types/Game/GameUtil.d.ts +7 -0
  41. package/{src/service/types/SmarticoProto/GetTranslationsRequest.ts → dist/service/types/SmarticoProto/GetTranslationsRequest.d.ts} +7 -9
  42. package/{src/service/types/SmarticoProto/GetTranslationsResponse.ts → dist/service/types/SmarticoProto/GetTranslationsResponse.d.ts} +7 -8
  43. package/dist/service/types/SmarticoProto/ProtocolMessage.d.ts +5 -0
  44. package/dist/service/types/SmarticoProto/ProtocolRequest.d.ts +6 -0
  45. package/dist/service/types/SmarticoProto/ProtocolResponse.d.ts +5 -0
  46. package/{src/service/types/SmarticoProto/PublicLabelInfo.ts → dist/service/types/SmarticoProto/PublicLabelInfo.d.ts} +34 -39
  47. package/{src/service/types/SmarticoProto/PublicProperties.ts → dist/service/types/SmarticoProto/PublicProperties.d.ts} +11 -11
  48. package/{src/service/types/SmarticoProto/ResponseIdentify.ts → dist/service/types/SmarticoProto/ResponseIdentify.d.ts} +12 -16
  49. package/dist/service/types/SmarticoProto/SAW/SAWAcknowledgeType.d.ts +5 -0
  50. package/{src/service/types/SmarticoProto/SAW/SAWBuyInType.ts → dist/service/types/SmarticoProto/SAW/SAWBuyInType.d.ts} +5 -5
  51. package/{src/service/types/SmarticoProto/SAW/SAWDoSpinRequest.ts → dist/service/types/SmarticoProto/SAW/SAWDoSpinRequest.d.ts} +5 -8
  52. package/dist/service/types/SmarticoProto/SAW/SAWDoSpinResponse.d.ts +15 -0
  53. package/dist/service/types/SmarticoProto/SAW/SAWGameType.d.ts +10 -0
  54. package/{src/service/types/SmarticoProto/SAW/SAWGetTemplatesRequest.ts → dist/service/types/SmarticoProto/SAW/SAWGetTemplatesRequest.d.ts} +3 -5
  55. package/{src/service/types/SmarticoProto/SAW/SAWGetTemplatesResponse.ts → dist/service/types/SmarticoProto/SAW/SAWGetTemplatesResponse.d.ts} +5 -8
  56. package/dist/service/types/SmarticoProto/SAW/SAWPrize.d.ts +11 -0
  57. package/dist/service/types/SmarticoProto/SAW/SAWPrizeType.d.ts +8 -0
  58. package/dist/service/types/SmarticoProto/SAW/SAWPrizeUI.d.ts +13 -0
  59. package/dist/service/types/SmarticoProto/SAW/SAWTemplate.d.ts +21 -0
  60. package/dist/service/types/SmarticoProto/SAW/SAWTemplateUI.d.ts +31 -0
  61. package/dist/service/types/SmarticoProto/SAW/SAWWinSoundType.d.ts +12 -0
  62. package/{src/service/types/SmarticoProto/TranslationArea.ts → dist/service/types/SmarticoProto/TranslationArea.d.ts} +9 -11
  63. package/{src/service/types/User/UserInfo.ts → dist/service/types/User/UserInfo.d.ts} +10 -12
  64. package/package.json +2 -1
  65. package/src/Base/ClassId.ts +26 -0
  66. package/src/{service/types/SmarticoProto → Base}/ProtocolMessage.ts +0 -0
  67. package/src/{service/types/SmarticoProto → Base}/ProtocolRequest.ts +0 -0
  68. package/src/{service/types/SmarticoProto → Base}/ProtocolResponse.ts +0 -0
  69. package/src/{service/types/ErrorCodes.ts → ErrorCodes.ts} +1 -3
  70. package/src/{service/types/GResponse.ts → GResponse.ts} +0 -0
  71. package/src/ILogger.ts +11 -0
  72. package/src/IntUtils.ts +39 -0
  73. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWAcknowledgeType.ts +0 -0
  74. package/src/MiniGames/SAWBuyInType.ts +11 -0
  75. package/src/MiniGames/SAWDoSpinRequest.ts +8 -0
  76. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWDoSpinResponse.ts +1 -1
  77. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWGameType.ts +2 -2
  78. package/src/MiniGames/SAWGetTemplatesRequest.ts +5 -0
  79. package/src/MiniGames/SAWGetTemplatesResponse.ts +8 -0
  80. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrize.ts +0 -0
  81. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrizeType.ts +0 -0
  82. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrizeUI.ts +0 -0
  83. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWTemplate.ts +5 -0
  84. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWTemplateUI.ts +0 -0
  85. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWWinSoundType.ts +0 -0
  86. package/src/MiniGames/index.ts +30 -0
  87. package/src/SmarticoAPI.ts +177 -0
  88. package/src/index.ts +11 -2
  89. package/tsconfig.json +17 -0
  90. package/src/service/index.ts +0 -12
  91. package/src/service/types/GRequest.ts +0 -18
  92. package/src/service/types/Game/GameAttemptType.ts +0 -8
  93. package/src/service/types/Game/GameExternalStatus.ts +0 -7
  94. package/src/service/types/Game/GameUtil.ts +0 -30
  95. package/src/util/Util.ts +0 -306
  96. 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
- export interface SAWDoSpinRequest extends ProtocolRequest {
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
+ }
@@ -0,0 +1,10 @@
1
+ export declare enum SAWGameType {
2
+ SpinAWheel = 1,
3
+ ScratchCard = 2,
4
+ SportPick = 3
5
+ }
6
+ export declare const SAWGameTypeName: {
7
+ 1: string;
8
+ 2: string;
9
+ 3: string;
10
+ };
@@ -1,5 +1,3 @@
1
- import { ProtocolRequest } from "../ProtocolRequest";
2
-
3
- export interface SAWGetTemplatesRequest extends ProtocolRequest {
4
-
5
- }
1
+ import { ProtocolRequest } from "../ProtocolRequest";
2
+ export interface SAWGetTemplatesRequest extends ProtocolRequest {
3
+ }
@@ -1,8 +1,5 @@
1
- import { ProtocolResponse } from "../ProtocolResponse";
2
- import { SAWTemplate } from "./SAWTemplate";
3
-
4
-
5
- export interface SAWGetTemplatesResponse extends ProtocolResponse {
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,8 @@
1
+ export declare enum SAWPrizeType {
2
+ NO_PRIZE = 1,
3
+ POINTS = 2,
4
+ BONUS = 3,
5
+ MANUAL = 4,
6
+ SPIN = 5,
7
+ JACKPOT = 6
8
+ }
@@ -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
+ }
@@ -0,0 +1,12 @@
1
+ export declare enum SAWWinSoundType {
2
+ Disappointing = 1,
3
+ Positive = 2,
4
+ HighlyPositive = 3,
5
+ NoSound = 4
6
+ }
7
+ export declare const SAWWinSoundFiles: {
8
+ 4: any;
9
+ 1: string;
10
+ 2: string;
11
+ 3: string;
12
+ };
@@ -1,11 +1,9 @@
1
- enum TranslationArea {
2
-
3
- Casino = 1,
4
- Gamification = 2,
5
- Trading = 3,
6
- Archived = 4,
7
- Affiliation = 5,
8
- RetentionGames = 6
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
- ext_user_id: string;
4
- int_user_id: number;
5
- public_username: string;
6
- avatar_url: string;
7
- last_wallet_sync_time?: Date;
8
- ach_points_balance?: number;
9
- pubic_username_set?: boolean;
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",
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
+ }
@@ -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 = SAWSpinErrorCode | ErrorCodesGame;
17
+ export type ErrorCodes = ErrorCodesGame;
File without changes
package/src/ILogger.ts ADDED
@@ -0,0 +1,11 @@
1
+
2
+
3
+ export interface ILogger {
4
+
5
+ debug(...any: any[]): void;
6
+ error(...any: any[]): void;
7
+ info(...any: any[]): void;
8
+ warn(...any: any[]): void;
9
+ always(...any: any[]): void;
10
+
11
+ }
@@ -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 }
@@ -0,0 +1,11 @@
1
+ export enum SAWBuyInType {
2
+ Free = 1,
3
+ Points = 2,
4
+ Spins = 3
5
+ }
6
+
7
+ export const SAWBuyInTypeName = {
8
+ [SAWBuyInType.Free]: "free",
9
+ [SAWBuyInType.Points]: "points",
10
+ [SAWBuyInType.Spins]: "spins",
11
+ }
@@ -0,0 +1,8 @@
1
+ import { ProtocolRequest } from "./../Base/ProtocolRequest";
2
+
3
+
4
+ export interface SAWDoSpinRequest extends ProtocolRequest {
5
+
6
+ request_id: string; // guid
7
+ saw_template_id: number;
8
+ }
@@ -1,4 +1,4 @@
1
- import { ProtocolResponse } from "../ProtocolResponse";
1
+ import { ProtocolResponse } from "./../Base/ProtocolResponse";
2
2
 
3
3
 
4
4
  export enum SAWSpinErrorCode {
@@ -1,11 +1,11 @@
1
1
  export enum SAWGameType {
2
2
  SpinAWheel = 1,
3
3
  ScratchCard = 2,
4
- SportPick = 3
4
+ MatchX = 3
5
5
  }
6
6
 
7
7
  export const SAWGameTypeName = {
8
8
  [SAWGameType.SpinAWheel]: "wheel",
9
9
  [SAWGameType.ScratchCard]: "scratch",
10
- [SAWGameType.SportPick]: "sportpick",
10
+ [SAWGameType.MatchX]: "matchx",
11
11
  }
@@ -0,0 +1,5 @@
1
+ import { ProtocolRequest } from "./../Base/ProtocolRequest";
2
+
3
+ export interface SAWGetTemplatesRequest extends ProtocolRequest {
4
+
5
+ }
@@ -0,0 +1,8 @@
1
+ import { ProtocolResponse } from "./../Base/ProtocolResponse";
2
+ import { SAWTemplate } from "./SAWTemplate";
3
+
4
+
5
+ export interface SAWGetTemplatesResponse extends ProtocolResponse {
6
+
7
+ templates: SAWTemplate[];
8
+ }
@@ -26,4 +26,9 @@ export interface SAWTemplate {
26
26
  maxSpinsCount: number;
27
27
  maxSpinsPediodMs: number;
28
28
 
29
+ saw_skin_key: string;
30
+ saw_skin_ui_definition: {
31
+ skin_folder: string;
32
+ skin_css: string;
33
+ };
29
34
  }
@@ -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
- export { Util } from './util/Util';
2
- export * from './service'
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
+ }