@kalamba/sdk 0.4.0 → 0.5.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.cjs CHANGED
@@ -2,4 +2,4 @@
2
2
  * BSD 3-Clause License
3
3
  * Copyright (c) 2024, Kalamba Games Limited
4
4
  */
5
- "use strict";var P=Object.defineProperty;var A=(r,i,t)=>i in r?P(r,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[i]=t;var f=(r,i,t)=>(A(r,typeof i!="symbol"?i+"":i,t),t),E=(r,i,t)=>{if(!i.has(r))throw TypeError("Cannot "+t)};var o=(r,i,t)=>(E(r,i,"read from private field"),t?t.call(r):i.get(r)),F=(r,i,t)=>{if(i.has(r))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(r):i.set(r,t)},y=(r,i,t,m)=>(E(r,i,"write to private field"),m?m.call(r,t):i.set(r,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function B(r,i){return r*i/100}function w(r,i,t){if(!["string","number"].includes(typeof i))return"NaN";const{locales:m}=r;try{return new Intl.NumberFormat(m,{...t,numberingSystem:"latn",style:"decimal"}).format(+i)}catch{return`${i}`}}const h="XTS";var u=(r=>(r.Currency="Currency",r.Number="Number",r))(u||{}),c=(r=>(r.Coins="Coins",r.Money="Money",r))(c||{});const p={ARSB:{displayAs:"ARS",maximumFractionDigits:2,minimumFractionDigits:2},CHIPS:{maximumFractionDigits:0,minimumFractionDigits:0},BNB:{maximumFractionDigits:6,minimumFractionDigits:6},BUSD:{maximumFractionDigits:4,minimumFractionDigits:4},BTC:{maximumFractionDigits:8,minimumFractionDigits:2},mBTC:{maximumFractionDigits:5,minimumFractionDigits:2},uBTC:{maximumFractionDigits:2,minimumFractionDigits:2},BCH:{maximumFractionDigits:8,minimumFractionDigits:2},mBCH:{maximumFractionDigits:2,minimumFractionDigits:2},ETH:{maximumFractionDigits:8,minimumFractionDigits:2},mETH:{maximumFractionDigits:5,minimumFractionDigits:2},uETH:{maximumFractionDigits:2,minimumFractionDigits:2},SOC:{maximumFractionDigits:8,minimumFractionDigits:2},LTC:{maximumFractionDigits:8,minimumFractionDigits:2},mLTC:{maximumFractionDigits:5,minimumFractionDigits:2},uLTC:{maximumFractionDigits:2,minimumFractionDigits:2},DOG:{maximumFractionDigits:4,minimumFractionDigits:2},USDC:{maximumFractionDigits:4,minimumFractionDigits:4},USDT:{maximumFractionDigits:4,minimumFractionDigits:2},TRX:{maximumFractionDigits:2,minimumFractionDigits:2},TUSD:{maximumFractionDigits:2,minimumFractionDigits:2},DAI:{maximumFractionDigits:2,minimumFractionDigits:2},XMR:{maximumFractionDigits:4,minimumFractionDigits:4},CBET:{maximumFractionDigits:0,minimumFractionDigits:0},kCBET:{maximumFractionDigits:2,minimumFractionDigits:2},SHIB:{maximumFractionDigits:0,minimumFractionDigits:0},kSHIB:{maximumFractionDigits:4,minimumFractionDigits:2},NEO:{maximumFractionDigits:4,minimumFractionDigits:4},BSV:{maximumFractionDigits:4,minimumFractionDigits:4},EOS:{maximumFractionDigits:4,minimumFractionDigits:4},DASH:{maximumFractionDigits:4,minimumFractionDigits:4},XLM:{maximumFractionDigits:2,minimumFractionDigits:2},KRW:{maximumFractionDigits:2,minimumFractionDigits:2},kVND:{maximumFractionDigits:4,minimumFractionDigits:2},kIDR:{maximumFractionDigits:4,minimumFractionDigits:2},RSD:{maximumFractionDigits:2,minimumFractionDigits:2},STAKEGC:{displayAs:"GC",maximumFractionDigits:0,minimumFractionDigits:0},STAKESC:{displayAs:"SC",maximumFractionDigits:2,minimumFractionDigits:2},"FC.":{maximumFractionDigits:2,minimumFractionDigits:2},"GC.":{maximumFractionDigits:2,minimumFractionDigits:2},"SC.":{maximumFractionDigits:2,minimumFractionDigits:2},SVC:{maximumFractionDigits:2,minimumFractionDigits:2},DOT:{maximumFractionDigits:4,minimumFractionDigits:4},SOL:{maximumFractionDigits:4,minimumFractionDigits:4},XRP:{maximumFractionDigits:4,minimumFractionDigits:4},ADA:{maximumFractionDigits:4,minimumFractionDigits:4},TON:{maximumFractionDigits:4,minimumFractionDigits:4},FTN:{maximumFractionDigits:4,minimumFractionDigits:4}};function T(r){return r in p}function I(r){return T(r)?{...p[r],currency:h}:{currency:r}}function R(r,i,t){const m=i.format(+r);return T(t)?m.replace(h,p[t].displayAs??t):m}function k(r,i,t){const{maximumFractionDigits:m,minimumFractionDigits:n}=t.resolvedOptions();return w(r,i,{maximumFractionDigits:m,minimumFractionDigits:n})}function G(r,i,{as:t}={as:"Currency"}){const{canShowCurrency:m,currency:n}=r;return t==="Number"||!m?`${i}`:`${i} ${n}`}function H(r,i,{as:t,from:m}={as:"Currency",from:"Money"},n){if(!["string","number"].includes(typeof i))return"NaN";const{canShowCurrency:s=!0,coinValueInCents:a,currency:C,locales:S}=r;m==="Coins"&&(i=B(+i,a));try{const O=I(C),d=new Intl.NumberFormat(S,{...O,...n,currencyDisplay:"symbol",numberingSystem:"latn",style:"currency"});return t==="Number"||!s?k(r,i,d):R(i,d,C)}catch{return G(r,i,{as:t})}}var e;class N{constructor({config:i}){F(this,e,void 0);y(this,e,i)}formatNumber(i,t){const m={locales:[o(this,e).ui.language]};return w(m,i,t)}formatCurrency(i,t={as:u.Currency,from:c.Money},m){const n=o(this,e).ui.feature.showCurrency,s=o(this,e).api.coinValueInCents,a=o(this,e).api.currency||h,C=[o(this,e).ui.language];return H({canShowCurrency:n,coinValueInCents:s,currency:a,locales:C},i,t,m)}formatCoins(i,t){return this.formatCurrency(i,{as:u.Number,from:c.Coins},t)}formatCoinsWithCurrency(i,t){return this.formatCurrency(i,{as:u.Currency,from:c.Coins},t)}formatMoney(i,t){return this.formatCurrency(i,{as:u.Number,from:c.Money},t)}formatMoneyWithCurrency(i,t){return this.formatCurrency(i,{as:u.Currency,from:c.Money},t)}}e=new WeakMap;const U=()=>{};class b extends Error{constructor(t){super("OpenGameError");f(this,"error");this.name="OpenGameError",this.error=t}}class M extends Error{constructor(t){super("PlayError");f(this,"error");this.name="PlayError",this.error=t}}class x extends Error{constructor(){super("TimeoutError"),this.name="TimeoutError"}}var g,D,l;class ${constructor({messagePort:i}){F(this,g,void 0);F(this,D,void 0);F(this,l,void 0);y(this,l,i),this.on("configured",t=>{y(this,g,t),y(this,D,new N({config:t}))})}get config(){if(!o(this,g))throw new Error("config is not initialized, you must open game first");return o(this,g)}get i18n(){if(!o(this,D))throw new Error("i18n is not initialized, you must open game first");return o(this,D)}request(i,...[t]){return new Promise(m=>{this.on(`${i}Response`,n=>m({type:"response",response:n}),{once:!0}),this.on(`${i}Error`,n=>m({type:"error",error:n}),{once:!0}),this.send(i,t)})}on(i,t,m){const n=function s(a){a.data.message===`kalamba:wrapper:${i}`&&(U("on",a.data.message.replace(/^kalamba:/,""),a.data.payload),t(a.data.payload),m!=null&&m.once&&window.removeEventListener("message",s))};window.addEventListener("message",n)}send(i,...[t]){o(this,l).postMessage({message:`kalamba:sdk:${i}`,payload:t},"*")}async openGame(i){var m;const[,t]=await Promise.all([new Promise(n=>this.on("configured",n,{once:!0})),this.request("openGame",i)]);if(t.type==="response")return t.response;throw((m=t.error)==null?void 0:m.type)==="timeout"?new x:new b(t.error)}async play(i,t={},m="SPIN"){var a;const n={contract:i,extra:t,actionType:m},s=await this.request("play",n);if(s.type==="response")return s.response;throw((a=s.error)==null?void 0:a.type)==="timeout"?new x:new M(s.error)}}g=new WeakMap,D=new WeakMap,l=new WeakMap;exports.KalambaSdk=$;exports.OpenGameError=b;exports.PlayError=M;exports.TimeoutError=x;exports.i18n=N;
5
+ "use strict";var G=Object.defineProperty;var L=(r,i,t)=>i in r?G(r,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[i]=t;var S=(r,i,t)=>(L(r,typeof i!="symbol"?i+"":i,t),t),R=(r,i,t)=>{if(!i.has(r))throw TypeError("Cannot "+t)};var m=(r,i,t)=>(R(r,i,"read from private field"),t?t.call(r):i.get(r)),u=(r,i,t)=>{if(i.has(r))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(r):i.set(r,t)},c=(r,i,t,n)=>(R(r,i,"write to private field"),n?n.call(r,t):i.set(r,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function I(r){const i=Object.prototype.toString.call(r);return r instanceof Date||typeof r=="object"&&i==="[object Date]"?new r.constructor(+r):typeof r=="number"||i==="[object Number]"||typeof r=="string"||i==="[object String]"?new Date(r):new Date(NaN)}function $(r){const i=I(r);return i.setHours(23,59,59,999),i}function _(){return $(Date.now())}function j(r){const i=I(r);return i.setHours(0,0,0,0),i}function q(){return j(Date.now())}const V=3e4;var D,x;class v{constructor(i){u(this,D,void 0);u(this,x,V);c(this,D,i)}buildHeaders(){const i={};return m(this,D).token&&(i.Authorization=`Bearer ${m(this,D).token}`),i}async request(i,t){const n=new URL(i,m(this,D).apiUrl??window.location.origin);return n.search=new URLSearchParams({...t}).toString(),await(await fetch(n,{signal:AbortSignal.timeout(m(this,x)),headers:this.buildHeaders()})).json()}async getRounds(i){return this.request("/rounds",i)}async getRound(i,t){return this.request(`/rounds/${i}`,t)}}D=new WeakMap,x=new WeakMap;const O={limit:100,page:0};var e,l;class A{constructor({config:i}){u(this,e,void 0);u(this,l,void 0);c(this,e,i),c(this,l,new v({apiUrl:i.api.gameHistoryUrl}))}async getRound(i,{pagination:t=O}={}){return m(this,l).getRound(i,{gameCode:m(this,e).api.game,operatorCode:m(this,e).api.brand,username:m(this,e).api.user,...t})}async getLastRound(){return m(this,e).api.lastRoundId?this.getRound(m(this,e).api.lastRoundId):null}async getRounds({searchPeriod:i={fromDateTime:q(),toDateTime:_()},pagination:t=O}={}){const n=m(this,e).api.user.replace(/^user_/,"").replace(new RegExp(`_${m(this,e).api.integration}$`),"");return m(this,l).getRounds({gameCode:m(this,e).api.game,operatorCode:m(this,e).api.integration,username:n,fromDataTime:i.fromDateTime.toISOString(),toDateTime:i.toDateTime.toISOString(),...t})}}e=new WeakMap,l=new WeakMap;function K(r,i){return r*i/100}function M(r,i,t){if(!["string","number"].includes(typeof i))return"NaN";const{locales:n}=r;try{return new Intl.NumberFormat(n,{...t,numberingSystem:"latn",style:"decimal"}).format(+i)}catch{return`${i}`}}const T="XTS";var F=(r=>(r.Currency="Currency",r.Number="Number",r))(F||{}),y=(r=>(r.Coins="Coins",r.Money="Money",r))(y||{});const E={ARSB:{displayAs:"ARS",maximumFractionDigits:2,minimumFractionDigits:2},CHIPS:{maximumFractionDigits:0,minimumFractionDigits:0},BNB:{maximumFractionDigits:6,minimumFractionDigits:6},BUSD:{maximumFractionDigits:4,minimumFractionDigits:4},BTC:{maximumFractionDigits:8,minimumFractionDigits:2},mBTC:{maximumFractionDigits:5,minimumFractionDigits:2},uBTC:{maximumFractionDigits:2,minimumFractionDigits:2},BCH:{maximumFractionDigits:8,minimumFractionDigits:2},mBCH:{maximumFractionDigits:2,minimumFractionDigits:2},ETH:{maximumFractionDigits:8,minimumFractionDigits:2},mETH:{maximumFractionDigits:5,minimumFractionDigits:2},uETH:{maximumFractionDigits:2,minimumFractionDigits:2},SOC:{maximumFractionDigits:8,minimumFractionDigits:2},LTC:{maximumFractionDigits:8,minimumFractionDigits:2},mLTC:{maximumFractionDigits:5,minimumFractionDigits:2},uLTC:{maximumFractionDigits:2,minimumFractionDigits:2},DOG:{maximumFractionDigits:4,minimumFractionDigits:2},USDC:{maximumFractionDigits:4,minimumFractionDigits:4},USDT:{maximumFractionDigits:4,minimumFractionDigits:2},TRX:{maximumFractionDigits:2,minimumFractionDigits:2},TUSD:{maximumFractionDigits:2,minimumFractionDigits:2},DAI:{maximumFractionDigits:2,minimumFractionDigits:2},XMR:{maximumFractionDigits:4,minimumFractionDigits:4},CBET:{maximumFractionDigits:0,minimumFractionDigits:0},kCBET:{maximumFractionDigits:2,minimumFractionDigits:2},SHIB:{maximumFractionDigits:0,minimumFractionDigits:0},kSHIB:{maximumFractionDigits:4,minimumFractionDigits:2},NEO:{maximumFractionDigits:4,minimumFractionDigits:4},BSV:{maximumFractionDigits:4,minimumFractionDigits:4},EOS:{maximumFractionDigits:4,minimumFractionDigits:4},DASH:{maximumFractionDigits:4,minimumFractionDigits:4},XLM:{maximumFractionDigits:2,minimumFractionDigits:2},KRW:{maximumFractionDigits:2,minimumFractionDigits:2},kVND:{maximumFractionDigits:4,minimumFractionDigits:2},kIDR:{maximumFractionDigits:4,minimumFractionDigits:2},RSD:{maximumFractionDigits:2,minimumFractionDigits:2},STAKEGC:{displayAs:"GC",maximumFractionDigits:0,minimumFractionDigits:0},STAKESC:{displayAs:"SC",maximumFractionDigits:2,minimumFractionDigits:2},"FC.":{maximumFractionDigits:2,minimumFractionDigits:2},"GC.":{maximumFractionDigits:2,minimumFractionDigits:2},"SC.":{maximumFractionDigits:2,minimumFractionDigits:2},SVC:{maximumFractionDigits:2,minimumFractionDigits:2},DOT:{maximumFractionDigits:4,minimumFractionDigits:4},SOL:{maximumFractionDigits:4,minimumFractionDigits:4},XRP:{maximumFractionDigits:4,minimumFractionDigits:4},ADA:{maximumFractionDigits:4,minimumFractionDigits:4},TON:{maximumFractionDigits:4,minimumFractionDigits:4},FTN:{maximumFractionDigits:4,minimumFractionDigits:4}};function H(r){return r in E}function X(r){return H(r)?{...E[r],currency:T}:{currency:r}}function z(r,i,t){const n=i.format(+r);return H(t)?n.replace(T,E[t].displayAs??t):n}function W(r,i,t){const{maximumFractionDigits:n,minimumFractionDigits:o}=t.resolvedOptions();return M(r,i,{maximumFractionDigits:n,minimumFractionDigits:o})}function J(r,i,{as:t}={as:"Currency"}){const{canShowCurrency:n,currency:o}=r;return t==="Number"||!n?`${i}`:`${i} ${o}`}function Y(r,i,{as:t,from:n}={as:"Currency",from:"Money"},o){if(!["string","number"].includes(typeof i))return"NaN";const{canShowCurrency:s=!0,coinValueInCents:a,currency:C,locales:b}=r;n==="Coins"&&(i=K(+i,a));try{const k=X(C),N=new Intl.NumberFormat(b,{...k,...o,currencyDisplay:"symbol",numberingSystem:"latn",style:"currency"});return t==="Number"||!s?W(r,i,N):z(i,N,C)}catch{return J(r,i,{as:t})}}var g;class P{constructor({config:i}){u(this,g,void 0);c(this,g,i)}formatNumber(i,t){const n={locales:[m(this,g).ui.language]};return M(n,i,t)}formatCurrency(i,t={as:F.Currency,from:y.Money},n){const o=m(this,g).ui.feature.showCurrency,s=m(this,g).api.coinValueInCents,a=m(this,g).api.currency||T,C=[m(this,g).ui.language];return Y({canShowCurrency:o,coinValueInCents:s,currency:a,locales:C},i,t,n)}formatCoins(i,t){return this.formatCurrency(i,{as:F.Number,from:y.Coins},t)}formatCoinsWithCurrency(i,t){return this.formatCurrency(i,{as:F.Currency,from:y.Coins},t)}formatMoney(i,t){return this.formatCurrency(i,{as:F.Number,from:y.Money},t)}formatMoneyWithCurrency(i,t){return this.formatCurrency(i,{as:F.Currency,from:y.Money},t)}}g=new WeakMap;const Q=()=>{};class U extends Error{constructor(t){super("OpenGameError");S(this,"error");this.name="OpenGameError",this.error=t}}class B extends Error{constructor(t){super("PlayError");S(this,"error");this.name="PlayError",this.error=t}}class w extends Error{constructor(){super("TimeoutError"),this.name="TimeoutError"}}var f,h,p,d;class Z{constructor({messagePort:i}){u(this,f,void 0);u(this,h,void 0);u(this,p,void 0);u(this,d,void 0);c(this,d,i),this.on("configured",t=>{c(this,f,t),c(this,p,new P({config:t})),c(this,h,new A({config:t}))}),this.on("playResponse",t=>{this.config.api.lastRoundId=t.contract.roundId})}get config(){if(!m(this,f))throw new Error("config is not initialized, you must open game first");return m(this,f)}get history(){if(!m(this,h))throw new Error("config is not initialized, you must open game first");return m(this,h)}get i18n(){if(!m(this,p))throw new Error("i18n is not initialized, you must open game first");return m(this,p)}request(i,...[t]){return new Promise(n=>{this.on(`${i}Response`,o=>n({type:"response",response:o}),{once:!0}),this.on(`${i}Error`,o=>n({type:"error",error:o}),{once:!0}),this.send(i,t)})}on(i,t,n){const o=function s(a){a.data.message===`kalamba:wrapper:${i}`&&(Q("on",a.data.message.replace(/^kalamba:/,""),a.data.payload),t(a.data.payload),n!=null&&n.once&&window.removeEventListener("message",s))};window.addEventListener("message",o)}send(i,...[t]){m(this,d).postMessage({message:`kalamba:sdk:${i}`,payload:t},"*")}async openGame(i){var n;const[,t]=await Promise.all([new Promise(o=>this.on("configured",o,{once:!0})),this.request("openGame",i)]);if(t.type==="response")return t.response;throw((n=t.error)==null?void 0:n.type)==="timeout"?new w:new U(t.error)}async play(i,t,n="SPIN"){var a;const o={contract:i,extra:t,actionType:n},s=await this.request("play",o);if(s.type==="response")return s.response;throw((a=s.error)==null?void 0:a.type)==="timeout"?new w:new B(s.error)}}f=new WeakMap,h=new WeakMap,p=new WeakMap,d=new WeakMap;exports.History=A;exports.I18n=P;exports.KalambaSdk=Z;exports.OpenGameError=U;exports.PlayError=B;exports.TimeoutError=w;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { CurrencyFormat } from '@kalamba/common/src/utils/format/currency';
2
+ import { CurrencyNumber } from '@kalamba/common/src/utils/format/currency';
1
3
  import { FormatCurrencyOptions } from '@kalamba/common/src/utils/format/currency';
2
4
 
3
5
  declare interface AddEventListenerOptions_2 {
@@ -39,7 +41,7 @@ export declare type CasinoOnlyMessagePayloadMap = {
39
41
  help: {
40
42
  show?: boolean;
41
43
  };
42
- history: History_2;
44
+ history: History_3;
43
45
  paytable: {
44
46
  show?: boolean;
45
47
  };
@@ -55,6 +57,10 @@ export declare type ContractPlayPayload = {
55
57
  bet: Bet | null;
56
58
  };
57
59
 
60
+ export { CurrencyFormat }
61
+
62
+ export { CurrencyNumber }
63
+
58
64
  export declare type DomainAllowedPayloadMap<P extends DomainPrefix> = DomainToMessagePayloadMap[P];
59
65
 
60
66
  export declare type DomainMessage<P extends DomainPrefix> = keyof DomainAllowedPayloadMap<P>;
@@ -83,9 +89,7 @@ declare type Error_2 = {
83
89
  };
84
90
  export { Error_2 as Error }
85
91
 
86
- export declare type ExtraPlayPayload = {
87
- [key: string]: any;
88
- };
92
+ export { FormatCurrencyOptions }
89
93
 
90
94
  export declare type ForwardToPluginsMessage<P extends PluginDomain> = keyof ForwardToPluginsMessageMap<'sdk'>[P] | keyof ForwardToPluginsMessageMap<'rgs'>[P] | keyof ForwardToPluginsMessageMap<'casino'>[P] | keyof ForwardToPluginsMessageMap<'telemetry'>[P];
91
95
 
@@ -101,12 +105,31 @@ export declare type ForwardToSdkMessage = keyof ToSdkForwardedMessageMap;
101
105
 
102
106
  export declare type ForwardToSdkMessagePayload<M extends ForwardToSdkMessage> = ToSdkForwardedMessageMap[M];
103
107
 
104
- declare type History_2 = {
108
+ export declare interface GetRoundOptions {
109
+ pagination?: Pagination;
110
+ }
111
+
112
+ export declare interface GetRoundsOptions {
113
+ searchPeriod?: SearchPeriod;
114
+ pagination?: Pagination;
115
+ }
116
+
117
+ declare class History_2 {
118
+ #private;
119
+ constructor({ config }: {
120
+ config: SdkConfig;
121
+ });
122
+ getRound(roundId: string, { pagination }?: GetRoundOptions): Promise<unknown>;
123
+ getLastRound(): Promise<unknown>;
124
+ getRounds({ searchPeriod, pagination, }?: GetRoundsOptions): Promise<unknown>;
125
+ }
126
+ export { History_2 as History }
127
+
128
+ declare type History_3 = {
105
129
  source: 'realityCheck' | 'settings' | 'casino';
106
130
  };
107
- export { History_2 as History }
108
131
 
109
- export declare class i18n {
132
+ export declare class I18n {
110
133
  #private;
111
134
  constructor({ config }: {
112
135
  config: SdkConfig;
@@ -125,12 +148,13 @@ export declare class KalambaSdk {
125
148
  messagePort: Window;
126
149
  });
127
150
  get config(): SdkConfig;
128
- get i18n(): i18n;
151
+ get history(): History_2;
152
+ get i18n(): I18n;
129
153
  protected request<M extends DomainMessage<'sdk'>>(message: M, ...[payload]: DomainMessagePayload<'sdk', M> extends never ? [] : [payload: DomainMessagePayload<'sdk', M>]): Promise<RgsResponse<M>>;
130
154
  on<M extends DomainMessage<'wrapper'> | ForwardToSdkMessage>(message: M, listener: (payload: M extends DomainMessage<'wrapper'> ? DomainMessagePayload<'wrapper', M> : M extends ForwardToSdkMessage ? ForwardToSdkMessagePayload<M> : never) => void, options?: AddEventListenerOptions_2): void;
131
155
  send<M extends DomainMessage<'sdk'>>(message: M, ...[payload]: DomainMessagePayload<'sdk', M> extends never ? [] : [DomainMessagePayload<'sdk', M>]): void;
132
156
  openGame(payload: DomainMessagePayload<'sdk', 'openGame'>): Promise<OpenGameResponse>;
133
- play(contract: ContractPlayPayload, extra?: ExtraPlayPayload, actionType?: string): Promise<PlayResponse>;
157
+ play(contract: ContractPlayPayload, extra?: unknown, actionType?: string): Promise<PlayResponse>;
134
158
  }
135
159
 
136
160
  export declare type Message = keyof MessageMap;
@@ -164,10 +188,7 @@ export declare type OpenGameResponse = {
164
188
  contract: {
165
189
  bet: {
166
190
  available: Record<number, number[]>;
167
- default: {
168
- base: number;
169
- multiplier: number;
170
- };
191
+ default: Bet;
171
192
  max: number;
172
193
  last: Bet | null;
173
194
  lastPaid: Bet | null;
@@ -189,6 +210,7 @@ export declare type OpenGameResponse = {
189
210
  }[];
190
211
  version: string;
191
212
  };
213
+ roundId?: string;
192
214
  serverTime: number;
193
215
  sessionId: string;
194
216
  stateType: {
@@ -204,6 +226,11 @@ export declare type OpenGameResponse = {
204
226
  data: unknown;
205
227
  };
206
228
 
229
+ export declare interface Pagination {
230
+ limit: number;
231
+ page: number;
232
+ }
233
+
207
234
  export declare class PlayError extends Error {
208
235
  error: any;
209
236
  constructor(error: any);
@@ -216,7 +243,7 @@ declare type PlayError_2 = {
216
243
 
217
244
  export declare type PlayRequest = {
218
245
  contract: ContractPlayPayload;
219
- extra: ExtraPlayPayload;
246
+ extra?: unknown;
220
247
  actionType: string;
221
248
  };
222
249
 
@@ -230,8 +257,8 @@ export declare type PlayResponse = {
230
257
  coins: number;
231
258
  version: number;
232
259
  };
233
- serverTime: number;
234
260
  roundId: string;
261
+ serverTime: number;
235
262
  stateType: {
236
263
  thisRound: string;
237
264
  nextRound: string;
@@ -382,7 +409,7 @@ export declare type SdkOnlyMessagePayloadMap = {
382
409
  fullscreen: {
383
410
  lock?: OrientationLockType;
384
411
  };
385
- history: History_2;
412
+ history: History_3;
386
413
  loadEnd: never;
387
414
  loadProgress: {
388
415
  progress: number;
@@ -406,6 +433,11 @@ export declare type SdkOnlyMessagePayloadMap = {
406
433
  'telemetry.orientationChange': never;
407
434
  };
408
435
 
436
+ export declare interface SearchPeriod {
437
+ fromDateTime: Date;
438
+ toDateTime: Date;
439
+ }
440
+
409
441
  export declare type Settings = {
410
442
  fastPlay?: boolean;
411
443
  fastPlaySpeed?: number;
@@ -452,7 +484,7 @@ export declare type WrapperOnlyMessagePayloadMap = {
452
484
  close: never;
453
485
  configured: SdkConfig;
454
486
  freeze: never;
455
- history: History_2;
487
+ history: History_3;
456
488
  resume: never;
457
489
  state: WrapperState;
458
490
  suspend: never;
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 = Object.defineProperty;
6
- var M = (r, i, t) => i in r ? b(r, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[i] = t;
7
- var l = (r, i, t) => (M(r, typeof i != "symbol" ? i + "" : i, t), t), d = (r, i, t) => {
5
+ var U = Object.defineProperty;
6
+ var B = (r, i, t) => i in r ? U(r, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[i] = t;
7
+ var w = (r, i, t) => (B(r, typeof i != "symbol" ? i + "" : i, t), t), R = (r, i, t) => {
8
8
  if (!i.has(r))
9
9
  throw TypeError("Cannot " + t);
10
10
  };
11
- var o = (r, i, t) => (d(r, i, "read from private field"), t ? t.call(r) : i.get(r)), F = (r, i, t) => {
11
+ var m = (r, i, t) => (R(r, i, "read from private field"), t ? t.call(r) : i.get(r)), u = (r, i, t) => {
12
12
  if (i.has(r))
13
13
  throw TypeError("Cannot add the same private member more than once");
14
14
  i instanceof WeakSet ? i.add(r) : i.set(r, t);
15
- }, y = (r, i, t, m) => (d(r, i, "write to private field"), m ? m.call(r, t) : i.set(r, t), t);
16
- function A(r, i) {
15
+ }, c = (r, i, t, n) => (R(r, i, "write to private field"), n ? n.call(r, t) : i.set(r, t), t);
16
+ function I(r) {
17
+ const i = Object.prototype.toString.call(r);
18
+ return r instanceof Date || typeof r == "object" && i === "[object Date]" ? new r.constructor(+r) : typeof r == "number" || i === "[object Number]" || typeof r == "string" || i === "[object String]" ? new Date(r) : /* @__PURE__ */ new Date(NaN);
19
+ }
20
+ function P(r) {
21
+ const i = I(r);
22
+ return i.setHours(23, 59, 59, 999), i;
23
+ }
24
+ function k() {
25
+ return P(Date.now());
26
+ }
27
+ function L(r) {
28
+ const i = I(r);
29
+ return i.setHours(0, 0, 0, 0), i;
30
+ }
31
+ function $() {
32
+ return L(Date.now());
33
+ }
34
+ const G = 3e4;
35
+ var D, x;
36
+ class _ {
37
+ constructor(i) {
38
+ u(this, D, void 0);
39
+ u(this, x, G);
40
+ c(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 n = new URL(i, m(this, D).apiUrl ?? window.location.origin);
48
+ return n.search = new URLSearchParams({
49
+ ...t
50
+ }).toString(), await (await fetch(n, {
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 b = {
64
+ limit: 100,
65
+ page: 0
66
+ };
67
+ var s, f;
68
+ class j {
69
+ constructor({
70
+ config: i
71
+ }) {
72
+ u(this, s, void 0);
73
+ u(this, f, void 0);
74
+ c(this, s, i), c(this, f, new _({
75
+ apiUrl: i.api.gameHistoryUrl
76
+ }));
77
+ }
78
+ async getRound(i, {
79
+ pagination: t = b
80
+ } = {}) {
81
+ return m(this, f).getRound(i, {
82
+ gameCode: m(this, s).api.game,
83
+ operatorCode: m(this, s).api.brand,
84
+ username: m(this, s).api.user,
85
+ ...t
86
+ });
87
+ }
88
+ async getLastRound() {
89
+ return m(this, s).api.lastRoundId ? this.getRound(m(this, s).api.lastRoundId) : null;
90
+ }
91
+ async getRounds({
92
+ searchPeriod: i = {
93
+ fromDateTime: $(),
94
+ toDateTime: k()
95
+ },
96
+ pagination: t = b
97
+ } = {}) {
98
+ const n = m(this, s).api.user.replace(/^user_/, "").replace(new RegExp(`_${m(this, s).api.integration}$`), "");
99
+ return m(this, f).getRounds({
100
+ gameCode: m(this, s).api.game,
101
+ operatorCode: m(this, s).api.integration,
102
+ username: n,
103
+ fromDataTime: i.fromDateTime.toISOString(),
104
+ toDateTime: i.toDateTime.toISOString(),
105
+ ...t
106
+ });
107
+ }
108
+ }
109
+ s = new WeakMap(), f = new WeakMap();
110
+ function q(r, i) {
17
111
  return r * i / 100;
18
112
  }
19
- function w(r, i, t) {
113
+ function A(r, i, t) {
20
114
  if (!["string", "number"].includes(typeof i))
21
115
  return "NaN";
22
- const { locales: m } = r;
116
+ const { locales: n } = r;
23
117
  try {
24
- return new Intl.NumberFormat(m, {
118
+ return new Intl.NumberFormat(n, {
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 x = "XTS";
36
- var u = /* @__PURE__ */ ((r) => (r.Currency = "Currency", r.Number = "Number", r))(u || {}), c = /* @__PURE__ */ ((r) => (r.Coins = "Coins", r.Money = "Money", r))(c || {});
37
- const h = {
129
+ const S = "XTS";
130
+ var F = /* @__PURE__ */ ((r) => (r.Currency = "Currency", r.Number = "Number", r))(F || {}), y = /* @__PURE__ */ ((r) => (r.Coins = "Coins", r.Money = "Money", r))(y || {});
131
+ const T = {
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,154 @@ const h = {
128
222
  FTN: { maximumFractionDigits: 4, minimumFractionDigits: 4 }
129
223
  /* eslint-enable sort-keys-fix/sort-keys-fix */
130
224
  };
131
- function T(r) {
132
- return r in h;
225
+ function M(r) {
226
+ return r in T;
133
227
  }
134
- function O(r) {
135
- return T(r) ? {
136
- ...h[r],
137
- currency: x
228
+ function V(r) {
229
+ return M(r) ? {
230
+ ...T[r],
231
+ currency: S
138
232
  } : {
139
233
  currency: r
140
234
  };
141
235
  }
142
- function B(r, i, t) {
143
- const m = i.format(+r);
144
- return T(t) ? m.replace(x, h[t].displayAs ?? t) : m;
236
+ function X(r, i, t) {
237
+ const n = i.format(+r);
238
+ return M(t) ? n.replace(S, T[t].displayAs ?? t) : n;
145
239
  }
146
- function P(r, i, t) {
147
- const { maximumFractionDigits: m, minimumFractionDigits: n } = t.resolvedOptions();
148
- return w(r, i, { maximumFractionDigits: m, minimumFractionDigits: n });
240
+ function v(r, i, t) {
241
+ const { maximumFractionDigits: n, minimumFractionDigits: o } = t.resolvedOptions();
242
+ return A(r, i, { maximumFractionDigits: n, minimumFractionDigits: o });
149
243
  }
150
- function I(r, i, { as: t } = {
244
+ function z(r, i, { as: t } = {
151
245
  as: "Currency"
152
246
  /* Currency */
153
247
  }) {
154
- const { canShowCurrency: m, currency: n } = r;
155
- return t === "Number" || !m ? `${i}` : `${i} ${n}`;
248
+ const { canShowCurrency: n, currency: o } = r;
249
+ return t === "Number" || !n ? `${i}` : `${i} ${o}`;
156
250
  }
157
- function R(r, i, { as: t, from: m } = {
251
+ function K(r, i, { as: t, from: n } = {
158
252
  as: "Currency",
159
253
  from: "Money"
160
254
  /* Money */
161
- }, n) {
255
+ }, o) {
162
256
  if (!["string", "number"].includes(typeof i))
163
257
  return "NaN";
164
- const { canShowCurrency: s = !0, coinValueInCents: a, currency: f, locales: p } = r;
165
- m === "Coins" && (i = A(+i, a));
258
+ const { canShowCurrency: e = !0, coinValueInCents: a, currency: C, locales: E } = r;
259
+ n === "Coins" && (i = q(+i, a));
166
260
  try {
167
- const N = O(f), S = new Intl.NumberFormat(p, {
168
- ...N,
169
- ...n,
261
+ const H = V(C), N = new Intl.NumberFormat(E, {
262
+ ...H,
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 ? P(r, i, S) : B(i, S, f);
270
+ return t === "Number" || !e ? v(r, i, N) : X(i, N, C);
177
271
  } catch {
178
- return I(r, i, { as: t });
272
+ return z(r, i, { as: t });
179
273
  }
180
274
  }
181
- var e;
182
- class k {
275
+ var g;
276
+ class W {
183
277
  constructor({ config: i }) {
184
- F(this, e, void 0);
185
- y(this, e, i);
278
+ u(this, g, void 0);
279
+ c(this, g, i);
186
280
  }
187
281
  formatNumber(i, t) {
188
- const m = { locales: [o(this, e).ui.language] };
189
- return w(m, i, t);
282
+ const n = { locales: [m(this, g).ui.language] };
283
+ return A(n, i, t);
190
284
  }
191
- formatCurrency(i, t = { as: u.Currency, from: c.Money }, m) {
192
- const n = o(this, e).ui.feature.showCurrency, s = o(this, e).api.coinValueInCents, a = o(this, e).api.currency || x, f = [o(this, e).ui.language];
193
- return R({
194
- canShowCurrency: n,
195
- coinValueInCents: s,
285
+ formatCurrency(i, t = { as: F.Currency, from: y.Money }, n) {
286
+ const o = m(this, g).ui.feature.showCurrency, e = m(this, g).api.coinValueInCents, a = m(this, g).api.currency || S, C = [m(this, g).ui.language];
287
+ return K({
288
+ canShowCurrency: o,
289
+ coinValueInCents: e,
196
290
  currency: a,
197
- locales: f
198
- }, i, t, m);
291
+ locales: C
292
+ }, i, t, n);
199
293
  }
200
294
  formatCoins(i, t) {
201
- return this.formatCurrency(i, { as: u.Number, from: c.Coins }, t);
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: u.Currency, from: c.Coins }, t);
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: u.Number, from: c.Money }, t);
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: u.Currency, from: c.Money }, t);
304
+ return this.formatCurrency(i, { as: F.Currency, from: y.Money }, t);
211
305
  }
212
306
  }
213
- e = new WeakMap();
214
- const G = () => {
307
+ g = new WeakMap();
308
+ const J = () => {
215
309
  };
216
- class H extends Error {
310
+ class Y extends Error {
217
311
  constructor(t) {
218
312
  super("OpenGameError");
219
- l(this, "error");
313
+ w(this, "error");
220
314
  this.name = "OpenGameError", this.error = t;
221
315
  }
222
316
  }
223
- class U extends Error {
317
+ class Q extends Error {
224
318
  constructor(t) {
225
319
  super("PlayError");
226
- l(this, "error");
320
+ w(this, "error");
227
321
  this.name = "PlayError", this.error = t;
228
322
  }
229
323
  }
230
- class E extends Error {
324
+ class O extends Error {
231
325
  constructor() {
232
326
  super("TimeoutError"), this.name = "TimeoutError";
233
327
  }
234
328
  }
235
- var g, D, C;
236
- class L {
329
+ var l, h, p, d;
330
+ class ii {
237
331
  constructor({ messagePort: i }) {
238
- F(this, g, void 0);
239
- F(this, D, void 0);
240
- F(this, C, void 0);
241
- y(this, C, i), this.on("configured", (t) => {
242
- y(this, g, t), y(this, D, new k({ config: t }));
332
+ u(this, l, void 0);
333
+ u(this, h, void 0);
334
+ u(this, p, void 0);
335
+ u(this, d, void 0);
336
+ c(this, d, i), this.on("configured", (t) => {
337
+ c(this, l, t), c(this, p, new W({ config: t })), c(this, h, new j({ config: t }));
338
+ }), this.on("playResponse", (t) => {
339
+ this.config.api.lastRoundId = t.contract.roundId;
243
340
  });
244
341
  }
245
342
  get config() {
246
- if (!o(this, g))
343
+ if (!m(this, l))
344
+ throw new Error("config is not initialized, you must open game first");
345
+ return m(this, l);
346
+ }
347
+ get history() {
348
+ if (!m(this, h))
247
349
  throw new Error("config is not initialized, you must open game first");
248
- return o(this, g);
350
+ return m(this, h);
249
351
  }
250
352
  get i18n() {
251
- if (!o(this, D))
353
+ if (!m(this, p))
252
354
  throw new Error("i18n is not initialized, you must open game first");
253
- return o(this, D);
355
+ return m(this, p);
254
356
  }
255
357
  request(i, ...[t]) {
256
- return new Promise((m) => {
257
- this.on(`${i}Response`, (n) => m({ type: "response", response: n }), {
358
+ return new Promise((n) => {
359
+ this.on(`${i}Response`, (o) => n({ type: "response", response: o }), {
258
360
  once: !0
259
- }), this.on(`${i}Error`, (n) => m({ type: "error", error: n }), { once: !0 }), this.send(i, t);
361
+ }), this.on(`${i}Error`, (o) => n({ type: "error", error: o }), { once: !0 }), this.send(i, t);
260
362
  });
261
363
  }
262
- on(i, t, m) {
263
- const n = function s(a) {
264
- a.data.message === `kalamba:wrapper:${i}` && (G("on", a.data.message.replace(/^kalamba:/, ""), a.data.payload), t(a.data.payload), m != null && m.once && window.removeEventListener("message", s));
364
+ on(i, t, n) {
365
+ const o = function e(a) {
366
+ a.data.message === `kalamba:wrapper:${i}` && (J("on", a.data.message.replace(/^kalamba:/, ""), a.data.payload), t(a.data.payload), n != null && n.once && window.removeEventListener("message", e));
265
367
  };
266
- window.addEventListener("message", n);
368
+ window.addEventListener("message", o);
267
369
  }
268
370
  // TODO error messages
269
371
  send(i, ...[t]) {
270
- o(this, C).postMessage(
372
+ m(this, d).postMessage(
271
373
  {
272
374
  message: `kalamba:sdk:${i}`,
273
375
  payload: t
@@ -276,29 +378,30 @@ class L {
276
378
  );
277
379
  }
278
380
  async openGame(i) {
279
- var m;
381
+ var n;
280
382
  const [, t] = await Promise.all([
281
383
  // TODO: return promise from call to this.on if listener is not provided
282
- new Promise((n) => this.on("configured", n, { once: !0 })),
384
+ new Promise((o) => this.on("configured", o, { once: !0 })),
283
385
  this.request("openGame", i)
284
386
  ]);
285
387
  if (t.type === "response")
286
388
  return t.response;
287
- throw ((m = t.error) == null ? void 0 : m.type) === "timeout" ? new E() : new H(t.error);
389
+ throw ((n = t.error) == null ? void 0 : n.type) === "timeout" ? new O() : new Y(t.error);
288
390
  }
289
- async play(i, t = {}, m = "SPIN") {
391
+ async play(i, t, n = "SPIN") {
290
392
  var a;
291
- const n = { contract: i, extra: t, actionType: m }, s = await this.request("play", n);
292
- if (s.type === "response")
293
- return s.response;
294
- throw ((a = s.error) == null ? void 0 : a.type) === "timeout" ? new E() : new U(s.error);
393
+ const o = { contract: i, extra: t, actionType: n }, e = await this.request("play", o);
394
+ if (e.type === "response")
395
+ return e.response;
396
+ throw ((a = e.error) == null ? void 0 : a.type) === "timeout" ? new O() : new Q(e.error);
295
397
  }
296
398
  }
297
- g = new WeakMap(), D = new WeakMap(), C = new WeakMap();
399
+ l = new WeakMap(), h = new WeakMap(), p = new WeakMap(), d = new WeakMap();
298
400
  export {
299
- L as KalambaSdk,
300
- H as OpenGameError,
301
- U as PlayError,
302
- E as TimeoutError,
303
- k as i18n
401
+ j as History,
402
+ W as I18n,
403
+ ii as KalambaSdk,
404
+ Y as OpenGameError,
405
+ Q as PlayError,
406
+ O as TimeoutError
304
407
  };