@kalamba/sdk 0.6.1 → 0.8.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/index.js CHANGED
@@ -2,41 +2,41 @@
2
2
  * BSD 3-Clause License
3
3
  * Copyright (c) 2024, Kalamba Games Limited
4
4
  */
5
- var b = (n, i, t) => {
5
+ var N = (n, i, t) => {
6
6
  if (!i.has(n))
7
7
  throw TypeError("Cannot " + t);
8
8
  };
9
- var m = (n, i, t) => (b(n, i, "read from private field"), t ? t.call(n) : i.get(n)), e = (n, i, t) => {
9
+ var m = (n, i, t) => (N(n, i, "read from private field"), t ? t.call(n) : i.get(n)), e = (n, i, t) => {
10
10
  if (i.has(n))
11
11
  throw TypeError("Cannot add the same private member more than once");
12
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) {
13
+ }, u = (n, i, t, r) => (N(n, i, "write to private field"), r ? r.call(n, t) : i.set(n, t), t);
14
+ import { T as b, R as E } from "./errors-afd9f527.js";
15
+ import { a as ii } from "./errors-afd9f527.js";
16
+ function A(n) {
17
17
  const i = Object.prototype.toString.call(n);
18
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);
19
19
  }
20
- function B(n) {
21
- const i = O(n);
20
+ function U(n) {
21
+ const i = A(n);
22
22
  return i.setHours(23, 59, 59, 999), i;
23
23
  }
24
- function P() {
25
- return B(Date.now());
24
+ function B() {
25
+ return U(Date.now());
26
26
  }
27
27
  function k(n) {
28
- const i = O(n);
28
+ const i = A(n);
29
29
  return i.setHours(0, 0, 0, 0), i;
30
30
  }
31
31
  function L() {
32
32
  return k(Date.now());
33
33
  }
34
- const $ = 3e4;
34
+ const P = 3e4;
35
35
  var D, x;
36
- class G {
36
+ class $ {
37
37
  constructor(i) {
38
38
  e(this, D, void 0);
39
- e(this, x, $);
39
+ e(this, x, P);
40
40
  u(this, D, i);
41
41
  }
42
42
  buildHeaders() {
@@ -60,45 +60,45 @@ class G {
60
60
  }
61
61
  }
62
62
  D = new WeakMap(), x = new WeakMap();
63
- const R = {
63
+ const I = {
64
64
  limit: 100,
65
65
  page: 0
66
66
  };
67
- var a, f;
67
+ var s, y;
68
68
  class _ {
69
69
  constructor({
70
70
  config: i
71
71
  }) {
72
- e(this, a, void 0);
73
- e(this, f, void 0);
74
- u(this, a, i), u(this, f, new G({
72
+ e(this, s, void 0);
73
+ e(this, y, void 0);
74
+ u(this, s, i), u(this, y, new $({
75
75
  apiUrl: i.api.gameHistoryUrl
76
76
  }));
77
77
  }
78
78
  async getRound(i, {
79
- pagination: t = R
79
+ pagination: t = I
80
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,
81
+ return m(this, y).getRound(i, {
82
+ gameCode: m(this, s).api.game,
83
+ operatorCode: m(this, s).api.brand,
84
+ username: m(this, s).api.user,
85
85
  ...t
86
86
  });
87
87
  }
88
88
  async getLastRound() {
89
- return m(this, a).api.lastRoundId ? this.getRound(m(this, a).api.lastRoundId) : null;
89
+ return m(this, s).api.lastRoundId ? this.getRound(m(this, s).api.lastRoundId) : null;
90
90
  }
91
91
  async getRounds({
92
92
  searchPeriod: i = {
93
93
  fromDateTime: L(),
94
- toDateTime: P()
94
+ toDateTime: B()
95
95
  },
96
- pagination: t = R
96
+ pagination: t = I
97
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,
98
+ const r = m(this, s).api.user.replace(/^user_/, "").replace(new RegExp(`_${m(this, s).api.integration}$`), "");
99
+ return m(this, y).getRounds({
100
+ gameCode: m(this, s).api.game,
101
+ operatorCode: m(this, s).api.integration,
102
102
  username: r,
103
103
  fromDataTime: i.fromDateTime.toISOString(),
104
104
  toDateTime: i.toDateTime.toISOString(),
@@ -106,11 +106,11 @@ class _ {
106
106
  });
107
107
  }
108
108
  }
109
- a = new WeakMap(), f = new WeakMap();
110
- function j(n, i) {
109
+ s = new WeakMap(), y = new WeakMap();
110
+ function G(n, i) {
111
111
  return n * i / 100;
112
112
  }
113
- function I(n, i, t) {
113
+ function O(n, i, t) {
114
114
  if (!["string", "number"].includes(typeof i))
115
115
  return "NaN";
116
116
  const { locales: r } = n;
@@ -127,7 +127,7 @@ function I(n, i, t) {
127
127
  }
128
128
  }
129
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 || {});
130
+ var F = /* @__PURE__ */ ((n) => (n.Currency = "Currency", n.Number = "Number", n))(F || {}), f = /* @__PURE__ */ ((n) => (n.Coins = "Coins", n.Money = "Money", n))(f || {});
131
131
  const S = {
132
132
  /* eslint-disable sort-keys-fix/sort-keys-fix */
133
133
  // ARSB is the internal currency relevant for invoicing purposes, players should see it as ARS
@@ -222,44 +222,44 @@ const S = {
222
222
  FTN: { maximumFractionDigits: 4, minimumFractionDigits: 4 }
223
223
  /* eslint-enable sort-keys-fix/sort-keys-fix */
224
224
  };
225
- function A(n) {
225
+ function M(n) {
226
226
  return n in S;
227
227
  }
228
- function q(n) {
229
- return A(n) ? {
228
+ function j(n) {
229
+ return M(n) ? {
230
230
  ...S[n],
231
231
  currency: w
232
232
  } : {
233
233
  currency: n
234
234
  };
235
235
  }
236
- function V(n, i, t) {
236
+ function q(n, i, t) {
237
237
  const r = i.format(+n);
238
- return A(t) ? r.replace(w, S[t].displayAs ?? t) : r;
238
+ return M(t) ? r.replace(w, S[t].displayAs ?? t) : r;
239
239
  }
240
- function X(n, i, t) {
240
+ function V(n, i, t) {
241
241
  const { maximumFractionDigits: r, minimumFractionDigits: o } = t.resolvedOptions();
242
- return I(n, i, { maximumFractionDigits: r, minimumFractionDigits: o });
242
+ return O(n, i, { maximumFractionDigits: r, minimumFractionDigits: o });
243
243
  }
244
- function v(n, i, { as: t } = {
244
+ function X(n, i, { as: t } = {
245
245
  as: "Currency"
246
246
  /* Currency */
247
247
  }) {
248
248
  const { canShowCurrency: r, currency: o } = n;
249
249
  return t === "Number" || !r ? `${i}` : `${i} ${o}`;
250
250
  }
251
- function z(n, i, { as: t, from: r } = {
251
+ function v(n, i, { as: t, from: r } = {
252
252
  as: "Currency",
253
253
  from: "Money"
254
254
  /* Money */
255
255
  }, o) {
256
256
  if (!["string", "number"].includes(typeof i))
257
257
  return "NaN";
258
- const { canShowCurrency: s = !0, coinValueInCents: g, currency: C, locales: T } = n;
259
- r === "Coins" && (i = j(+i, g));
258
+ const { canShowCurrency: a = !0, coinValueInCents: g, currency: C, locales: T } = n;
259
+ r === "Coins" && (i = G(+i, g));
260
260
  try {
261
- const M = q(C), N = new Intl.NumberFormat(T, {
262
- ...M,
261
+ const H = j(C), R = new Intl.NumberFormat(T, {
262
+ ...H,
263
263
  ...o,
264
264
  currencyDisplay: "symbol",
265
265
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -267,68 +267,68 @@ function z(n, i, { as: t, from: r } = {
267
267
  numberingSystem: "latn",
268
268
  style: "currency"
269
269
  });
270
- return t === "Number" || !s ? X(n, i, N) : V(i, N, C);
270
+ return t === "Number" || !a ? V(n, i, R) : q(i, R, C);
271
271
  } catch {
272
- return v(n, i, { as: t });
272
+ return X(n, i, { as: t });
273
273
  }
274
274
  }
275
275
  var c;
276
- class K {
276
+ class z {
277
277
  constructor({ config: i }) {
278
278
  e(this, c, void 0);
279
279
  u(this, c, i);
280
280
  }
281
281
  formatNumber(i, t) {
282
282
  const r = { locales: [m(this, c).ui.language] };
283
- return I(r, i, t);
283
+ return O(r, i, t);
284
284
  }
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({
285
+ formatCurrency(i, t = { as: F.Currency, from: f.Money }, r) {
286
+ const o = m(this, c).ui.feature.showCurrency, a = m(this, c).api.coinValueInCents, g = m(this, c).api.currency || w, C = [m(this, c).ui.language];
287
+ return v({
288
288
  canShowCurrency: o,
289
- coinValueInCents: s,
289
+ coinValueInCents: a,
290
290
  currency: g,
291
291
  locales: C
292
292
  }, i, t, r);
293
293
  }
294
294
  formatCoins(i, t) {
295
- return this.formatCurrency(i, { as: F.Number, from: y.Coins }, t);
295
+ return this.formatCurrency(i, { as: F.Number, from: f.Coins }, t);
296
296
  }
297
297
  formatCoinsWithCurrency(i, t) {
298
- return this.formatCurrency(i, { as: F.Currency, from: y.Coins }, t);
298
+ return this.formatCurrency(i, { as: F.Currency, from: f.Coins }, t);
299
299
  }
300
300
  formatMoney(i, t) {
301
- return this.formatCurrency(i, { as: F.Number, from: y.Money }, t);
301
+ return this.formatCurrency(i, { as: F.Number, from: f.Money }, t);
302
302
  }
303
303
  formatMoneyWithCurrency(i, t) {
304
- return this.formatCurrency(i, { as: F.Currency, from: y.Money }, t);
304
+ return this.formatCurrency(i, { as: F.Currency, from: f.Money }, t);
305
305
  }
306
306
  }
307
307
  c = new WeakMap();
308
- const W = () => {
308
+ const K = () => {
309
309
  };
310
- var l, h, p, d;
311
- class Q {
310
+ var h, l, p, d;
311
+ class Y {
312
312
  constructor({ messagePort: i }) {
313
- e(this, l, void 0);
314
313
  e(this, h, void 0);
314
+ e(this, l, void 0);
315
315
  e(this, p, void 0);
316
316
  e(this, d, void 0);
317
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 }));
318
+ u(this, h, t), u(this, p, new z({ config: t })), u(this, l, new _({ config: t }));
319
319
  }), this.on("playResponse", (t) => {
320
320
  this.config.api.lastRoundId = t.contract.roundId;
321
321
  });
322
322
  }
323
323
  get config() {
324
- if (!m(this, l))
324
+ if (!m(this, h))
325
325
  throw new Error("config is not initialized, you must open game first");
326
- return m(this, l);
326
+ return m(this, h);
327
327
  }
328
328
  get history() {
329
- if (!m(this, h))
329
+ if (!m(this, l))
330
330
  throw new Error("config is not initialized, you must open game first");
331
- return m(this, h);
331
+ return m(this, l);
332
332
  }
333
333
  get i18n() {
334
334
  if (!m(this, p))
@@ -343,8 +343,8 @@ class Q {
343
343
  });
344
344
  }
345
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));
346
+ const o = function a(g) {
347
+ g.data.message === `kalamba:wrapper:${i}` && (K("on", g.data.message.replace(/^kalamba:/, ""), g.data.payload), t(g.data.payload), r != null && r.once && window.removeEventListener("message", a));
348
348
  };
349
349
  window.addEventListener("message", o);
350
350
  }
@@ -358,31 +358,28 @@ class Q {
358
358
  "*"
359
359
  );
360
360
  }
361
- async openGame(i) {
362
- const [, t] = await Promise.all([
363
- // TODO: return promise from call to this.on if listener is not provided
364
- new Promise((r) => this.on("configured", r, { once: !0 })),
365
- this.request("openGame", i)
366
- ]);
361
+ configure(i) {
362
+ this.send("configure", i);
363
+ }
364
+ async openGame() {
365
+ const i = new Promise((r) => this.on("configured", r, { once: !0 })), t = await this.request("openGame");
367
366
  if (t.type === "response")
368
- return t.response;
369
- throw t.error.type === "timeout" ? new E() : new H(t.error.data);
367
+ return await i, t.response;
368
+ throw t.error.type === "timeout" ? new b() : new E(t.error.data);
370
369
  }
371
370
  async play(i, t, r = "SPIN") {
372
- const o = { contract: i, extra: t, actionType: r }, s = await this.request("play", o);
373
- if (s.type === "response")
374
- return s.response;
375
- throw s.error.type === "timeout" ? new E() : new U(s.error.data);
371
+ const o = { contract: i, extra: t, actionType: r }, a = await this.request("play", o);
372
+ if (a.type === "response")
373
+ return a.response;
374
+ throw a.error.type === "timeout" ? new b() : new E(a.error.data);
376
375
  }
377
376
  }
378
- l = new WeakMap(), h = new WeakMap(), p = new WeakMap(), d = new WeakMap();
377
+ h = new WeakMap(), l = new WeakMap(), p = new WeakMap(), d = new WeakMap();
379
378
  export {
380
379
  _ as History,
381
- K as I18n,
382
- Q as KalambaSdk,
383
- H as OpenGameError,
384
- ti as OpenGameErrorCode,
385
- U as PlayError,
386
- ni as PlayErrorCode,
387
- E as TimeoutError
380
+ z as I18n,
381
+ Y as KalambaSdk,
382
+ E as RgsError,
383
+ ii as RgsErrorCode,
384
+ b as TimeoutError
388
385
  };