@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
package/dist/index.js CHANGED
@@ -1,269 +1,350 @@
1
- var md5Typescript = require('md5-typescript');
2
- var typescriptMap = require('typescript-map');
1
+ var superagent = require('superagent');
3
2
 
4
- var Util = /*#__PURE__*/function () {
5
- function Util() {}
6
- Util.isNumber = function isNumber(value) {
7
- return /^\d+$/.test(value);
8
- };
9
- Util.parseNumber = function parseNumber(v) {
10
- if (Util.isNotEmpty(v)) {
11
- var result = parseFloat(v);
12
- if (isNaN(result)) {
13
- return null;
14
- }
15
- return result;
3
+ function _interopNamespace(e) {
4
+ if (e && e.__esModule) return e;
5
+ var n = Object.create(null);
6
+ if (e) {
7
+ Object.keys(e).forEach(function (k) {
8
+ if (k !== 'default') {
9
+ var d = Object.getOwnPropertyDescriptor(e, k);
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: function () { return e[k]; }
13
+ });
14
+ }
15
+ });
16
16
  }
17
- return null;
18
- };
19
- Util.parseBoolean = function parseBoolean(v) {
20
- return v === "true" || v === true ? true : v === "false" || v === false ? false : null;
21
- };
22
- Util.escapeRegExp = function escapeRegExp(v) {
23
- if (Util.isNotEmpty(v)) {
24
- return v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17
+ n["default"] = e;
18
+ return n;
19
+ }
20
+
21
+ var superagent__namespace = /*#__PURE__*/_interopNamespace(superagent);
22
+
23
+ exports.ClassId = void 0;
24
+ (function (ClassId) {
25
+ ClassId[ClassId["GET_LABEL_INFO"] = 3] = "GET_LABEL_INFO";
26
+ ClassId[ClassId["GET_LABEL_INFO_RESPONSE"] = 4] = "GET_LABEL_INFO_RESPONSE";
27
+ ClassId[ClassId["IDENTIFY"] = 5] = "IDENTIFY";
28
+ ClassId[ClassId["IDENTIFY_RESPONSE"] = 6] = "IDENTIFY_RESPONSE";
29
+ ClassId[ClassId["EVENT"] = 9] = "EVENT";
30
+ ClassId[ClassId["EVENT_RESPONSE"] = 10] = "EVENT_RESPONSE";
31
+ ClassId[ClassId["GET_TRANSLATIONS_REQUEST"] = 13] = "GET_TRANSLATIONS_REQUEST";
32
+ ClassId[ClassId["GET_TRANSLATIONS_RESPONSE"] = 14] = "GET_TRANSLATIONS_RESPONSE";
33
+ ClassId[ClassId["CHANGE_USERNAME"] = 159] = "CHANGE_USERNAME";
34
+ ClassId[ClassId["CHANGE_USERNAME_RESPONSE"] = 160] = "CHANGE_USERNAME_RESPONSE";
35
+ ClassId[ClassId["SAW_GET_SPINS_REQUEST"] = 700] = "SAW_GET_SPINS_REQUEST";
36
+ ClassId[ClassId["SAW_GET_SPINS_RESPONSE"] = 701] = "SAW_GET_SPINS_RESPONSE";
37
+ ClassId[ClassId["SAW_DO_SPIN_REQUEST"] = 702] = "SAW_DO_SPIN_REQUEST";
38
+ ClassId[ClassId["SAW_DO_SPIN_RESPONSE"] = 703] = "SAW_DO_SPIN_RESPONSE";
39
+ ClassId[ClassId["SAW_AKNOWLEDGE_REQUEST"] = 704] = "SAW_AKNOWLEDGE_REQUEST";
40
+ ClassId[ClassId["SAW_AKNOWLEDGE_RESPONSE"] = 705] = "SAW_AKNOWLEDGE_RESPONSE";
41
+ ClassId[ClassId["SAW_SPINS_COUNT_PUSH"] = 706] = "SAW_SPINS_COUNT_PUSH";
42
+ ClassId[ClassId["SAW_SHOW_SPIN_PUSH"] = 707] = "SAW_SHOW_SPIN_PUSH";
43
+ ClassId[ClassId["UNSUPPORTED_COMMAND"] = 99999] = "UNSUPPORTED_COMMAND";
44
+ })(exports.ClassId || (exports.ClassId = {}));
45
+
46
+ function _extends() {
47
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
48
+ for (var i = 1; i < arguments.length; i++) {
49
+ var source = arguments[i];
50
+ for (var key in source) {
51
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
52
+ target[key] = source[key];
53
+ }
54
+ }
25
55
  }
26
- return v;
27
- };
28
- Util.nullToEmpty = function nullToEmpty(val) {
29
- return this.isNotEmpty(val) ? val : "";
30
- };
31
- Util.nullTo0 = function nullTo0(val) {
32
- return this.isNotNull(val) ? val : 0;
33
- };
34
- Util.isNotEmpty = function isNotEmpty(val) {
35
- return typeof val !== "undefined" && val !== null && val.length > 0;
36
- };
37
- Util.isNotNull = function isNotNull(val) {
56
+ return target;
57
+ };
58
+ return _extends.apply(this, arguments);
59
+ }
60
+ function _unsupportedIterableToArray(o, minLen) {
61
+ if (!o) return;
62
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
63
+ var n = Object.prototype.toString.call(o).slice(8, -1);
64
+ if (n === "Object" && o.constructor) n = o.constructor.name;
65
+ if (n === "Map" || n === "Set") return Array.from(o);
66
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
67
+ }
68
+ function _arrayLikeToArray(arr, len) {
69
+ if (len == null || len > arr.length) len = arr.length;
70
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
71
+ return arr2;
72
+ }
73
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
74
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
75
+ if (it) return (it = it.call(o)).next.bind(it);
76
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
77
+ if (it) o = it;
78
+ var i = 0;
79
+ return function () {
80
+ if (i >= o.length) return {
81
+ done: true
82
+ };
83
+ return {
84
+ done: false,
85
+ value: o[i++]
86
+ };
87
+ };
88
+ }
89
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
90
+ }
91
+
92
+ var IntUtils = /*#__PURE__*/function () {
93
+ function IntUtils() {}
94
+ IntUtils.uuid = function uuid() {
95
+ var a;
96
+ var b;
97
+ for (b = a = ""; a++ < 36; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : "-") {}
98
+ return b;
99
+ };
100
+ IntUtils.isNotNull = function isNotNull(val) {
38
101
  return typeof val !== "undefined" && val !== null;
39
102
  };
40
- Util.isNull = function isNull(val) {
41
- return typeof val === "undefined" || val === null;
42
- };
43
- Util.isArrayNotEmpty = function isArrayNotEmpty(val) {
103
+ IntUtils.isNotEmpty = function isNotEmpty(val) {
44
104
  return typeof val !== "undefined" && val !== null && val.length > 0;
45
105
  };
46
- Util.isArrayEmpty = function isArrayEmpty(val) {
47
- return typeof val === "undefined" || val === null || val.length === 0;
48
- };
49
- Util.isObjectEmpty = function isObjectEmpty(val) {
50
- return Util.isNull(val) || Object.keys(val).length === 0 && val.constructor === Object;
51
- };
52
- Util.isMapNotEmpty = function isMapNotEmpty(val) {
53
- return typeof val !== "undefined" && val !== null && (val.size() > 0 || val.keys().length > 0);
54
- };
55
- Util.isMapEmpty = function isMapEmpty(val) {
56
- return typeof val === "undefined" || val === null || val.size() === 0 || val.keys().length === 0;
57
- };
58
- Util.objectToMap = function objectToMap(obj) {
59
- if (Util.isNotNull(obj)) {
60
- var map = new typescriptMap.TSMap();
61
- Object.keys(obj).forEach(function (key) {
62
- map.set(key, obj[key]);
63
- });
64
- return map;
65
- }
66
- return null;
67
- };
68
- Util.keyByValue = function keyByValue(obj, value) {
69
- for (var prop in obj) {
70
- if (obj.hasOwnProperty(prop)) {
71
- if (obj[prop] === value) {
72
- return prop;
73
- }
74
- }
106
+ IntUtils.replaceAll = function replaceAll(value, regex, replacement) {
107
+ if (IntUtils.isNotNull(value)) {
108
+ return value.replace(new RegExp(IntUtils.escapeRegExp(regex), "g"), replacement == null ? void 0 : replacement.toString());
75
109
  }
76
- return null;
77
- };
78
- Util.greaterThen0 = function greaterThen0(val) {
79
- return this.isNotNull(val) && val > 0;
80
- };
81
- Util.not0 = function not0(val) {
82
- return this.isNotNull(val) && val !== 0;
83
- };
84
- Util.lessThen0 = function lessThen0(val) {
85
- return this.isNotNull(val) && val < 0;
110
+ return value;
86
111
  };
87
- Util.compareUndefined = function 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;
112
+ IntUtils.escapeRegExp = function escapeRegExp(v) {
113
+ if (IntUtils.isNotEmpty(v)) {
114
+ return v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
93
115
  }
94
- return 0;
116
+ return v;
95
117
  };
96
- Util.compareArrayLength = function compareArrayLength(o1, o2) {
97
- var 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;
118
+ return IntUtils;
119
+ }();
120
+
121
+ exports.SAWAcknowledgeType = void 0;
122
+ (function (SAWAcknowledgeType) {
123
+ SAWAcknowledgeType[SAWAcknowledgeType["Silent"] = 1] = "Silent";
124
+ SAWAcknowledgeType[SAWAcknowledgeType["QuickMessage"] = 2] = "QuickMessage";
125
+ SAWAcknowledgeType[SAWAcknowledgeType["FullMessage"] = 3] = "FullMessage";
126
+ })(exports.SAWAcknowledgeType || (exports.SAWAcknowledgeType = {}));
127
+
128
+ var _SAWBuyInTypeName;
129
+ exports.SAWBuyInType = void 0;
130
+ (function (SAWBuyInType) {
131
+ SAWBuyInType[SAWBuyInType["Free"] = 1] = "Free";
132
+ SAWBuyInType[SAWBuyInType["Points"] = 2] = "Points";
133
+ SAWBuyInType[SAWBuyInType["Spins"] = 3] = "Spins";
134
+ })(exports.SAWBuyInType || (exports.SAWBuyInType = {}));
135
+ var SAWBuyInTypeName = (_SAWBuyInTypeName = {}, _SAWBuyInTypeName[exports.SAWBuyInType.Free] = "free", _SAWBuyInTypeName[exports.SAWBuyInType.Points] = "points", _SAWBuyInTypeName[exports.SAWBuyInType.Spins] = "spins", _SAWBuyInTypeName);
136
+
137
+ exports.SAWSpinErrorCode = void 0;
138
+ (function (SAWSpinErrorCode) {
139
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_OK"] = 0] = "SAW_OK";
140
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_NO_SPINS"] = 40001] = "SAW_NO_SPINS";
141
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_PRIZE_POOL_EMPTY"] = 40002] = "SAW_PRIZE_POOL_EMPTY";
142
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_NOT_ENOUGH_POINTS"] = 40003] = "SAW_NOT_ENOUGH_POINTS";
143
+ SAWSpinErrorCode[SAWSpinErrorCode["SAW_FAILED_MAX_SPINS_REACHED"] = 40004] = "SAW_FAILED_MAX_SPINS_REACHED";
144
+ })(exports.SAWSpinErrorCode || (exports.SAWSpinErrorCode = {}));
145
+
146
+ var _SAWGameTypeName;
147
+ exports.SAWGameType = void 0;
148
+ (function (SAWGameType) {
149
+ SAWGameType[SAWGameType["SpinAWheel"] = 1] = "SpinAWheel";
150
+ SAWGameType[SAWGameType["ScratchCard"] = 2] = "ScratchCard";
151
+ SAWGameType[SAWGameType["MatchX"] = 3] = "MatchX";
152
+ })(exports.SAWGameType || (exports.SAWGameType = {}));
153
+ var SAWGameTypeName = (_SAWGameTypeName = {}, _SAWGameTypeName[exports.SAWGameType.SpinAWheel] = "wheel", _SAWGameTypeName[exports.SAWGameType.ScratchCard] = "scratch", _SAWGameTypeName[exports.SAWGameType.MatchX] = "matchx", _SAWGameTypeName);
154
+
155
+ exports.SAWPrizeType = void 0;
156
+ (function (SAWPrizeType) {
157
+ SAWPrizeType[SAWPrizeType["NO_PRIZE"] = 1] = "NO_PRIZE";
158
+ SAWPrizeType[SAWPrizeType["POINTS"] = 2] = "POINTS";
159
+ SAWPrizeType[SAWPrizeType["BONUS"] = 3] = "BONUS";
160
+ SAWPrizeType[SAWPrizeType["MANUAL"] = 4] = "MANUAL";
161
+ SAWPrizeType[SAWPrizeType["SPIN"] = 5] = "SPIN";
162
+ SAWPrizeType[SAWPrizeType["JACKPOT"] = 6] = "JACKPOT";
163
+ })(exports.SAWPrizeType || (exports.SAWPrizeType = {}));
164
+
165
+ var _SAWWinSoundFiles;
166
+ exports.SAWWinSoundType = void 0;
167
+ (function (SAWWinSoundType) {
168
+ SAWWinSoundType[SAWWinSoundType["Disappointing"] = 1] = "Disappointing";
169
+ SAWWinSoundType[SAWWinSoundType["Positive"] = 2] = "Positive";
170
+ SAWWinSoundType[SAWWinSoundType["HighlyPositive"] = 3] = "HighlyPositive";
171
+ SAWWinSoundType[SAWWinSoundType["NoSound"] = 4] = "NoSound";
172
+ })(exports.SAWWinSoundType || (exports.SAWWinSoundType = {}));
173
+ var SAWWinSoundFiles = (_SAWWinSoundFiles = {}, _SAWWinSoundFiles[exports.SAWWinSoundType.NoSound] = null, _SAWWinSoundFiles[exports.SAWWinSoundType.Disappointing] = "saw-disappointed.m4a", _SAWWinSoundFiles[exports.SAWWinSoundType.Positive] = "saw-positive.m4a", _SAWWinSoundFiles[exports.SAWWinSoundType.HighlyPositive] = "saw-highly-positive.m4a", _SAWWinSoundFiles);
174
+
175
+ function _catch(body, recover) {
176
+ try {
177
+ var result = body();
178
+ } catch (e) {
179
+ return recover(e);
180
+ }
181
+ if (result && result.then) {
182
+ return result.then(void 0, recover);
183
+ }
184
+ return result;
185
+ }
186
+ var PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
187
+ var SmarticoAPI = /*#__PURE__*/function () {
188
+ function SmarticoAPI(label_api_key, brand_api_key, options) {
189
+ if (options === void 0) {
190
+ options = {};
100
191
  }
101
- return result;
102
- };
103
- Util.compareObject = function compareObject(a, b) {
104
- for (var key in a) {
105
- if (!(key in b) || a[key] !== b[key]) {
106
- return false;
107
- }
192
+ this.label_api_key = void 0;
193
+ this.brand_api_key = void 0;
194
+ this.publicUrl = void 0;
195
+ this.logger = void 0;
196
+ this.logCIDs = void 0;
197
+ this.logHTTPTiming = void 0;
198
+ this.label_api_key = label_api_key;
199
+ this.brand_api_key = brand_api_key;
200
+ this.logger = options.logger || console;
201
+ if (this.logger.always === undefined) {
202
+ this.logger.always = this.logger.info;
108
203
  }
109
- for (var _key in b) {
110
- if (!(_key in a) || a[_key] !== b[_key]) {
111
- return false;
112
- }
204
+ this.logCIDs = options.logCIDs || [];
205
+ this.logHTTPTiming = options.logHTTPTiming || false;
206
+ var ENV_ID = this.label_api_key.length === 38 ? label_api_key.substring(37, 38) : '';
207
+ if (ENV_ID === '1' || ENV_ID === '2') {
208
+ ENV_ID = '';
113
209
  }
114
- return true;
115
- };
116
- Util.compareArrays = function compareArrays(arr1, arr2, comparator) {
117
- Util.checkNotNull(comparator);
118
- var result = this.compareArrayLength(arr1, arr2);
119
- if (result === 0 && Util.isNotNull(arr1) && Util.isNotNull(arr2)) {
120
- for (var i = 0; i < arr1.length; i++) {
121
- result = comparator(arr1[i], arr2[i]);
122
- if (result !== 0) {
123
- break;
210
+ label_api_key = label_api_key.substring(0, 36);
211
+ this.publicUrl = PUBLIC_API_URL.replace('{ENV_ID}', ENV_ID);
212
+ }
213
+ var _proto = SmarticoAPI.prototype;
214
+ _proto.send = function send(message, expectCID) {
215
+ try {
216
+ var _temp2 = function _temp2(_result) {
217
+ if (_exit) return _result;
218
+ if (_this.logCIDs.includes(message.cid)) {
219
+ _this.logger.info('RES', result);
124
220
  }
125
- }
126
- }
127
- return result;
128
- };
129
- Util.compareBool = function compareBool(o1, o2) {
130
- var result = this.compareUndefined(o1, o2);
131
- if (result === 0 && this.isNotNull(o1) && this.isNotNull(o2)) {
132
- return Boolean(o2) - Boolean(o1);
133
- }
134
- return result;
135
- };
136
- Util.compareNumber = function compareNumber(o1, o2) {
137
- var result = this.compareUndefined(o1, o2);
138
- if (result === 0 && this.isNotNull(o1) && this.isNotNull(o2)) {
139
- return o1 === o2 ? 0 : o1 < o2 ? -1 : 1;
140
- }
141
- return result;
142
- };
143
- Util.compareString = function compareString(o1, o2) {
144
- var result = Util.compareUndefined(o1, o2);
145
- if (result === 0 && Util.isNotNull(o1) && Util.isNotNull(o2)) {
146
- return o1 < o2 ? -1 : o1 > o2 ? 1 : 0;
147
- }
148
- return result;
149
- };
150
- Util.range = function range(from, to) {
151
- return Array(to - from + 1).fill(null).map(function (_, idx) {
152
- return from + idx;
153
- });
154
- };
155
- Util.has = function has(array, val) {
156
- if (Util.isArrayNotEmpty(array) && Util.isNotNull(val)) {
157
- for (var i = 0; i < array.length; i++) {
158
- if (array[i] === val) {
159
- return true;
221
+ if (expectCID) {
222
+ if (Array.isArray(result)) {
223
+ for (var _iterator = _createForOfIteratorHelperLoose(result), _step; !(_step = _iterator()).done;) {
224
+ var str = _step.value;
225
+ var obj = JSON.parse(str);
226
+ if (_this.logCIDs.includes(obj.cid)) {
227
+ _this.logger.info('RES', result);
228
+ }
229
+ if (obj.cid === expectCID) {
230
+ return obj;
231
+ }
232
+ }
233
+ _this.logger.error("Cant find proper response in array, expected CID " + expectCID, {
234
+ request: message,
235
+ response: result
236
+ });
237
+ } else {
238
+ return result;
239
+ }
240
+ } else {
241
+ if (Array.isArray(result)) {
242
+ if (result.length === 1) {
243
+ var _obj = JSON.parse(result[0]);
244
+ if (_this.logCIDs.includes(_obj.cid)) {
245
+ _this.logger.info('RES', result);
246
+ }
247
+ return _obj;
248
+ } else {
249
+ _this.logger.error('Expected one response, but got array', {
250
+ request: message,
251
+ response: result
252
+ });
253
+ }
254
+ }
255
+ return result;
160
256
  }
257
+ };
258
+ var _exit;
259
+ var _this = this;
260
+ if (_this.logCIDs.includes(message.cid)) {
261
+ _this.logger.info('REQ', message);
161
262
  }
263
+ var result;
264
+ var _temp = _catch(function () {
265
+ var timeStart = new Date().getTime();
266
+ return Promise.resolve(superagent__namespace.post(_this.publicUrl).send(message)).then(function (res) {
267
+ var timeEnd = new Date().getTime();
268
+ if (_this.logHTTPTiming) {
269
+ _this.logger.always('HTTP time, ms:' + (timeEnd - timeStart));
270
+ }
271
+ result = JSON.parse(res.text);
272
+ });
273
+ }, function (e) {
274
+ _this.logger.error("Failed to make request to smartico channel. " + e.message, {
275
+ url: _this.publicUrl,
276
+ request: message,
277
+ error: e.message
278
+ });
279
+ throw new Error("Failed to make request to smartico channel. " + e.message);
280
+ });
281
+ return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
282
+ } catch (e) {
283
+ return Promise.reject(e);
162
284
  }
163
- return false;
164
- };
165
- Util.isEmpty = function isEmpty(val) {
166
- return typeof val === "undefined" || val === null || val.length === 0;
167
285
  };
168
- Util.checkNotNull = function checkNotNull(reference, msg) {
169
- if (Util.isNull(reference)) {
170
- throw new ReferenceError(msg);
286
+ _proto.buildMessage = function buildMessage(user_ext_id, cid, payload) {
287
+ if (payload === void 0) {
288
+ payload = {};
171
289
  }
172
- return reference;
173
- };
174
- Util.randomInt = function randomInt(min, max) {
175
- return Math.floor(Math.random() * (max - min + 1)) + min;
176
- };
177
- Util.randomArr = function randomArr(arr) {
178
- if (Util.isArrayEmpty(arr)) {
179
- return undefined;
180
- }
181
- return arr[Util.randomInt(0, arr.length - 1)];
182
- };
183
- Util.remove = function remove(arr, item) {
184
- if (Util.isArrayNotEmpty(arr) && item) {
185
- for (var i = 0; i < arr.length; i++) {
186
- if (arr[i] === item) {
187
- arr.splice(i, 1);
188
- return true;
290
+ var message = _extends({
291
+ api_key: this.label_api_key,
292
+ brand_key: this.brand_api_key,
293
+ ext_user_id: user_ext_id,
294
+ cid: cid,
295
+ uuid: IntUtils.uuid(),
296
+ ts: new Date().getTime()
297
+ }, payload);
298
+ return message;
299
+ };
300
+ _proto.miniGamesGetTemplates = function miniGamesGetTemplates(user_ext_id) {
301
+ try {
302
+ var _this2 = this;
303
+ var message = _this2.buildMessage(user_ext_id, exports.ClassId.SAW_GET_SPINS_REQUEST);
304
+ return Promise.resolve(_this2.send(message)).then(function (response) {
305
+ if (response && response.templates) {
306
+ response.templates.forEach(function (t) {
307
+ if (t.jackpot_current) {
308
+ t.saw_template_ui_definition.name = IntUtils.replaceAll(t.saw_template_ui_definition.name, '{{jackpot}}', t.jackpot_current);
309
+ t.saw_template_ui_definition.description = IntUtils.replaceAll(t.saw_template_ui_definition.description, '{{jackpot}}', t.jackpot_current);
310
+ t.saw_template_ui_definition.promo_text = IntUtils.replaceAll(t.saw_template_ui_definition.promo_text, '{{jackpot}}', t.jackpot_current);
311
+ t.prizes.forEach(function (p) {
312
+ p.saw_prize_ui_definition.name = IntUtils.replaceAll(p.saw_prize_ui_definition.name, '{{jackpot}}', t.jackpot_current);
313
+ p.saw_prize_ui_definition.aknowledge_message = IntUtils.replaceAll(p.saw_prize_ui_definition.aknowledge_message, '{{jackpot}}', t.jackpot_current);
314
+ });
315
+ }
316
+ });
189
317
  }
190
- }
318
+ return response;
319
+ });
320
+ } catch (e) {
321
+ return Promise.reject(e);
191
322
  }
192
- return false;
193
323
  };
194
- Util.replaceAll = function replaceAll(value, regex, replacement) {
195
- if (Util.isNotNull(value)) {
196
- return value.replace(new RegExp(Util.escapeRegExp(regex), "g"), replacement);
197
- }
198
- return value;
199
- };
200
- Util.to = function to(promise, errorExt) {
201
- return promise.then(function (data) {
202
- return [null, data];
203
- })["catch"](function (err) {
204
- if (errorExt) {
205
- Object.assign(err, errorExt);
206
- }
207
- return [err, undefined];
324
+ _proto.miniGamesFormatTemplatesForWidget = function miniGamesFormatTemplatesForWidget(templates, pointsBalance) {
325
+ return templates.filter(function (r) {
326
+ return r.saw_template_id >= 1;
327
+ }).map(function (r) {
328
+ var _r$saw_skin_ui_defini, _r$saw_skin_ui_defini2;
329
+ return {
330
+ id: r.saw_template_id,
331
+ name: r.saw_template_ui_definition.name,
332
+ // description: r.saw_template_ui_definition.description,
333
+ game_type: SAWGameTypeName[r.saw_game_type_id] || 'unknown',
334
+ buyin_type: SAWBuyInTypeName[r.saw_buyin_type_id] || 'unknown',
335
+ jackpot: r.jackpot_current,
336
+ spin_count: r.spin_count,
337
+ buyin_cost_points: r.buyin_cost_points,
338
+ can_play: r.saw_buyin_type_id === exports.SAWBuyInType.Free || r.saw_buyin_type_id === exports.SAWBuyInType.Points && r.buyin_cost_points <= pointsBalance || r.saw_buyin_type_id === exports.SAWBuyInType.Spins && r.spin_count > 0,
339
+ 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"
340
+ };
208
341
  });
209
342
  };
210
- Util.isObject = function isObject(item) {
211
- return item && typeof item === "object" && !Array.isArray(item);
212
- };
213
- Util.merge = function merge(target) {
214
- var sources = [].slice.call(arguments, 1);
215
- if (!sources.length) {
216
- return target;
217
- }
218
- var source = sources.shift();
219
- if (this.isObject(target) && this.isObject(source)) {
220
- for (var key in source) {
221
- if (this.isObject(source[key])) {
222
- if (!target[key]) {
223
- var _Object$assign;
224
- Object.assign(target, (_Object$assign = {}, _Object$assign[key] = {}, _Object$assign));
225
- }
226
- this.merge(target[key], source[key]);
227
- } else if (Array.isArray(source[key])) {
228
- var _Object$assign2;
229
- Object.assign(target, (_Object$assign2 = {}, _Object$assign2[key] = [].concat(source[key]), _Object$assign2));
230
- } else if (typeof source[key] !== "undefined") {
231
- var _Object$assign3;
232
- Object.assign(target, (_Object$assign3 = {}, _Object$assign3[key] = source[key], _Object$assign3));
233
- }
234
- }
235
- }
236
- return this.merge.apply(this, [target].concat(sources));
237
- };
238
- Util.deepCopy = function deepCopy(source) {
239
- return JSON.parse(JSON.stringify(source));
240
- };
241
- Util.getStackTrace = function getStackTrace() {
242
- return new Error().stack;
243
- };
244
- Util.shuffleArray = function shuffleArray(array) {
245
- for (var i = array.length - 1; i > 0; i--) {
246
- var j = Math.floor(Math.random() * (i + 1));
247
- var _ref = [array[j], array[i]];
248
- array[i] = _ref[0];
249
- array[j] = _ref[1];
250
- }
251
- return array;
252
- };
253
- Util.buildValidationHash = function buildValidationHash(ext_user_id, ext_game_id, customer_id, secretKey) {
254
- var toHash = ext_user_id + "|" + ext_game_id + "|" + customer_id + ":" + secretKey;
255
- return md5Typescript.Md5.init(toHash);
256
- };
257
- return Util;
343
+ return SmarticoAPI;
258
344
  }();
259
- Util.uuid = function () {
260
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
261
- // eslint-disable-next-line no-mixed-operators
262
- var r = Math.random() * 16 | 0,
263
- v = c === "x" ? r : r & 0x3 | 0x8;
264
- return v.toString(16);
265
- });
266
- };
267
345
 
268
- exports.Util = Util;
346
+ exports.SAWBuyInTypeName = SAWBuyInTypeName;
347
+ exports.SAWGameTypeName = SAWGameTypeName;
348
+ exports.SAWWinSoundFiles = SAWWinSoundFiles;
349
+ exports.SmarticoAPI = SmarticoAPI;
269
350
  //# sourceMappingURL=index.js.map