@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.
Files changed (123) hide show
  1. package/.nvmrc +1 -1
  2. package/README.md +23 -44
  3. package/dist/Base/ClassId.d.ts +21 -0
  4. package/dist/Base/ProtocolMessage.d.ts +5 -0
  5. package/dist/Base/ProtocolRequest.d.ts +6 -0
  6. package/dist/Base/ProtocolResponse.d.ts +5 -0
  7. package/dist/Core/GetLabelInfoRequest.d.ts +3 -0
  8. package/dist/Core/GetLabelInfoResponse.d.ts +7 -0
  9. package/dist/Core/GetTranslationsRequest.d.ts +7 -0
  10. package/dist/Core/GetTranslationsResponse.d.ts +7 -0
  11. package/dist/Core/PublicLabelSettings.d.ts +28 -0
  12. package/dist/Core/PublicProperties.d.ts +11 -0
  13. package/dist/Core/ResponseIdentify.d.ts +12 -0
  14. package/dist/Core/TranslationArea.d.ts +9 -0
  15. package/dist/Core/index.d.ts +8 -0
  16. package/dist/ErrorCodes.d.ts +12 -0
  17. package/dist/GResponse.d.ts +9 -0
  18. package/dist/ILogger.d.ts +7 -0
  19. package/dist/IntUtils.d.ts +8 -0
  20. package/dist/MiniGames/SAWAcknowledgeType.d.ts +5 -0
  21. package/dist/MiniGames/SAWAskForUsername.d.ts +4 -0
  22. package/dist/MiniGames/SAWBuyInType.d.ts +10 -0
  23. package/dist/MiniGames/SAWDoSpinRequest.d.ts +5 -0
  24. package/dist/MiniGames/SAWDoSpinResponse.d.ts +9 -0
  25. package/dist/MiniGames/SAWGameType.d.ts +10 -0
  26. package/dist/MiniGames/SAWGetTemplatesRequest.d.ts +3 -0
  27. package/dist/MiniGames/SAWGetTemplatesResponse.d.ts +5 -0
  28. package/dist/MiniGames/SAWPrize.d.ts +11 -0
  29. package/dist/MiniGames/SAWPrizeType.d.ts +8 -0
  30. package/dist/MiniGames/SAWPrizeUI.d.ts +13 -0
  31. package/dist/MiniGames/SAWSpinErrorCode.d.ts +7 -0
  32. package/dist/MiniGames/SAWTemplate.d.ts +26 -0
  33. package/dist/MiniGames/SAWTemplateUI.d.ts +28 -0
  34. package/dist/MiniGames/SAWUtils.d.ts +5 -0
  35. package/dist/MiniGames/SAWWinSoundType.d.ts +12 -0
  36. package/dist/MiniGames/index.d.ts +17 -0
  37. package/dist/OCache.d.ts +11 -0
  38. package/dist/SmarticoAPI.d.ts +35 -0
  39. package/dist/SmarticoPublicAPI.d.ts +23 -0
  40. package/dist/index.d.ts +6 -2
  41. package/dist/index.js +576 -219
  42. package/dist/index.js.map +1 -1
  43. package/dist/index.modern.mjs +417 -218
  44. package/dist/index.modern.mjs.map +1 -1
  45. package/dist/service/index.d.ts +3 -2
  46. package/dist/service/types/ErrorCodes.d.ts +13 -0
  47. package/dist/service/types/GRequest.d.ts +16 -0
  48. package/dist/service/types/GResponse.d.ts +10 -0
  49. package/dist/service/types/Game/GameAttemptType.d.ts +6 -0
  50. package/{src/service/types/Game/GameCanPlayType.ts → dist/service/types/Game/GameCanPlayType.d.ts} +10 -11
  51. package/dist/service/types/Game/GameExternalStatus.d.ts +6 -0
  52. package/{src/service/types/Game/GameInfo.ts → dist/service/types/Game/GameInfo.d.ts} +9 -11
  53. package/{src/service/types/Game/GamePick.ts → dist/service/types/Game/GamePick.d.ts} +90 -104
  54. package/dist/service/types/Game/GameUtil.d.ts +7 -0
  55. package/{src/service/types/SmarticoProto/GetTranslationsRequest.ts → dist/service/types/SmarticoProto/GetTranslationsRequest.d.ts} +7 -9
  56. package/dist/service/types/SmarticoProto/GetTranslationsResponse.d.ts +7 -0
  57. package/dist/service/types/SmarticoProto/ProtocolMessage.d.ts +5 -0
  58. package/dist/service/types/SmarticoProto/ProtocolRequest.d.ts +6 -0
  59. package/dist/service/types/SmarticoProto/ProtocolResponse.d.ts +5 -0
  60. package/dist/service/types/SmarticoProto/PublicLabelInfo.d.ts +34 -0
  61. package/dist/service/types/SmarticoProto/PublicProperties.d.ts +11 -0
  62. package/{src/service/types/SmarticoProto/ResponseIdentify.ts → dist/service/types/SmarticoProto/ResponseIdentify.d.ts} +12 -16
  63. package/dist/service/types/SmarticoProto/SAW/SAWAcknowledgeType.d.ts +5 -0
  64. package/{src/service/types/SmarticoProto/SAW/SAWBuyInType.ts → dist/service/types/SmarticoProto/SAW/SAWBuyInType.d.ts} +5 -5
  65. package/{src/service/types/SmarticoProto/SAW/SAWDoSpinRequest.ts → dist/service/types/SmarticoProto/SAW/SAWDoSpinRequest.d.ts} +5 -8
  66. package/{src/service/types/SmarticoProto/SAW/SAWDoSpinResponse.ts → dist/service/types/SmarticoProto/SAW/SAWDoSpinResponse.d.ts} +15 -18
  67. package/dist/service/types/SmarticoProto/SAW/SAWGameType.d.ts +10 -0
  68. package/{src/service/types/SmarticoProto/SAW/SAWGetTemplatesRequest.ts → dist/service/types/SmarticoProto/SAW/SAWGetTemplatesRequest.d.ts} +3 -5
  69. package/{src/service/types/SmarticoProto/SAW/SAWGetTemplatesResponse.ts → dist/service/types/SmarticoProto/SAW/SAWGetTemplatesResponse.d.ts} +5 -8
  70. package/dist/service/types/SmarticoProto/SAW/SAWPrize.d.ts +11 -0
  71. package/dist/service/types/SmarticoProto/SAW/SAWPrizeType.d.ts +8 -0
  72. package/dist/service/types/SmarticoProto/SAW/SAWPrizeUI.d.ts +13 -0
  73. package/dist/service/types/SmarticoProto/SAW/SAWTemplate.d.ts +21 -0
  74. package/{src/service/types/SmarticoProto/SAW/SAWTemplateUI.ts → dist/service/types/SmarticoProto/SAW/SAWTemplateUI.d.ts} +31 -33
  75. package/dist/service/types/SmarticoProto/SAW/SAWWinSoundType.d.ts +12 -0
  76. package/dist/service/types/SmarticoProto/TranslationArea.d.ts +9 -0
  77. package/{src/service/types/User/UserInfo.ts → dist/service/types/User/UserInfo.d.ts} +10 -12
  78. package/package.json +10 -3
  79. package/src/Base/ClassId.ts +26 -0
  80. package/src/{service/types/SmarticoProto → Base}/ProtocolMessage.ts +0 -0
  81. package/src/{service/types/SmarticoProto → Base}/ProtocolRequest.ts +0 -0
  82. package/src/{service/types/SmarticoProto → Base}/ProtocolResponse.ts +0 -0
  83. package/src/Core/GetLabelInfoRequest.ts +5 -0
  84. package/src/Core/GetLabelInfoResponse.ts +6 -0
  85. package/src/Core/GetTranslationsRequest.ts +10 -0
  86. package/src/{service/types/SmarticoProto → Core}/GetTranslationsResponse.ts +1 -1
  87. package/src/{service/types/SmarticoProto/PublicLabelInfo.ts → Core/PublicLabelSettings.ts} +1 -6
  88. package/src/{service/types/SmarticoProto → Core}/PublicProperties.ts +0 -0
  89. package/src/Core/ResponseIdentify.ts +14 -0
  90. package/src/{service/types/SmarticoProto → Core}/TranslationArea.ts +1 -1
  91. package/src/Core/index.ts +18 -0
  92. package/src/{service/types/ErrorCodes.ts → ErrorCodes.ts} +1 -3
  93. package/src/{service/types/GResponse.ts → GResponse.ts} +0 -0
  94. package/src/ILogger.ts +11 -0
  95. package/src/IntUtils.ts +39 -0
  96. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWAcknowledgeType.ts +0 -0
  97. package/src/MiniGames/SAWAskForUsername.ts +5 -0
  98. package/src/MiniGames/SAWBuyInType.ts +11 -0
  99. package/src/MiniGames/SAWDoSpinRequest.ts +8 -0
  100. package/src/MiniGames/SAWDoSpinResponse.ts +11 -0
  101. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWGameType.ts +2 -2
  102. package/src/MiniGames/SAWGetTemplatesRequest.ts +5 -0
  103. package/src/MiniGames/SAWGetTemplatesResponse.ts +8 -0
  104. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrize.ts +0 -0
  105. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrizeType.ts +0 -0
  106. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWPrizeUI.ts +0 -0
  107. package/src/MiniGames/SAWSpinErrorCode.ts +8 -0
  108. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWTemplate.ts +5 -0
  109. package/src/MiniGames/SAWTemplateUI.ts +31 -0
  110. package/src/MiniGames/SAWUtils.ts +31 -0
  111. package/src/{service/types/SmarticoProto/SAW → MiniGames}/SAWWinSoundType.ts +0 -0
  112. package/src/MiniGames/index.ts +35 -0
  113. package/src/OCache.ts +54 -0
  114. package/src/SmarticoAPI.ts +296 -0
  115. package/src/index.ts +12 -2
  116. package/tsconfig.json +17 -0
  117. package/src/service/index.ts +0 -12
  118. package/src/service/types/GRequest.ts +0 -18
  119. package/src/service/types/Game/GameAttemptType.ts +0 -8
  120. package/src/service/types/Game/GameExternalStatus.ts +0 -7
  121. package/src/service/types/Game/GameUtil.ts +0 -30
  122. package/src/util/Util.ts +0 -306
  123. package/test/package.json +0 -11
