@idosgames/core 0.24.2 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 O(){return crypto.randomUUID()}var D="idos_device_id",d=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(D);return e||(e=O(),this.storage.setString(D,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 M="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(M);return e||(e="noop-device",this.storage.setString(M,e)),e}getDeviceModel(){return "Noop"}shareLink(){}openInvoice(){}async showAd(){}async copyToClipboard(){}};var s=["https://idosgames.com","https://www.idosgames.com"];function U(t){return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t.endsWith(".localhost")}function p(t){if(s.includes(t))return true;if(typeof window>"u"||!U(window.location.hostname))return false;try{return U(new URL(t).hostname)}catch{return false}}var L="IDOS_PLATFORM_WALLET_ACK",v="PLATFORM_WALLET_UNAVAILABLE",k=5e3,C=18e4;function F(){let t=[...s],e=window.location.ancestorOrigins?.[0];return e&&!t.includes(e)&&p(e)&&t.push(e),t}function N(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function i(t,e,r,l={}){let u={ok:false,error:v,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(u);let A=window.parent;if(!A)return Promise.resolve(u);let R=N(),x=l.answerTimeoutMs??C;return new Promise(h=>{let y=false,m,c=a=>{y||(y=true,window.removeEventListener("message",E),clearTimeout(m),h(a));},E=a=>{if(!p(a.origin))return;let o=a.data;if(!(!o||o.requestId!==R)){if(o.type===L){clearTimeout(m),m=setTimeout(()=>c({ok:false,error:"TIMEOUT",data:{}}),x);return}o.type===e&&c({ok:o.ok===true,error:typeof o.error=="string"?o.error:void 0,data:o});}};m=setTimeout(()=>c(u),k),window.addEventListener("message",E);for(let a of F())try{A.postMessage({type:t,requestId:R,...r},a);}catch{}})}var w={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},b=15*6e4,W=/^[a-z0-9]{8}-preview\.idos\.games$/;function I(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !W.test(window.location.hostname.toLowerCase())}async function G(t){let e=await i(w.request,w.response,{titleID:t.titleID,userID:t.userID,currencyID:t.currencyID,amount:t.amount},{answerTimeoutMs:b});return e.ok?{ok:true}:{ok:false,error:e.error}}var S={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},K=30*6e4,V=/^[a-z0-9]{8}-preview\.idos\.games$/,T="idos:platformSignIn:declined:";function q(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(V.test(window.location.hostname.toLowerCase()))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 B(t){let e=await i(S.request,S.response,{titleID:t,supports:["pgs"]},{answerTimeoutMs:K}),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 H(t){try{window.localStorage.setItem(T+t,"1");}catch{}}function $(t){try{window.localStorage.removeItem(T+t);}catch{}}function Q(t){try{return window.localStorage.getItem(T+t)==="1"}catch{return false}}var _={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},Y=10*6e4;function z(){return I()}async function X(t){let e=await i(_.request,_.response,{titleID:t.titleID,confirmationID:t.confirmationID},{answerTimeoutMs:Y});return e.ok?{ok:true}:{ok:false,error:e.error}}
2
- exports.BrowserPlatformAdapter=d;exports.BrowserStorage=f;exports.MemoryStorage=g;exports.NoopPlatformAdapter=P;exports.PLATFORM_BRIDGE_ACK=L;exports.PLATFORM_CREDITS_CONFIRM_MESSAGES=_;exports.PLATFORM_ORIGINS=s;exports.PLATFORM_PAGE_UNAVAILABLE=v;exports.PLATFORM_SIGN_IN_MESSAGES=S;exports.PLATFORM_TOPUP_MESSAGES=w;exports.askPlatformPage=i;exports.canUsePlatformCreditsConfirm=z;exports.canUsePlatformSignIn=q;exports.canUsePlatformTopUp=I;exports.clearPlatformSignInDeclined=$;exports.getTelegramWebApp=n;exports.isPlatformParentOrigin=p;exports.isPlatformSignInDeclined=Q;exports.markPlatformSignInDeclined=H;exports.requestPlatformCreditsConfirm=X;exports.requestPlatformSignIn=B;exports.requestPlatformTopUp=G;
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 U="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(U);return e||(e=M(),this.storage.setString(U,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 v="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(v);return e||(e="noop-device",this.storage.setString(v,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",L=/^[a-z0-9]{8}-preview\.idos\.games$/;function I(t){return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t.endsWith(".localhost")}function h(){if(typeof window>"u")return false;let t=window.location.hostname.toLowerCase();return L.test(t)?true:I(t)&&globalThis.__IDOS_PREVIEW__!=null}function p(t){if(typeof window<"u"&&L.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 x="IDOS_PLATFORM_WALLET_ACK",C="PLATFORM_WALLET_UNAVAILABLE",b=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(N=>{let O=false,m,d=a=>{O||(O=true,window.removeEventListener("message",D),clearTimeout(m),N(a));},D=a=>{if(!p(a.origin))return;let o=a.data;if(!(!o||o.requestId!==E)){if(o.type===x){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),b),window.addEventListener("message",D);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 _(){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 T={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(h())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(T.request,T.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(){return _()}async function J(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.BrowserPlatformAdapter=w;exports.BrowserStorage=f;exports.MemoryStorage=g;exports.NoopPlatformAdapter=P;exports.PLATFORM_BRIDGE_ACK=x;exports.PLATFORM_CREDITS_CONFIRM_MESSAGES=R;exports.PLATFORM_ORIGINS=s;exports.PLATFORM_PAGE_UNAVAILABLE=C;exports.PLATFORM_SIGN_IN_MESSAGES=T;exports.PLATFORM_TOPUP_MESSAGES=S;exports.askPlatformPage=i;exports.canUsePlatformCreditsConfirm=j;exports.canUsePlatformSignIn=H;exports.canUsePlatformTopUp=_;exports.clearPlatformSignInDeclined=Y;exports.getTelegramWebApp=n;exports.isPlatformParentOrigin=p;exports.isPlatformSignInDeclined=z;exports.markPlatformSignInDeclined=Q;exports.requestPlatformCreditsConfirm=J;exports.requestPlatformSignIn=$;exports.requestPlatformTopUp=q;
@@ -1,184 +1,2 @@
1
- import { K as KeyValueStorage, P as PlatformAdapter } from '../PlatformAdapter-DU_8HalI.cjs';
2
-
3
- /** localStorage-backed key/value store (replaces Unity PlayerPrefs). Fails soft. */
4
- declare class BrowserStorage implements KeyValueStorage {
5
- getString(key: string): string | null;
6
- setString(key: string, value: string): void;
7
- remove(key: string): void;
8
- }
9
- /** In-memory store for tests / SSR. */
10
- declare class MemoryStorage implements KeyValueStorage {
11
- private readonly map;
12
- getString(key: string): string | null;
13
- setString(key: string, value: string): void;
14
- remove(key: string): void;
15
- }
16
-
17
- /** Browser/Telegram platform adapter. Auto-detects Telegram WebApp when present. */
18
- declare class BrowserPlatformAdapter implements PlatformAdapter {
19
- readonly storage: KeyValueStorage;
20
- constructor(storage?: KeyValueStorage);
21
- getPlatform(): string;
22
- getFullURL(): string;
23
- getStartParameter(): string | null;
24
- getReferrer(): string | null;
25
- getTelegramInitDataRaw(): string | null;
26
- getDeviceID(): string;
27
- getDeviceModel(): string;
28
- shareLink(url: string): void;
29
- openInvoice(url: string): void;
30
- showAd(blockId: string): Promise<void>;
31
- copyToClipboard(text: string): Promise<void>;
32
- }
33
-
34
- /** No-op adapter for tests and non-browser (SSR) contexts. In-memory storage, no Telegram. */
35
- declare class NoopPlatformAdapter implements PlatformAdapter {
36
- readonly storage: KeyValueStorage;
37
- constructor(storage?: KeyValueStorage);
38
- getPlatform(): string;
39
- getFullURL(): string;
40
- getStartParameter(): string | null;
41
- getTelegramInitDataRaw(): string | null;
42
- getDeviceID(): string;
43
- getDeviceModel(): string;
44
- shareLink(): void;
45
- openInvoice(): void;
46
- showAd(): Promise<void>;
47
- copyToClipboard(): Promise<void>;
48
- }
49
-
50
- interface TelegramInitDataUnsafe {
51
- start_param?: string;
52
- [key: string]: unknown;
53
- }
54
- interface TelegramWebApp {
55
- platform?: string;
56
- initData?: string;
57
- initDataUnsafe?: TelegramInitDataUnsafe;
58
- openTelegramLink?: (url: string) => void;
59
- openInvoice?: (url: string, callback?: (status: string) => void) => void;
60
- }
61
- declare function getTelegramWebApp(): TelegramWebApp | null;
62
-
63
- declare const PLATFORM_ORIGINS: readonly string[];
64
- /**
65
- * Is `origin` the platform page that framed us — including the local stand?
66
- *
67
- * The local allowance is deliberately symmetric: a localhost parent is accepted ONLY while this
68
- * game is itself served from localhost. A shipped build lives on `{id}.idos.games`, so it answers
69
- * nothing but the real site — a page on the player's own machine cannot ask it for anything.
70
- * That is what makes the allowance safe enough to ship, instead of a build-time flag that has to
71
- * survive four bundlers.
72
- *
73
- * Use this for bridges a game exposes to its parent. A bridge that must NOT widen its existing
74
- * behaviour (the wallet's) keeps checking {@link PLATFORM_ORIGINS} directly.
75
- */
76
- declare function isPlatformParentOrigin(origin: string): boolean;
77
-
78
- /** Sent by the site the moment it receives any bridge request. Shared with the site — keep in step. */
79
- declare const PLATFORM_BRIDGE_ACK = "IDOS_PLATFORM_WALLET_ACK";
80
- /**
81
- * The page around the game did not answer at all — an old site build without the bridge, or a
82
- * parent that is not the platform. The value is the wallet bridge's historical one, kept as is.
83
- */
84
- declare const PLATFORM_PAGE_UNAVAILABLE = "PLATFORM_WALLET_UNAVAILABLE";
85
- interface PlatformPageAnswer {
86
- ok: boolean;
87
- error?: string;
88
- /** The answer message as the site sent it — the caller reads its own fields from here. */
89
- data: Record<string, unknown>;
90
- }
91
- /**
92
- * Posts `type` with `payload` to the parent page and resolves with its `responseType` answer.
93
- * Never rejects: silence, a foreign origin and a refusal all resolve to `{ ok: false }` with a reason.
94
- */
95
- declare function askPlatformPage(type: string, responseType: string, payload: Record<string, unknown>, options?: {
96
- answerTimeoutMs?: number;
97
- }): Promise<PlatformPageAnswer>;
98
-
99
- /** Message names. Shared with the website's `GameWalletLoginBridge` — keep both in step. */
100
- declare const PLATFORM_TOPUP_MESSAGES: {
101
- readonly request: "IDOS_PLATFORM_TOPUP_REQUEST";
102
- readonly response: "IDOS_PLATFORM_TOPUP_RESPONSE";
103
- };
104
- interface PlatformTopUpRequest {
105
- titleID: string;
106
- /** The game's player. The site refuses when its own session is another account. */
107
- userID: string;
108
- currencyID: string;
109
- /** Tokens to deposit, as an exact decimal string ("12.5"). */
110
- amount: string;
111
- }
112
- interface PlatformTopUpResult {
113
- /** The deposit is credited to the player's in-game balance. */
114
- ok: boolean;
115
- /**
116
- * Why not: `CANCELLED`, `PENDING` (sent, the engine has not credited it yet), `ACCOUNT_MISMATCH`,
117
- * `NOT_DEPOSITABLE`, `NO_WALLET`, `TIMEOUT`, `PLATFORM_WALLET_UNAVAILABLE`, `BUSY` (a top-up window is already
118
- * open), `COOLDOWN` (the previous top-up failed less than 30 s ago — the site pauses repeat requests), …
119
- */
120
- error?: string;
121
- }
122
- /**
123
- * Whether this page can ask the site for a top-up at all: it sits in a frame exactly one level deep
124
- * (the platform's own `/app/{id}` page; on a foreign site the game is two frames deep, behind our
125
- * `/embed` page) and is not the AI Coder preview. When the browser names the parent's origin, it must
126
- * be the platform's. The site's ACK is still what really decides — this only spares a 5-second wait
127
- * where an answer cannot come.
128
- */
129
- declare function canUsePlatformTopUp(): boolean;
130
- /** Asks the idosgames.com page around the game to top the player's balance up. Never rejects. */
131
- declare function requestPlatformTopUp(request: PlatformTopUpRequest): Promise<PlatformTopUpResult>;
132
-
133
- /** Message names. Shared with the website's `PlatformWebGLAuthBridge` — keep both in step. */
134
- declare const PLATFORM_SIGN_IN_MESSAGES: {
135
- readonly request: "IDOS_PLATFORM_AUTH_REQUEST";
136
- readonly response: "IDOS_PLATFORM_AUTH_RESPONSE";
137
- };
138
- /**
139
- * Whether the page around this game is the platform's own `/app/{id}` page: a frame exactly one level
140
- * deep (on a foreign site the game sits two frames deep, behind our `/embed` page), not the AI Coder
141
- * preview, and — where the browser names it — a parent on a platform origin. The site's ACK is still
142
- * what really decides; this only spares a 5-second wait where an answer cannot come.
143
- */
144
- declare function canUsePlatformSignIn(): boolean;
145
- interface PlatformSignInAnswer {
146
- /** The one-time SSO code — exchange it with `client.auth.loginWithSsoCode`. */
147
- code?: string;
148
- /** A game ticket of the app's shared game session — enter with `client.auth.loginWithPlatformGameTicket`. */
149
- ticket?: string;
150
- /** Why not: `no_session`, `wrong_title`, `no_title`, `issue_failed`, `TIMEOUT`, `PLATFORM_WALLET_UNAVAILABLE` (no answer). */
151
- error?: string;
152
- }
153
- /** Asks the idosgames.com page around the game for a sign-in code. Never rejects. */
154
- declare function requestPlatformSignIn(titleID: string): Promise<PlatformSignInAnswer>;
155
- /**
156
- * The player signed out of this game themselves: the site must not sign them straight back in on the
157
- * next visit. Cleared by the next sign-in of any kind (`clearPlatformSignInDeclined`).
158
- */
159
- declare function markPlatformSignInDeclined(titleID: string): void;
160
- declare function clearPlatformSignInDeclined(titleID: string): void;
161
- declare function isPlatformSignInDeclined(titleID: string): boolean;
162
-
163
- /** Message names. Shared with the website's `GameCreditsConfirmBridge` — keep both in step. */
164
- declare const PLATFORM_CREDITS_CONFIRM_MESSAGES: {
165
- readonly request: "IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST";
166
- readonly response: "IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE";
167
- };
168
- interface PlatformCreditsConfirmResult {
169
- /** The player confirmed the request in the site's window. */
170
- ok: boolean;
171
- error?: string;
172
- }
173
- /**
174
- * Whether the page around the game can be asked at all: one frame deep (the site's `/app/{id}`; behind `/embed`
175
- * the game is two frames deep and a foreign page could cover our window) and not the AI Coder preview.
176
- */
177
- declare function canUsePlatformCreditsConfirm(): boolean;
178
- /** Asks the idosgames.com page around the game to confirm the Credits purchase request. Never rejects. */
179
- declare function requestPlatformCreditsConfirm(request: {
180
- titleID: string;
181
- confirmationID: string;
182
- }): Promise<PlatformCreditsConfirmResult>;
183
-
184
- export { BrowserPlatformAdapter, BrowserStorage, KeyValueStorage, MemoryStorage, NoopPlatformAdapter, PLATFORM_BRIDGE_ACK, PLATFORM_CREDITS_CONFIRM_MESSAGES, PLATFORM_ORIGINS, PLATFORM_PAGE_UNAVAILABLE, PLATFORM_SIGN_IN_MESSAGES, PLATFORM_TOPUP_MESSAGES, PlatformAdapter, type PlatformCreditsConfirmResult, type PlatformPageAnswer, type PlatformSignInAnswer, type PlatformTopUpRequest, type PlatformTopUpResult, type TelegramInitDataUnsafe, type TelegramWebApp, askPlatformPage, canUsePlatformCreditsConfirm, canUsePlatformSignIn, canUsePlatformTopUp, clearPlatformSignInDeclined, getTelegramWebApp, isPlatformParentOrigin, isPlatformSignInDeclined, markPlatformSignInDeclined, requestPlatformCreditsConfirm, requestPlatformSignIn, requestPlatformTopUp };
1
+ export { K as KeyValueStorage, P as PlatformAdapter } from '../PlatformAdapter-DU_8HalI.cjs';
2
+ export { B as BrowserPlatformAdapter, a as BrowserStorage, M as MemoryStorage, N as NoopPlatformAdapter, P as PLATFORM_BRIDGE_ACK, b as PLATFORM_CREDITS_CONFIRM_MESSAGES, c as PLATFORM_ORIGINS, d as PLATFORM_PAGE_UNAVAILABLE, e as PLATFORM_SIGN_IN_MESSAGES, f as PLATFORM_TOPUP_MESSAGES, g as PlatformCreditsConfirmResult, h as PlatformPageAnswer, i as PlatformSignInAnswer, j as PlatformTopUpRequest, k as PlatformTopUpResult, T as TelegramInitDataUnsafe, l as TelegramWebApp, m as askPlatformPage, n as canUsePlatformCreditsConfirm, o as canUsePlatformSignIn, p as canUsePlatformTopUp, r as clearPlatformSignInDeclined, y as getTelegramWebApp, s as isPlatformParentOrigin, t as isPlatformSignInDeclined, u as markPlatformSignInDeclined, v as requestPlatformCreditsConfirm, w as requestPlatformSignIn, x as requestPlatformTopUp } from '../index-DMmtsWR2.cjs';
@@ -1,184 +1,2 @@
1
- import { K as KeyValueStorage, P as PlatformAdapter } from '../PlatformAdapter-DU_8HalI.js';
2
-
3
- /** localStorage-backed key/value store (replaces Unity PlayerPrefs). Fails soft. */
4
- declare class BrowserStorage implements KeyValueStorage {
5
- getString(key: string): string | null;
6
- setString(key: string, value: string): void;
7
- remove(key: string): void;
8
- }
9
- /** In-memory store for tests / SSR. */
10
- declare class MemoryStorage implements KeyValueStorage {
11
- private readonly map;
12
- getString(key: string): string | null;
13
- setString(key: string, value: string): void;
14
- remove(key: string): void;
15
- }
16
-
17
- /** Browser/Telegram platform adapter. Auto-detects Telegram WebApp when present. */
18
- declare class BrowserPlatformAdapter implements PlatformAdapter {
19
- readonly storage: KeyValueStorage;
20
- constructor(storage?: KeyValueStorage);
21
- getPlatform(): string;
22
- getFullURL(): string;
23
- getStartParameter(): string | null;
24
- getReferrer(): string | null;
25
- getTelegramInitDataRaw(): string | null;
26
- getDeviceID(): string;
27
- getDeviceModel(): string;
28
- shareLink(url: string): void;
29
- openInvoice(url: string): void;
30
- showAd(blockId: string): Promise<void>;
31
- copyToClipboard(text: string): Promise<void>;
32
- }
33
-
34
- /** No-op adapter for tests and non-browser (SSR) contexts. In-memory storage, no Telegram. */
35
- declare class NoopPlatformAdapter implements PlatformAdapter {
36
- readonly storage: KeyValueStorage;
37
- constructor(storage?: KeyValueStorage);
38
- getPlatform(): string;
39
- getFullURL(): string;
40
- getStartParameter(): string | null;
41
- getTelegramInitDataRaw(): string | null;
42
- getDeviceID(): string;
43
- getDeviceModel(): string;
44
- shareLink(): void;
45
- openInvoice(): void;
46
- showAd(): Promise<void>;
47
- copyToClipboard(): Promise<void>;
48
- }
49
-
50
- interface TelegramInitDataUnsafe {
51
- start_param?: string;
52
- [key: string]: unknown;
53
- }
54
- interface TelegramWebApp {
55
- platform?: string;
56
- initData?: string;
57
- initDataUnsafe?: TelegramInitDataUnsafe;
58
- openTelegramLink?: (url: string) => void;
59
- openInvoice?: (url: string, callback?: (status: string) => void) => void;
60
- }
61
- declare function getTelegramWebApp(): TelegramWebApp | null;
62
-
63
- declare const PLATFORM_ORIGINS: readonly string[];
64
- /**
65
- * Is `origin` the platform page that framed us — including the local stand?
66
- *
67
- * The local allowance is deliberately symmetric: a localhost parent is accepted ONLY while this
68
- * game is itself served from localhost. A shipped build lives on `{id}.idos.games`, so it answers
69
- * nothing but the real site — a page on the player's own machine cannot ask it for anything.
70
- * That is what makes the allowance safe enough to ship, instead of a build-time flag that has to
71
- * survive four bundlers.
72
- *
73
- * Use this for bridges a game exposes to its parent. A bridge that must NOT widen its existing
74
- * behaviour (the wallet's) keeps checking {@link PLATFORM_ORIGINS} directly.
75
- */
76
- declare function isPlatformParentOrigin(origin: string): boolean;
77
-
78
- /** Sent by the site the moment it receives any bridge request. Shared with the site — keep in step. */
79
- declare const PLATFORM_BRIDGE_ACK = "IDOS_PLATFORM_WALLET_ACK";
80
- /**
81
- * The page around the game did not answer at all — an old site build without the bridge, or a
82
- * parent that is not the platform. The value is the wallet bridge's historical one, kept as is.
83
- */
84
- declare const PLATFORM_PAGE_UNAVAILABLE = "PLATFORM_WALLET_UNAVAILABLE";
85
- interface PlatformPageAnswer {
86
- ok: boolean;
87
- error?: string;
88
- /** The answer message as the site sent it — the caller reads its own fields from here. */
89
- data: Record<string, unknown>;
90
- }
91
- /**
92
- * Posts `type` with `payload` to the parent page and resolves with its `responseType` answer.
93
- * Never rejects: silence, a foreign origin and a refusal all resolve to `{ ok: false }` with a reason.
94
- */
95
- declare function askPlatformPage(type: string, responseType: string, payload: Record<string, unknown>, options?: {
96
- answerTimeoutMs?: number;
97
- }): Promise<PlatformPageAnswer>;
98
-
99
- /** Message names. Shared with the website's `GameWalletLoginBridge` — keep both in step. */
100
- declare const PLATFORM_TOPUP_MESSAGES: {
101
- readonly request: "IDOS_PLATFORM_TOPUP_REQUEST";
102
- readonly response: "IDOS_PLATFORM_TOPUP_RESPONSE";
103
- };
104
- interface PlatformTopUpRequest {
105
- titleID: string;
106
- /** The game's player. The site refuses when its own session is another account. */
107
- userID: string;
108
- currencyID: string;
109
- /** Tokens to deposit, as an exact decimal string ("12.5"). */
110
- amount: string;
111
- }
112
- interface PlatformTopUpResult {
113
- /** The deposit is credited to the player's in-game balance. */
114
- ok: boolean;
115
- /**
116
- * Why not: `CANCELLED`, `PENDING` (sent, the engine has not credited it yet), `ACCOUNT_MISMATCH`,
117
- * `NOT_DEPOSITABLE`, `NO_WALLET`, `TIMEOUT`, `PLATFORM_WALLET_UNAVAILABLE`, `BUSY` (a top-up window is already
118
- * open), `COOLDOWN` (the previous top-up failed less than 30 s ago — the site pauses repeat requests), …
119
- */
120
- error?: string;
121
- }
122
- /**
123
- * Whether this page can ask the site for a top-up at all: it sits in a frame exactly one level deep
124
- * (the platform's own `/app/{id}` page; on a foreign site the game is two frames deep, behind our
125
- * `/embed` page) and is not the AI Coder preview. When the browser names the parent's origin, it must
126
- * be the platform's. The site's ACK is still what really decides — this only spares a 5-second wait
127
- * where an answer cannot come.
128
- */
129
- declare function canUsePlatformTopUp(): boolean;
130
- /** Asks the idosgames.com page around the game to top the player's balance up. Never rejects. */
131
- declare function requestPlatformTopUp(request: PlatformTopUpRequest): Promise<PlatformTopUpResult>;
132
-
133
- /** Message names. Shared with the website's `PlatformWebGLAuthBridge` — keep both in step. */
134
- declare const PLATFORM_SIGN_IN_MESSAGES: {
135
- readonly request: "IDOS_PLATFORM_AUTH_REQUEST";
136
- readonly response: "IDOS_PLATFORM_AUTH_RESPONSE";
137
- };
138
- /**
139
- * Whether the page around this game is the platform's own `/app/{id}` page: a frame exactly one level
140
- * deep (on a foreign site the game sits two frames deep, behind our `/embed` page), not the AI Coder
141
- * preview, and — where the browser names it — a parent on a platform origin. The site's ACK is still
142
- * what really decides; this only spares a 5-second wait where an answer cannot come.
143
- */
144
- declare function canUsePlatformSignIn(): boolean;
145
- interface PlatformSignInAnswer {
146
- /** The one-time SSO code — exchange it with `client.auth.loginWithSsoCode`. */
147
- code?: string;
148
- /** A game ticket of the app's shared game session — enter with `client.auth.loginWithPlatformGameTicket`. */
149
- ticket?: string;
150
- /** Why not: `no_session`, `wrong_title`, `no_title`, `issue_failed`, `TIMEOUT`, `PLATFORM_WALLET_UNAVAILABLE` (no answer). */
151
- error?: string;
152
- }
153
- /** Asks the idosgames.com page around the game for a sign-in code. Never rejects. */
154
- declare function requestPlatformSignIn(titleID: string): Promise<PlatformSignInAnswer>;
155
- /**
156
- * The player signed out of this game themselves: the site must not sign them straight back in on the
157
- * next visit. Cleared by the next sign-in of any kind (`clearPlatformSignInDeclined`).
158
- */
159
- declare function markPlatformSignInDeclined(titleID: string): void;
160
- declare function clearPlatformSignInDeclined(titleID: string): void;
161
- declare function isPlatformSignInDeclined(titleID: string): boolean;
162
-
163
- /** Message names. Shared with the website's `GameCreditsConfirmBridge` — keep both in step. */
164
- declare const PLATFORM_CREDITS_CONFIRM_MESSAGES: {
165
- readonly request: "IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST";
166
- readonly response: "IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE";
167
- };
168
- interface PlatformCreditsConfirmResult {
169
- /** The player confirmed the request in the site's window. */
170
- ok: boolean;
171
- error?: string;
172
- }
173
- /**
174
- * Whether the page around the game can be asked at all: one frame deep (the site's `/app/{id}`; behind `/embed`
175
- * the game is two frames deep and a foreign page could cover our window) and not the AI Coder preview.
176
- */
177
- declare function canUsePlatformCreditsConfirm(): boolean;
178
- /** Asks the idosgames.com page around the game to confirm the Credits purchase request. Never rejects. */
179
- declare function requestPlatformCreditsConfirm(request: {
180
- titleID: string;
181
- confirmationID: string;
182
- }): Promise<PlatformCreditsConfirmResult>;
183
-
184
- export { BrowserPlatformAdapter, BrowserStorage, KeyValueStorage, MemoryStorage, NoopPlatformAdapter, PLATFORM_BRIDGE_ACK, PLATFORM_CREDITS_CONFIRM_MESSAGES, PLATFORM_ORIGINS, PLATFORM_PAGE_UNAVAILABLE, PLATFORM_SIGN_IN_MESSAGES, PLATFORM_TOPUP_MESSAGES, PlatformAdapter, type PlatformCreditsConfirmResult, type PlatformPageAnswer, type PlatformSignInAnswer, type PlatformTopUpRequest, type PlatformTopUpResult, type TelegramInitDataUnsafe, type TelegramWebApp, askPlatformPage, canUsePlatformCreditsConfirm, canUsePlatformSignIn, canUsePlatformTopUp, clearPlatformSignInDeclined, getTelegramWebApp, isPlatformParentOrigin, isPlatformSignInDeclined, markPlatformSignInDeclined, requestPlatformCreditsConfirm, requestPlatformSignIn, requestPlatformTopUp };
1
+ export { K as KeyValueStorage, P as PlatformAdapter } from '../PlatformAdapter-DU_8HalI.js';
2
+ export { B as BrowserPlatformAdapter, a as BrowserStorage, M as MemoryStorage, N as NoopPlatformAdapter, P as PLATFORM_BRIDGE_ACK, b as PLATFORM_CREDITS_CONFIRM_MESSAGES, c as PLATFORM_ORIGINS, d as PLATFORM_PAGE_UNAVAILABLE, e as PLATFORM_SIGN_IN_MESSAGES, f as PLATFORM_TOPUP_MESSAGES, g as PlatformCreditsConfirmResult, h as PlatformPageAnswer, i as PlatformSignInAnswer, j as PlatformTopUpRequest, k as PlatformTopUpResult, T as TelegramInitDataUnsafe, l as TelegramWebApp, m as askPlatformPage, n as canUsePlatformCreditsConfirm, o as canUsePlatformSignIn, p as canUsePlatformTopUp, r as clearPlatformSignInDeclined, y as getTelegramWebApp, s as isPlatformParentOrigin, t as isPlatformSignInDeclined, u as markPlatformSignInDeclined, v as requestPlatformCreditsConfirm, w as requestPlatformSignIn, x as requestPlatformTopUp } from '../index-BKjfSSxG.js';
@@ -1 +1 @@
1
- export{e as BrowserPlatformAdapter,a as BrowserStorage,b as MemoryStorage,w as NoopPlatformAdapter,h as PLATFORM_BRIDGE_ACK,t as PLATFORM_CREDITS_CONFIRM_MESSAGES,f as PLATFORM_ORIGINS,i as PLATFORM_PAGE_UNAVAILABLE,k as PLATFORM_SIGN_IN_MESSAGES,q as PLATFORM_TOPUP_MESSAGES,j as askPlatformPage,u as canUsePlatformCreditsConfirm,l as canUsePlatformSignIn,r as canUsePlatformTopUp,o as clearPlatformSignInDeclined,c as getTelegramWebApp,g as isPlatformParentOrigin,p as isPlatformSignInDeclined,n as markPlatformSignInDeclined,v as requestPlatformCreditsConfirm,m as requestPlatformSignIn,s as requestPlatformTopUp}from'../chunk-J3S34XCF.js';
1
+ export{e as BrowserPlatformAdapter,a as BrowserStorage,b as MemoryStorage,x as NoopPlatformAdapter,h as PLATFORM_BRIDGE_ACK,u as PLATFORM_CREDITS_CONFIRM_MESSAGES,f as PLATFORM_ORIGINS,i as PLATFORM_PAGE_UNAVAILABLE,k as PLATFORM_SIGN_IN_MESSAGES,r as PLATFORM_TOPUP_MESSAGES,j as askPlatformPage,v as canUsePlatformCreditsConfirm,l as canUsePlatformSignIn,s as canUsePlatformTopUp,p as clearPlatformSignInDeclined,c as getTelegramWebApp,g as isPlatformParentOrigin,q as isPlatformSignInDeclined,o as markPlatformSignInDeclined,w as requestPlatformCreditsConfirm,n as requestPlatformSignIn,t as requestPlatformTopUp}from'../chunk-YSPGQWAB.js';
@@ -1,5 +1,5 @@
1
- import { I as IceServer } from '../VoiceController-7H1grlKL.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-7H1grlKL.cjs';
1
+ import { I as IceServer } from '../VoiceController-CAqhPZ15.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-CAqhPZ15.cjs';
3
3
  import 'zod';
4
4
  import '../PlatformAdapter-DU_8HalI.cjs';
5
5
  import 'decimal.js';
@@ -1,5 +1,5 @@
1
- import { I as IceServer } from '../VoiceController-B2m4oYGx.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-B2m4oYGx.js';
1
+ import { I as IceServer } from '../VoiceController-CNq9Lm0f.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-CNq9Lm0f.js';
3
3
  import 'zod';
4
4
  import '../PlatformAdapter-DU_8HalI.js';
5
5
  import 'decimal.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/core",
3
- "version": "0.24.2",
3
+ "version": "0.25.0",
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
- 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 O(){return crypto.randomUUID()}var D="idos_device_id",d=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(D);return e||(e=O(),this.storage.setString(D,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 M="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(M);return e||(e="noop-device",this.storage.setString(M,e)),e}getDeviceModel(){return "Noop"}shareLink(){}openInvoice(){}async showAd(){}async copyToClipboard(){}};var s=["https://idosgames.com","https://www.idosgames.com"];function U(t){return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t.endsWith(".localhost")}function p(t){if(s.includes(t))return true;if(typeof window>"u"||!U(window.location.hostname))return false;try{return U(new URL(t).hostname)}catch{return false}}var L="IDOS_PLATFORM_WALLET_ACK",v="PLATFORM_WALLET_UNAVAILABLE",k=5e3,C=18e4;function F(){let t=[...s],e=window.location.ancestorOrigins?.[0];return e&&!t.includes(e)&&p(e)&&t.push(e),t}function N(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function i(t,e,r,l={}){let u={ok:false,error:v,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(u);let A=window.parent;if(!A)return Promise.resolve(u);let R=N(),x=l.answerTimeoutMs??C;return new Promise(h=>{let y=false,m,c=a=>{y||(y=true,window.removeEventListener("message",E),clearTimeout(m),h(a));},E=a=>{if(!p(a.origin))return;let o=a.data;if(!(!o||o.requestId!==R)){if(o.type===L){clearTimeout(m),m=setTimeout(()=>c({ok:false,error:"TIMEOUT",data:{}}),x);return}o.type===e&&c({ok:o.ok===true,error:typeof o.error=="string"?o.error:void 0,data:o});}};m=setTimeout(()=>c(u),k),window.addEventListener("message",E);for(let a of F())try{A.postMessage({type:t,requestId:R,...r},a);}catch{}})}var w={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},b=15*6e4,W=/^[a-z0-9]{8}-preview\.idos\.games$/;function I(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !W.test(window.location.hostname.toLowerCase())}async function G(t){let e=await i(w.request,w.response,{titleID:t.titleID,userID:t.userID,currencyID:t.currencyID,amount:t.amount},{answerTimeoutMs:b});return e.ok?{ok:true}:{ok:false,error:e.error}}var S={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},K=30*6e4,V=/^[a-z0-9]{8}-preview\.idos\.games$/,T="idos:platformSignIn:declined:";function q(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(V.test(window.location.hostname.toLowerCase()))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 B(t){let e=await i(S.request,S.response,{titleID:t,supports:["pgs"]},{answerTimeoutMs:K}),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 H(t){try{window.localStorage.setItem(T+t,"1");}catch{}}function $(t){try{window.localStorage.removeItem(T+t);}catch{}}function Q(t){try{return window.localStorage.getItem(T+t)==="1"}catch{return false}}var _={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},Y=10*6e4;function z(){return I()}async function X(t){let e=await i(_.request,_.response,{titleID:t.titleID,confirmationID:t.confirmationID},{answerTimeoutMs:Y});return e.ok?{ok:true}:{ok:false,error:e.error}}
2
- export{f as a,g as b,n as c,O as d,d as e,s as f,p as g,L as h,v as i,i as j,S as k,q as l,B as m,H as n,$ as o,Q as p,w as q,I as r,G as s,_ as t,z as u,X as v,P as w};