@idosgames/core 0.26.5 → 0.26.6
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/GameHost-xACJW0x5.d.cts +406 -0
- package/dist/GameHost-xACJW0x5.d.ts +406 -0
- package/dist/{VoiceController-Bq2Chg3Z.d.ts → VoiceController-BMXi4MNo.d.ts} +73 -112
- package/dist/{VoiceController-Cno4whMf.d.cts → VoiceController-BWb8NTp2.d.cts} +73 -112
- package/dist/chunk-YZ32MQXQ.js +2 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +11 -29
- package/dist/index.d.ts +11 -29
- package/dist/index.js +2 -2
- package/dist/platform/index.cjs +2 -2
- package/dist/platform/index.d.cts +449 -2
- package/dist/platform/index.d.ts +449 -2
- package/dist/platform/index.js +1 -1
- package/dist/realtime/index.d.cts +3 -3
- package/dist/realtime/index.d.ts +3 -3
- package/package.json +1 -1
- package/dist/PlatformAdapter-DU_8HalI.d.cts +0 -34
- package/dist/PlatformAdapter-DU_8HalI.d.ts +0 -34
- package/dist/chunk-4VTWZXB4.js +0 -2
- package/dist/index-BCY6F_tf.d.cts +0 -197
- package/dist/index-YNXpT5ol.d.ts +0 -197
package/dist/platform/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var f=class{getString(e){if(typeof localStorage>"u")return null;try{return localStorage.getItem(e)}catch{return null}}setString(e,r){if(!(typeof localStorage>"u"))try{localStorage.setItem(e,r);}catch{}}remove(e){if(!(typeof localStorage>"u"))try{localStorage.removeItem(e);}catch{}}},g=class{map=new Map;getString(e){return this.map.get(e)??null}setString(e,r){this.map.set(e,r);}remove(e){this.map.delete(e);}};function n(){return globalThis.Telegram?.WebApp??null}function M(){return crypto.randomUUID()}var v="idos_device_id",w=class{storage;constructor(e=new f){this.storage=e;}getPlatform(){return n()?.platform??"Web"}getFullURL(){return typeof location<"u"?location.href:""}getStartParameter(){let e=n()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getReferrer(){if(typeof document>"u")return null;let e=document.referrer;return e&&e.length>0?e:null}getTelegramInitDataRaw(){let e=n()?.initData;return e&&e.length>0?e:null}getDeviceID(){let e=this.storage.getString(v);return e||(e=M(),this.storage.setString(v,e)),e}getDeviceModel(){return typeof navigator<"u"&&navigator.userAgent?navigator.userAgent:"Web"}shareLink(e){let r=n();if(r?.openTelegramLink){r.openTelegramLink(e);return}typeof window<"u"&&window.open(e,"_blank");}openInvoice(e){let r=n();if(r?.openInvoice){r.openInvoice(e);return}typeof window<"u"&&window.open(e,"_blank");}async showAd(e){let r=globalThis;typeof r.showAd=="function"&&await r.showAd(e);}async copyToClipboard(e){typeof navigator<"u"&&navigator.clipboard&&await navigator.clipboard.writeText(e);}};var h="idos_device_id",P=class{storage;constructor(e=new g){this.storage=e;}getPlatform(){return "Web"}getFullURL(){return ""}getStartParameter(){return null}getTelegramInitDataRaw(){return null}getDeviceID(){let e=this.storage.getString(h);return e||(e="noop-device",this.storage.setString(h,e)),e}getDeviceModel(){return "Noop"}shareLink(){}openInvoice(){}async showAd(){}async copyToClipboard(){}};var s=["https://idosgames.com","https://www.idosgames.com"],u="https://platform.idosgames.com",U=/^[a-z0-9]{8}-preview\.idos\.games$/;function I(t){return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t.endsWith(".localhost")}function x(){if(typeof window>"u")return false;let t=window.location.hostname.toLowerCase();return U.test(t)?true:I(t)&&globalThis.__IDOS_PREVIEW__!=null}function p(t){if(typeof window<"u"&&U.test(window.location.hostname.toLowerCase()))return t===u;if(s.includes(t))return true;if(typeof window>"u"||!I(window.location.hostname))return false;try{return I(new URL(t).hostname)}catch{return false}}var L="IDOS_PLATFORM_WALLET_ACK",C="PLATFORM_WALLET_UNAVAILABLE",N=5e3,F=18e4;function W(){if(p(u))return [u];let t=[...s],e=window.location.ancestorOrigins?.[0];return e&&!t.includes(e)&&p(e)&&t.push(e),t}function G(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function i(t,e,r,l={}){let c={ok:false,error:C,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(c);let y=window.parent;if(!y)return Promise.resolve(c);let E=G(),k=l.answerTimeoutMs??F;return new Promise(b=>{let D=false,m,d=a=>{D||(D=true,window.removeEventListener("message",O),clearTimeout(m),b(a));},O=a=>{if(!p(a.origin))return;let o=a.data;if(!(!o||o.requestId!==E)){if(o.type===L){clearTimeout(m),m=setTimeout(()=>d({ok:false,error:"TIMEOUT",data:{}}),k);return}o.type===e&&d({ok:o.ok===true,error:typeof o.error=="string"?o.error:void 0,data:o});}};m=setTimeout(()=>d(c),N),window.addEventListener("message",O);for(let a of W())try{y.postMessage({type:t,requestId:E,...r},a);}catch{}})}var S={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},V=15*6e4,K=/^[a-z0-9]{8}-preview\.idos\.games$/;function T(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !K.test(window.location.hostname.toLowerCase())}async function q(t){let e=await i(S.request,S.response,{titleID:t.titleID,userID:t.userID,currencyID:t.currencyID,amount:t.amount},{answerTimeoutMs:V});return e.ok?{ok:true}:{ok:false,error:e.error}}var _={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},B=30*6e4,A="idos:platformSignIn:declined:";function H(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(x())return false;let t=window.location.ancestorOrigins?.[0];if(t&&!s.includes(t))try{let e=new URL(t).hostname;if(e!=="localhost"&&e!=="127.0.0.1")return !1}catch{return false}return true}async function $(t){let e=await i(_.request,_.response,{titleID:t,supports:["pgs"]},{answerTimeoutMs:B}),r=e.data.ticket;if(e.ok&&typeof r=="string"&&r.length>0)return {ticket:r};let l=e.data.code;return e.ok&&typeof l=="string"&&l.length>0?{code:l}:{error:e.error??"no_code"}}function Q(t){try{window.localStorage.setItem(A+t,"1");}catch{}}function Y(t){try{window.localStorage.removeItem(A+t);}catch{}}function z(t){try{return window.localStorage.getItem(A+t)==="1"}catch{return false}}var R={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},X=10*6e4;function j(){let t=globalThis.navigator?.userAgent??"";if(!/\biDosGamesApp\/(?:player|studio)\//.test(t))return true;let e=/\biDosGamesPlatform\/(ios|android)\b/.exec(t);return (e?e[1]:/\bAndroid\b/.test(t)?"android":"ios")!=="ios"}function J(){return T()}async function Z(t){let e=await i(R.request,R.response,{titleID:t.titleID,confirmationID:t.confirmationID},{answerTimeoutMs:X});return e.ok?{ok:true}:{ok:false,error:e.error}}
|
|
2
|
-
exports.
|
|
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"]).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,2 +1,449 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
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-xACJW0x5.cjs';
|
|
2
|
+
export { H as HostAdProvider, p as HostStore, x as shareFallbackText } from '../GameHost-xACJW0x5.cjs';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
declare abstract class BaseHost implements GameHost {
|
|
6
|
+
abstract readonly id: string;
|
|
7
|
+
abstract readonly supports: HostCapabilities;
|
|
8
|
+
readonly storage: KeyValueStorage;
|
|
9
|
+
readonly files: HostFileStore;
|
|
10
|
+
private visible;
|
|
11
|
+
private readonly visibilityListeners;
|
|
12
|
+
private readonly linkListeners;
|
|
13
|
+
protected constructor(storage: KeyValueStorage, files?: HostFileStore);
|
|
14
|
+
abstract getPlatform(): string;
|
|
15
|
+
abstract getClientPlatform(): ClientPlatform;
|
|
16
|
+
abstract getFullURL(): string;
|
|
17
|
+
abstract getStartParameter(): string | null;
|
|
18
|
+
abstract getReferrer(): string | null;
|
|
19
|
+
abstract getTelegramInitDataRaw(): string | null;
|
|
20
|
+
abstract getDeviceModel(): string;
|
|
21
|
+
abstract getLanguage(): string;
|
|
22
|
+
abstract signIn(titleID: string): Promise<HostSignInAnswer>;
|
|
23
|
+
abstract showRewardedAd(request: HostAdRequest): Promise<HostAdResult>;
|
|
24
|
+
abstract confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
|
|
25
|
+
abstract topUp(request: HostTopUpRequest): Promise<HostResult>;
|
|
26
|
+
/** No store here: every host except a creator's native app. */
|
|
27
|
+
buyProduct(_request: HostStorePurchaseRequest): Promise<HostStorePurchaseResult>;
|
|
28
|
+
finishPurchase(_receipt: HostStoreReceipt, _consumable: boolean): Promise<boolean>;
|
|
29
|
+
pendingPurchases(): Promise<HostStoreReceipt[]>;
|
|
30
|
+
/** No file picker here (tests, the server); browser-engine hosts override it. */
|
|
31
|
+
pickFiles(_request?: HostPickFilesRequest): Promise<HostFile[]>;
|
|
32
|
+
/** No device push here: every host except a native app with its own push service. */
|
|
33
|
+
requestPushToken(_request: HostPushTokenRequest): Promise<HostPushToken>;
|
|
34
|
+
abstract openInvoice(url: string): void;
|
|
35
|
+
abstract openUrl(url: string): void;
|
|
36
|
+
abstract share(request: HostShareRequest): Promise<HostShareOutcome>;
|
|
37
|
+
abstract shareFile(file: HostFile): Promise<HostFileOutcome>;
|
|
38
|
+
abstract copyText(text: string): Promise<boolean>;
|
|
39
|
+
abstract vibrate(pattern: number | readonly number[]): void;
|
|
40
|
+
abstract createWorker(url: string, options?: HostWorkerOptions): Worker | null;
|
|
41
|
+
getDeviceID(): string;
|
|
42
|
+
/** A fresh installation id (a host that knows its own overrides this). */
|
|
43
|
+
protected newDeviceID(): string;
|
|
44
|
+
setSignInDeclined(titleID: string, declined: boolean): void;
|
|
45
|
+
isSignInDeclined(titleID: string): boolean;
|
|
46
|
+
isVisible(): boolean;
|
|
47
|
+
onVisibilityChange(listener: (visible: boolean) => void): HostUnsubscribe;
|
|
48
|
+
onLinkOpened(listener: (url: string) => void): HostUnsubscribe;
|
|
49
|
+
/** The implementation reports a link that opened the running game. */
|
|
50
|
+
protected emitLink(url: string): void;
|
|
51
|
+
/** The implementation reports a change; listeners hear only real changes. */
|
|
52
|
+
protected setVisible(visible: boolean): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Sent by the site's feed to the game's frame when the card goes behind another tab or comes back
|
|
57
|
+
* (`GameFeedCard` in iDosGames_com: `{ type, hidden }`). Shared with the site: keep in step.
|
|
58
|
+
*/
|
|
59
|
+
declare const SITE_FRAME_HIDDEN_MESSAGE = "IDOS_APP_FRAME_HIDDEN";
|
|
60
|
+
declare class WebHost extends BaseHost {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly supports: HostCapabilities;
|
|
63
|
+
private hiddenBySite;
|
|
64
|
+
private documentHidden;
|
|
65
|
+
constructor(storage?: KeyValueStorage);
|
|
66
|
+
private watchVisibility;
|
|
67
|
+
private update;
|
|
68
|
+
getPlatform(): string;
|
|
69
|
+
getClientPlatform(): ClientPlatform;
|
|
70
|
+
getFullURL(): string;
|
|
71
|
+
getStartParameter(): string | null;
|
|
72
|
+
getReferrer(): string | null;
|
|
73
|
+
getTelegramInitDataRaw(): string | null;
|
|
74
|
+
getDeviceModel(): string;
|
|
75
|
+
getLanguage(): string;
|
|
76
|
+
signIn(titleID: string): Promise<HostSignInAnswer>;
|
|
77
|
+
showRewardedAd(request: HostAdRequest): Promise<HostAdResult>;
|
|
78
|
+
confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
|
|
79
|
+
topUp(request: HostTopUpRequest): Promise<HostResult>;
|
|
80
|
+
openInvoice(url: string): void;
|
|
81
|
+
openUrl(url: string): void;
|
|
82
|
+
share(request: HostShareRequest): Promise<HostShareOutcome>;
|
|
83
|
+
pickFiles(request?: HostPickFilesRequest): Promise<HostFile[]>;
|
|
84
|
+
shareFile(file: HostFile): Promise<HostFileOutcome>;
|
|
85
|
+
copyText(text: string): Promise<boolean>;
|
|
86
|
+
vibrate(pattern: number | readonly number[]): void;
|
|
87
|
+
createWorker(url: string, options?: HostWorkerOptions): Worker | null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Protocol version this SDK speaks. */
|
|
91
|
+
declare const NATIVE_HOST_PROTOCOL = 1;
|
|
92
|
+
/** Name of the global the native shell installs. */
|
|
93
|
+
declare const NATIVE_HOST_GLOBAL = "__IDOS_HOST__";
|
|
94
|
+
/** Launch facts the shell knows before the game starts. */
|
|
95
|
+
interface NativeHostInfo {
|
|
96
|
+
deviceId?: string;
|
|
97
|
+
deviceModel?: string;
|
|
98
|
+
language?: string;
|
|
99
|
+
launchUrl?: string;
|
|
100
|
+
startParameter?: string | null;
|
|
101
|
+
/** The game starts visible unless the shell says otherwise. */
|
|
102
|
+
visible?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/** What the shell installs at `globalThis.__IDOS_HOST__`. */
|
|
105
|
+
interface NativeHostGlobal {
|
|
106
|
+
protocol: number;
|
|
107
|
+
id?: string;
|
|
108
|
+
clientPlatform?: string;
|
|
109
|
+
capabilities?: Partial<Record<keyof HostCapabilities, boolean>>;
|
|
110
|
+
info?: NativeHostInfo;
|
|
111
|
+
post(message: string): void;
|
|
112
|
+
/** Set by the SDK: the shell calls it with each message. */
|
|
113
|
+
receive?: (message: string) => void;
|
|
114
|
+
}
|
|
115
|
+
/** Request methods: params → result. */
|
|
116
|
+
interface NativeHostMethods {
|
|
117
|
+
signIn: {
|
|
118
|
+
params: {
|
|
119
|
+
titleID: string;
|
|
120
|
+
};
|
|
121
|
+
result: {
|
|
122
|
+
code?: string;
|
|
123
|
+
ticket?: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
showRewardedAd: {
|
|
127
|
+
params: HostAdRequest;
|
|
128
|
+
result: {
|
|
129
|
+
via?: "ad" | "unit";
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
confirmCredits: {
|
|
133
|
+
params: HostCreditsConfirmRequest;
|
|
134
|
+
result: Record<string, never>;
|
|
135
|
+
};
|
|
136
|
+
topUp: {
|
|
137
|
+
params: HostTopUpRequest;
|
|
138
|
+
result: Record<string, never>;
|
|
139
|
+
};
|
|
140
|
+
openInvoice: {
|
|
141
|
+
params: {
|
|
142
|
+
url: string;
|
|
143
|
+
};
|
|
144
|
+
result: Record<string, never>;
|
|
145
|
+
};
|
|
146
|
+
openUrl: {
|
|
147
|
+
params: {
|
|
148
|
+
url: string;
|
|
149
|
+
};
|
|
150
|
+
result: Record<string, never>;
|
|
151
|
+
};
|
|
152
|
+
share: {
|
|
153
|
+
params: HostShareRequest;
|
|
154
|
+
result: {
|
|
155
|
+
outcome: HostShareOutcome;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
/** The file's bytes travel as base64 (`data`). */
|
|
159
|
+
shareFile: {
|
|
160
|
+
params: {
|
|
161
|
+
name: string;
|
|
162
|
+
mime: string;
|
|
163
|
+
data: string;
|
|
164
|
+
};
|
|
165
|
+
result: {
|
|
166
|
+
outcome: HostFileOutcome;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
copyText: {
|
|
170
|
+
params: {
|
|
171
|
+
text: string;
|
|
172
|
+
};
|
|
173
|
+
result: Record<string, never>;
|
|
174
|
+
};
|
|
175
|
+
vibrate: {
|
|
176
|
+
params: {
|
|
177
|
+
pattern: number[];
|
|
178
|
+
};
|
|
179
|
+
result: Record<string, never>;
|
|
180
|
+
};
|
|
181
|
+
/** The store's purchase window (`storePurchases`). Errors: `CANCELLED`, `PENDING`, `ALREADY_OWNED`, … */
|
|
182
|
+
buyProduct: {
|
|
183
|
+
params: HostStorePurchaseRequest;
|
|
184
|
+
result: {
|
|
185
|
+
receipt: HostStoreReceipt;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
/** Consume / acknowledge after the server granted. */
|
|
189
|
+
finishPurchase: {
|
|
190
|
+
params: {
|
|
191
|
+
receipt: HostStoreReceipt;
|
|
192
|
+
consumable: boolean;
|
|
193
|
+
};
|
|
194
|
+
result: Record<string, never>;
|
|
195
|
+
};
|
|
196
|
+
/** Paid, not closed purchases. */
|
|
197
|
+
pendingPurchases: {
|
|
198
|
+
params: Record<string, never>;
|
|
199
|
+
result: {
|
|
200
|
+
receipts: HostStoreReceipt[];
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* The device's push token (`pushNotifications`); `prompt` asks for permission. Errors: `NOT_GRANTED`, `BLOCKED`,
|
|
205
|
+
* `UNAVAILABLE`.
|
|
206
|
+
*/
|
|
207
|
+
requestPushToken: {
|
|
208
|
+
params: {
|
|
209
|
+
prompt: boolean;
|
|
210
|
+
};
|
|
211
|
+
result: {
|
|
212
|
+
token: string;
|
|
213
|
+
transport?: "Fcm" | "Apns";
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
type NativeHostMethod = keyof NativeHostMethods;
|
|
218
|
+
/** Events the shell sends. */
|
|
219
|
+
interface NativeHostEvents {
|
|
220
|
+
/** The game went on / off screen (app to background, the feed scrolled away). */
|
|
221
|
+
visibility: {
|
|
222
|
+
visible: boolean;
|
|
223
|
+
};
|
|
224
|
+
/** A link opened the running game (an app link, a notification's link). */
|
|
225
|
+
link: {
|
|
226
|
+
url: string;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
interface NativeRequestMessage {
|
|
230
|
+
v: number;
|
|
231
|
+
kind: "request";
|
|
232
|
+
id: string;
|
|
233
|
+
method: NativeHostMethod;
|
|
234
|
+
params: unknown;
|
|
235
|
+
}
|
|
236
|
+
interface NativeResponseMessage {
|
|
237
|
+
v: number;
|
|
238
|
+
kind: "response";
|
|
239
|
+
id: string;
|
|
240
|
+
ok: boolean;
|
|
241
|
+
result?: unknown;
|
|
242
|
+
error?: string;
|
|
243
|
+
}
|
|
244
|
+
interface NativeEventMessage {
|
|
245
|
+
v: number;
|
|
246
|
+
kind: "event";
|
|
247
|
+
name: string;
|
|
248
|
+
data?: unknown;
|
|
249
|
+
}
|
|
250
|
+
/** The shell's global, when this page runs inside a native shell of a protocol this SDK speaks. */
|
|
251
|
+
declare function readNativeHostGlobal(): NativeHostGlobal | null;
|
|
252
|
+
|
|
253
|
+
declare class NativeHost extends BaseHost {
|
|
254
|
+
readonly id: string;
|
|
255
|
+
readonly supports: HostCapabilities;
|
|
256
|
+
private readonly shell;
|
|
257
|
+
private readonly pending;
|
|
258
|
+
private nextId;
|
|
259
|
+
constructor(shell: NativeHostGlobal, storage?: KeyValueStorage);
|
|
260
|
+
private receive;
|
|
261
|
+
/** One request to the shell. Never rejects. */
|
|
262
|
+
private request;
|
|
263
|
+
/** Fire and forget: the answer only matters to the shell. */
|
|
264
|
+
private notify;
|
|
265
|
+
protected newDeviceID(): string;
|
|
266
|
+
getPlatform(): string;
|
|
267
|
+
getClientPlatform(): ClientPlatform;
|
|
268
|
+
getFullURL(): string;
|
|
269
|
+
getStartParameter(): string | null;
|
|
270
|
+
getReferrer(): string | null;
|
|
271
|
+
getTelegramInitDataRaw(): string | null;
|
|
272
|
+
getDeviceModel(): string;
|
|
273
|
+
getLanguage(): string;
|
|
274
|
+
signIn(titleID: string): Promise<HostSignInAnswer>;
|
|
275
|
+
showRewardedAd(request: HostAdRequest): Promise<HostAdResult>;
|
|
276
|
+
confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
|
|
277
|
+
topUp(request: HostTopUpRequest): Promise<HostResult>;
|
|
278
|
+
openInvoice(url: string): void;
|
|
279
|
+
buyProduct(request: HostStorePurchaseRequest): Promise<HostStorePurchaseResult>;
|
|
280
|
+
finishPurchase(receipt: HostStoreReceipt, consumable: boolean): Promise<boolean>;
|
|
281
|
+
pendingPurchases(): Promise<HostStoreReceipt[]>;
|
|
282
|
+
requestPushToken(request: HostPushTokenRequest): Promise<HostPushToken>;
|
|
283
|
+
openUrl(url: string): void;
|
|
284
|
+
share(request: HostShareRequest): Promise<HostShareOutcome>;
|
|
285
|
+
pickFiles(request?: HostPickFilesRequest): Promise<HostFile[]>;
|
|
286
|
+
shareFile(file: HostFile): Promise<HostFileOutcome>;
|
|
287
|
+
copyText(text: string): Promise<boolean>;
|
|
288
|
+
vibrate(pattern: number | readonly number[]): void;
|
|
289
|
+
createWorker(url: string, options?: HostWorkerOptions): Worker | null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
interface MemoryHostOptions {
|
|
293
|
+
storage?: KeyValueStorage;
|
|
294
|
+
supports?: Partial<HostCapabilities>;
|
|
295
|
+
clientPlatform?: ClientPlatform;
|
|
296
|
+
deviceId?: string;
|
|
297
|
+
}
|
|
298
|
+
declare class MemoryHost extends BaseHost {
|
|
299
|
+
readonly id = "memory";
|
|
300
|
+
readonly supports: HostCapabilities;
|
|
301
|
+
private readonly clientPlatform;
|
|
302
|
+
private readonly deviceId;
|
|
303
|
+
constructor(options?: MemoryHostOptions | KeyValueStorage);
|
|
304
|
+
/** Lets a test drive the pause signal. */
|
|
305
|
+
setVisibleForTest(visible: boolean): void;
|
|
306
|
+
protected newDeviceID(): string;
|
|
307
|
+
getPlatform(): string;
|
|
308
|
+
getClientPlatform(): ClientPlatform;
|
|
309
|
+
getFullURL(): string;
|
|
310
|
+
getStartParameter(): string | null;
|
|
311
|
+
getReferrer(): string | null;
|
|
312
|
+
getTelegramInitDataRaw(): string | null;
|
|
313
|
+
getDeviceModel(): string;
|
|
314
|
+
getLanguage(): string;
|
|
315
|
+
signIn(): Promise<HostSignInAnswer>;
|
|
316
|
+
showRewardedAd(): Promise<HostAdResult>;
|
|
317
|
+
confirmCredits(): Promise<HostResult>;
|
|
318
|
+
topUp(): Promise<HostResult>;
|
|
319
|
+
openInvoice(): void;
|
|
320
|
+
openUrl(): void;
|
|
321
|
+
share(): Promise<HostShareOutcome>;
|
|
322
|
+
shareFile(): Promise<HostFileOutcome>;
|
|
323
|
+
copyText(): Promise<boolean>;
|
|
324
|
+
vibrate(): void;
|
|
325
|
+
createWorker(): Worker | null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* The host of this page, decided once when the client is created: a native shell that installed
|
|
330
|
+
* `__IDOS_HOST__` → `NativeHost`; a browser → `WebHost`; neither (SSR, a worker) → `MemoryHost`.
|
|
331
|
+
*/
|
|
332
|
+
declare function createDefaultHost(): GameHost;
|
|
333
|
+
|
|
334
|
+
/** localStorage-backed key/value store (replaces Unity PlayerPrefs). Fails soft. */
|
|
335
|
+
declare class BrowserStorage implements KeyValueStorage {
|
|
336
|
+
getString(key: string): string | null;
|
|
337
|
+
setString(key: string, value: string): void;
|
|
338
|
+
remove(key: string): void;
|
|
339
|
+
}
|
|
340
|
+
/** In-memory store for tests / SSR. */
|
|
341
|
+
declare class MemoryStorage implements KeyValueStorage {
|
|
342
|
+
private readonly map;
|
|
343
|
+
getString(key: string): string | null;
|
|
344
|
+
setString(key: string, value: string): void;
|
|
345
|
+
remove(key: string): void;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Files in memory: tests, the server, a page without IndexedDB. */
|
|
349
|
+
declare class MemoryFileStore implements HostFileStore {
|
|
350
|
+
private readonly map;
|
|
351
|
+
read(key: string): Promise<Uint8Array | null>;
|
|
352
|
+
write(key: string, bytes: Uint8Array): Promise<boolean>;
|
|
353
|
+
remove(key: string): Promise<void>;
|
|
354
|
+
list(prefix?: string): Promise<HostStoredFileInfo[]>;
|
|
355
|
+
}
|
|
356
|
+
/** Files in IndexedDB of this address; memory when IndexedDB is not there or refuses. */
|
|
357
|
+
declare class BrowserFileStore implements HostFileStore {
|
|
358
|
+
private db;
|
|
359
|
+
private readonly fallback;
|
|
360
|
+
private open;
|
|
361
|
+
private store;
|
|
362
|
+
read(key: string): Promise<Uint8Array | null>;
|
|
363
|
+
write(key: string, bytes: Uint8Array): Promise<boolean>;
|
|
364
|
+
remove(key: string): Promise<void>;
|
|
365
|
+
list(prefix?: string): Promise<HostStoredFileInfo[]>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
interface TelegramInitDataUnsafe {
|
|
369
|
+
start_param?: string;
|
|
370
|
+
[key: string]: unknown;
|
|
371
|
+
}
|
|
372
|
+
interface TelegramWebApp {
|
|
373
|
+
platform?: string;
|
|
374
|
+
initData?: string;
|
|
375
|
+
initDataUnsafe?: TelegramInitDataUnsafe;
|
|
376
|
+
openTelegramLink?: (url: string) => void;
|
|
377
|
+
openInvoice?: (url: string, callback?: (status: string) => void) => void;
|
|
378
|
+
}
|
|
379
|
+
declare function getTelegramWebApp(): TelegramWebApp | null;
|
|
380
|
+
|
|
381
|
+
declare const PLATFORM_ORIGINS: readonly string[];
|
|
382
|
+
/**
|
|
383
|
+
* Is `origin` the platform page that framed us — including the local stand?
|
|
384
|
+
*
|
|
385
|
+
* The local allowance is deliberately symmetric: a localhost parent is accepted ONLY while this
|
|
386
|
+
* game is itself served from localhost. A shipped build lives on `{id}.idos.games`, so it answers
|
|
387
|
+
* nothing but the real site — a page on the player's own machine cannot ask it for anything.
|
|
388
|
+
* That is what makes the allowance safe enough to ship, instead of a build-time flag that has to
|
|
389
|
+
* survive four bundlers.
|
|
390
|
+
*
|
|
391
|
+
* On the AI Coder's preview host the parent is the dashboard, and only the dashboard.
|
|
392
|
+
*
|
|
393
|
+
* Use this for bridges a game exposes to its parent. A bridge that must NOT widen its existing
|
|
394
|
+
* behaviour (the wallet's) keeps checking {@link PLATFORM_ORIGINS} directly.
|
|
395
|
+
*/
|
|
396
|
+
declare function isPlatformParentOrigin(origin: string): boolean;
|
|
397
|
+
|
|
398
|
+
/** Sent by the site the moment it receives any bridge request. Shared with the site — keep in step. */
|
|
399
|
+
declare const PLATFORM_BRIDGE_ACK = "IDOS_PLATFORM_WALLET_ACK";
|
|
400
|
+
/**
|
|
401
|
+
* The page around the game did not answer at all — an old site build without the bridge, or a
|
|
402
|
+
* parent that is not the platform. The value is the wallet bridge's historical one, kept as is.
|
|
403
|
+
*/
|
|
404
|
+
declare const PLATFORM_PAGE_UNAVAILABLE = "PLATFORM_WALLET_UNAVAILABLE";
|
|
405
|
+
interface PlatformPageAnswer {
|
|
406
|
+
ok: boolean;
|
|
407
|
+
error?: string;
|
|
408
|
+
/** The answer message as the site sent it — the caller reads its own fields from here. */
|
|
409
|
+
data: Record<string, unknown>;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Posts `type` with `payload` to the parent page and resolves with its `responseType` answer.
|
|
413
|
+
* Never rejects: silence, a foreign origin and a refusal all resolve to `{ ok: false }` with a reason.
|
|
414
|
+
*/
|
|
415
|
+
declare function askPlatformPage(type: string, responseType: string, payload: Record<string, unknown>, options?: {
|
|
416
|
+
answerTimeoutMs?: number;
|
|
417
|
+
}): Promise<PlatformPageAnswer>;
|
|
418
|
+
|
|
419
|
+
/** Message names. Shared with the website's `PlatformWebGLAuthBridge` — keep both in step. */
|
|
420
|
+
declare const PLATFORM_SIGN_IN_MESSAGES: {
|
|
421
|
+
readonly request: "IDOS_PLATFORM_AUTH_REQUEST";
|
|
422
|
+
readonly response: "IDOS_PLATFORM_AUTH_RESPONSE";
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
/** Message names. Shared with the website's `GameWalletLoginBridge` — keep both in step. */
|
|
426
|
+
declare const PLATFORM_TOPUP_MESSAGES: {
|
|
427
|
+
readonly request: "IDOS_PLATFORM_TOPUP_REQUEST";
|
|
428
|
+
readonly response: "IDOS_PLATFORM_TOPUP_RESPONSE";
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/** Message names. Shared with the website's `GameCreditsConfirmBridge` — keep both in step. */
|
|
432
|
+
declare const PLATFORM_CREDITS_CONFIRM_MESSAGES: {
|
|
433
|
+
readonly request: "IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST";
|
|
434
|
+
readonly response: "IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE";
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* Refusals after which the player already decided — do NOT fall back to the confirmation page.
|
|
438
|
+
* Anything else (`PLATFORM_WALLET_UNAVAILABLE`, `NOT_SIGNED_IN`, `ACCOUNT_MISMATCH`, `BUSY`, …) means "the site
|
|
439
|
+
* could not ask" and the game falls back to the link.
|
|
440
|
+
*/
|
|
441
|
+
declare const PLATFORM_CREDITS_CONFIRM_FINAL: readonly ["DECLINED", "NOT_ENOUGH_CREDITS"];
|
|
442
|
+
|
|
443
|
+
/** Message names. Shared with the website's `GameAdBridge`: keep both in step. */
|
|
444
|
+
declare const PLATFORM_AD_MESSAGES: {
|
|
445
|
+
readonly request: "IDOS_PLATFORM_AD_REQUEST";
|
|
446
|
+
readonly response: "IDOS_PLATFORM_AD_RESPONSE";
|
|
447
|
+
};
|
|
448
|
+
|
|
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 };
|