@@ -1,264 +1,463 @@
1
- import { Md5 } from 'md5-typescript';
2
- import { TSMap } from 'typescript-map';
1
+ import * as superagent from 'superagent';
2
+ import NodeCache from 'node-cache';
3
3
 
4
- class Util {
5
- constructor() {}
6
- static isNumber(value) {
7
- return /^\d+$/.test(value);
8
- }
9
- static parseNumber(v) {
10
- if (Util.isNotEmpty(v)) {
11
- const result = parseFloat(v);
12
- if (isNaN(result)) {
13
- return null;
4
+ var ClassId;
5
+ (function (ClassId) {
6
+ ClassId[ClassId["GET_LABEL_INFO"] = 3] = "GET_LABEL_INFO";
7
+ ClassId[ClassId["GET_LABEL_INFO_RESPONSE"] = 4] = "GET_LABEL_INFO_RESPONSE";
8
+ ClassId[ClassId["IDENTIFY"] = 5] = "IDENTIFY";
9
+ ClassId[ClassId["IDENTIFY_RESPONSE"] = 6] = "IDENTIFY_RESPONSE";
10
+ ClassId[ClassId["EVENT"] = 9] = "EVENT";
11
+ ClassId[ClassId["EVENT_RESPONSE"] = 10] = "EVENT_RESPONSE";
12
+ ClassId[ClassId["GET_TRANSLATIONS_REQUEST"] = 13] = "GET_TRANSLATIONS_REQUEST";
13
+ ClassId[ClassId["GET_TRANSLATIONS_RESPONSE"] = 14] = "GET_TRANSLATIONS_RESPONSE";
14
+ ClassId[ClassId["CHANGE_USERNAME"] = 159] = "CHANGE_USERNAME";
15
+ ClassId[ClassId["CHANGE_USERNAME_RESPONSE"] = 160] = "CHANGE_USERNAME_RESPONSE";
16
+ ClassId[ClassId["SAW_GET_SPINS_REQUEST"] = 700] = "SAW_GET_SPINS_REQUEST";
17
+ ClassId[ClassId["SAW_GET_SPINS_RESPONSE"] = 701] = "SAW_GET_SPINS_RESPONSE";
18
+ ClassId[ClassId["SAW_DO_SPIN_REQUEST"] = 702] = "SAW_DO_SPIN_REQUEST";
19
+ ClassId[ClassId["SAW_DO_SPIN_RESPONSE"] = 703] = "SAW_DO_SPIN_RESPONSE";
20
+ ClassId[ClassId["SAW_AKNOWLEDGE_REQUEST"] = 704] = "SAW_AKNOWLEDGE_REQUEST";
21
+ ClassId[ClassId["SAW_AKNOWLEDGE_RESPONSE"] = 705] = "SAW_AKNOWLEDGE_RESPONSE";
22
+ ClassId[ClassId["SAW_SPINS_COUNT_PUSH"] = 706] = "SAW_SPINS_COUNT_PUSH";
23
+ ClassId[ClassId["SAW_SHOW_SPIN_PUSH"] = 707] = "SAW_SHOW_SPIN_PUSH";
24
+ ClassId[ClassId["UNSUPPORTED_COMMAND"] = 99999] = "UNSUPPORTED_COMMAND";
25
+ })(ClassId || (ClassId = {}));
26
+
27
+ function _extends() {
28
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
29
+ for (var i = 1; i < arguments.length; i++) {
30
+ var source = arguments[i];
31
+ for (var key in source) {
32
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
33
+ target[key] = source[key];
34
+ }
14
35
  }
15
- return result;
16
- }
17
- return null;
18
- }
19
- static parseBoolean(v) {
20
- return v === "true" || v === true ? true : v === "false" || v === false ? false : null;
21
- }
22
- static escapeRegExp(v) {
23
- if (Util.isNotEmpty(v)) {
24
- return v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25
36
  }
26
- return v;
27
- }
28
- static nullToEmpty(val) {
29
- return this.isNotEmpty(val) ? val : "";
30
- }
31
- static nullTo0(val) {
32
- return this.isNotNull(val) ? val : 0;
33
- }
34
- static isNotEmpty(val) {
35
- return typeof val !== "undefined" && val !== null && val.length > 0;
37
+ return target;
38
+ };
39
+ return _extends.apply(this, arguments);
40
+ }
41
+
42
+ class IntUtils {
43
+ static uuid() {
44
+ let a;
45
+ let b;
46
+ for (b = a = ""; a++ < 36; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : "-") {}
47
+ return b;
36
48
  }
37
49
  static isNotNull(val) {
38
50
  return typeof val !== "undefined" && val !== null;
39
51
  }
40
- static isNull(val) {
41
- return typeof val === "undefined" || val === null;
42
- }
43
- static isArrayNotEmpty(val) {
52
+ static isNotEmpty(val) {
44
53
  return typeof val !== "undefined" && val !== null && val.length > 0;
45
54
  }
46
- static isArrayEmpty(val) {
47
- return typeof val === "undefined" || val === null || val.length === 0;
48
- }
49
- static isObjectEmpty(val) {
50
- return Util.isNull(val) || Object.keys(val).length === 0 && val.constructor === Object;
51
- }
52
- static isMapNotEmpty(val) {
53
- return typeof val !== "undefined" && val !== null && (val.size() > 0 || val.keys().length > 0);
54
- }
55
- static isMapEmpty(val) {
56
- return typeof val === "undefined" || val === null || val.size() === 0 || val.keys().length === 0;
57
- }
58
- static objectToMap(obj) {
59
- if (Util.isNotNull(obj)) {
60
- const map = new TSMap();
61
- Object.keys(obj).forEach(key => {
62
- map.set(key, obj[key]);
63
- });
64
- return map;
65
- }
66
- return null;
67
- }
68
- static keyByValue(obj, value) {
69
- for (const prop in obj) {
70
- if (obj.hasOwnProperty(prop)) {
71
- if (obj[prop] === value) {
72
- return prop;
73
- }
74
- }
55
+ static replaceAll(value, regex, replacement) {
56
+ if (IntUtils.isNotNull(value)) {
57
+ return value.replace(new RegExp(IntUtils.escapeRegExp(regex), "g"), replacement == null ? void 0 : replacement.toString());
75
58
  }
76
- return null;
77
- }
78
- static greaterThen0(val) {
79
- return this.isNotNull(val) && val > 0;
80
- }
81
- static not0(val) {
82
- return this.isNotNull(val) && val !== 0;
83
- }
84
- static lessThen0(val) {
85
- return this.isNotNull(val) && val < 0;
59
+ return value;
86
60
  }
87
- static compareUndefined(o1, o2) {
88
- if (this.isNotNull(o1) && this.isNull(o2)) {
89
- return -1;
90
- }
91
- if (this.isNull(o1) && this.isNotNull(o2)) {
92
- return 1;
61
+ static escapeRegExp(v) {
62
+ if (IntUtils.isNotEmpty(v)) {
63
+ return v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
93
64
  }
94
- return 0;
65
+ return v;
95
66
  }
96
- static compareArrayLength(o1, o2) {
97
- const result = Util.compareUndefined(o1, o2);
98
- if (result === 0 && Util.isNotNull(o1) && Util.isNotNull(o2)) {
99
- return o1.length < o2.length ? -1 : o1.length > o2.length ? 1 : 0;
100
- }
101
- return result;
67
+ }
68
+
69
+ var SAWBuyInType;
70
+ (function (SAWBuyInType) {
71
+ SAWBuyInType[SAWBuyInType["Free"] = 1] = "Free";
72
+ SAWBuyInType[SAWBuyInType["Points"] = 2] = "Points";
73
+ SAWBuyInType[SAWBuyInType["Spins"] = 3] = "Spins";
74
+ })(SAWBuyInType || (SAWBuyInType = {}));
75
+ const SAWBuyInTypeName = {
76
+ [SAWBuyInType.Free]: "free",
77
+ [SAWBuyInType.Points]: "points",
78
+ [SAWBuyInType.Spins]: "spins"
79
+ };
80
+
81
+ class SAWUtils {}
82
+ SAWUtils.canPlay = (t, pointsBalance) => {
83
+ if (t === null || t === undefined) {
84
+ return false;
102
85
  }
103
- static compareObject(a, b) {
104
- for (const key in a) {
105
- if (!(key in b) || a[key] !== b[key]) {
106
- return false;
86
+ switch (t.saw_buyin_type_id) {
87
+ case SAWBuyInType.Free:
88
+ {
89
+ return true;
107
90
  }
108
- }
109
- for (const key in b) {
110
- if (!(key in a) || a[key] !== b[key]) {
91
+ case SAWBuyInType.Spins:
92
+ {
93
+ return t.spin_count !== null && t.spin_count > 0;
94
+ }
95
+ case SAWBuyInType.Points:
96
+ {
97
+ return t.buyin_cost_points <= pointsBalance;
98
+ }
99
+ default:
100
+ {
101
+ console.error("MiniGamesUtils.canPlay: Unknwon SAW buyin type " + t.saw_buyin_type_id);
111
102
  return false;
112
103
  }
113
- }
114
- return true;
115
104
  }
116
- static compareArrays(arr1, arr2, comparator) {
117
- Util.checkNotNull(comparator);
118
- let result = this.compareArrayLength(arr1, arr2);
119
- if (result === 0 && Util.isNotNull(arr1) && Util.isNotNull(arr2)) {
120
- for (let i = 0; i < arr1.length; i++) {
121
- result = comparator(arr1[i], arr2[i]);
122
- if (result !== 0) {
123
- break;
124
- }
105
+ };
106
+
107
+ var SAWAcknowledgeType;
108
+ (function (SAWAcknowledgeType) {
109
+ SAWAcknowledgeType[SAWAcknowledgeType["Silent"] = 1] = "Silent";
110
+ SAWAcknowledgeType[SAWAcknowledgeType["QuickMessage"] = 2] = "QuickMessage";
111
+ SAWAcknowledgeType[SAWAcknowledgeType["FullMessage"] = 3] = "FullMessage";
112
+ })(SAWAcknowledgeType || (SAWAcknowledgeType = {}));
113
+
114
+ var SAWAskForUsername;
115
+ (function (SAWAskForUsername) {
116
+ SAWAskForUsername["NOASK"] = "no-ask";
117
+ SAWAskForUsername["ONSUMBIT"] = "on-submit";
118
+ })(SAWAskForUsername || (SAWAskForUsername = {}));
119
+
120
+ var SAWGameType;
121
+ (function (SAWGameType) {
122
+ SAWGameType[SAWGameType["SpinAWheel"] = 1] = "SpinAWheel";
123
+ SAWGameType[SAWGameType["ScratchCard"] = 2] = "ScratchCard";
124
+ SAWGameType[SAWGameType["MatchX"] = 3] = "MatchX";
125
+ })(SAWGameType || (SAWGameType = {}));
126
+ const SAWGameTypeName = {
127
+ [SAWGameType.SpinAWheel]: "wheel",
128
+ [SAWGameType.ScratchCard]: "scratch",
129
+ [SAWGameType.MatchX]: "matchx"
130
+ };
131
+
132
+ var SAWPrizeType;
133
+ (function (SAWPrizeType) {
134
+ SAWPrizeType[SAWPrizeType["NO_PRIZE"] = 1] = "NO_PRIZE";
135
+ SAWPrizeType[SAWPrizeType["POINTS"] = 2] = "POINTS";
136
+ SAWPrizeType[SAWPrizeType["BONUS"] = 3] = "BONUS";
137
+ SAWPrizeType[SAWPrizeType["MANUAL"] = 4] = "MANUAL";
138
+ SAWPrizeType[SAWPrizeType["SPIN"] = 5] = "SPIN";
139
+ SAWPrizeType[SAWPrizeType["JACKPOT"] = 6] = "JACKPOT";
140
+ })(SAWPrizeType || (SAWPrizeType = {}));
141
+
142
+ var SAWSpinErrorCode;
143
+ (function (SAWSpinErrorCode) {
144
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_OK"] = 0] = "SAW_OK";
145
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_NO_SPINS"] = 40001] = "SAW_NO_SPINS";
146
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_PRIZE_POOL_EMPTY"] = 40002] = "SAW_PRIZE_POOL_EMPTY";
147
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_NOT_ENOUGH_POINTS"] = 40003] = "SAW_NOT_ENOUGH_POINTS";
148
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_FAILED_MAX_SPINS_REACHED"] = 40004] = "SAW_FAILED_MAX_SPINS_REACHED";
149
+ })(SAWSpinErrorCode || (SAWSpinErrorCode = {}));
150
+
151
+ var SAWWinSoundType;
152
+ (function (SAWWinSoundType) {
153
+ SAWWinSoundType[SAWWinSoundType["Disappointing"] = 1] = "Disappointing";
154
+ SAWWinSoundType[SAWWinSoundType["Positive"] = 2] = "Positive";
155
+ SAWWinSoundType[SAWWinSoundType["HighlyPositive"] = 3] = "HighlyPositive";
156
+ SAWWinSoundType[SAWWinSoundType["NoSound"] = 4] = "NoSound";
157
+ })(SAWWinSoundType || (SAWWinSoundType = {}));
158
+ const SAWWinSoundFiles = {
159
+ [SAWWinSoundType.NoSound]: null,
160
+ [SAWWinSoundType.Disappointing]: "saw-disappointed.m4a",
161
+ [SAWWinSoundType.Positive]: "saw-positive.m4a",
162
+ [SAWWinSoundType.HighlyPositive]: "saw-highly-positive.m4a"
163
+ };
164
+
165
+ var ECacheContext;
166
+ (function (ECacheContext) {
167
+ ECacheContext[ECacheContext["Translations"] = 0] = "Translations";
168
+ ECacheContext[ECacheContext["LabelInfo"] = 1] = "LabelInfo";
169
+ })(ECacheContext || (ECacheContext = {}));
170
+ const WITH_REF_CACHE = [ECacheContext.Translations];
171
+ class OCache {
172
+ static get(oKey, cacheContext) {
173
+ const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
174
+ if (this.cache[cacheContext] === undefined) {
175
+ this.cache[cacheContext] = new NodeCache({
176
+ useClones: !WITH_REF_CACHE.includes(cacheContext)
177
+ });
178
+ }
179
+ return this.cache[cacheContext].get(key);
180
+ }
181
+ static set(oKey, o, cacheContext, ttlSeconds = 60) {
182
+ const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
183
+ this.cache[cacheContext].set(key, o, ttlSeconds);
184
+ }
185
+ static async use(oKey, cacheContext, f, ttlSeconds = 60) {
186
+ if (ttlSeconds <= 0) {
187
+ return await f();
188
+ } else {
189
+ let o = OCache.get(oKey, cacheContext);
190
+ if (o === undefined) {
191
+ o = await f();
192
+ OCache.set(oKey, o, cacheContext, ttlSeconds);
125
193
  }
194
+ return o;
126
195
  }
127
- return result;
128
196
  }
129
- static compareBool(o1, o2) {
130
- const result = this.compareUndefined(o1, o2);
131
- if (result === 0 && this.isNotNull(o1) && this.isNotNull(o2)) {
132
- return Boolean(o2) - Boolean(o1);
197
+ static async clear(cacheContext) {
198
+ if (this.cache[cacheContext]) {
199
+ this.cache[cacheContext].flushAll();
133
200
  }
134
- return result;
135
201
  }
136
- static compareNumber(o1, o2) {
137
- const result = this.compareUndefined(o1, o2);
138
- if (result === 0 && this.isNotNull(o1) && this.isNotNull(o2)) {
139
- return o1 === o2 ? 0 : o1 < o2 ? -1 : 1;
202
+ }
203
+ OCache.cache = {};
204
+
205
+ const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
206
+ const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
207
+ class SmarticoAPI {
208
+ constructor(label_api_key, brand_api_key, options = {}) {
209
+ this.label_api_key = void 0;
210
+ this.brand_api_key = void 0;
211
+ this.publicUrl = void 0;
212
+ this.avatarDomain = void 0;
213
+ this.logger = void 0;
214
+ this.logCIDs = void 0;
215
+ this.logHTTPTiming = void 0;
216
+ this.label_api_key = label_api_key;
217
+ this.brand_api_key = brand_api_key;
218
+ this.logger = options.logger || console;
219
+ if (this.logger.always === undefined) {
220
+ this.logger.always = this.logger.info;
140
221
  }
141
- return result;
142
- }
143
- static compareString(o1, o2) {
144
- const result = Util.compareUndefined(o1, o2);
145
- if (result === 0 && Util.isNotNull(o1) && Util.isNotNull(o2)) {
146
- return o1 < o2 ? -1 : o1 > o2 ? 1 : 0;
222
+ this.logCIDs = options.logCIDs || [];
223
+ this.logHTTPTiming = options.logHTTPTiming || false;
224
+ let ENV_ID = this.label_api_key.length === 38 ? label_api_key.substring(37, 38) : '';
225
+ if (ENV_ID === '1' || ENV_ID === '2') {
226
+ ENV_ID = '';
147
227
  }
148
- return result;
228
+ label_api_key = label_api_key.substring(0, 36);
229
+ this.publicUrl = PUBLIC_API_URL.replace('{ENV_ID}', ENV_ID);
230
+ this.avatarDomain = AVATAR_DOMAIN.replace('{ENV_ID}', ENV_ID);
149
231
  }
150
- static range(from, to) {
151
- return Array(to - from + 1).fill(null).map((_, idx) => from + idx);
152
- }
153
- static has(array, val) {
154
- if (Util.isArrayNotEmpty(array) && Util.isNotNull(val)) {
155
- for (let i = 0; i < array.length; i++) {
156
- if (array[i] === val) {
157
- return true;
158
- }
159
- }
232
+ async send(message, expectCID) {
233
+ if (this.logCIDs.includes(message.cid)) {
234
+ this.logger.info('REQ', message);
160
235
  }
161
- return false;
162
- }
163
- static isEmpty(val) {
164
- return typeof val === "undefined" || val === null || val.length === 0;
165
- }
166
- static checkNotNull(reference, msg) {
167
- if (Util.isNull(reference)) {
168
- throw new ReferenceError(msg);
236
+ let result;
237
+ try {
238
+ const timeStart = new Date().getTime();
239
+ const res = await superagent.post(this.publicUrl).send(message);
240
+ // const res = await superagent.post('http://channel01.int.smartico.ai:81/services/public').send(message);
241
+ const timeEnd = new Date().getTime();
242
+ if (this.logHTTPTiming) {
243
+ this.logger.always('HTTP time, ms:' + (timeEnd - timeStart));
244
+ }
245
+ result = JSON.parse(res.text);
246
+ } catch (e) {
247
+ this.logger.error(`Failed to make request to smartico channel. ${e.message}`, {
248
+ url: this.publicUrl,
249
+ request: message,
250
+ error: e.message
251
+ });
252
+ throw new Error(`Failed to make request to smartico channel. ${e.message}`);
169
253
  }
170
- return reference;
171
- }
172
- static randomInt(min, max) {
173
- return Math.floor(Math.random() * (max - min + 1)) + min;
174
- }
175
- static randomArr(arr) {
176
- if (Util.isArrayEmpty(arr)) {
177
- return undefined;
254
+ if (this.logCIDs.includes(message.cid)) {
255
+ this.logger.info('RES', result);
178
256
  }
179
- return arr[Util.randomInt(0, arr.length - 1)];
180
- }
181
- static remove(arr, item) {
182
- if (Util.isArrayNotEmpty(arr) && item) {
183
- for (let i = 0; i < arr.length; i++) {
184
- if (arr[i] === item) {
185
- arr.splice(i, 1);
186
- return true;
257
+ if (expectCID) {
258
+ if (Array.isArray(result)) {
259
+ for (const str of result) {
260
+ const obj = JSON.parse(str);
261
+ if (this.logCIDs.includes(obj.cid)) {
262
+ this.logger.info('RES', result);
263
+ }
264
+ if (obj.cid === expectCID) {
265
+ return obj;
266
+ }
187
267
  }
268
+ this.logger.error(`Cant find proper response in array, expected CID ${expectCID}`, {
269
+ request: message,
270
+ response: result
271
+ });
272
+ } else {
273
+ return result;
188
274
  }
275
+ } else {
276
+ if (Array.isArray(result)) {
277
+ if (result.length === 1) {
278
+ const obj = JSON.parse(result[0]);
279
+ if (this.logCIDs.includes(obj.cid)) {
280
+ this.logger.info('RES', result);
281
+ }
282
+ return obj;
283
+ } else {
284
+ this.logger.error('Expected one response, but got array', {
285
+ request: message,
286
+ response: result
287
+ });
288
+ }
289
+ }
290
+ return result;
189
291
  }
190
- return false;
191
292
  }
192
- static replaceAll(value, regex, replacement) {
193
- if (Util.isNotNull(value)) {
194
- return value.replace(new RegExp(Util.escapeRegExp(regex), "g"), replacement);
293
+ buildMessage(user_ext_id, cid, payload = {}) {
294
+ const message = _extends({
295
+ api_key: this.label_api_key,
296
+ brand_key: this.brand_api_key,
297
+ ext_user_id: user_ext_id,
298
+ cid,
299
+ uuid: IntUtils.uuid(),
300
+ ts: new Date().getTime()
301
+ }, payload);
302
+ if (message.ext_user_id === undefined || message.ext_user_id === null) {
303
+ delete message.ext_user_id;
195
304
  }
196
- return value;
305
+ return message;
197
306
  }
198
- static to(promise, errorExt) {
199
- return promise.then(data => [null, data]).catch(err => {
200
- if (errorExt) {
201
- Object.assign(err, errorExt);
307
+ async coreReportCustomEvent(user_ext_id, eventType, payload = {}) {
308
+ const eventMessage = this.buildMessage(user_ext_id, ClassId.EVENT, {
309
+ eventType,
310
+ payload
311
+ });
312
+ const eventResponse = await this.send(eventMessage, ClassId.EVENT_RESPONSE);
313
+ return eventResponse;
314
+ }
315
+ async coreGetTranslations(user_ext_id, lang_code, areas, cacheSec = 60) {
316
+ var _this = this;
317
+ const response = await OCache.use(`${lang_code}-${this.label_api_key}-${this.brand_api_key}`, ECacheContext.Translations, async function () {
318
+ const tsBaseRQ = _this.buildMessage(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
319
+ lang_code: "EN",
320
+ hash_code: 0,
321
+ areas
322
+ });
323
+ const trBase = await _this.send(tsBaseRQ);
324
+ if (lang_code !== "EN") {
325
+ const trUserRQ = _this.buildMessage(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
326
+ lang_code,
327
+ hash_code: 0,
328
+ areas
329
+ });
330
+ const trUser = await _this.send(trUserRQ);
331
+ Object.keys(trUser.translations).forEach(k => {
332
+ trBase.translations[k] = trUser.translations[k];
333
+ });
202
334
  }
203
- return [err, undefined];
335
+ return trBase;
336
+ }, cacheSec);
337
+ return response;
338
+ }
339
+ async coreIdentifyLabel(user_ext_id, cacheSec = 60) {
340
+ var _this2 = this;
341
+ return OCache.use(`${this.label_api_key} - ${this.brand_api_key}`, ECacheContext.LabelInfo, async function () {
342
+ const message = _this2.buildMessage(user_ext_id, ClassId.GET_LABEL_INFO);
343
+ return _this2.send(message, ClassId.GET_LABEL_INFO_RESPONSE);
344
+ }, cacheSec);
345
+ }
346
+ async coreIdentifyUser(user_ext_id) {
347
+ const message = this.buildMessage(user_ext_id, ClassId.IDENTIFY, {
348
+ request_id: IntUtils.uuid() // AA: do we need request_id?
204
349
  });
205
- }
206
- static isObject(item) {
207
- return item && typeof item === "object" && !Array.isArray(item);
208
- }
209
- static merge(target, ...sources) {
210
- if (!sources.length) {
211
- return target;
350
+
351
+ const r = await this.send(message, ClassId.IDENTIFY_RESPONSE);
352
+ if (!(r.avatar_id && r.avatar_id.startsWith('http'))) {
353
+ r.avatar_id = AVATAR_DOMAIN + '/avatar/' + r.avatar_id;
212
354
  }
213
- const source = sources.shift();
214
- if (this.isObject(target) && this.isObject(source)) {
215
- for (const key in source) {
216
- if (this.isObject(source[key])) {
217
- if (!target[key]) {
218
- Object.assign(target, {
219
- [key]: {}
220
- });
221
- }
222
- this.merge(target[key], source[key]);
223
- } else if (Array.isArray(source[key])) {
224
- Object.assign(target, {
225
- [key]: [...source[key]]
226
- });
227
- } else if (typeof source[key] !== "undefined") {
228
- Object.assign(target, {
229
- [key]: source[key]
355
+ return r;
356
+ }
357
+ async coreChangeUsername(user_ext_id, public_username_custom) {
358
+ const message = this.buildMessage(user_ext_id, ClassId.CHANGE_USERNAME, {
359
+ public_username_custom
360
+ });
361
+ return this.send(message, ClassId.CHANGE_USERNAME_RESPONSE);
362
+ }
363
+ async sawGetTemplates(user_ext_id) {
364
+ const message = this.buildMessage(user_ext_id, ClassId.SAW_GET_SPINS_REQUEST);
365
+ const response = await this.send(message);
366
+ if (response && response.templates) {
367
+ response.templates.forEach(t => {
368
+ if (t.jackpot_current) {
369
+ t.saw_template_ui_definition.name = IntUtils.replaceAll(t.saw_template_ui_definition.name, '{{jackpot}}', t.jackpot_current);
370
+ t.saw_template_ui_definition.description = IntUtils.replaceAll(t.saw_template_ui_definition.description, '{{jackpot}}', t.jackpot_current);
371
+ t.saw_template_ui_definition.promo_text = IntUtils.replaceAll(t.saw_template_ui_definition.promo_text, '{{jackpot}}', t.jackpot_current);
372
+ t.prizes.forEach(p => {
373
+ p.saw_prize_ui_definition.name = IntUtils.replaceAll(p.saw_prize_ui_definition.name, '{{jackpot}}', t.jackpot_current);
374
+ p.saw_prize_ui_definition.aknowledge_message = IntUtils.replaceAll(p.saw_prize_ui_definition.aknowledge_message, '{{jackpot}}', t.jackpot_current);
230
375
  });
231
376
  }
232
- }
233
- }
234
- return this.merge(target, ...sources);
235
- }
236
- static deepCopy(source) {
237
- return JSON.parse(JSON.stringify(source));
238
- }
239
- static getStackTrace() {
240
- return new Error().stack;
241
- }
242
- static shuffleArray(array) {
243
- for (let i = array.length - 1; i > 0; i--) {
244
- const j = Math.floor(Math.random() * (i + 1));
245
- [array[i], array[j]] = [array[j], array[i]];
377
+ });
246
378
  }
247
- return array;
379
+ return response;
380
+ }
381
+ async sawFormatTemplatesForWidget(templates, pointsBalance) {
382
+ return templates.filter(r => r.saw_template_id >= 1).map(r => {
383
+ var _r$saw_skin_ui_defini, _r$saw_skin_ui_defini2;
384
+ return {
385
+ id: r.saw_template_id,
386
+ name: r.saw_template_ui_definition.name,
387
+ // description: r.saw_template_ui_definition.description,
388
+ game_type: SAWGameTypeName[r.saw_game_type_id] || 'unknown',
389
+ buyin_type: SAWBuyInTypeName[r.saw_buyin_type_id] || 'unknown',
390
+ jackpot: r.jackpot_current,
391
+ spin_count: r.spin_count,
392
+ buyin_cost_points: r.buyin_cost_points,
393
+ can_play: SAWUtils.canPlay(r, pointsBalance),
394
+ icon: (_r$saw_skin_ui_defini = r.saw_skin_ui_definition) != null && _r$saw_skin_ui_defini.skin_folder ? ((_r$saw_skin_ui_defini2 = r.saw_skin_ui_definition) == null ? void 0 : _r$saw_skin_ui_defini2.skin_folder) + '/ico.png' : `https://libs.smartico.ai/gf/images/saw/${r.saw_skin_key}/ico.png`
395
+ };
396
+ });
248
397
  }
249
- static buildValidationHash(ext_user_id, ext_game_id, customer_id, secretKey) {
250
- const toHash = `${ext_user_id}|${ext_game_id}|${customer_id}:${secretKey}`;
251
- return Md5.init(toHash);
398
+ async sawSpinRequest(user_ext_id, saw_template_id, round_id) {
399
+ const message = this.buildMessage(user_ext_id, ClassId.SAW_DO_SPIN_REQUEST, {
400
+ saw_template_id,
401
+ request_id: IntUtils.uuid()
402
+ });
403
+ const spinAttemptResponse = await this.send(message, ClassId.SAW_DO_SPIN_RESPONSE);
404
+ // to simulate fail
405
+ // response.errCode = SAWSpinErrorCode.SAW_NO_SPINS;
406
+ const status = {
407
+ [SAWSpinErrorCode.SAW_OK]: 'OK',
408
+ [SAWSpinErrorCode.SAW_NO_SPINS]: 'NO SPINS AVAILABLE',
409
+ [SAWSpinErrorCode.SAW_PRIZE_POOL_EMPTY]: 'PRIZE POOL IS EMPTY',
410
+ [SAWSpinErrorCode.SAW_NOT_ENOUGH_POINTS]: 'NOT ENOUGH POINTS',
411
+ [SAWSpinErrorCode.SAW_FAILED_MAX_SPINS_REACHED]: 'MAX SPIN ATTEMPTS REACHED'
412
+ }[spinAttemptResponse.errCode] || 'OTHER';
413
+ await this.coreReportCustomEvent(user_ext_id, 'minigame_attempt', {
414
+ saw_template_id,
415
+ status,
416
+ round_id
417
+ });
418
+ return spinAttemptResponse;
252
419
  }
253
420
  }
254
- Util.uuid = () => {
255
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => {
256
- // eslint-disable-next-line no-mixed-operators
257
- const r = Math.random() * 16 | 0,
258
- v = c === "x" ? r : r & 0x3 | 0x8;
259
- return v.toString(16);
260
- });
261
- };
262
421
 
263
- export { Util };
422
+ var PublicLabelSettings;
423
+ (function (PublicLabelSettings) {
424
+ PublicLabelSettings["FCM_SENDER_ID"] = "FCM_SENDER_ID";
425
+ PublicLabelSettings["PUBLIC_API_URL"] = "PUBLIC_API_URL";
426
+ PublicLabelSettings["FCM_SW_URL"] = "FCM_SW_URL";
427
+ PublicLabelSettings["RECORDING_ENABLED_FOR_ALL_USERS"] = "RECORDING_ENABLED_FOR_ALL_USERS";
428
+ PublicLabelSettings["JS_INJECTION"] = "JS_INJECTION";
429
+ PublicLabelSettings["GAMIFICATION_UI_MAIN"] = "GAMIFICATION_UI_MAIN";
430
+ PublicLabelSettings["GAMIFICATION_UI_WIDGET"] = "GAMIFICATION_UI_WIDGET";
431
+ PublicLabelSettings["GAMIFICATION_UI_MINI_GAME"] = "GAMIFICATION_UI_MINI_GAME";
432
+ PublicLabelSettings["GAMIFICATION_UI_SETTINGS"] = "GAMIFICATION_UI_SETTINGS";
433
+ PublicLabelSettings["GAMIFICATION_UI_MAIN_TEST"] = "GAMIFICATION_UI_MAIN_TEST";
434
+ PublicLabelSettings["GAMIFICATION_UI_WIDGET_TEST"] = "GAMIFICATION_UI_WIDGET_TEST";
435
+ PublicLabelSettings["GAMIFICATION_UI_SETTINGS_TEST"] = "GAMIFICATION_UI_SETTINGS_TEST";
436
+ PublicLabelSettings["FRONT_END_ALLOWED_LANGUAGES"] = "FRONT_END_ALLOWED_LANGUAGES";
437
+ PublicLabelSettings["FRONT_END_ALLOW_DOMAINS"] = "FRONT_END_ALLOW_DOMAINS";
438
+ PublicLabelSettings["DELAY_ENGAGEMENT_EXECUTION_ON_LOGIN_MS"] = "DELAY_ENGAGEMENT_EXECUTION_ON_LOGIN_MS";
439
+ PublicLabelSettings["SHADOW_LABEL_PUBLIC_KEY"] = "SHADOW_LABEL_PUBLIC_KEY";
440
+ PublicLabelSettings["DYNAMIC_IMAGE_DOMAIN"] = "DYNAMIC_IMAGE_DOMAIN";
441
+ PublicLabelSettings["GAMIFICATION_UI_LEVEL_ENABLED"] = "GAMIFICATION_UI_LEVEL_ENABLED";
442
+ PublicLabelSettings["GAMIFICATION_UI_LEVEL_IMAGE_MOB"] = "GAMIFICATION_UI_LEVEL_IMAGE_MOB";
443
+ PublicLabelSettings["GAMIFICATION_UI_LEVEL_IMAGE_DESK"] = "GAMIFICATION_UI_LEVEL_IMAGE_DESK";
444
+ PublicLabelSettings["GAMIFICATION_LEVELS_LOGIC2"] = "GAMIFICATION_LEVELS_LOGIC2";
445
+ PublicLabelSettings["AVATAR_CUSTOM_IMAGE_MAX_ID"] = "AVATAR_CUSTOM_IMAGE_MAX_ID";
446
+ PublicLabelSettings["AVATAR_CUSTOM_IMAGE_FOLDER"] = "AVATAR_CUSTOM_IMAGE_FOLDER";
447
+ PublicLabelSettings["RETENTION_GAMES_CUSTOMER_ID"] = "RETENTION_GAMES_CUSTOMER_ID";
448
+ PublicLabelSettings["GAMIFICATION_SHOW_POWERED_BY"] = "GAMIFICATION_SHOW_POWERED_BY";
449
+ PublicLabelSettings["_system_leader_board_mask_username"] = "_system_leader_board_mask_username";
450
+ })(PublicLabelSettings || (PublicLabelSettings = {}));
451
+
452
+ var TranslationArea;
453
+ (function (TranslationArea) {
454
+ TranslationArea[TranslationArea["Casino"] = 1] = "Casino";
455
+ TranslationArea[TranslationArea["Gamification"] = 2] = "Gamification";
456
+ TranslationArea[TranslationArea["Trading"] = 3] = "Trading";
457
+ TranslationArea[TranslationArea["Archived"] = 4] = "Archived";
458
+ TranslationArea[TranslationArea["Affiliation"] = 5] = "Affiliation";
459
+ TranslationArea[TranslationArea["RetentionGames"] = 6] = "RetentionGames";
460
+ })(TranslationArea || (TranslationArea = {}));
461
+
462
+ export { ClassId, PublicLabelSettings, SAWAcknowledgeType, SAWAskForUsername, SAWBuyInType, SAWBuyInTypeName, SAWGameType, SAWGameTypeName, SAWPrizeType, SAWSpinErrorCode, SAWUtils, SAWWinSoundFiles, SAWWinSoundType, SmarticoAPI, TranslationArea };
264
463
  //# sourceMappingURL=index.modern.mjs.map