@smartico/public-api 0.0.3 → 0.0.5
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/README.md +23 -44
- 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/Core/GetLabelInfoRequest.d.ts +3 -0
- package/dist/Core/GetLabelInfoResponse.d.ts +7 -0
- package/dist/Core/GetTranslationsRequest.d.ts +7 -0
- package/dist/Core/GetTranslationsResponse.d.ts +7 -0
- package/dist/Core/PublicLabelSettings.d.ts +28 -0
- package/dist/Core/PublicProperties.d.ts +11 -0
- package/dist/Core/ResponseIdentify.d.ts +12 -0
- package/dist/Core/TranslationArea.d.ts +9 -0
- package/dist/Core/index.d.ts +8 -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/SAWAskForUsername.d.ts +4 -0
- package/dist/MiniGames/SAWBuyInType.d.ts +10 -0
- package/dist/MiniGames/SAWDoSpinRequest.d.ts +5 -0
- package/dist/MiniGames/SAWDoSpinResponse.d.ts +9 -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/SAWSpinErrorCode.d.ts +7 -0
- package/dist/MiniGames/SAWTemplate.d.ts +26 -0
- package/dist/MiniGames/SAWTemplateUI.d.ts +28 -0
- package/dist/MiniGames/SAWUtils.d.ts +5 -0
- package/dist/MiniGames/SAWWinSoundType.d.ts +12 -0
- package/dist/MiniGames/index.d.ts +17 -0
- package/dist/OCache.d.ts +11 -0
- package/dist/SmarticoAPI.d.ts +35 -0
- package/dist/SmarticoPublicAPI.d.ts +23 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +576 -219
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +417 -218
- 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/dist/service/types/SmarticoProto/GetTranslationsResponse.d.ts +7 -0
- 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/dist/service/types/SmarticoProto/PublicLabelInfo.d.ts +34 -0
- package/dist/service/types/SmarticoProto/PublicProperties.d.ts +11 -0
- 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/{src/service/types/SmarticoProto/SAW/SAWDoSpinResponse.ts → dist/service/types/SmarticoProto/SAW/SAWDoSpinResponse.d.ts} +15 -18
- 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/{src/service/types/SmarticoProto/SAW/SAWTemplateUI.ts → dist/service/types/SmarticoProto/SAW/SAWTemplateUI.d.ts} +31 -33
- package/dist/service/types/SmarticoProto/SAW/SAWWinSoundType.d.ts +12 -0
- package/dist/service/types/SmarticoProto/TranslationArea.d.ts +9 -0
- package/{src/service/types/User/UserInfo.ts → dist/service/types/User/UserInfo.d.ts} +10 -12
- package/package.json +10 -3
- 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/Core/GetLabelInfoRequest.ts +5 -0
- package/src/Core/GetLabelInfoResponse.ts +6 -0
- package/src/Core/GetTranslationsRequest.ts +10 -0
- package/src/{service/types/SmarticoProto → Core}/GetTranslationsResponse.ts +1 -1
- package/src/{service/types/SmarticoProto/PublicLabelInfo.ts → Core/PublicLabelSettings.ts} +1 -6
- package/src/{service/types/SmarticoProto → Core}/PublicProperties.ts +0 -0
- package/src/Core/ResponseIdentify.ts +14 -0
- package/src/{service/types/SmarticoProto → Core}/TranslationArea.ts +1 -1
- package/src/Core/index.ts +18 -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/SAWAskForUsername.ts +5 -0
- package/src/MiniGames/SAWBuyInType.ts +11 -0
- package/src/MiniGames/SAWDoSpinRequest.ts +8 -0
- package/src/MiniGames/SAWDoSpinResponse.ts +11 -0
- 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/MiniGames/SAWSpinErrorCode.ts +8 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWTemplate.ts +5 -0
- package/src/MiniGames/SAWTemplateUI.ts +31 -0
- package/src/MiniGames/SAWUtils.ts +31 -0
- package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWWinSoundType.ts +0 -0
- package/src/MiniGames/index.ts +35 -0
- package/src/OCache.ts +54 -0
- package/src/SmarticoAPI.ts +296 -0
- package/src/index.ts +12 -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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SAWBuyInType } from "./SAWBuyInType";
|
|
2
|
+
import { SAWTemplate } from "./SAWTemplate";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SAWUtils {
|
|
6
|
+
|
|
7
|
+
public static canPlay = (t: SAWTemplate, pointsBalance: number): boolean => {
|
|
8
|
+
if (t === null || t === undefined) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
switch (t.saw_buyin_type_id) {
|
|
13
|
+
case SAWBuyInType.Free: {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
case SAWBuyInType.Spins: {
|
|
17
|
+
return t.spin_count !== null && t.spin_count > 0
|
|
18
|
+
}
|
|
19
|
+
case SAWBuyInType.Points: {
|
|
20
|
+
return t.buyin_cost_points <= pointsBalance;
|
|
21
|
+
}
|
|
22
|
+
default: {
|
|
23
|
+
console.error("MiniGamesUtils.canPlay: Unknwon SAW buyin type " + t.saw_buyin_type_id);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { SAWUtils }
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SAWUtils } from "./SAWUtils";
|
|
2
|
+
import { SAWAcknowledgeType } from "./SAWAcknowledgeType";
|
|
3
|
+
import { SAWAskForUsername } from "./SAWAskForUsername";
|
|
4
|
+
import { SAWBuyInType, SAWBuyInTypeName } from "./SAWBuyInType";
|
|
5
|
+
import { SAWDoSpinRequest } from "./SAWDoSpinRequest";
|
|
6
|
+
import { SAWDoSpinResponse } from "./SAWDoSpinResponse";
|
|
7
|
+
import { SAWGameType, SAWGameTypeName } from "./SAWGameType";
|
|
8
|
+
import { SAWGetTemplatesRequest } from "./SAWGetTemplatesRequest";
|
|
9
|
+
import { SAWGetTemplatesResponse } from "./SAWGetTemplatesResponse";
|
|
10
|
+
import { SAWPrize } from "./SAWPrize";
|
|
11
|
+
import { SAWPrizeType } from "./SAWPrizeType";
|
|
12
|
+
import { SAWPrizeUI } from "./SAWPrizeUI";
|
|
13
|
+
import { SAWSpinErrorCode } from "./SAWSpinErrorCode";
|
|
14
|
+
import { SAWTemplate } from "./SAWTemplate";
|
|
15
|
+
import { SAWTemplateUI } from "./SAWTemplateUI";
|
|
16
|
+
import { SAWWinSoundType, SAWWinSoundFiles } from "./SAWWinSoundType";
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
SAWUtils,
|
|
20
|
+
SAWAcknowledgeType,
|
|
21
|
+
SAWBuyInType, SAWBuyInTypeName,
|
|
22
|
+
SAWDoSpinRequest,
|
|
23
|
+
SAWDoSpinResponse,
|
|
24
|
+
SAWGameType, SAWGameTypeName,
|
|
25
|
+
SAWGetTemplatesRequest,
|
|
26
|
+
SAWGetTemplatesResponse,
|
|
27
|
+
SAWPrize,
|
|
28
|
+
SAWPrizeType,
|
|
29
|
+
SAWPrizeUI,
|
|
30
|
+
SAWTemplate,
|
|
31
|
+
SAWTemplateUI,
|
|
32
|
+
SAWWinSoundType, SAWWinSoundFiles,
|
|
33
|
+
SAWAskForUsername,
|
|
34
|
+
SAWSpinErrorCode
|
|
35
|
+
}
|
package/src/OCache.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import NodeCache from 'node-cache';
|
|
2
|
+
|
|
3
|
+
export enum ECacheContext {
|
|
4
|
+
Translations,
|
|
5
|
+
LabelInfo
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const WITH_REF_CACHE = [
|
|
9
|
+
ECacheContext.Translations
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export class OCache {
|
|
13
|
+
|
|
14
|
+
private static cache: { [key: string] : NodeCache } = {}
|
|
15
|
+
|
|
16
|
+
public static get<T>(oKey: any, cacheContext: ECacheContext): T | undefined {
|
|
17
|
+
|
|
18
|
+
const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
|
|
19
|
+
|
|
20
|
+
if (this.cache[cacheContext] === undefined) {
|
|
21
|
+
this.cache[cacheContext] = new NodeCache( { useClones: !WITH_REF_CACHE.includes(cacheContext) } );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return this.cache[cacheContext].get(key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static set(oKey: any, o: any, cacheContext: ECacheContext, ttlSeconds: number = 60) {
|
|
28
|
+
|
|
29
|
+
const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
|
|
30
|
+
|
|
31
|
+
this.cache[cacheContext].set(key, o, ttlSeconds);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static async use<T>(oKey: any, cacheContext: ECacheContext, f: () => Promise<T>, ttlSeconds: number = 60) {
|
|
35
|
+
if (ttlSeconds <= 0) {
|
|
36
|
+
return await f();
|
|
37
|
+
} else {
|
|
38
|
+
let o: T = OCache.get(oKey, cacheContext);
|
|
39
|
+
|
|
40
|
+
if (o === undefined) {
|
|
41
|
+
o = await f();
|
|
42
|
+
OCache.set(oKey, o, cacheContext, ttlSeconds);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return o;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public static async clear(cacheContext: ECacheContext) {
|
|
50
|
+
if (this.cache[cacheContext]) {
|
|
51
|
+
this.cache[cacheContext].flushAll();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
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, SAWDoSpinRequest, SAWDoSpinResponse, SAWGameType, SAWGameTypeName, SAWSpinErrorCode, SAWUtils } from './MiniGames';
|
|
11
|
+
import { ECacheContext, OCache } from './OCache';
|
|
12
|
+
import { GetTranslationsRequest, GetTranslationsResponse, ResponseIdentify, TranslationArea } from './Core';
|
|
13
|
+
import { GetLabelInfoResponse } from './Core/GetLabelInfoResponse';
|
|
14
|
+
import { GetLabelInfoRequest } from './Core/GetLabelInfoRequest';
|
|
15
|
+
|
|
16
|
+
const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
|
|
17
|
+
const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
|
|
18
|
+
|
|
19
|
+
interface IOptions {
|
|
20
|
+
logger?: ILogger;
|
|
21
|
+
logCIDs?: ClassId[];
|
|
22
|
+
logHTTPTiming?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SmarticoAPI {
|
|
27
|
+
|
|
28
|
+
private publicUrl: string;
|
|
29
|
+
private avatarDomain: string;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
private logger: ILogger;
|
|
33
|
+
private logCIDs: ClassId[];
|
|
34
|
+
private logHTTPTiming: boolean;
|
|
35
|
+
|
|
36
|
+
public constructor(private label_api_key: string, private brand_api_key: string, options: IOptions = {}) {
|
|
37
|
+
|
|
38
|
+
this.logger = options.logger || (console as any);
|
|
39
|
+
|
|
40
|
+
if (this.logger.always === undefined) {
|
|
41
|
+
this.logger.always = this.logger.info;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.logCIDs = options.logCIDs || [];
|
|
45
|
+
this.logHTTPTiming = options.logHTTPTiming || false;
|
|
46
|
+
|
|
47
|
+
let ENV_ID = this.label_api_key.length === 38 ? label_api_key.substring(37, 38) : '';
|
|
48
|
+
|
|
49
|
+
if (ENV_ID === '1' || ENV_ID === '2') {
|
|
50
|
+
ENV_ID = ''
|
|
51
|
+
}
|
|
52
|
+
label_api_key = label_api_key.substring(0, 36);
|
|
53
|
+
|
|
54
|
+
this.publicUrl = PUBLIC_API_URL.replace('{ENV_ID}', ENV_ID);
|
|
55
|
+
this.avatarDomain = AVATAR_DOMAIN.replace('{ENV_ID}', ENV_ID);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async send<T>(message: any, expectCID?: ClassId): Promise<T> {
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if (this.logCIDs.includes(message.cid)) {
|
|
62
|
+
this.logger.info('REQ', message)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
let result: any;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const timeStart = new Date().getTime();
|
|
70
|
+
const res = await superagent.post(this.publicUrl).send(message);
|
|
71
|
+
// const res = await superagent.post('http://channel01.int.smartico.ai:81/services/public').send(message);
|
|
72
|
+
const timeEnd = new Date().getTime();
|
|
73
|
+
|
|
74
|
+
if (this.logHTTPTiming) {
|
|
75
|
+
this.logger.always('HTTP time, ms:' + (timeEnd - timeStart))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
result = JSON.parse(res.text);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
this.logger.error(`Failed to make request to smartico channel. ${e.message}`, { url: this.publicUrl, request: message, error: e.message });
|
|
81
|
+
throw(new Error(`Failed to make request to smartico channel. ${e.message}`));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.logCIDs.includes(message.cid)) {
|
|
85
|
+
this.logger.info('RES', result)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (expectCID) {
|
|
89
|
+
if (Array.isArray(result)) {
|
|
90
|
+
for (const str of result as string[]) {
|
|
91
|
+
const obj: ProtocolResponse = JSON.parse(str);
|
|
92
|
+
if (this.logCIDs.includes(obj.cid)) {
|
|
93
|
+
this.logger.info('RES', result)
|
|
94
|
+
}
|
|
95
|
+
if (obj.cid === expectCID) {
|
|
96
|
+
return obj as any;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.logger.error(`Cant find proper response in array, expected CID ${expectCID}`, { request: message, response: result });
|
|
100
|
+
} else {
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
if (Array.isArray(result)) {
|
|
105
|
+
if (result.length === 1) {
|
|
106
|
+
const obj = JSON.parse(result[0]);
|
|
107
|
+
if (this.logCIDs.includes(obj.cid)) {
|
|
108
|
+
this.logger.info('RES', result)
|
|
109
|
+
}
|
|
110
|
+
return obj;
|
|
111
|
+
} else {
|
|
112
|
+
this.logger.error('Expected one response, but got array', { request: message, response: result });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private buildMessage<TRequest,TResponse>(user_ext_id: string, cid: ClassId, payload: Partial<TRequest> = {}): TResponse {
|
|
120
|
+
|
|
121
|
+
const message: ProtocolRequest = {
|
|
122
|
+
api_key: this.label_api_key,
|
|
123
|
+
brand_key: this.brand_api_key,
|
|
124
|
+
ext_user_id: user_ext_id,
|
|
125
|
+
cid,
|
|
126
|
+
uuid: IntUtils.uuid(),
|
|
127
|
+
ts: new Date().getTime(),
|
|
128
|
+
...payload
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (message.ext_user_id === undefined || message.ext_user_id === null) {
|
|
132
|
+
delete message.ext_user_id;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return message as any
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public async coreReportCustomEvent(user_ext_id: string, eventType: string, payload: any = {}): Promise<any> {
|
|
139
|
+
const eventMessage = this.buildMessage<any, any>(user_ext_id, ClassId.EVENT, {
|
|
140
|
+
eventType,
|
|
141
|
+
payload
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const eventResponse = await this.send<any>(eventMessage, ClassId.EVENT_RESPONSE);
|
|
145
|
+
return eventResponse;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public async coreGetTranslations(user_ext_id: string, lang_code: string, areas: TranslationArea[], cacheSec: number = 60): Promise<GetTranslationsResponse> {
|
|
149
|
+
|
|
150
|
+
const response = await OCache.use<GetTranslationsResponse>(`${lang_code}-${this.label_api_key}-${this.brand_api_key}`, ECacheContext.Translations, async () => {
|
|
151
|
+
|
|
152
|
+
const tsBaseRQ = this.buildMessage<GetTranslationsRequest, GetTranslationsResponse>(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
|
|
153
|
+
lang_code: "EN",
|
|
154
|
+
hash_code: 0,
|
|
155
|
+
areas
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const trBase = await this.send<GetTranslationsResponse>(tsBaseRQ);
|
|
159
|
+
|
|
160
|
+
if (lang_code !== "EN") {
|
|
161
|
+
const trUserRQ = this.buildMessage<GetTranslationsRequest, GetTranslationsResponse>(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
|
|
162
|
+
lang_code,
|
|
163
|
+
hash_code: 0,
|
|
164
|
+
areas
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const trUser = await this.send<GetTranslationsResponse>(trUserRQ);
|
|
168
|
+
|
|
169
|
+
Object.keys(trUser.translations).forEach( k => {
|
|
170
|
+
trBase.translations[k] = trUser.translations[k];
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return trBase;
|
|
175
|
+
|
|
176
|
+
}, cacheSec );
|
|
177
|
+
|
|
178
|
+
return response;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public async coreIdentifyLabel(user_ext_id: string, cacheSec: number = 60): Promise<GetLabelInfoResponse> {
|
|
182
|
+
|
|
183
|
+
return OCache.use<GetLabelInfoResponse>(`${this.label_api_key} - ${this.brand_api_key}`, ECacheContext.LabelInfo, async () => {
|
|
184
|
+
|
|
185
|
+
const message = this.buildMessage<GetLabelInfoResponse, GetLabelInfoRequest>(user_ext_id, ClassId.GET_LABEL_INFO);
|
|
186
|
+
|
|
187
|
+
return this.send<GetLabelInfoResponse>(message, ClassId.GET_LABEL_INFO_RESPONSE)
|
|
188
|
+
|
|
189
|
+
}, cacheSec);
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public async coreIdentifyUser(user_ext_id: string): Promise<ResponseIdentify> {
|
|
194
|
+
|
|
195
|
+
const message = this.buildMessage<any, ResponseIdentify>(user_ext_id, ClassId.IDENTIFY, {
|
|
196
|
+
request_id: IntUtils.uuid() // AA: do we need request_id?
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const r = await this.send<ResponseIdentify>(message, ClassId.IDENTIFY_RESPONSE);
|
|
200
|
+
|
|
201
|
+
if (!(r.avatar_id && r.avatar_id.startsWith('http'))) {
|
|
202
|
+
r.avatar_id = AVATAR_DOMAIN + '/avatar/' + r.avatar_id
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return r;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public async coreChangeUsername(user_ext_id: string, public_username_custom: string): Promise<{ public_username_custom: string }> {
|
|
209
|
+
|
|
210
|
+
const message = this.buildMessage<any, any>(user_ext_id, ClassId.CHANGE_USERNAME, {
|
|
211
|
+
public_username_custom
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return this.send(message, ClassId.CHANGE_USERNAME_RESPONSE);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
public async sawGetTemplates(user_ext_id: string): Promise<SAWGetTemplatesResponse> {
|
|
219
|
+
|
|
220
|
+
const message = this.buildMessage<SAWGetTemplatesResponse, SAWGetTemplatesRequest>(user_ext_id, ClassId.SAW_GET_SPINS_REQUEST);
|
|
221
|
+
|
|
222
|
+
const response = await this.send<SAWGetTemplatesResponse>(message);
|
|
223
|
+
|
|
224
|
+
if (response && response.templates) {
|
|
225
|
+
response.templates.forEach(t => {
|
|
226
|
+
|
|
227
|
+
if (t.jackpot_current) {
|
|
228
|
+
t.saw_template_ui_definition.name = IntUtils.replaceAll(t.saw_template_ui_definition.name, '{{jackpot}}', t.jackpot_current);
|
|
229
|
+
t.saw_template_ui_definition.description = IntUtils.replaceAll(t.saw_template_ui_definition.description, '{{jackpot}}', t.jackpot_current);
|
|
230
|
+
t.saw_template_ui_definition.promo_text = IntUtils.replaceAll(t.saw_template_ui_definition.promo_text, '{{jackpot}}', t.jackpot_current);
|
|
231
|
+
t.prizes.forEach(p => {
|
|
232
|
+
p.saw_prize_ui_definition.name = IntUtils.replaceAll(p.saw_prize_ui_definition.name, '{{jackpot}}', t.jackpot_current);
|
|
233
|
+
p.saw_prize_ui_definition.aknowledge_message = IntUtils.replaceAll(p.saw_prize_ui_definition.aknowledge_message, '{{jackpot}}', t.jackpot_current);
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return response;
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public async sawFormatTemplatesForWidget(templates: SAWTemplate[], pointsBalance: number): Promise<any[]> {
|
|
244
|
+
|
|
245
|
+
return templates.filter( r => r.saw_template_id >= 1).map( r => (
|
|
246
|
+
{
|
|
247
|
+
id: r.saw_template_id,
|
|
248
|
+
name: r.saw_template_ui_definition.name,
|
|
249
|
+
// description: r.saw_template_ui_definition.description,
|
|
250
|
+
game_type: SAWGameTypeName[r.saw_game_type_id] || 'unknown',
|
|
251
|
+
buyin_type: SAWBuyInTypeName[r.saw_buyin_type_id] || 'unknown',
|
|
252
|
+
jackpot: r.jackpot_current,
|
|
253
|
+
spin_count: r.spin_count,
|
|
254
|
+
buyin_cost_points: r.buyin_cost_points,
|
|
255
|
+
can_play: SAWUtils.canPlay(r, pointsBalance),
|
|
256
|
+
icon:
|
|
257
|
+
r.saw_skin_ui_definition?.skin_folder
|
|
258
|
+
? r.saw_skin_ui_definition?.skin_folder + '/ico.png'
|
|
259
|
+
: `https://libs.smartico.ai/gf/images/saw/${r.saw_skin_key}/ico.png`
|
|
260
|
+
}
|
|
261
|
+
));
|
|
262
|
+
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
public async sawSpinRequest(user_ext_id: string, saw_template_id: number, round_id: number): Promise<SAWDoSpinResponse> {
|
|
266
|
+
|
|
267
|
+
const message = this.buildMessage<SAWDoSpinRequest, SAWDoSpinResponse>(user_ext_id, ClassId.SAW_DO_SPIN_REQUEST, {
|
|
268
|
+
saw_template_id,
|
|
269
|
+
request_id: IntUtils.uuid()
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const spinAttemptResponse = await this.send<SAWDoSpinResponse>(message, ClassId.SAW_DO_SPIN_RESPONSE);
|
|
273
|
+
|
|
274
|
+
// to simulate fail
|
|
275
|
+
// response.errCode = SAWSpinErrorCode.SAW_NO_SPINS;
|
|
276
|
+
|
|
277
|
+
const status: string = {
|
|
278
|
+
[SAWSpinErrorCode.SAW_OK]: 'OK',
|
|
279
|
+
[SAWSpinErrorCode.SAW_NO_SPINS]: 'NO SPINS AVAILABLE',
|
|
280
|
+
[SAWSpinErrorCode.SAW_PRIZE_POOL_EMPTY]: 'PRIZE POOL IS EMPTY',
|
|
281
|
+
[SAWSpinErrorCode.SAW_NOT_ENOUGH_POINTS]: 'NOT ENOUGH POINTS',
|
|
282
|
+
[SAWSpinErrorCode.SAW_FAILED_MAX_SPINS_REACHED]: 'MAX SPIN ATTEMPTS REACHED',
|
|
283
|
+
}[spinAttemptResponse.errCode] || 'OTHER';
|
|
284
|
+
|
|
285
|
+
await this.coreReportCustomEvent(user_ext_id, 'minigame_attempt', {
|
|
286
|
+
saw_template_id,
|
|
287
|
+
status,
|
|
288
|
+
round_id,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
return spinAttemptResponse;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { SmarticoAPI }
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ClassId } from './Base/ClassId'
|
|
2
|
+
import { ILogger } from './ILogger';
|
|
3
|
+
import { SmarticoAPI } from './SmarticoAPI'
|
|
4
|
+
|
|
5
|
+
export * from './MiniGames';
|
|
6
|
+
export * from './Core';
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
SmarticoAPI,
|
|
10
|
+
ClassId,
|
|
11
|
+
ILogger
|
|
12
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"noImplicitAny": false,
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"baseUrl": ".",
|
|
11
|
+
"allowJs": true
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src/**/*"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
|
package/src/service/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
interface GBaseRequest {
|
|
3
|
-
customer_id: string;
|
|
4
|
-
ext_user_id: string; // int in the smartico system
|
|
5
|
-
int_user_id: number; // int in the retention games
|
|
6
|
-
smartico_ext_user_id: string; // string in the smartico system, that is referencing to user identification in the partner system
|
|
7
|
-
ext_game_id: number;
|
|
8
|
-
lang: string;
|
|
9
|
-
hash: string;
|
|
10
|
-
zoom?: number;
|
|
11
|
-
label_api_key?: string;
|
|
12
|
-
brand_key?: string;
|
|
13
|
-
bridgeId?: string;
|
|
14
|
-
height?: 'auto' | string;
|
|
15
|
-
theme?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { GBaseRequest }
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { GameInfo } from "./GameInfo";
|
|
2
|
-
import { GamePickRound, GamePickRoundBase } from "./GamePick";
|
|
3
|
-
import { Util } from "../../../util/Util";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class GameUtil {
|
|
7
|
-
|
|
8
|
-
public static getRoundName(round: GamePickRoundBase, gameInfo: GameInfo): string {
|
|
9
|
-
if (gameInfo.sawTemplate.jackpot_current) {
|
|
10
|
-
const t = gameInfo.sawTemplate;
|
|
11
|
-
const jackpotValue = t.jackpot_current + (t.saw_template_ui_definition?.jackpot_symbol ? ' ' + t.saw_template_ui_definition?.jackpot_symbol : '');
|
|
12
|
-
return Util.replaceAll(round.round_name, "{{jackpot}}", jackpotValue);
|
|
13
|
-
} else {
|
|
14
|
-
return round.round_name;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public static getRoundDescription(round: GamePickRound, gameInfo: GameInfo): string {
|
|
19
|
-
if (gameInfo.sawTemplate.jackpot_current) {
|
|
20
|
-
const t = gameInfo.sawTemplate;
|
|
21
|
-
const jackpotValue = t.jackpot_current + (t.saw_template_ui_definition?.jackpot_symbol ? ' ' + t.saw_template_ui_definition?.jackpot_symbol : '');
|
|
22
|
-
return Util.replaceAll(round.round_description, "{{jackpot}}", jackpotValue);
|
|
23
|
-
} else {
|
|
24
|
-
return round.round_description;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export { GameUtil }
|