@kalamba/sdk 0.4.1 → 0.6.0
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/dist/errors-66b5612a.cjs +5 -0
- package/dist/errors-96eb18f7.js +52 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +99 -24
- package/dist/index.js +193 -109
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.d.ts +39 -9
- package/dist/plugins.js +590 -499
- package/dist/wrapper.d.ts +38 -9
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -2,26 +2,120 @@
|
|
|
2
2
|
* BSD 3-Clause License
|
|
3
3
|
* Copyright (c) 2024, Kalamba Games Limited
|
|
4
4
|
*/
|
|
5
|
-
var b =
|
|
6
|
-
|
|
7
|
-
var l = (r, i, t) => (M(r, typeof i != "symbol" ? i + "" : i, t), t), d = (r, i, t) => {
|
|
8
|
-
if (!i.has(r))
|
|
5
|
+
var b = (n, i, t) => {
|
|
6
|
+
if (!i.has(n))
|
|
9
7
|
throw TypeError("Cannot " + t);
|
|
10
8
|
};
|
|
11
|
-
var
|
|
12
|
-
if (i.has(
|
|
9
|
+
var m = (n, i, t) => (b(n, i, "read from private field"), t ? t.call(n) : i.get(n)), e = (n, i, t) => {
|
|
10
|
+
if (i.has(n))
|
|
13
11
|
throw TypeError("Cannot add the same private member more than once");
|
|
14
|
-
i instanceof WeakSet ? i.add(
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
i instanceof WeakSet ? i.add(n) : i.set(n, t);
|
|
13
|
+
}, u = (n, i, t, r) => (b(n, i, "write to private field"), r ? r.call(n, t) : i.set(n, t), t);
|
|
14
|
+
import { T as E, O as H, P as U } from "./errors-96eb18f7.js";
|
|
15
|
+
import { a as ti, b as ni } from "./errors-96eb18f7.js";
|
|
16
|
+
function O(n) {
|
|
17
|
+
const i = Object.prototype.toString.call(n);
|
|
18
|
+
return n instanceof Date || typeof n == "object" && i === "[object Date]" ? new n.constructor(+n) : typeof n == "number" || i === "[object Number]" || typeof n == "string" || i === "[object String]" ? new Date(n) : /* @__PURE__ */ new Date(NaN);
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function B(n) {
|
|
21
|
+
const i = O(n);
|
|
22
|
+
return i.setHours(23, 59, 59, 999), i;
|
|
23
|
+
}
|
|
24
|
+
function P() {
|
|
25
|
+
return B(Date.now());
|
|
26
|
+
}
|
|
27
|
+
function k(n) {
|
|
28
|
+
const i = O(n);
|
|
29
|
+
return i.setHours(0, 0, 0, 0), i;
|
|
30
|
+
}
|
|
31
|
+
function L() {
|
|
32
|
+
return k(Date.now());
|
|
33
|
+
}
|
|
34
|
+
const $ = 3e4;
|
|
35
|
+
var D, x;
|
|
36
|
+
class G {
|
|
37
|
+
constructor(i) {
|
|
38
|
+
e(this, D, void 0);
|
|
39
|
+
e(this, x, $);
|
|
40
|
+
u(this, D, i);
|
|
41
|
+
}
|
|
42
|
+
buildHeaders() {
|
|
43
|
+
const i = {};
|
|
44
|
+
return m(this, D).token && (i.Authorization = `Bearer ${m(this, D).token}`), i;
|
|
45
|
+
}
|
|
46
|
+
async request(i, t) {
|
|
47
|
+
const r = new URL(i, m(this, D).apiUrl ?? window.location.origin);
|
|
48
|
+
return r.search = new URLSearchParams({
|
|
49
|
+
...t
|
|
50
|
+
}).toString(), await (await fetch(r, {
|
|
51
|
+
signal: AbortSignal.timeout(m(this, x)),
|
|
52
|
+
headers: this.buildHeaders()
|
|
53
|
+
})).json();
|
|
54
|
+
}
|
|
55
|
+
async getRounds(i) {
|
|
56
|
+
return this.request("/rounds", i);
|
|
57
|
+
}
|
|
58
|
+
async getRound(i, t) {
|
|
59
|
+
return this.request(`/rounds/${i}`, t);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
D = new WeakMap(), x = new WeakMap();
|
|
63
|
+
const R = {
|
|
64
|
+
limit: 100,
|
|
65
|
+
page: 0
|
|
66
|
+
};
|
|
67
|
+
var a, f;
|
|
68
|
+
class _ {
|
|
69
|
+
constructor({
|
|
70
|
+
config: i
|
|
71
|
+
}) {
|
|
72
|
+
e(this, a, void 0);
|
|
73
|
+
e(this, f, void 0);
|
|
74
|
+
u(this, a, i), u(this, f, new G({
|
|
75
|
+
apiUrl: i.api.gameHistoryUrl
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
async getRound(i, {
|
|
79
|
+
pagination: t = R
|
|
80
|
+
} = {}) {
|
|
81
|
+
return m(this, f).getRound(i, {
|
|
82
|
+
gameCode: m(this, a).api.game,
|
|
83
|
+
operatorCode: m(this, a).api.brand,
|
|
84
|
+
username: m(this, a).api.user,
|
|
85
|
+
...t
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async getLastRound() {
|
|
89
|
+
return m(this, a).api.lastRoundId ? this.getRound(m(this, a).api.lastRoundId) : null;
|
|
90
|
+
}
|
|
91
|
+
async getRounds({
|
|
92
|
+
searchPeriod: i = {
|
|
93
|
+
fromDateTime: L(),
|
|
94
|
+
toDateTime: P()
|
|
95
|
+
},
|
|
96
|
+
pagination: t = R
|
|
97
|
+
} = {}) {
|
|
98
|
+
const r = m(this, a).api.user.replace(/^user_/, "").replace(new RegExp(`_${m(this, a).api.integration}$`), "");
|
|
99
|
+
return m(this, f).getRounds({
|
|
100
|
+
gameCode: m(this, a).api.game,
|
|
101
|
+
operatorCode: m(this, a).api.integration,
|
|
102
|
+
username: r,
|
|
103
|
+
fromDataTime: i.fromDateTime.toISOString(),
|
|
104
|
+
toDateTime: i.toDateTime.toISOString(),
|
|
105
|
+
...t
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
a = new WeakMap(), f = new WeakMap();
|
|
110
|
+
function j(n, i) {
|
|
111
|
+
return n * i / 100;
|
|
112
|
+
}
|
|
113
|
+
function I(n, i, t) {
|
|
20
114
|
if (!["string", "number"].includes(typeof i))
|
|
21
115
|
return "NaN";
|
|
22
|
-
const { locales:
|
|
116
|
+
const { locales: r } = n;
|
|
23
117
|
try {
|
|
24
|
-
return new Intl.NumberFormat(
|
|
118
|
+
return new Intl.NumberFormat(r, {
|
|
25
119
|
...t,
|
|
26
120
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
27
121
|
// @ts-ignore
|
|
@@ -32,9 +126,9 @@ function w(r, i, t) {
|
|
|
32
126
|
return `${i}`;
|
|
33
127
|
}
|
|
34
128
|
}
|
|
35
|
-
const
|
|
36
|
-
var
|
|
37
|
-
const
|
|
129
|
+
const w = "XTS";
|
|
130
|
+
var F = /* @__PURE__ */ ((n) => (n.Currency = "Currency", n.Number = "Number", n))(F || {}), y = /* @__PURE__ */ ((n) => (n.Coins = "Coins", n.Money = "Money", n))(y || {});
|
|
131
|
+
const S = {
|
|
38
132
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
39
133
|
// ARSB is the internal currency relevant for invoicing purposes, players should see it as ARS
|
|
40
134
|
ARSB: { displayAs: "ARS", maximumFractionDigits: 2, minimumFractionDigits: 2 },
|
|
@@ -128,146 +222,135 @@ const h = {
|
|
|
128
222
|
FTN: { maximumFractionDigits: 4, minimumFractionDigits: 4 }
|
|
129
223
|
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
130
224
|
};
|
|
131
|
-
function
|
|
132
|
-
return
|
|
225
|
+
function A(n) {
|
|
226
|
+
return n in S;
|
|
133
227
|
}
|
|
134
|
-
function
|
|
135
|
-
return
|
|
136
|
-
...
|
|
137
|
-
currency:
|
|
228
|
+
function q(n) {
|
|
229
|
+
return A(n) ? {
|
|
230
|
+
...S[n],
|
|
231
|
+
currency: w
|
|
138
232
|
} : {
|
|
139
|
-
currency:
|
|
233
|
+
currency: n
|
|
140
234
|
};
|
|
141
235
|
}
|
|
142
|
-
function
|
|
143
|
-
const
|
|
144
|
-
return
|
|
236
|
+
function V(n, i, t) {
|
|
237
|
+
const r = i.format(+n);
|
|
238
|
+
return A(t) ? r.replace(w, S[t].displayAs ?? t) : r;
|
|
145
239
|
}
|
|
146
|
-
function
|
|
147
|
-
const { maximumFractionDigits:
|
|
148
|
-
return
|
|
240
|
+
function X(n, i, t) {
|
|
241
|
+
const { maximumFractionDigits: r, minimumFractionDigits: o } = t.resolvedOptions();
|
|
242
|
+
return I(n, i, { maximumFractionDigits: r, minimumFractionDigits: o });
|
|
149
243
|
}
|
|
150
|
-
function
|
|
244
|
+
function v(n, i, { as: t } = {
|
|
151
245
|
as: "Currency"
|
|
152
246
|
/* Currency */
|
|
153
247
|
}) {
|
|
154
|
-
const { canShowCurrency:
|
|
155
|
-
return t === "Number" || !
|
|
248
|
+
const { canShowCurrency: r, currency: o } = n;
|
|
249
|
+
return t === "Number" || !r ? `${i}` : `${i} ${o}`;
|
|
156
250
|
}
|
|
157
|
-
function
|
|
251
|
+
function z(n, i, { as: t, from: r } = {
|
|
158
252
|
as: "Currency",
|
|
159
253
|
from: "Money"
|
|
160
254
|
/* Money */
|
|
161
|
-
},
|
|
255
|
+
}, o) {
|
|
162
256
|
if (!["string", "number"].includes(typeof i))
|
|
163
257
|
return "NaN";
|
|
164
|
-
const { canShowCurrency: s = !0, coinValueInCents:
|
|
165
|
-
|
|
258
|
+
const { canShowCurrency: s = !0, coinValueInCents: g, currency: C, locales: T } = n;
|
|
259
|
+
r === "Coins" && (i = j(+i, g));
|
|
166
260
|
try {
|
|
167
|
-
const
|
|
168
|
-
...
|
|
169
|
-
...
|
|
261
|
+
const M = q(C), N = new Intl.NumberFormat(T, {
|
|
262
|
+
...M,
|
|
263
|
+
...o,
|
|
170
264
|
currencyDisplay: "symbol",
|
|
171
265
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
172
266
|
// @ts-ignore
|
|
173
267
|
numberingSystem: "latn",
|
|
174
268
|
style: "currency"
|
|
175
269
|
});
|
|
176
|
-
return t === "Number" || !s ?
|
|
270
|
+
return t === "Number" || !s ? X(n, i, N) : V(i, N, C);
|
|
177
271
|
} catch {
|
|
178
|
-
return
|
|
272
|
+
return v(n, i, { as: t });
|
|
179
273
|
}
|
|
180
274
|
}
|
|
181
|
-
var
|
|
182
|
-
class
|
|
275
|
+
var c;
|
|
276
|
+
class K {
|
|
183
277
|
constructor({ config: i }) {
|
|
184
|
-
|
|
185
|
-
|
|
278
|
+
e(this, c, void 0);
|
|
279
|
+
u(this, c, i);
|
|
186
280
|
}
|
|
187
281
|
formatNumber(i, t) {
|
|
188
|
-
const
|
|
189
|
-
return
|
|
282
|
+
const r = { locales: [m(this, c).ui.language] };
|
|
283
|
+
return I(r, i, t);
|
|
190
284
|
}
|
|
191
|
-
formatCurrency(i, t = { as:
|
|
192
|
-
const
|
|
193
|
-
return
|
|
194
|
-
canShowCurrency:
|
|
285
|
+
formatCurrency(i, t = { as: F.Currency, from: y.Money }, r) {
|
|
286
|
+
const o = m(this, c).ui.feature.showCurrency, s = m(this, c).api.coinValueInCents, g = m(this, c).api.currency || w, C = [m(this, c).ui.language];
|
|
287
|
+
return z({
|
|
288
|
+
canShowCurrency: o,
|
|
195
289
|
coinValueInCents: s,
|
|
196
|
-
currency:
|
|
197
|
-
locales:
|
|
198
|
-
}, i, t,
|
|
290
|
+
currency: g,
|
|
291
|
+
locales: C
|
|
292
|
+
}, i, t, r);
|
|
199
293
|
}
|
|
200
294
|
formatCoins(i, t) {
|
|
201
|
-
return this.formatCurrency(i, { as:
|
|
295
|
+
return this.formatCurrency(i, { as: F.Number, from: y.Coins }, t);
|
|
202
296
|
}
|
|
203
297
|
formatCoinsWithCurrency(i, t) {
|
|
204
|
-
return this.formatCurrency(i, { as:
|
|
298
|
+
return this.formatCurrency(i, { as: F.Currency, from: y.Coins }, t);
|
|
205
299
|
}
|
|
206
300
|
formatMoney(i, t) {
|
|
207
|
-
return this.formatCurrency(i, { as:
|
|
301
|
+
return this.formatCurrency(i, { as: F.Number, from: y.Money }, t);
|
|
208
302
|
}
|
|
209
303
|
formatMoneyWithCurrency(i, t) {
|
|
210
|
-
return this.formatCurrency(i, { as:
|
|
304
|
+
return this.formatCurrency(i, { as: F.Currency, from: y.Money }, t);
|
|
211
305
|
}
|
|
212
306
|
}
|
|
213
|
-
|
|
214
|
-
const
|
|
307
|
+
c = new WeakMap();
|
|
308
|
+
const W = () => {
|
|
215
309
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
super("OpenGameError");
|
|
219
|
-
l(this, "error");
|
|
220
|
-
this.name = "OpenGameError", this.error = t;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
class U extends Error {
|
|
224
|
-
constructor(t) {
|
|
225
|
-
super("PlayError");
|
|
226
|
-
l(this, "error");
|
|
227
|
-
this.name = "PlayError", this.error = t;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
class E extends Error {
|
|
231
|
-
constructor() {
|
|
232
|
-
super("TimeoutError"), this.name = "TimeoutError";
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
var g, D, C;
|
|
236
|
-
class L {
|
|
310
|
+
var l, h, p, d;
|
|
311
|
+
class Q {
|
|
237
312
|
constructor({ messagePort: i }) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
313
|
+
e(this, l, void 0);
|
|
314
|
+
e(this, h, void 0);
|
|
315
|
+
e(this, p, void 0);
|
|
316
|
+
e(this, d, void 0);
|
|
317
|
+
u(this, d, i), this.on("configured", (t) => {
|
|
318
|
+
u(this, l, t), u(this, p, new K({ config: t })), u(this, h, new _({ config: t }));
|
|
319
|
+
}), this.on("playResponse", (t) => {
|
|
320
|
+
this.config.api.lastRoundId = t.contract.roundId;
|
|
243
321
|
});
|
|
244
322
|
}
|
|
245
323
|
get config() {
|
|
246
|
-
if (!
|
|
324
|
+
if (!m(this, l))
|
|
325
|
+
throw new Error("config is not initialized, you must open game first");
|
|
326
|
+
return m(this, l);
|
|
327
|
+
}
|
|
328
|
+
get history() {
|
|
329
|
+
if (!m(this, h))
|
|
247
330
|
throw new Error("config is not initialized, you must open game first");
|
|
248
|
-
return
|
|
331
|
+
return m(this, h);
|
|
249
332
|
}
|
|
250
333
|
get i18n() {
|
|
251
|
-
if (!
|
|
334
|
+
if (!m(this, p))
|
|
252
335
|
throw new Error("i18n is not initialized, you must open game first");
|
|
253
|
-
return
|
|
336
|
+
return m(this, p);
|
|
254
337
|
}
|
|
255
338
|
request(i, ...[t]) {
|
|
256
|
-
return new Promise((
|
|
257
|
-
this.on(`${i}Response`, (
|
|
339
|
+
return new Promise((r) => {
|
|
340
|
+
this.on(`${i}Response`, (o) => r({ type: "response", response: o }), {
|
|
258
341
|
once: !0
|
|
259
|
-
}), this.on(`${i}Error`, (
|
|
342
|
+
}), this.on(`${i}Error`, (o) => r({ type: "error", error: o }), { once: !0 }), this.send(i, t);
|
|
260
343
|
});
|
|
261
344
|
}
|
|
262
|
-
on(i, t,
|
|
263
|
-
const
|
|
264
|
-
|
|
345
|
+
on(i, t, r) {
|
|
346
|
+
const o = function s(g) {
|
|
347
|
+
g.data.message === `kalamba:wrapper:${i}` && (W("on", g.data.message.replace(/^kalamba:/, ""), g.data.payload), t(g.data.payload), r != null && r.once && window.removeEventListener("message", s));
|
|
265
348
|
};
|
|
266
|
-
window.addEventListener("message",
|
|
349
|
+
window.addEventListener("message", o);
|
|
267
350
|
}
|
|
268
351
|
// TODO error messages
|
|
269
352
|
send(i, ...[t]) {
|
|
270
|
-
|
|
353
|
+
m(this, d).postMessage(
|
|
271
354
|
{
|
|
272
355
|
message: `kalamba:sdk:${i}`,
|
|
273
356
|
payload: t
|
|
@@ -276,29 +359,30 @@ class L {
|
|
|
276
359
|
);
|
|
277
360
|
}
|
|
278
361
|
async openGame(i) {
|
|
279
|
-
var m;
|
|
280
362
|
const [, t] = await Promise.all([
|
|
281
363
|
// TODO: return promise from call to this.on if listener is not provided
|
|
282
|
-
new Promise((
|
|
364
|
+
new Promise((r) => this.on("configured", r, { once: !0 })),
|
|
283
365
|
this.request("openGame", i)
|
|
284
366
|
]);
|
|
285
367
|
if (t.type === "response")
|
|
286
368
|
return t.response;
|
|
287
|
-
throw
|
|
369
|
+
throw t.error.type === "timeout" ? new E() : new H(t.error.data);
|
|
288
370
|
}
|
|
289
|
-
async play(i, t,
|
|
290
|
-
|
|
291
|
-
const n = { contract: i, extra: t, actionType: m }, s = await this.request("play", n);
|
|
371
|
+
async play(i, t, r = "SPIN") {
|
|
372
|
+
const o = { contract: i, extra: t, actionType: r }, s = await this.request("play", o);
|
|
292
373
|
if (s.type === "response")
|
|
293
374
|
return s.response;
|
|
294
|
-
throw
|
|
375
|
+
throw s.error.type === "timeout" ? new E() : new U(s.error.data);
|
|
295
376
|
}
|
|
296
377
|
}
|
|
297
|
-
|
|
378
|
+
l = new WeakMap(), h = new WeakMap(), p = new WeakMap(), d = new WeakMap();
|
|
298
379
|
export {
|
|
299
|
-
|
|
380
|
+
_ as History,
|
|
381
|
+
K as I18n,
|
|
382
|
+
Q as KalambaSdk,
|
|
300
383
|
H as OpenGameError,
|
|
384
|
+
ti as OpenGameErrorCode,
|
|
301
385
|
U as PlayError,
|
|
302
|
-
|
|
303
|
-
|
|
386
|
+
ni as PlayErrorCode,
|
|
387
|
+
E as TimeoutError
|
|
304
388
|
};
|