@idosgames/core 0.26.8 → 0.26.9

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.
@@ -1,2 +1,2 @@
1
- 'use strict';var zod=require('zod');function I(r){return [r.text,r.url].filter(e=>!!e).join(" ")}function Z(){return crypto.randomUUID()}var he="idos-host-files",E="files";function D(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error);})}function Pe(r){return r.slice().buffer}var v=class{map=new Map;async read(e){let t=this.map.get(e);return t?t.bytes.slice():null}async write(e,t){return this.map.set(e,{bytes:t.slice(),updatedAt:Date.now()}),true}async remove(e){this.map.delete(e);}async list(e=""){let t=[];for(let[o,s]of this.map)o.startsWith(e)&&t.push({key:o,size:s.bytes.byteLength,updatedAt:s.updatedAt});return t.sort((o,s)=>s.updatedAt-o.updatedAt)}},g=class{db=null;fallback=new v;open(){return this.db||(this.db=(async()=>{try{if(typeof indexedDB>"u")return null;let e=indexedDB.open(he,1);return e.onupgradeneeded=()=>{e.result.objectStoreNames.contains(E)||e.result.createObjectStore(E,{keyPath:"key"});},await D(e)}catch{return null}})()),this.db}async store(e){let t=await this.open();if(!t)return null;try{return t.transaction(E,e).objectStore(E)}catch{return null}}async read(e){let t=await this.store("readonly");if(!t)return this.fallback.read(e);try{let o=await D(t.get(e));return o?new Uint8Array(o.bytes):null}catch{return null}}async write(e,t){let o=await this.store("readwrite");if(!o)return this.fallback.write(e,t);try{let s={key:e,bytes:Pe(t),size:t.byteLength,updatedAt:Date.now()};return await D(o.put(s)),!0}catch{return false}}async remove(e){let t=await this.store("readwrite");if(!t)return this.fallback.remove(e);try{await D(t.delete(e));}catch{}}async list(e=""){let t=await this.store("readonly");if(!t)return this.fallback.list(e);try{let o=e&&typeof IDBKeyRange<"u"?IDBKeyRange.bound(e,e+"\uFFFF"):void 0,s=[];return await new Promise((n,i)=>{let c=t.openCursor(o);c.onerror=()=>i(c.error),c.onsuccess=()=>{let R=c.result;if(!R)return n();let f=R.value;f.key.startsWith(e)&&s.push({key:f.key,size:f.size,updatedAt:f.updatedAt}),R.continue();};}),s.sort((n,i)=>i.updatedAt-n.updatedAt)}catch{return []}}};function k(){return typeof document<"u"&&typeof document.createElement=="function"}function U(r={}){return k()?new Promise(e=>{let t=false,o=document.createElement("input");o.type="file",r.accept?.length&&(o.accept=r.accept.join(",")),o.multiple=r.multiple===true,o.style.display="none";let s=n=>{t||(t=true,o.remove(),e(n));};o.addEventListener("cancel",()=>s([])),o.addEventListener("change",()=>{let n=[...o.files??[]];Promise.all(n.map(async i=>{try{return {bytes:new Uint8Array(await i.arrayBuffer()),name:i.name,mime:i.type||"application/octet-stream"}}catch{return null}})).then(i=>s(i.filter(c=>c!==null)));}),document.body?.appendChild(o),o.click();}):Promise.resolve([])}var ee="idos_device_id",B="idos:platformSignIn:declined:",l="UNAVAILABLE",H=Object.freeze({autoSignIn:false,signIn:false,rewardedAds:false,titleAds:false,storePurchases:false,creditsPayments:true,creditsConfirm:false,cryptoTopUp:false,sceneCaptureRequests:false,share:false,vibration:false,sharedMemory:false,filePicker:false,pushNotifications:false}),d=class{storage;files;visible=true;visibilityListeners=new Set;linkListeners=new Set;constructor(e,t=new v){this.storage=e,this.files=t;}buyProduct(e){return Promise.resolve({ok:false,error:l})}finishPurchase(e,t){return Promise.resolve(false)}pendingPurchases(){return Promise.resolve([])}pickFiles(e){return Promise.resolve([])}requestPushToken(e){return Promise.resolve({error:l})}getDeviceID(){let e=this.storage.getString(ee);return e||(e=this.newDeviceID(),this.storage.setString(ee,e)),e}newDeviceID(){return Z()}setSignInDeclined(e,t){t?this.storage.setString(B+e,"1"):this.storage.remove(B+e);}isSignInDeclined(e){return this.storage.getString(B+e)==="1"}isVisible(){return this.visible}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e);}}onLinkOpened(e){return this.linkListeners.add(e),()=>{this.linkListeners.delete(e);}}emitLink(e){for(let t of [...this.linkListeners])try{t(e);}catch{}}setVisible(e){if(e!==this.visible){this.visible=e;for(let t of [...this.visibilityListeners])try{t(e);}catch{}}}};function M(r){return (typeof r=="number"?[r]:[...r]).map(t=>Math.max(0,Math.round(t)))}var y=class{getString(e){if(typeof localStorage>"u")return null;try{return localStorage.getItem(e)}catch{return null}}setString(e,t){if(!(typeof localStorage>"u"))try{localStorage.setItem(e,t);}catch{}}remove(e){if(!(typeof localStorage>"u"))try{localStorage.removeItem(e);}catch{}}},T=class{map=new Map;getString(e){return this.map.get(e)??null}setString(e,t){this.map.set(e,t);}remove(e){this.map.delete(e);}};function F(){return globalThis.crossOriginIsolated===true&&typeof SharedArrayBuffer<"u"}function L(r,e={}){if(typeof Worker>"u")return null;try{let t=typeof location<"u"?location.href:void 0,o=t?new URL(r,t):new URL(r),s={type:"module",name:e.name};if(o.protocol==="blob:"||o.protocol==="data:"||!t||o.origin===new URL(t).origin)return new Worker(o.href,s);let n=URL.createObjectURL(new Blob([`import ${JSON.stringify(o.href)};`],{type:"text/javascript"}));return new Worker(n,s)}catch{return null}}function m(){return globalThis.Telegram?.WebApp??null}zod.z.enum(["Virtual","Crypto"]).catch("Virtual");zod.z.enum(["Item","VirtualCurrency","CryptoCurrency","RewardedVideoCredit","Purchase","PlatformCredits"]).catch("Item");var a={Unknown:"Unknown",Web:"Web",Android:"Android",Ios:"Ios"};zod.z.enum(["Unknown","Web","Android","Ios"]).catch("Unknown");zod.z.enum(["GooglePlay","AppleAppStore","TelegramStars"]).catch("GooglePlay");zod.z.enum(["TimedEvent","Quest","Leaderboard","CoopEvent","Season","Challenge","ChallengePoints"]).catch("TimedEvent");zod.z.enum(["AlwaysOn","Scheduled","Chained","Triggered","Cyclic","Relative"]).catch("Cyclic");function re(){let r=globalThis,e=r.Capacitor?.getPlatform?.();if(e)return te(e);let t=r.cordova?.platformId;return t?te(t):r.navigator?.userAgent??""?a.Web:a.Unknown}function te(r){let e=r.toLowerCase();return e==="android"?a.Android:e==="ios"?a.Ios:e==="web"?a.Web:a.Unknown}var S=["https://idosgames.com","https://www.idosgames.com"],N="https://platform.idosgames.com",oe=/^[a-z0-9]{8}-preview\.idos\.games$/;function G(r){return r==="localhost"||r==="127.0.0.1"||r==="[::1]"||r.endsWith(".localhost")}function V(){if(typeof window>"u")return false;let r=window.location.hostname.toLowerCase();return oe.test(r)?true:G(r)&&globalThis.__IDOS_PREVIEW__!=null}function h(r){if(typeof window<"u"&&oe.test(window.location.hostname.toLowerCase()))return r===N;if(S.includes(r))return true;if(typeof window>"u"||!G(window.location.hostname))return false;try{return G(new URL(r).hostname)}catch{return false}}var se="IDOS_PLATFORM_WALLET_ACK",ne="PLATFORM_WALLET_UNAVAILABLE",be=5e3,ve=18e4;function He(){if(h(N))return [N];let r=[...S],e=window.location.ancestorOrigins?.[0];return e&&!r.includes(e)&&h(e)&&r.push(e),r}function we(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function u(r,e,t,o={}){let s={ok:false,error:ne,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(s);let n=window.parent;if(!n)return Promise.resolve(s);let i=we(),c=o.answerTimeoutMs??ve;return new Promise(R=>{let f=false,x,W=b=>{f||(f=true,window.removeEventListener("message",X),clearTimeout(x),R(b));},X=b=>{if(!h(b.origin))return;let p=b.data;if(!(!p||p.requestId!==i)){if(p.type===se){clearTimeout(x),x=setTimeout(()=>W({ok:false,error:"TIMEOUT",data:{}}),c);return}p.type===e&&W({ok:p.ok===true,error:typeof p.error=="string"?p.error:void 0,data:p});}};x=setTimeout(()=>W(s),be),window.addEventListener("message",X);for(let b of He())try{n.postMessage({type:r,requestId:i,...t},b);}catch{}})}var K={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},Se=30*6e4;function ie(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(V())return false;let r=window.location.ancestorOrigins?.[0];if(r&&!S.includes(r))try{let e=new URL(r).hostname;if(e!=="localhost"&&e!=="127.0.0.1")return !1}catch{return false}return true}function z(){if(typeof window>"u"||!V())return false;try{return window.self!==window.top&&window.parent===window.top}catch{return false}}async function ae(r){let e=await u(K.request,K.response,{titleID:r,supports:["pgs"]},{answerTimeoutMs:Se}),t=e.data.ticket;if(e.ok&&typeof t=="string"&&t.length>0)return {ticket:t};let o=e.data.code;return e.ok&&typeof o=="string"&&o.length>0?{code:o}:{error:e.error??"no_code"}}var j={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},Ae=15*6e4,Re=/^[a-z0-9]{8}-preview\.idos\.games$/;function A(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !Re.test(window.location.hostname.toLowerCase())}async function le(r){let e=await u(j.request,j.response,{titleID:r.titleID,userID:r.userID,currencyID:r.currencyID,amount:r.amount},{answerTimeoutMs:Ae});return e.ok?{ok:true}:{ok:false,error:e.error}}var Q={request:"IDOS_PLATFORM_AD_REQUEST",response:"IDOS_PLATFORM_AD_RESPONSE"},Ie=5*6e4;function ue(){return A()}async function ce(r){let e=await u(Q.request,Q.response,{titleID:r.titleID,userID:r.userID,requestID:r.requestID,placementID:r.placementID,adUnitID:r.adUnitID??null},{answerTimeoutMs:Ie});return e.ok?{ok:true,via:e.data.via==="unit"?"unit":"ad"}:{ok:false,error:e.error}}var $={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},ke=10*6e4,Te=["DECLINED","NOT_ENOUGH_CREDITS"];function pe(){let r=globalThis.navigator?.userAgent??"";if(!/\biDosGamesApp\/(?:player|studio)\//.test(r))return true;let e=/\biDosGamesPlatform\/(ios|android)\b/.exec(r);return (e?e[1]:/\bAndroid\b/.test(r)?"android":"ios")!=="ios"}function de(){return A()}async function me(r){let e=await u($.request,$.response,{titleID:r.titleID,confirmationID:r.confirmationID},{answerTimeoutMs:ke});return e.ok?{ok:true}:{ok:false,error:e.error}}var ge="IDOS_APP_FRAME_HIDDEN";function P(){return globalThis.navigator??null}function q(){return typeof window<"u"}function fe(){if(!q())return false;try{return window.self!==window.top}catch{return true}}var C=class extends d{id;supports;hiddenBySite=false;documentHidden=false;constructor(e=new y){if(super(e,new g),!q()){this.id="web",this.supports=H;return}let t=P(),o=ie();this.supports=Object.freeze({autoSignIn:o,signIn:o||z(),rewardedAds:ue(),titleAds:false,storePurchases:false,creditsPayments:pe(),creditsConfirm:de(),cryptoTopUp:A(),sceneCaptureRequests:fe(),share:typeof t?.share=="function",vibration:typeof t?.vibrate=="function",sharedMemory:F(),filePicker:k(),pushNotifications:false}),this.id=m()?"telegram":z()?"preview":this.supports.cryptoTopUp?"site":"web",this.watchVisibility(),window.addEventListener("hashchange",()=>this.emitLink(window.location.href));}watchVisibility(){typeof document<"u"&&(this.documentHidden=document.visibilityState==="hidden",document.addEventListener("visibilitychange",()=>{this.documentHidden=document.visibilityState==="hidden",this.update();})),fe()&&window.addEventListener("message",e=>{let t=e.data;!t||t.type!==ge||h(e.origin)&&(this.hiddenBySite=t.hidden===true,this.update());}),this.update();}update(){this.setVisible(!this.documentHidden&&!this.hiddenBySite);}getPlatform(){return m()?.platform??"Web"}getClientPlatform(){return re()}getFullURL(){return q()?window.location.href:""}getStartParameter(){let e=m()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getReferrer(){return typeof document>"u"?null:document.referrer||null}getTelegramInitDataRaw(){let e=m()?.initData;return e&&e.length>0?e:null}getDeviceModel(){return P()?.userAgent||"Web"}getLanguage(){return P()?.language||""}async signIn(e){return this.supports.signIn?ae(e):{error:l}}async showRewardedAd(e){return this.supports.rewardedAds?ce(e):{ok:false,error:l}}async confirmCredits(e){return this.supports.creditsConfirm?me(e):{ok:false,error:l}}async topUp(e){return this.supports.cryptoTopUp?le(e):{ok:false,error:l}}openInvoice(e){let t=m();if(t?.openInvoice){t.openInvoice(e);return}this.openUrl(e);}openUrl(e){let t=m();if(t?.openTelegramLink&&/^https:\/\/t\.me\//i.test(e)){t.openTelegramLink(e);return}q()&&window.open(e,"_blank","noopener");}async share(e){let t=P();if(t?.share)try{return await t.share({url:e.url||void 0,title:e.title,text:e.text}),"shared"}catch(o){if(o?.name==="AbortError")return "cancelled"}return await this.copyText(I(e))?"copied":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){if(typeof document>"u"||typeof Blob>"u")return "unavailable";let t=new Blob([e.bytes],{type:e.mime}),o=P();if(typeof File<"u"&&o?.share&&o.canShare){let n=new File([t],e.name,{type:e.mime});if(o.canShare({files:[n]}))try{return await o.share({files:[n],title:e.name}),"shared"}catch(i){if(i?.name==="AbortError")return "cancelled"}}let s=document.createElement("a");return s.href=URL.createObjectURL(t),s.download=e.name,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(s.href),3e4),"saved"}async copyText(e){let t=P();if(t?.clipboard)try{return await t.clipboard.writeText(e),!0}catch{}return Ce(e)}vibrate(e){try{P()?.vibrate?.(M(e));}catch{}}createWorker(e,t){return L(e,t)}};function Ce(r){if(typeof document>"u"||!document.body)return false;let e=document.createElement("textarea");e.value=r,e.setAttribute("readonly",""),e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let t=false;try{t=document.execCommand("copy");}catch{t=false;}return e.remove(),t}var J=1,ye="__IDOS_HOST__";function Y(){let r=globalThis[ye];return !r||typeof r!="object"||r.protocol!==1||typeof r.post!="function"?null:r}var Oe={signIn:30*6e4,showRewardedAd:5*6e4,confirmCredits:10*6e4,topUp:15*6e4,openInvoice:3e4,openUrl:3e4,share:10*6e4,shareFile:10*6e4,copyText:3e4,vibrate:3e4,buyProduct:30*6e4,finishPurchase:6e4,pendingPurchases:6e4,requestPushToken:10*6e4};function _e(r){switch((r??"").toLowerCase()){case "android":return a.Android;case "ios":return a.Ios;case "web":return a.Web;default:return a.Unknown}}var O=class extends d{id;supports;shell;pending=new Map;nextId=1;constructor(e,t=new y){super(t,new g),this.shell=e,this.id=`native:${e.id??"unknown"}`;let o=e.capabilities??{},s=n=>o[n]??H[n];this.supports=Object.freeze({autoSignIn:s("autoSignIn"),signIn:s("signIn")||s("autoSignIn"),rewardedAds:s("rewardedAds")||s("titleAds"),titleAds:s("titleAds"),storePurchases:s("storePurchases"),creditsPayments:s("creditsPayments"),creditsConfirm:s("creditsConfirm"),cryptoTopUp:s("cryptoTopUp"),sceneCaptureRequests:false,share:s("share"),vibration:s("vibration"),sharedMemory:F(),filePicker:k(),pushNotifications:s("pushNotifications")}),e.receive=n=>this.receive(n),e.info?.visible===false&&this.setVisible(false);}receive(e){let t;try{t=JSON.parse(e);}catch{return}if(!(!t||t.v!==1)){if(t.kind==="response"&&typeof t.id=="string"){let o=this.pending.get(t.id);if(!o)return;this.pending.delete(t.id),clearTimeout(o.timer),o.resolve(t.ok===true?{ok:true,result:t.result??{}}:{ok:false,error:typeof t.error=="string"?t.error:"FAILED"});return}if(t.kind==="event"&&t.name==="visibility"){let o=t.data;typeof o?.visible=="boolean"&&this.setVisible(o.visible);return}if(t.kind==="event"&&t.name==="link"){let o=t.data;typeof o?.url=="string"&&o.url&&this.emitLink(o.url);}}}request(e,t){let o=`r${this.nextId++}`,s={v:1,kind:"request",id:o,method:e,params:t};return new Promise(n=>{let i=setTimeout(()=>{this.pending.delete(o),n({ok:false,error:"TIMEOUT"});},Oe[e]);this.pending.set(o,{resolve:n,timer:i});try{this.shell.post(JSON.stringify(s));}catch{clearTimeout(i),this.pending.delete(o),n({ok:false,error:"UNAVAILABLE"});}})}notify(e,t){this.request(e,t);}newDeviceID(){return this.shell.info?.deviceId||super.newDeviceID()}getPlatform(){return this.getClientPlatform()===a.Ios?"iOS":this.getClientPlatform()}getClientPlatform(){return _e(this.shell.clientPlatform)}getFullURL(){return this.shell.info?.launchUrl??""}getStartParameter(){return this.shell.info?.startParameter??null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return this.shell.info?.deviceModel||this.id}getLanguage(){return this.shell.info?.language||""}async signIn(e){if(!this.supports.signIn)return {error:"UNAVAILABLE"};let t=await this.request("signIn",{titleID:e});if(!t.ok)return {error:t.error};let{code:o,ticket:s}=t.result;return typeof s=="string"&&s.length>0?{ticket:s}:typeof o=="string"&&o.length>0?{code:o}:{error:"no_code"}}async showRewardedAd(e){if(!this.supports.rewardedAds)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("showRewardedAd",e);return t.ok?{ok:true,via:t.result.via==="unit"?"unit":"ad"}:{ok:false,error:t.error}}async confirmCredits(e){if(!this.supports.creditsConfirm)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("confirmCredits",e);return t.ok?{ok:true}:{ok:false,error:t.error}}async topUp(e){if(!this.supports.cryptoTopUp)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("topUp",e);return t.ok?{ok:true}:{ok:false,error:t.error}}openInvoice(e){this.notify("openInvoice",{url:e});}async buyProduct(e){if(!this.supports.storePurchases)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("buyProduct",e);if(!t.ok)return {ok:false,error:t.error};let o=t.result.receipt;return o&&typeof o.receipt=="string"&&o.receipt?{ok:true,receipt:o}:{ok:false,error:"FAILED"}}async finishPurchase(e,t){return this.supports.storePurchases?(await this.request("finishPurchase",{receipt:e,consumable:t})).ok:false}async pendingPurchases(){if(!this.supports.storePurchases)return [];let e=await this.request("pendingPurchases",{});return !e.ok||!Array.isArray(e.result.receipts)?[]:e.result.receipts.filter(t=>t&&typeof t.receipt=="string"&&t.receipt)}async requestPushToken(e){if(!this.supports.pushNotifications)return {error:"UNAVAILABLE"};let t=await this.request("requestPushToken",{prompt:e.prompt===true});if(!t.ok)return {error:t.error};let{token:o,transport:s}=t.result;return typeof o!="string"||!o?{error:"UNAVAILABLE"}:{token:o,transport:s==="Apns"?"Apns":"Fcm"}}openUrl(e){this.notify("openUrl",{url:e});}async share(e){if(!this.supports.share)return await this.copyText(I(e))?"copied":"unavailable";let t=await this.request("share",e);return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){let t=await this.request("shareFile",{name:e.name,mime:e.mime,data:xe(e.bytes)});return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}async copyText(e){return (await this.request("copyText",{text:e})).ok}vibrate(e){this.supports.vibration&&this.notify("vibrate",{pattern:M(e)});}createWorker(e,t){return L(e,t)}};function xe(r){let e="";for(let o=0;o<r.length;o+=32768)e+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(e)}var _=class extends d{id="memory";supports;clientPlatform;deviceId;constructor(e={}){let t="getString"in e?{storage:e}:e;super(t.storage??new T),this.supports=Object.freeze({...H,...t.supports}),this.clientPlatform=t.clientPlatform??a.Web,this.deviceId=t.deviceId??"memory-device";}setVisibleForTest(e){this.setVisible(e);}newDeviceID(){return this.deviceId}getPlatform(){return "Web"}getClientPlatform(){return this.clientPlatform}getFullURL(){return ""}getStartParameter(){return null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return "Memory"}getLanguage(){return ""}async signIn(){return {error:l}}async showRewardedAd(){return {ok:false,error:l}}async confirmCredits(){return {ok:false,error:l}}async topUp(){return {ok:false,error:l}}openInvoice(){}openUrl(){}async share(){return "unavailable"}async shareFile(){return "unavailable"}async copyText(){return false}vibrate(){}createWorker(){return null}};function Ee(){let r=Y();return r?new O(r):typeof window>"u"?new _:new C}
2
- exports.BrowserFileStore=g;exports.BrowserStorage=y;exports.MemoryFileStore=v;exports.MemoryHost=_;exports.MemoryStorage=T;exports.NATIVE_HOST_GLOBAL=ye;exports.NATIVE_HOST_PROTOCOL=J;exports.NativeHost=O;exports.PLATFORM_AD_MESSAGES=Q;exports.PLATFORM_BRIDGE_ACK=se;exports.PLATFORM_CREDITS_CONFIRM_FINAL=Te;exports.PLATFORM_CREDITS_CONFIRM_MESSAGES=$;exports.PLATFORM_ORIGINS=S;exports.PLATFORM_PAGE_UNAVAILABLE=ne;exports.PLATFORM_SIGN_IN_MESSAGES=K;exports.PLATFORM_TOPUP_MESSAGES=j;exports.SITE_FRAME_HIDDEN_MESSAGE=ge;exports.WebHost=C;exports.askPlatformPage=u;exports.createDefaultHost=Ee;exports.getTelegramWebApp=m;exports.isPlatformParentOrigin=h;exports.readNativeHostGlobal=Y;exports.shareFallbackText=I;
1
+ 'use strict';var zod=require('zod');function I(r){return [r.text,r.url].filter(e=>!!e).join(" ")}function re(){return crypto.randomUUID()}var ve="idos-host-files",D="files";function U(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error);})}function we(r){return r.slice().buffer}var v=class{map=new Map;async read(e){let t=this.map.get(e);return t?t.bytes.slice():null}async write(e,t){return this.map.set(e,{bytes:t.slice(),updatedAt:Date.now()}),true}async remove(e){this.map.delete(e);}async list(e=""){let t=[];for(let[o,s]of this.map)o.startsWith(e)&&t.push({key:o,size:s.bytes.byteLength,updatedAt:s.updatedAt});return t.sort((o,s)=>s.updatedAt-o.updatedAt)}},y=class{db=null;fallback=new v;open(){return this.db||(this.db=(async()=>{try{if(typeof indexedDB>"u")return null;let e=indexedDB.open(ve,1);return e.onupgradeneeded=()=>{e.result.objectStoreNames.contains(D)||e.result.createObjectStore(D,{keyPath:"key"});},await U(e)}catch{return null}})()),this.db}async store(e){let t=await this.open();if(!t)return null;try{return t.transaction(D,e).objectStore(D)}catch{return null}}async read(e){let t=await this.store("readonly");if(!t)return this.fallback.read(e);try{let o=await U(t.get(e));return o?new Uint8Array(o.bytes):null}catch{return null}}async write(e,t){let o=await this.store("readwrite");if(!o)return this.fallback.write(e,t);try{let s={key:e,bytes:we(t),size:t.byteLength,updatedAt:Date.now()};return await U(o.put(s)),!0}catch{return false}}async remove(e){let t=await this.store("readwrite");if(!t)return this.fallback.remove(e);try{await U(t.delete(e));}catch{}}async list(e=""){let t=await this.store("readonly");if(!t)return this.fallback.list(e);try{let o=e&&typeof IDBKeyRange<"u"?IDBKeyRange.bound(e,e+"\uFFFF"):void 0,s=[];return await new Promise((n,i)=>{let c=t.openCursor(o);c.onerror=()=>i(c.error),c.onsuccess=()=>{let A=c.result;if(!A)return n();let g=A.value;g.key.startsWith(e)&&s.push({key:g.key,size:g.size,updatedAt:g.updatedAt}),A.continue();};}),s.sort((n,i)=>i.updatedAt-n.updatedAt)}catch{return []}}};function T(){return typeof document<"u"&&typeof document.createElement=="function"}function M(r={}){return T()?new Promise(e=>{let t=false,o=document.createElement("input");o.type="file",r.accept?.length&&(o.accept=r.accept.join(",")),o.multiple=r.multiple===true,o.style.display="none";let s=n=>{t||(t=true,o.remove(),e(n));};o.addEventListener("cancel",()=>s([])),o.addEventListener("change",()=>{let n=[...o.files??[]];Promise.all(n.map(async i=>{try{return {bytes:new Uint8Array(await i.arrayBuffer()),name:i.name,mime:i.type||"application/octet-stream"}}catch{return null}})).then(i=>s(i.filter(c=>c!==null)));}),document.body?.appendChild(o),o.click();}):Promise.resolve([])}var oe="idos_device_id",V="idos:platformSignIn:declined:",a="UNAVAILABLE",w=Object.freeze({autoSignIn:false,signIn:false,rewardedAds:false,titleAds:false,storePurchases:false,creditsPayments:true,creditsConfirm:false,cryptoTopUp:false,tokenTrade:false,sceneCaptureRequests:false,share:false,vibration:false,sharedMemory:false,filePicker:false,pushNotifications:false}),d=class{storage;files;visible=true;visibilityListeners=new Set;linkListeners=new Set;constructor(e,t=new v){this.storage=e,this.files=t;}openTrade(e){return Promise.resolve({ok:false,error:a})}buyProduct(e){return Promise.resolve({ok:false,error:a})}finishPurchase(e,t){return Promise.resolve(false)}pendingPurchases(){return Promise.resolve([])}pickFiles(e){return Promise.resolve([])}requestPushToken(e){return Promise.resolve({error:a})}getDeviceID(){let e=this.storage.getString(oe);return e||(e=this.newDeviceID(),this.storage.setString(oe,e)),e}newDeviceID(){return re()}setSignInDeclined(e,t){t?this.storage.setString(V+e,"1"):this.storage.remove(V+e);}isSignInDeclined(e){return this.storage.getString(V+e)==="1"}isVisible(){return this.visible}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e);}}onLinkOpened(e){return this.linkListeners.add(e),()=>{this.linkListeners.delete(e);}}emitLink(e){for(let t of [...this.linkListeners])try{t(e);}catch{}}setVisible(e){if(e!==this.visible){this.visible=e;for(let t of [...this.visibilityListeners])try{t(e);}catch{}}}};function F(r){return (typeof r=="number"?[r]:[...r]).map(t=>Math.max(0,Math.round(t)))}var h=class{getString(e){if(typeof localStorage>"u")return null;try{return localStorage.getItem(e)}catch{return null}}setString(e,t){if(!(typeof localStorage>"u"))try{localStorage.setItem(e,t);}catch{}}remove(e){if(!(typeof localStorage>"u"))try{localStorage.removeItem(e);}catch{}}},k=class{map=new Map;getString(e){return this.map.get(e)??null}setString(e,t){this.map.set(e,t);}remove(e){this.map.delete(e);}};function L(){return globalThis.crossOriginIsolated===true&&typeof SharedArrayBuffer<"u"}function q(r,e={}){if(typeof Worker>"u")return null;try{let t=typeof location<"u"?location.href:void 0,o=t?new URL(r,t):new URL(r),s={type:"module",name:e.name};if(o.protocol==="blob:"||o.protocol==="data:"||!t||o.origin===new URL(t).origin)return new Worker(o.href,s);let n=URL.createObjectURL(new Blob([`import ${JSON.stringify(o.href)};`],{type:"text/javascript"}));return new Worker(n,s)}catch{return null}}function m(){return globalThis.Telegram?.WebApp??null}zod.z.enum(["Virtual","Crypto"]).catch("Virtual");zod.z.enum(["Item","VirtualCurrency","CryptoCurrency","RewardedVideoCredit","Purchase","PlatformCredits"]).catch("Item");var l={Unknown:"Unknown",Web:"Web",Android:"Android",Ios:"Ios"};zod.z.enum(["Unknown","Web","Android","Ios"]).catch("Unknown");zod.z.enum(["GooglePlay","AppleAppStore","TelegramStars"]).catch("GooglePlay");zod.z.enum(["TimedEvent","Quest","Leaderboard","CoopEvent","Season","Challenge","ChallengePoints"]).catch("TimedEvent");zod.z.enum(["AlwaysOn","Scheduled","Chained","Triggered","Cyclic","Relative"]).catch("Cyclic");function ne(){let r=globalThis,e=r.Capacitor?.getPlatform?.();if(e)return se(e);let t=r.cordova?.platformId;return t?se(t):r.navigator?.userAgent??""?l.Web:l.Unknown}function se(r){let e=r.toLowerCase();return e==="android"?l.Android:e==="ios"?l.Ios:e==="web"?l.Web:l.Unknown}var f=["https://idosgames.com","https://www.idosgames.com"],N="https://platform.idosgames.com",ie=/^[a-z0-9]{8}-preview\.idos\.games$/;function K(r){return r==="localhost"||r==="127.0.0.1"||r==="[::1]"||r.endsWith(".localhost")}function C(){if(typeof window>"u")return false;let r=window.location.hostname.toLowerCase();return ie.test(r)?true:K(r)&&globalThis.__IDOS_PREVIEW__!=null}function P(r){if(typeof window<"u"&&ie.test(window.location.hostname.toLowerCase()))return r===N;if(f.includes(r))return true;if(typeof window>"u"||!K(window.location.hostname))return false;try{return K(new URL(r).hostname)}catch{return false}}var ae="IDOS_PLATFORM_WALLET_ACK",B="PLATFORM_WALLET_UNAVAILABLE",Se=5e3,Re=18e4;function Ae(){if(P(N))return [N];let r=[...f],e=window.location.ancestorOrigins?.[0];return e&&!r.includes(e)&&P(e)&&r.push(e),r}function Ie(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function u(r,e,t,o={}){let s={ok:false,error:B,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(s);let n=window.parent;if(!n)return Promise.resolve(s);let i=Ie(),c=o.answerTimeoutMs??Re;return new Promise(A=>{let g=false,x,W=H=>{g||(g=true,window.removeEventListener("message",te),clearTimeout(x),A(H));},te=H=>{if(!P(H.origin))return;let p=H.data;if(!(!p||p.requestId!==i)){if(p.type===ae){clearTimeout(x),x=setTimeout(()=>W({ok:false,error:"TIMEOUT",data:{}}),c);return}p.type===e&&W({ok:p.ok===true,error:typeof p.error=="string"?p.error:void 0,data:p});}};x=setTimeout(()=>W(s),Se),window.addEventListener("message",te);for(let H of Ae())try{n.postMessage({type:r,requestId:i,...t},H);}catch{}})}var z={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},Te=30*6e4;function le(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(C())return false;let r=window.location.ancestorOrigins?.[0];if(r&&!f.includes(r))try{let e=new URL(r).hostname;if(e!=="localhost"&&e!=="127.0.0.1")return !1}catch{return false}return true}function j(){if(typeof window>"u"||!C())return false;try{return window.self!==window.top&&window.parent===window.top}catch{return false}}async function ue(r){let e=await u(z.request,z.response,{titleID:r,supports:["pgs"]},{answerTimeoutMs:Te}),t=e.data.ticket;if(e.ok&&typeof t=="string"&&t.length>0)return {ticket:t};let o=e.data.code;return e.ok&&typeof o=="string"&&o.length>0?{code:o}:{error:e.error??"no_code"}}var $={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},ke=15*6e4,Ce=/^[a-z0-9]{8}-preview\.idos\.games$/;function R(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !Ce.test(window.location.hostname.toLowerCase())}async function ce(r){let e=await u($.request,$.response,{titleID:r.titleID,userID:r.userID,currencyID:r.currencyID,amount:r.amount},{answerTimeoutMs:ke});return e.ok?{ok:true}:{ok:false,error:e.error}}var Q={request:"IDOS_PLATFORM_AD_REQUEST",response:"IDOS_PLATFORM_AD_RESPONSE"},_e=5*6e4;function pe(){return R()}async function de(r){let e=await u(Q.request,Q.response,{titleID:r.titleID,userID:r.userID,requestID:r.requestID,placementID:r.placementID,adUnitID:r.adUnitID??null},{answerTimeoutMs:_e});return e.ok?{ok:true,via:e.data.via==="unit"?"unit":"ad"}:{ok:false,error:e.error}}var J={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},Oe=10*6e4,Ee=["DECLINED","NOT_ENOUGH_CREDITS"];function me(){let r=globalThis.navigator?.userAgent??"";if(!/\biDosGamesApp\/(?:player|studio)\//.test(r))return true;let e=/\biDosGamesPlatform\/(ios|android)\b/.exec(r);return (e?e[1]:/\bAndroid\b/.test(r)?"android":"ios")!=="ios"}function fe(){return R()}async function ge(r){let e=await u(J.request,J.response,{titleID:r.titleID,confirmationID:r.confirmationID},{answerTimeoutMs:Oe});return e.ok?{ok:true}:{ok:false,error:e.error}}var Y={request:"IDOS_PLATFORM_TRADE_REQUEST",response:"IDOS_PLATFORM_TRADE_RESPONSE"};function ye(r){return typeof r=="string"&&/^\d{1,15}(\.\d{1,18})?$/.test(r)&&Number(r)>0}function X(r,e,t){let o=`trade=${e}${t?`&amount=${encodeURIComponent(t)}`:""}`;return `${f[0]}/app/${encodeURIComponent(r)}?${o}`}async function he(r){let e=await u(Y.request,Y.response,{titleID:r.titleID,side:r.side,amount:r.amount??null});return e.ok?{ok:true}:{ok:false,error:e.error}}var be="IDOS_APP_FRAME_HIDDEN";function b(){return globalThis.navigator??null}function G(){return typeof window<"u"}function Pe(){if(!G())return false;try{return window.self!==window.top}catch{return true}}var _=class extends d{id;supports;hiddenBySite=false;documentHidden=false;constructor(e=new h){if(super(e,new y),!G()){this.id="web",this.supports=w;return}let t=b(),o=le();this.supports=Object.freeze({autoSignIn:o,signIn:o||j(),rewardedAds:pe(),titleAds:false,storePurchases:false,creditsPayments:me(),creditsConfirm:fe(),cryptoTopUp:R(),tokenTrade:!C(),sceneCaptureRequests:Pe(),share:typeof t?.share=="function",vibration:typeof t?.vibrate=="function",sharedMemory:L(),filePicker:T(),pushNotifications:false}),this.id=m()?"telegram":j()?"preview":this.supports.cryptoTopUp?"site":"web",this.watchVisibility(),window.addEventListener("hashchange",()=>this.emitLink(window.location.href));}watchVisibility(){typeof document<"u"&&(this.documentHidden=document.visibilityState==="hidden",document.addEventListener("visibilitychange",()=>{this.documentHidden=document.visibilityState==="hidden",this.update();})),Pe()&&window.addEventListener("message",e=>{let t=e.data;!t||t.type!==be||P(e.origin)&&(this.hiddenBySite=t.hidden===true,this.update());}),this.update();}update(){this.setVisible(!this.documentHidden&&!this.hiddenBySite);}getPlatform(){return m()?.platform??"Web"}getClientPlatform(){return ne()}getFullURL(){return G()?window.location.href:""}getStartParameter(){let e=m()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getReferrer(){return typeof document>"u"?null:document.referrer||null}getTelegramInitDataRaw(){let e=m()?.initData;return e&&e.length>0?e:null}getDeviceModel(){return b()?.userAgent||"Web"}getLanguage(){return b()?.language||""}async signIn(e){return this.supports.signIn?ue(e):{error:a}}async showRewardedAd(e){return this.supports.rewardedAds?de(e):{ok:false,error:a}}async confirmCredits(e){return this.supports.creditsConfirm?ge(e):{ok:false,error:a}}async topUp(e){return this.supports.cryptoTopUp?ce(e):{ok:false,error:a}}async openTrade(e){if(!this.supports.tokenTrade)return {ok:false,error:a};let t=e?.side,o=e?.amount;if(!e?.titleID||t!=="buy"&&t!=="sell"||o!=null&&o!==""&&!ye(o))return {ok:false,error:"BAD_REQUEST"};if(this.supports.cryptoTopUp){let s=await he({titleID:e.titleID,side:t,amount:o||null});return s.ok?{ok:true}:{ok:false,error:s.error===B?a:s.error}}return this.openUrl(X(e.titleID,t,o||null)),{ok:true}}openInvoice(e){let t=m();if(t?.openInvoice){t.openInvoice(e);return}this.openUrl(e);}openUrl(e){let t=m();if(t?.openTelegramLink&&/^https:\/\/t\.me\//i.test(e)){t.openTelegramLink(e);return}G()&&window.open(e,"_blank","noopener");}async share(e){let t=b();if(t?.share)try{return await t.share({url:e.url||void 0,title:e.title,text:e.text}),"shared"}catch(o){if(o?.name==="AbortError")return "cancelled"}return await this.copyText(I(e))?"copied":"unavailable"}pickFiles(e){return M(e)}async shareFile(e){if(typeof document>"u"||typeof Blob>"u")return "unavailable";let t=new Blob([e.bytes],{type:e.mime}),o=b();if(typeof File<"u"&&o?.share&&o.canShare){let n=new File([t],e.name,{type:e.mime});if(o.canShare({files:[n]}))try{return await o.share({files:[n],title:e.name}),"shared"}catch(i){if(i?.name==="AbortError")return "cancelled"}}let s=document.createElement("a");return s.href=URL.createObjectURL(t),s.download=e.name,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(s.href),3e4),"saved"}async copyText(e){let t=b();if(t?.clipboard)try{return await t.clipboard.writeText(e),!0}catch{}return xe(e)}vibrate(e){try{b()?.vibrate?.(F(e));}catch{}}createWorker(e,t){return q(e,t)}};function xe(r){if(typeof document>"u"||!document.body)return false;let e=document.createElement("textarea");e.value=r,e.setAttribute("readonly",""),e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let t=false;try{t=document.execCommand("copy");}catch{t=false;}return e.remove(),t}var Z=1,He="__IDOS_HOST__";function ee(){let r=globalThis[He];return !r||typeof r!="object"||r.protocol!==1||typeof r.post!="function"?null:r}var De={signIn:30*6e4,showRewardedAd:5*6e4,confirmCredits:10*6e4,topUp:15*6e4,openInvoice:3e4,openUrl:3e4,share:10*6e4,shareFile:10*6e4,copyText:3e4,vibrate:3e4,buyProduct:30*6e4,finishPurchase:6e4,pendingPurchases:6e4,requestPushToken:10*6e4};function Ue(r){switch((r??"").toLowerCase()){case "android":return l.Android;case "ios":return l.Ios;case "web":return l.Web;default:return l.Unknown}}var O=class extends d{id;supports;shell;pending=new Map;nextId=1;constructor(e,t=new h){super(t,new y),this.shell=e,this.id=`native:${e.id??"unknown"}`;let o=e.capabilities??{},s=n=>o[n]??w[n];this.supports=Object.freeze({autoSignIn:s("autoSignIn"),signIn:s("signIn")||s("autoSignIn"),rewardedAds:s("rewardedAds")||s("titleAds"),titleAds:s("titleAds"),storePurchases:s("storePurchases"),creditsPayments:s("creditsPayments"),creditsConfirm:s("creditsConfirm"),cryptoTopUp:s("cryptoTopUp"),tokenTrade:false,sceneCaptureRequests:false,share:s("share"),vibration:s("vibration"),sharedMemory:L(),filePicker:T(),pushNotifications:s("pushNotifications")}),e.receive=n=>this.receive(n),e.info?.visible===false&&this.setVisible(false);}receive(e){let t;try{t=JSON.parse(e);}catch{return}if(!(!t||t.v!==1)){if(t.kind==="response"&&typeof t.id=="string"){let o=this.pending.get(t.id);if(!o)return;this.pending.delete(t.id),clearTimeout(o.timer),o.resolve(t.ok===true?{ok:true,result:t.result??{}}:{ok:false,error:typeof t.error=="string"?t.error:"FAILED"});return}if(t.kind==="event"&&t.name==="visibility"){let o=t.data;typeof o?.visible=="boolean"&&this.setVisible(o.visible);return}if(t.kind==="event"&&t.name==="link"){let o=t.data;typeof o?.url=="string"&&o.url&&this.emitLink(o.url);}}}request(e,t){let o=`r${this.nextId++}`,s={v:1,kind:"request",id:o,method:e,params:t};return new Promise(n=>{let i=setTimeout(()=>{this.pending.delete(o),n({ok:false,error:"TIMEOUT"});},De[e]);this.pending.set(o,{resolve:n,timer:i});try{this.shell.post(JSON.stringify(s));}catch{clearTimeout(i),this.pending.delete(o),n({ok:false,error:"UNAVAILABLE"});}})}notify(e,t){this.request(e,t);}newDeviceID(){return this.shell.info?.deviceId||super.newDeviceID()}getPlatform(){return this.getClientPlatform()===l.Ios?"iOS":this.getClientPlatform()}getClientPlatform(){return Ue(this.shell.clientPlatform)}getFullURL(){return this.shell.info?.launchUrl??""}getStartParameter(){return this.shell.info?.startParameter??null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return this.shell.info?.deviceModel||this.id}getLanguage(){return this.shell.info?.language||""}async signIn(e){if(!this.supports.signIn)return {error:"UNAVAILABLE"};let t=await this.request("signIn",{titleID:e});if(!t.ok)return {error:t.error};let{code:o,ticket:s}=t.result;return typeof s=="string"&&s.length>0?{ticket:s}:typeof o=="string"&&o.length>0?{code:o}:{error:"no_code"}}async showRewardedAd(e){if(!this.supports.rewardedAds)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("showRewardedAd",e);return t.ok?{ok:true,via:t.result.via==="unit"?"unit":"ad"}:{ok:false,error:t.error}}async confirmCredits(e){if(!this.supports.creditsConfirm)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("confirmCredits",e);return t.ok?{ok:true}:{ok:false,error:t.error}}async topUp(e){if(!this.supports.cryptoTopUp)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("topUp",e);return t.ok?{ok:true}:{ok:false,error:t.error}}openInvoice(e){this.notify("openInvoice",{url:e});}async buyProduct(e){if(!this.supports.storePurchases)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("buyProduct",e);if(!t.ok)return {ok:false,error:t.error};let o=t.result.receipt;return o&&typeof o.receipt=="string"&&o.receipt?{ok:true,receipt:o}:{ok:false,error:"FAILED"}}async finishPurchase(e,t){return this.supports.storePurchases?(await this.request("finishPurchase",{receipt:e,consumable:t})).ok:false}async pendingPurchases(){if(!this.supports.storePurchases)return [];let e=await this.request("pendingPurchases",{});return !e.ok||!Array.isArray(e.result.receipts)?[]:e.result.receipts.filter(t=>t&&typeof t.receipt=="string"&&t.receipt)}async requestPushToken(e){if(!this.supports.pushNotifications)return {error:"UNAVAILABLE"};let t=await this.request("requestPushToken",{prompt:e.prompt===true});if(!t.ok)return {error:t.error};let{token:o,transport:s}=t.result;return typeof o!="string"||!o?{error:"UNAVAILABLE"}:{token:o,transport:s==="Apns"?"Apns":"Fcm"}}openUrl(e){this.notify("openUrl",{url:e});}async share(e){if(!this.supports.share)return await this.copyText(I(e))?"copied":"unavailable";let t=await this.request("share",e);return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}pickFiles(e){return M(e)}async shareFile(e){let t=await this.request("shareFile",{name:e.name,mime:e.mime,data:Me(e.bytes)});return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}async copyText(e){return (await this.request("copyText",{text:e})).ok}vibrate(e){this.supports.vibration&&this.notify("vibrate",{pattern:F(e)});}createWorker(e,t){return q(e,t)}};function Me(r){let e="";for(let o=0;o<r.length;o+=32768)e+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(e)}var E=class extends d{id="memory";supports;clientPlatform;deviceId;constructor(e={}){let t="getString"in e?{storage:e}:e;super(t.storage??new k),this.supports=Object.freeze({...w,...t.supports}),this.clientPlatform=t.clientPlatform??l.Web,this.deviceId=t.deviceId??"memory-device";}setVisibleForTest(e){this.setVisible(e);}newDeviceID(){return this.deviceId}getPlatform(){return "Web"}getClientPlatform(){return this.clientPlatform}getFullURL(){return ""}getStartParameter(){return null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return "Memory"}getLanguage(){return ""}async signIn(){return {error:a}}async showRewardedAd(){return {ok:false,error:a}}async confirmCredits(){return {ok:false,error:a}}async topUp(){return {ok:false,error:a}}openInvoice(){}openUrl(){}async share(){return "unavailable"}async shareFile(){return "unavailable"}async copyText(){return false}vibrate(){}createWorker(){return null}};function Fe(){let r=ee();return r?new O(r):typeof window>"u"?new E:new _}
2
+ exports.BrowserFileStore=y;exports.BrowserStorage=h;exports.MemoryFileStore=v;exports.MemoryHost=E;exports.MemoryStorage=k;exports.NATIVE_HOST_GLOBAL=He;exports.NATIVE_HOST_PROTOCOL=Z;exports.NativeHost=O;exports.PLATFORM_AD_MESSAGES=Q;exports.PLATFORM_BRIDGE_ACK=ae;exports.PLATFORM_CREDITS_CONFIRM_FINAL=Ee;exports.PLATFORM_CREDITS_CONFIRM_MESSAGES=J;exports.PLATFORM_ORIGINS=f;exports.PLATFORM_PAGE_UNAVAILABLE=B;exports.PLATFORM_SIGN_IN_MESSAGES=z;exports.PLATFORM_TOPUP_MESSAGES=$;exports.PLATFORM_TRADE_MESSAGES=Y;exports.SITE_FRAME_HIDDEN_MESSAGE=be;exports.WebHost=_;exports.askPlatformPage=u;exports.createDefaultHost=Fe;exports.getTelegramWebApp=m;exports.isPlatformParentOrigin=P;exports.platformTradeUrl=X;exports.readNativeHostGlobal=ee;exports.shareFallbackText=I;
@@ -1,5 +1,5 @@
1
- import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, w as HostWorkerOptions, v as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-gNo-pSSn.cjs';
2
- export { H as HostAdProvider, p as HostStore, x as shareFallbackText } from '../GameHost-gNo-pSSn.cjs';
1
+ import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, v as HostTradeRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, x as HostWorkerOptions, w as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-CkI6loS9.cjs';
2
+ export { H as HostAdProvider, p as HostStore, y as shareFallbackText } from '../GameHost-CkI6loS9.cjs';
3
3
  import 'zod';
4
4
 
5
5
  declare abstract class BaseHost implements GameHost {
@@ -23,6 +23,8 @@ declare abstract class BaseHost implements GameHost {
23
23
  abstract showRewardedAd(request: HostAdRequest): Promise<HostAdResult>;
24
24
  abstract confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
25
25
  abstract topUp(request: HostTopUpRequest): Promise<HostResult>;
26
+ /** No trade panel here: every host except the browser's (`WebHost`). */
27
+ openTrade(_request: HostTradeRequest): Promise<HostResult>;
26
28
  /** No store here: every host except a creator's native app. */
27
29
  buyProduct(_request: HostStorePurchaseRequest): Promise<HostStorePurchaseResult>;
28
30
  finishPurchase(_receipt: HostStoreReceipt, _consumable: boolean): Promise<boolean>;
@@ -77,6 +79,7 @@ declare class WebHost extends BaseHost {
77
79
  showRewardedAd(request: HostAdRequest): Promise<HostAdResult>;
78
80
  confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
79
81
  topUp(request: HostTopUpRequest): Promise<HostResult>;
82
+ openTrade(request: HostTradeRequest): Promise<HostResult>;
80
83
  openInvoice(url: string): void;
81
84
  openUrl(url: string): void;
82
85
  share(request: HostShareRequest): Promise<HostShareOutcome>;
@@ -428,6 +431,15 @@ declare const PLATFORM_TOPUP_MESSAGES: {
428
431
  readonly response: "IDOS_PLATFORM_TOPUP_RESPONSE";
429
432
  };
430
433
 
434
+ /** Message names. Shared with the website's `GameWalletLoginBridge`: keep both in step. */
435
+ declare const PLATFORM_TRADE_MESSAGES: {
436
+ readonly request: "IDOS_PLATFORM_TRADE_REQUEST";
437
+ readonly response: "IDOS_PLATFORM_TRADE_RESPONSE";
438
+ };
439
+ type TradeSide = "buy" | "sell";
440
+ /** The game's page on the site with its trade panel open on `side` (and `amount`). */
441
+ declare function platformTradeUrl(titleID: string, side: TradeSide, amount?: string | null): string;
442
+
431
443
  /** Message names. Shared with the website's `GameCreditsConfirmBridge` — keep both in step. */
432
444
  declare const PLATFORM_CREDITS_CONFIRM_MESSAGES: {
433
445
  readonly request: "IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST";
@@ -446,4 +458,4 @@ declare const PLATFORM_AD_MESSAGES: {
446
458
  readonly response: "IDOS_PLATFORM_AD_RESPONSE";
447
459
  };
448
460
 
449
- export { BrowserFileStore, BrowserStorage, GameHost, HostAdRequest, HostAdResult, HostCapabilities, HostCreditsConfirmRequest, HostFile, HostFileOutcome, HostFileStore, HostPickFilesRequest, HostPushToken, HostPushTokenRequest, HostResult, HostShareOutcome, HostShareRequest, HostSignInAnswer, HostStorePurchaseRequest, HostStorePurchaseResult, HostStoreReceipt, HostStoredFileInfo, HostTopUpRequest, HostUnsubscribe, HostWorkerOptions, KeyValueStorage, MemoryFileStore, MemoryHost, type MemoryHostOptions, MemoryStorage, NATIVE_HOST_GLOBAL, NATIVE_HOST_PROTOCOL, type NativeEventMessage, NativeHost, type NativeHostEvents, type NativeHostGlobal, type NativeHostInfo, type NativeHostMethod, type NativeHostMethods, type NativeRequestMessage, type NativeResponseMessage, PLATFORM_AD_MESSAGES, PLATFORM_BRIDGE_ACK, PLATFORM_CREDITS_CONFIRM_FINAL, PLATFORM_CREDITS_CONFIRM_MESSAGES, PLATFORM_ORIGINS, PLATFORM_PAGE_UNAVAILABLE, PLATFORM_SIGN_IN_MESSAGES, PLATFORM_TOPUP_MESSAGES, type PlatformPageAnswer, SITE_FRAME_HIDDEN_MESSAGE, type TelegramInitDataUnsafe, type TelegramWebApp, WebHost, askPlatformPage, createDefaultHost, getTelegramWebApp, isPlatformParentOrigin, readNativeHostGlobal };
461
+ export { BrowserFileStore, BrowserStorage, GameHost, HostAdRequest, HostAdResult, HostCapabilities, HostCreditsConfirmRequest, HostFile, HostFileOutcome, HostFileStore, HostPickFilesRequest, HostPushToken, HostPushTokenRequest, HostResult, HostShareOutcome, HostShareRequest, HostSignInAnswer, HostStorePurchaseRequest, HostStorePurchaseResult, HostStoreReceipt, HostStoredFileInfo, HostTopUpRequest, HostTradeRequest, HostUnsubscribe, HostWorkerOptions, KeyValueStorage, MemoryFileStore, MemoryHost, type MemoryHostOptions, MemoryStorage, NATIVE_HOST_GLOBAL, NATIVE_HOST_PROTOCOL, type NativeEventMessage, NativeHost, type NativeHostEvents, type NativeHostGlobal, type NativeHostInfo, type NativeHostMethod, type NativeHostMethods, type NativeRequestMessage, type NativeResponseMessage, PLATFORM_AD_MESSAGES, PLATFORM_BRIDGE_ACK, PLATFORM_CREDITS_CONFIRM_FINAL, PLATFORM_CREDITS_CONFIRM_MESSAGES, PLATFORM_ORIGINS, PLATFORM_PAGE_UNAVAILABLE, PLATFORM_SIGN_IN_MESSAGES, PLATFORM_TOPUP_MESSAGES, PLATFORM_TRADE_MESSAGES, type PlatformPageAnswer, SITE_FRAME_HIDDEN_MESSAGE, type TelegramInitDataUnsafe, type TelegramWebApp, WebHost, askPlatformPage, createDefaultHost, getTelegramWebApp, isPlatformParentOrigin, platformTradeUrl, readNativeHostGlobal };
@@ -1,5 +1,5 @@
1
- import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, w as HostWorkerOptions, v as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-gNo-pSSn.js';
2
- export { H as HostAdProvider, p as HostStore, x as shareFallbackText } from '../GameHost-gNo-pSSn.js';
1
+ import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, v as HostTradeRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, x as HostWorkerOptions, w as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-CkI6loS9.js';
2
+ export { H as HostAdProvider, p as HostStore, y as shareFallbackText } from '../GameHost-CkI6loS9.js';
3
3
  import 'zod';
4
4
 
5
5
  declare abstract class BaseHost implements GameHost {
@@ -23,6 +23,8 @@ declare abstract class BaseHost implements GameHost {
23
23
  abstract showRewardedAd(request: HostAdRequest): Promise<HostAdResult>;
24
24
  abstract confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
25
25
  abstract topUp(request: HostTopUpRequest): Promise<HostResult>;
26
+ /** No trade panel here: every host except the browser's (`WebHost`). */
27
+ openTrade(_request: HostTradeRequest): Promise<HostResult>;
26
28
  /** No store here: every host except a creator's native app. */
27
29
  buyProduct(_request: HostStorePurchaseRequest): Promise<HostStorePurchaseResult>;
28
30
  finishPurchase(_receipt: HostStoreReceipt, _consumable: boolean): Promise<boolean>;
@@ -77,6 +79,7 @@ declare class WebHost extends BaseHost {
77
79
  showRewardedAd(request: HostAdRequest): Promise<HostAdResult>;
78
80
  confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
79
81
  topUp(request: HostTopUpRequest): Promise<HostResult>;
82
+ openTrade(request: HostTradeRequest): Promise<HostResult>;
80
83
  openInvoice(url: string): void;
81
84
  openUrl(url: string): void;
82
85
  share(request: HostShareRequest): Promise<HostShareOutcome>;
@@ -428,6 +431,15 @@ declare const PLATFORM_TOPUP_MESSAGES: {
428
431
  readonly response: "IDOS_PLATFORM_TOPUP_RESPONSE";
429
432
  };
430
433
 
434
+ /** Message names. Shared with the website's `GameWalletLoginBridge`: keep both in step. */
435
+ declare const PLATFORM_TRADE_MESSAGES: {
436
+ readonly request: "IDOS_PLATFORM_TRADE_REQUEST";
437
+ readonly response: "IDOS_PLATFORM_TRADE_RESPONSE";
438
+ };
439
+ type TradeSide = "buy" | "sell";
440
+ /** The game's page on the site with its trade panel open on `side` (and `amount`). */
441
+ declare function platformTradeUrl(titleID: string, side: TradeSide, amount?: string | null): string;
442
+
431
443
  /** Message names. Shared with the website's `GameCreditsConfirmBridge` — keep both in step. */
432
444
  declare const PLATFORM_CREDITS_CONFIRM_MESSAGES: {
433
445
  readonly request: "IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST";
@@ -446,4 +458,4 @@ declare const PLATFORM_AD_MESSAGES: {
446
458
  readonly response: "IDOS_PLATFORM_AD_RESPONSE";
447
459
  };
448
460
 
449
- export { BrowserFileStore, BrowserStorage, GameHost, HostAdRequest, HostAdResult, HostCapabilities, HostCreditsConfirmRequest, HostFile, HostFileOutcome, HostFileStore, HostPickFilesRequest, HostPushToken, HostPushTokenRequest, HostResult, HostShareOutcome, HostShareRequest, HostSignInAnswer, HostStorePurchaseRequest, HostStorePurchaseResult, HostStoreReceipt, HostStoredFileInfo, HostTopUpRequest, HostUnsubscribe, HostWorkerOptions, KeyValueStorage, MemoryFileStore, MemoryHost, type MemoryHostOptions, MemoryStorage, NATIVE_HOST_GLOBAL, NATIVE_HOST_PROTOCOL, type NativeEventMessage, NativeHost, type NativeHostEvents, type NativeHostGlobal, type NativeHostInfo, type NativeHostMethod, type NativeHostMethods, type NativeRequestMessage, type NativeResponseMessage, PLATFORM_AD_MESSAGES, PLATFORM_BRIDGE_ACK, PLATFORM_CREDITS_CONFIRM_FINAL, PLATFORM_CREDITS_CONFIRM_MESSAGES, PLATFORM_ORIGINS, PLATFORM_PAGE_UNAVAILABLE, PLATFORM_SIGN_IN_MESSAGES, PLATFORM_TOPUP_MESSAGES, type PlatformPageAnswer, SITE_FRAME_HIDDEN_MESSAGE, type TelegramInitDataUnsafe, type TelegramWebApp, WebHost, askPlatformPage, createDefaultHost, getTelegramWebApp, isPlatformParentOrigin, readNativeHostGlobal };
461
+ export { BrowserFileStore, BrowserStorage, GameHost, HostAdRequest, HostAdResult, HostCapabilities, HostCreditsConfirmRequest, HostFile, HostFileOutcome, HostFileStore, HostPickFilesRequest, HostPushToken, HostPushTokenRequest, HostResult, HostShareOutcome, HostShareRequest, HostSignInAnswer, HostStorePurchaseRequest, HostStorePurchaseResult, HostStoreReceipt, HostStoredFileInfo, HostTopUpRequest, HostTradeRequest, HostUnsubscribe, HostWorkerOptions, KeyValueStorage, MemoryFileStore, MemoryHost, type MemoryHostOptions, MemoryStorage, NATIVE_HOST_GLOBAL, NATIVE_HOST_PROTOCOL, type NativeEventMessage, NativeHost, type NativeHostEvents, type NativeHostGlobal, type NativeHostInfo, type NativeHostMethod, type NativeHostMethods, type NativeRequestMessage, type NativeResponseMessage, PLATFORM_AD_MESSAGES, PLATFORM_BRIDGE_ACK, PLATFORM_CREDITS_CONFIRM_FINAL, PLATFORM_CREDITS_CONFIRM_MESSAGES, PLATFORM_ORIGINS, PLATFORM_PAGE_UNAVAILABLE, PLATFORM_SIGN_IN_MESSAGES, PLATFORM_TOPUP_MESSAGES, PLATFORM_TRADE_MESSAGES, type PlatformPageAnswer, SITE_FRAME_HIDDEN_MESSAGE, type TelegramInitDataUnsafe, type TelegramWebApp, WebHost, askPlatformPage, createDefaultHost, getTelegramWebApp, isPlatformParentOrigin, platformTradeUrl, readNativeHostGlobal };
@@ -1 +1 @@
1
- export{c as BrowserFileStore,d as BrowserStorage,b as MemoryFileStore,s as MemoryHost,e as MemoryStorage,v as NATIVE_HOST_GLOBAL,u as NATIVE_HOST_PROTOCOL,x as NativeHost,G as PLATFORM_AD_MESSAGES,B as PLATFORM_BRIDGE_ACK,I as PLATFORM_CREDITS_CONFIRM_FINAL,H as PLATFORM_CREDITS_CONFIRM_MESSAGES,z as PLATFORM_ORIGINS,C as PLATFORM_PAGE_UNAVAILABLE,E as PLATFORM_SIGN_IN_MESSAGES,F as PLATFORM_TOPUP_MESSAGES,J as SITE_FRAME_HIDDEN_MESSAGE,K as WebHost,D as askPlatformPage,L as createDefaultHost,y as getTelegramWebApp,A as isPlatformParentOrigin,w as readNativeHostGlobal,t as shareFallbackText}from'../chunk-S24V5BGG.js';
1
+ export{c as BrowserFileStore,d as BrowserStorage,b as MemoryFileStore,s as MemoryHost,e as MemoryStorage,v as NATIVE_HOST_GLOBAL,u as NATIVE_HOST_PROTOCOL,x as NativeHost,G as PLATFORM_AD_MESSAGES,B as PLATFORM_BRIDGE_ACK,I as PLATFORM_CREDITS_CONFIRM_FINAL,H as PLATFORM_CREDITS_CONFIRM_MESSAGES,z as PLATFORM_ORIGINS,C as PLATFORM_PAGE_UNAVAILABLE,E as PLATFORM_SIGN_IN_MESSAGES,F as PLATFORM_TOPUP_MESSAGES,J as PLATFORM_TRADE_MESSAGES,L as SITE_FRAME_HIDDEN_MESSAGE,M as WebHost,D as askPlatformPage,N as createDefaultHost,y as getTelegramWebApp,A as isPlatformParentOrigin,K as platformTradeUrl,w as readNativeHostGlobal,t as shareFallbackText}from'../chunk-TFBN7PEL.js';
@@ -1,7 +1,7 @@
1
- import { I as IceServer } from '../VoiceController-FdN8yiN8.cjs';
2
- export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-FdN8yiN8.cjs';
1
+ import { I as IceServer } from '../VoiceController-Q7ykZCdU.cjs';
2
+ export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-Q7ykZCdU.cjs';
3
3
  import 'zod';
4
- import '../GameHost-gNo-pSSn.cjs';
4
+ import '../GameHost-CkI6loS9.cjs';
5
5
  import 'decimal.js';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
- import { I as IceServer } from '../VoiceController-BHAlGvEd.js';
2
- export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-BHAlGvEd.js';
1
+ import { I as IceServer } from '../VoiceController-Bwa5nrlo.js';
2
+ export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-Bwa5nrlo.js';
3
3
  import 'zod';
4
- import '../GameHost-gNo-pSSn.js';
4
+ import '../GameHost-CkI6loS9.js';
5
5
  import 'decimal.js';
6
6
 
7
7
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/core",
3
- "version": "0.26.8",
3
+ "version": "0.26.9",
4
4
  "description": "Engine-agnostic core of the IDosGames SDK (transport, auth, cache, services, events).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- import {z as z$1}from'zod';function I(r){return [r.text,r.url].filter(e=>!!e).join(" ")}function Z(){return crypto.randomUUID()}var he="idos-host-files",E="files";function D(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error);})}function Pe(r){return r.slice().buffer}var v=class{map=new Map;async read(e){let t=this.map.get(e);return t?t.bytes.slice():null}async write(e,t){return this.map.set(e,{bytes:t.slice(),updatedAt:Date.now()}),true}async remove(e){this.map.delete(e);}async list(e=""){let t=[];for(let[o,s]of this.map)o.startsWith(e)&&t.push({key:o,size:s.bytes.byteLength,updatedAt:s.updatedAt});return t.sort((o,s)=>s.updatedAt-o.updatedAt)}},g=class{db=null;fallback=new v;open(){return this.db||(this.db=(async()=>{try{if(typeof indexedDB>"u")return null;let e=indexedDB.open(he,1);return e.onupgradeneeded=()=>{e.result.objectStoreNames.contains(E)||e.result.createObjectStore(E,{keyPath:"key"});},await D(e)}catch{return null}})()),this.db}async store(e){let t=await this.open();if(!t)return null;try{return t.transaction(E,e).objectStore(E)}catch{return null}}async read(e){let t=await this.store("readonly");if(!t)return this.fallback.read(e);try{let o=await D(t.get(e));return o?new Uint8Array(o.bytes):null}catch{return null}}async write(e,t){let o=await this.store("readwrite");if(!o)return this.fallback.write(e,t);try{let s={key:e,bytes:Pe(t),size:t.byteLength,updatedAt:Date.now()};return await D(o.put(s)),!0}catch{return false}}async remove(e){let t=await this.store("readwrite");if(!t)return this.fallback.remove(e);try{await D(t.delete(e));}catch{}}async list(e=""){let t=await this.store("readonly");if(!t)return this.fallback.list(e);try{let o=e&&typeof IDBKeyRange<"u"?IDBKeyRange.bound(e,e+"\uFFFF"):void 0,s=[];return await new Promise((n,i)=>{let c=t.openCursor(o);c.onerror=()=>i(c.error),c.onsuccess=()=>{let R=c.result;if(!R)return n();let f=R.value;f.key.startsWith(e)&&s.push({key:f.key,size:f.size,updatedAt:f.updatedAt}),R.continue();};}),s.sort((n,i)=>i.updatedAt-n.updatedAt)}catch{return []}}};function k(){return typeof document<"u"&&typeof document.createElement=="function"}function U(r={}){return k()?new Promise(e=>{let t=false,o=document.createElement("input");o.type="file",r.accept?.length&&(o.accept=r.accept.join(",")),o.multiple=r.multiple===true,o.style.display="none";let s=n=>{t||(t=true,o.remove(),e(n));};o.addEventListener("cancel",()=>s([])),o.addEventListener("change",()=>{let n=[...o.files??[]];Promise.all(n.map(async i=>{try{return {bytes:new Uint8Array(await i.arrayBuffer()),name:i.name,mime:i.type||"application/octet-stream"}}catch{return null}})).then(i=>s(i.filter(c=>c!==null)));}),document.body?.appendChild(o),o.click();}):Promise.resolve([])}var ee="idos_device_id",B="idos:platformSignIn:declined:",l="UNAVAILABLE",H=Object.freeze({autoSignIn:false,signIn:false,rewardedAds:false,titleAds:false,storePurchases:false,creditsPayments:true,creditsConfirm:false,cryptoTopUp:false,sceneCaptureRequests:false,share:false,vibration:false,sharedMemory:false,filePicker:false,pushNotifications:false}),d=class{storage;files;visible=true;visibilityListeners=new Set;linkListeners=new Set;constructor(e,t=new v){this.storage=e,this.files=t;}buyProduct(e){return Promise.resolve({ok:false,error:l})}finishPurchase(e,t){return Promise.resolve(false)}pendingPurchases(){return Promise.resolve([])}pickFiles(e){return Promise.resolve([])}requestPushToken(e){return Promise.resolve({error:l})}getDeviceID(){let e=this.storage.getString(ee);return e||(e=this.newDeviceID(),this.storage.setString(ee,e)),e}newDeviceID(){return Z()}setSignInDeclined(e,t){t?this.storage.setString(B+e,"1"):this.storage.remove(B+e);}isSignInDeclined(e){return this.storage.getString(B+e)==="1"}isVisible(){return this.visible}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e);}}onLinkOpened(e){return this.linkListeners.add(e),()=>{this.linkListeners.delete(e);}}emitLink(e){for(let t of [...this.linkListeners])try{t(e);}catch{}}setVisible(e){if(e!==this.visible){this.visible=e;for(let t of [...this.visibilityListeners])try{t(e);}catch{}}}};function M(r){return (typeof r=="number"?[r]:[...r]).map(t=>Math.max(0,Math.round(t)))}var y=class{getString(e){if(typeof localStorage>"u")return null;try{return localStorage.getItem(e)}catch{return null}}setString(e,t){if(!(typeof localStorage>"u"))try{localStorage.setItem(e,t);}catch{}}remove(e){if(!(typeof localStorage>"u"))try{localStorage.removeItem(e);}catch{}}},T=class{map=new Map;getString(e){return this.map.get(e)??null}setString(e,t){this.map.set(e,t);}remove(e){this.map.delete(e);}};function F(){return globalThis.crossOriginIsolated===true&&typeof SharedArrayBuffer<"u"}function L(r,e={}){if(typeof Worker>"u")return null;try{let t=typeof location<"u"?location.href:void 0,o=t?new URL(r,t):new URL(r),s={type:"module",name:e.name};if(o.protocol==="blob:"||o.protocol==="data:"||!t||o.origin===new URL(t).origin)return new Worker(o.href,s);let n=URL.createObjectURL(new Blob([`import ${JSON.stringify(o.href)};`],{type:"text/javascript"}));return new Worker(n,s)}catch{return null}}function m(){return globalThis.Telegram?.WebApp??null}var Ve={Virtual:"Virtual",Crypto:"Crypto"},Ke=z$1.enum(["Virtual","Crypto"]).catch("Virtual"),ze={Item:"Item",VirtualCurrency:"VirtualCurrency",CryptoCurrency:"CryptoCurrency",RewardedVideoCredit:"RewardedVideoCredit",Purchase:"Purchase",PlatformCredits:"PlatformCredits"},je=z$1.enum(["Item","VirtualCurrency","CryptoCurrency","RewardedVideoCredit","Purchase","PlatformCredits"]).catch("Item"),a={Unknown:"Unknown",Web:"Web",Android:"Android",Ios:"Ios"},Qe=z$1.enum(["Unknown","Web","Android","Ios"]).catch("Unknown"),$e={GooglePlay:"GooglePlay",AppleAppStore:"AppleAppStore"},Je=z$1.enum(["GooglePlay","AppleAppStore","TelegramStars"]).catch("GooglePlay"),Ye={TimedEvent:"TimedEvent",Quest:"Quest",Leaderboard:"Leaderboard",CoopEvent:"CoopEvent",Season:"Season",Challenge:"Challenge",ChallengePoints:"ChallengePoints"},Xe=z$1.enum(["TimedEvent","Quest","Leaderboard","CoopEvent","Season","Challenge","ChallengePoints"]).catch("TimedEvent"),Ze={AlwaysOn:"AlwaysOn",Scheduled:"Scheduled",Chained:"Chained",Triggered:"Triggered",Cyclic:"Cyclic",Relative:"Relative"},et=z$1.enum(["AlwaysOn","Scheduled","Chained","Triggered","Cyclic","Relative"]).catch("Cyclic"),tt={None:"None",Device:"Device",Email:"Email",iDosGames:"iDosGames",Facebook:"Facebook",Google:"Google",Apple:"Apple",GooglePlay:"GooglePlay",Telegram:"Telegram",Wallet:"Wallet"};function re(){let r=globalThis,e=r.Capacitor?.getPlatform?.();if(e)return te(e);let t=r.cordova?.platformId;return t?te(t):r.navigator?.userAgent??""?a.Web:a.Unknown}function te(r){let e=r.toLowerCase();return e==="android"?a.Android:e==="ios"?a.Ios:e==="web"?a.Web:a.Unknown}var S=["https://idosgames.com","https://www.idosgames.com"],N="https://platform.idosgames.com",oe=/^[a-z0-9]{8}-preview\.idos\.games$/;function G(r){return r==="localhost"||r==="127.0.0.1"||r==="[::1]"||r.endsWith(".localhost")}function V(){if(typeof window>"u")return false;let r=window.location.hostname.toLowerCase();return oe.test(r)?true:G(r)&&globalThis.__IDOS_PREVIEW__!=null}function h(r){if(typeof window<"u"&&oe.test(window.location.hostname.toLowerCase()))return r===N;if(S.includes(r))return true;if(typeof window>"u"||!G(window.location.hostname))return false;try{return G(new URL(r).hostname)}catch{return false}}var se="IDOS_PLATFORM_WALLET_ACK",ne="PLATFORM_WALLET_UNAVAILABLE",be=5e3,ve=18e4;function He(){if(h(N))return [N];let r=[...S],e=window.location.ancestorOrigins?.[0];return e&&!r.includes(e)&&h(e)&&r.push(e),r}function we(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function u(r,e,t,o={}){let s={ok:false,error:ne,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(s);let n=window.parent;if(!n)return Promise.resolve(s);let i=we(),c=o.answerTimeoutMs??ve;return new Promise(R=>{let f=false,x,W=b=>{f||(f=true,window.removeEventListener("message",X),clearTimeout(x),R(b));},X=b=>{if(!h(b.origin))return;let p=b.data;if(!(!p||p.requestId!==i)){if(p.type===se){clearTimeout(x),x=setTimeout(()=>W({ok:false,error:"TIMEOUT",data:{}}),c);return}p.type===e&&W({ok:p.ok===true,error:typeof p.error=="string"?p.error:void 0,data:p});}};x=setTimeout(()=>W(s),be),window.addEventListener("message",X);for(let b of He())try{n.postMessage({type:r,requestId:i,...t},b);}catch{}})}var K={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},Se=30*6e4;function ie(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(V())return false;let r=window.location.ancestorOrigins?.[0];if(r&&!S.includes(r))try{let e=new URL(r).hostname;if(e!=="localhost"&&e!=="127.0.0.1")return !1}catch{return false}return true}function z(){if(typeof window>"u"||!V())return false;try{return window.self!==window.top&&window.parent===window.top}catch{return false}}async function ae(r){let e=await u(K.request,K.response,{titleID:r,supports:["pgs"]},{answerTimeoutMs:Se}),t=e.data.ticket;if(e.ok&&typeof t=="string"&&t.length>0)return {ticket:t};let o=e.data.code;return e.ok&&typeof o=="string"&&o.length>0?{code:o}:{error:e.error??"no_code"}}var j={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},Ae=15*6e4,Re=/^[a-z0-9]{8}-preview\.idos\.games$/;function A(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !Re.test(window.location.hostname.toLowerCase())}async function le(r){let e=await u(j.request,j.response,{titleID:r.titleID,userID:r.userID,currencyID:r.currencyID,amount:r.amount},{answerTimeoutMs:Ae});return e.ok?{ok:true}:{ok:false,error:e.error}}var Q={request:"IDOS_PLATFORM_AD_REQUEST",response:"IDOS_PLATFORM_AD_RESPONSE"},Ie=5*6e4;function ue(){return A()}async function ce(r){let e=await u(Q.request,Q.response,{titleID:r.titleID,userID:r.userID,requestID:r.requestID,placementID:r.placementID,adUnitID:r.adUnitID??null},{answerTimeoutMs:Ie});return e.ok?{ok:true,via:e.data.via==="unit"?"unit":"ad"}:{ok:false,error:e.error}}var $={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},ke=10*6e4,Te=["DECLINED","NOT_ENOUGH_CREDITS"];function pe(){let r=globalThis.navigator?.userAgent??"";if(!/\biDosGamesApp\/(?:player|studio)\//.test(r))return true;let e=/\biDosGamesPlatform\/(ios|android)\b/.exec(r);return (e?e[1]:/\bAndroid\b/.test(r)?"android":"ios")!=="ios"}function de(){return A()}async function me(r){let e=await u($.request,$.response,{titleID:r.titleID,confirmationID:r.confirmationID},{answerTimeoutMs:ke});return e.ok?{ok:true}:{ok:false,error:e.error}}var ge="IDOS_APP_FRAME_HIDDEN";function P(){return globalThis.navigator??null}function q(){return typeof window<"u"}function fe(){if(!q())return false;try{return window.self!==window.top}catch{return true}}var C=class extends d{id;supports;hiddenBySite=false;documentHidden=false;constructor(e=new y){if(super(e,new g),!q()){this.id="web",this.supports=H;return}let t=P(),o=ie();this.supports=Object.freeze({autoSignIn:o,signIn:o||z(),rewardedAds:ue(),titleAds:false,storePurchases:false,creditsPayments:pe(),creditsConfirm:de(),cryptoTopUp:A(),sceneCaptureRequests:fe(),share:typeof t?.share=="function",vibration:typeof t?.vibrate=="function",sharedMemory:F(),filePicker:k(),pushNotifications:false}),this.id=m()?"telegram":z()?"preview":this.supports.cryptoTopUp?"site":"web",this.watchVisibility(),window.addEventListener("hashchange",()=>this.emitLink(window.location.href));}watchVisibility(){typeof document<"u"&&(this.documentHidden=document.visibilityState==="hidden",document.addEventListener("visibilitychange",()=>{this.documentHidden=document.visibilityState==="hidden",this.update();})),fe()&&window.addEventListener("message",e=>{let t=e.data;!t||t.type!==ge||h(e.origin)&&(this.hiddenBySite=t.hidden===true,this.update());}),this.update();}update(){this.setVisible(!this.documentHidden&&!this.hiddenBySite);}getPlatform(){return m()?.platform??"Web"}getClientPlatform(){return re()}getFullURL(){return q()?window.location.href:""}getStartParameter(){let e=m()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getReferrer(){return typeof document>"u"?null:document.referrer||null}getTelegramInitDataRaw(){let e=m()?.initData;return e&&e.length>0?e:null}getDeviceModel(){return P()?.userAgent||"Web"}getLanguage(){return P()?.language||""}async signIn(e){return this.supports.signIn?ae(e):{error:l}}async showRewardedAd(e){return this.supports.rewardedAds?ce(e):{ok:false,error:l}}async confirmCredits(e){return this.supports.creditsConfirm?me(e):{ok:false,error:l}}async topUp(e){return this.supports.cryptoTopUp?le(e):{ok:false,error:l}}openInvoice(e){let t=m();if(t?.openInvoice){t.openInvoice(e);return}this.openUrl(e);}openUrl(e){let t=m();if(t?.openTelegramLink&&/^https:\/\/t\.me\//i.test(e)){t.openTelegramLink(e);return}q()&&window.open(e,"_blank","noopener");}async share(e){let t=P();if(t?.share)try{return await t.share({url:e.url||void 0,title:e.title,text:e.text}),"shared"}catch(o){if(o?.name==="AbortError")return "cancelled"}return await this.copyText(I(e))?"copied":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){if(typeof document>"u"||typeof Blob>"u")return "unavailable";let t=new Blob([e.bytes],{type:e.mime}),o=P();if(typeof File<"u"&&o?.share&&o.canShare){let n=new File([t],e.name,{type:e.mime});if(o.canShare({files:[n]}))try{return await o.share({files:[n],title:e.name}),"shared"}catch(i){if(i?.name==="AbortError")return "cancelled"}}let s=document.createElement("a");return s.href=URL.createObjectURL(t),s.download=e.name,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(s.href),3e4),"saved"}async copyText(e){let t=P();if(t?.clipboard)try{return await t.clipboard.writeText(e),!0}catch{}return Ce(e)}vibrate(e){try{P()?.vibrate?.(M(e));}catch{}}createWorker(e,t){return L(e,t)}};function Ce(r){if(typeof document>"u"||!document.body)return false;let e=document.createElement("textarea");e.value=r,e.setAttribute("readonly",""),e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let t=false;try{t=document.execCommand("copy");}catch{t=false;}return e.remove(),t}var J=1,ye="__IDOS_HOST__";function Y(){let r=globalThis[ye];return !r||typeof r!="object"||r.protocol!==1||typeof r.post!="function"?null:r}var Oe={signIn:30*6e4,showRewardedAd:5*6e4,confirmCredits:10*6e4,topUp:15*6e4,openInvoice:3e4,openUrl:3e4,share:10*6e4,shareFile:10*6e4,copyText:3e4,vibrate:3e4,buyProduct:30*6e4,finishPurchase:6e4,pendingPurchases:6e4,requestPushToken:10*6e4};function _e(r){switch((r??"").toLowerCase()){case "android":return a.Android;case "ios":return a.Ios;case "web":return a.Web;default:return a.Unknown}}var O=class extends d{id;supports;shell;pending=new Map;nextId=1;constructor(e,t=new y){super(t,new g),this.shell=e,this.id=`native:${e.id??"unknown"}`;let o=e.capabilities??{},s=n=>o[n]??H[n];this.supports=Object.freeze({autoSignIn:s("autoSignIn"),signIn:s("signIn")||s("autoSignIn"),rewardedAds:s("rewardedAds")||s("titleAds"),titleAds:s("titleAds"),storePurchases:s("storePurchases"),creditsPayments:s("creditsPayments"),creditsConfirm:s("creditsConfirm"),cryptoTopUp:s("cryptoTopUp"),sceneCaptureRequests:false,share:s("share"),vibration:s("vibration"),sharedMemory:F(),filePicker:k(),pushNotifications:s("pushNotifications")}),e.receive=n=>this.receive(n),e.info?.visible===false&&this.setVisible(false);}receive(e){let t;try{t=JSON.parse(e);}catch{return}if(!(!t||t.v!==1)){if(t.kind==="response"&&typeof t.id=="string"){let o=this.pending.get(t.id);if(!o)return;this.pending.delete(t.id),clearTimeout(o.timer),o.resolve(t.ok===true?{ok:true,result:t.result??{}}:{ok:false,error:typeof t.error=="string"?t.error:"FAILED"});return}if(t.kind==="event"&&t.name==="visibility"){let o=t.data;typeof o?.visible=="boolean"&&this.setVisible(o.visible);return}if(t.kind==="event"&&t.name==="link"){let o=t.data;typeof o?.url=="string"&&o.url&&this.emitLink(o.url);}}}request(e,t){let o=`r${this.nextId++}`,s={v:1,kind:"request",id:o,method:e,params:t};return new Promise(n=>{let i=setTimeout(()=>{this.pending.delete(o),n({ok:false,error:"TIMEOUT"});},Oe[e]);this.pending.set(o,{resolve:n,timer:i});try{this.shell.post(JSON.stringify(s));}catch{clearTimeout(i),this.pending.delete(o),n({ok:false,error:"UNAVAILABLE"});}})}notify(e,t){this.request(e,t);}newDeviceID(){return this.shell.info?.deviceId||super.newDeviceID()}getPlatform(){return this.getClientPlatform()===a.Ios?"iOS":this.getClientPlatform()}getClientPlatform(){return _e(this.shell.clientPlatform)}getFullURL(){return this.shell.info?.launchUrl??""}getStartParameter(){return this.shell.info?.startParameter??null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return this.shell.info?.deviceModel||this.id}getLanguage(){return this.shell.info?.language||""}async signIn(e){if(!this.supports.signIn)return {error:"UNAVAILABLE"};let t=await this.request("signIn",{titleID:e});if(!t.ok)return {error:t.error};let{code:o,ticket:s}=t.result;return typeof s=="string"&&s.length>0?{ticket:s}:typeof o=="string"&&o.length>0?{code:o}:{error:"no_code"}}async showRewardedAd(e){if(!this.supports.rewardedAds)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("showRewardedAd",e);return t.ok?{ok:true,via:t.result.via==="unit"?"unit":"ad"}:{ok:false,error:t.error}}async confirmCredits(e){if(!this.supports.creditsConfirm)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("confirmCredits",e);return t.ok?{ok:true}:{ok:false,error:t.error}}async topUp(e){if(!this.supports.cryptoTopUp)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("topUp",e);return t.ok?{ok:true}:{ok:false,error:t.error}}openInvoice(e){this.notify("openInvoice",{url:e});}async buyProduct(e){if(!this.supports.storePurchases)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("buyProduct",e);if(!t.ok)return {ok:false,error:t.error};let o=t.result.receipt;return o&&typeof o.receipt=="string"&&o.receipt?{ok:true,receipt:o}:{ok:false,error:"FAILED"}}async finishPurchase(e,t){return this.supports.storePurchases?(await this.request("finishPurchase",{receipt:e,consumable:t})).ok:false}async pendingPurchases(){if(!this.supports.storePurchases)return [];let e=await this.request("pendingPurchases",{});return !e.ok||!Array.isArray(e.result.receipts)?[]:e.result.receipts.filter(t=>t&&typeof t.receipt=="string"&&t.receipt)}async requestPushToken(e){if(!this.supports.pushNotifications)return {error:"UNAVAILABLE"};let t=await this.request("requestPushToken",{prompt:e.prompt===true});if(!t.ok)return {error:t.error};let{token:o,transport:s}=t.result;return typeof o!="string"||!o?{error:"UNAVAILABLE"}:{token:o,transport:s==="Apns"?"Apns":"Fcm"}}openUrl(e){this.notify("openUrl",{url:e});}async share(e){if(!this.supports.share)return await this.copyText(I(e))?"copied":"unavailable";let t=await this.request("share",e);return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){let t=await this.request("shareFile",{name:e.name,mime:e.mime,data:xe(e.bytes)});return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}async copyText(e){return (await this.request("copyText",{text:e})).ok}vibrate(e){this.supports.vibration&&this.notify("vibrate",{pattern:M(e)});}createWorker(e,t){return L(e,t)}};function xe(r){let e="";for(let o=0;o<r.length;o+=32768)e+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(e)}var _=class extends d{id="memory";supports;clientPlatform;deviceId;constructor(e={}){let t="getString"in e?{storage:e}:e;super(t.storage??new T),this.supports=Object.freeze({...H,...t.supports}),this.clientPlatform=t.clientPlatform??a.Web,this.deviceId=t.deviceId??"memory-device";}setVisibleForTest(e){this.setVisible(e);}newDeviceID(){return this.deviceId}getPlatform(){return "Web"}getClientPlatform(){return this.clientPlatform}getFullURL(){return ""}getStartParameter(){return null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return "Memory"}getLanguage(){return ""}async signIn(){return {error:l}}async showRewardedAd(){return {ok:false,error:l}}async confirmCredits(){return {ok:false,error:l}}async topUp(){return {ok:false,error:l}}openInvoice(){}openUrl(){}async share(){return "unavailable"}async shareFile(){return "unavailable"}async copyText(){return false}vibrate(){}createWorker(){return null}};function Ee(){let r=Y();return r?new O(r):typeof window>"u"?new _:new C}
2
- export{h as A,se as B,ne as C,u as D,K as E,j as F,Q as G,$ as H,Te as I,ge as J,C as K,Ee as L,Z as a,v as b,g as c,y as d,T as e,Ve as f,Ke as g,ze as h,je as i,a as j,Qe as k,$e as l,Je as m,Ye as n,Xe as o,Ze as p,et as q,tt as r,_ as s,I as t,J as u,ye as v,Y as w,O as x,m as y,S as z};