@idosgames/core 0.1.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.
@@ -0,0 +1 @@
1
+ 'use strict';var n=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{}}},o=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 r(){return globalThis.Telegram?.WebApp??null}function l(){return crypto.randomUUID()}var s="idos_device_id",i=class{storage;constructor(e=new n){this.storage=e;}getPlatform(){return r()?.platform??"Web"}getFullURL(){return typeof location<"u"?location.href:""}getStartParameter(){let e=r()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getTelegramInitDataRaw(){let e=r()?.initData;return e&&e.length>0?e:null}getDeviceID(){let e=this.storage.getString(s);return e||(e=l(),this.storage.setString(s,e)),e}getDeviceModel(){return typeof navigator<"u"&&navigator.userAgent?navigator.userAgent:"Web"}shareLink(e){let t=r();if(t?.openTelegramLink){t.openTelegramLink(e);return}typeof window<"u"&&window.open(e,"_blank");}openInvoice(e){let t=r();if(t?.openInvoice){t.openInvoice(e);return}typeof window<"u"&&window.open(e,"_blank");}async showAd(e){let t=globalThis;typeof t.showAd=="function"&&await t.showAd(e);}async copyToClipboard(e){typeof navigator<"u"&&navigator.clipboard&&await navigator.clipboard.writeText(e);}};var p="idos_device_id",g=class{storage;constructor(e=new o){this.storage=e;}getPlatform(){return "Web"}getFullURL(){return ""}getStartParameter(){return null}getTelegramInitDataRaw(){return null}getDeviceID(){let e=this.storage.getString(p);return e||(e="noop-device",this.storage.setString(p,e)),e}getDeviceModel(){return "Noop"}shareLink(){}openInvoice(){}async showAd(){}async copyToClipboard(){}};exports.BrowserPlatformAdapter=i;exports.BrowserStorage=n;exports.MemoryStorage=o;exports.NoopPlatformAdapter=g;exports.getTelegramWebApp=r;
@@ -0,0 +1,85 @@
1
+ interface KeyValueStorage {
2
+ getString(key: string): string | null;
3
+ setString(key: string, value: string): void;
4
+ remove(key: string): void;
5
+ }
6
+ interface PlatformAdapter {
7
+ readonly storage: KeyValueStorage;
8
+ /** Platform id (e.g. Telegram `tdesktop`/`android`, or `Web`). */
9
+ getPlatform(): string;
10
+ /** Full launch URL — mirrors WebSDK.GetFullURL. */
11
+ getFullURL(): string;
12
+ /** Telegram `start_param` (referral/deeplink) if present. */
13
+ getStartParameter(): string | null;
14
+ /** Raw Telegram `initData` string for server-side auth (validated only on the server). */
15
+ getTelegramInitDataRaw(): string | null;
16
+ /** Stable per-device id (persisted) — replaces SystemInfo.deviceUniqueIdentifier. */
17
+ getDeviceID(): string;
18
+ /** Device/user-agent string — replaces SystemInfo.deviceModel. */
19
+ getDeviceModel(): string;
20
+ shareLink(url: string): void;
21
+ openInvoice(url: string): void;
22
+ showAd(blockId: string): Promise<void>;
23
+ copyToClipboard(text: string): Promise<void>;
24
+ }
25
+
26
+ /** localStorage-backed key/value store (replaces Unity PlayerPrefs). Fails soft. */
27
+ declare class BrowserStorage implements KeyValueStorage {
28
+ getString(key: string): string | null;
29
+ setString(key: string, value: string): void;
30
+ remove(key: string): void;
31
+ }
32
+ /** In-memory store for tests / SSR. */
33
+ declare class MemoryStorage implements KeyValueStorage {
34
+ private readonly map;
35
+ getString(key: string): string | null;
36
+ setString(key: string, value: string): void;
37
+ remove(key: string): void;
38
+ }
39
+
40
+ /** Browser/Telegram platform adapter. Auto-detects Telegram WebApp when present. */
41
+ declare class BrowserPlatformAdapter implements PlatformAdapter {
42
+ readonly storage: KeyValueStorage;
43
+ constructor(storage?: KeyValueStorage);
44
+ getPlatform(): string;
45
+ getFullURL(): string;
46
+ getStartParameter(): string | null;
47
+ getTelegramInitDataRaw(): string | null;
48
+ getDeviceID(): string;
49
+ getDeviceModel(): string;
50
+ shareLink(url: string): void;
51
+ openInvoice(url: string): void;
52
+ showAd(blockId: string): Promise<void>;
53
+ copyToClipboard(text: string): Promise<void>;
54
+ }
55
+
56
+ /** No-op adapter for tests and non-browser (SSR) contexts. In-memory storage, no Telegram. */
57
+ declare class NoopPlatformAdapter implements PlatformAdapter {
58
+ readonly storage: KeyValueStorage;
59
+ constructor(storage?: KeyValueStorage);
60
+ getPlatform(): string;
61
+ getFullURL(): string;
62
+ getStartParameter(): string | null;
63
+ getTelegramInitDataRaw(): string | null;
64
+ getDeviceID(): string;
65
+ getDeviceModel(): string;
66
+ shareLink(): void;
67
+ openInvoice(): void;
68
+ showAd(): Promise<void>;
69
+ copyToClipboard(): Promise<void>;
70
+ }
71
+
72
+ interface TelegramInitDataUnsafe {
73
+ start_param?: string;
74
+ [key: string]: unknown;
75
+ }
76
+ interface TelegramWebApp {
77
+ platform?: string;
78
+ initData?: string;
79
+ initDataUnsafe?: TelegramInitDataUnsafe;
80
+ openTelegramLink?: (url: string) => void;
81
+ openInvoice?: (url: string, callback?: (status: string) => void) => void;
82
+ }
83
+ declare function getTelegramWebApp(): TelegramWebApp | null;
84
+
85
+ export { BrowserPlatformAdapter, BrowserStorage, type KeyValueStorage, MemoryStorage, NoopPlatformAdapter, type PlatformAdapter, type TelegramInitDataUnsafe, type TelegramWebApp, getTelegramWebApp };
@@ -0,0 +1,85 @@
1
+ interface KeyValueStorage {
2
+ getString(key: string): string | null;
3
+ setString(key: string, value: string): void;
4
+ remove(key: string): void;
5
+ }
6
+ interface PlatformAdapter {
7
+ readonly storage: KeyValueStorage;
8
+ /** Platform id (e.g. Telegram `tdesktop`/`android`, or `Web`). */
9
+ getPlatform(): string;
10
+ /** Full launch URL — mirrors WebSDK.GetFullURL. */
11
+ getFullURL(): string;
12
+ /** Telegram `start_param` (referral/deeplink) if present. */
13
+ getStartParameter(): string | null;
14
+ /** Raw Telegram `initData` string for server-side auth (validated only on the server). */
15
+ getTelegramInitDataRaw(): string | null;
16
+ /** Stable per-device id (persisted) — replaces SystemInfo.deviceUniqueIdentifier. */
17
+ getDeviceID(): string;
18
+ /** Device/user-agent string — replaces SystemInfo.deviceModel. */
19
+ getDeviceModel(): string;
20
+ shareLink(url: string): void;
21
+ openInvoice(url: string): void;
22
+ showAd(blockId: string): Promise<void>;
23
+ copyToClipboard(text: string): Promise<void>;
24
+ }
25
+
26
+ /** localStorage-backed key/value store (replaces Unity PlayerPrefs). Fails soft. */
27
+ declare class BrowserStorage implements KeyValueStorage {
28
+ getString(key: string): string | null;
29
+ setString(key: string, value: string): void;
30
+ remove(key: string): void;
31
+ }
32
+ /** In-memory store for tests / SSR. */
33
+ declare class MemoryStorage implements KeyValueStorage {
34
+ private readonly map;
35
+ getString(key: string): string | null;
36
+ setString(key: string, value: string): void;
37
+ remove(key: string): void;
38
+ }
39
+
40
+ /** Browser/Telegram platform adapter. Auto-detects Telegram WebApp when present. */
41
+ declare class BrowserPlatformAdapter implements PlatformAdapter {
42
+ readonly storage: KeyValueStorage;
43
+ constructor(storage?: KeyValueStorage);
44
+ getPlatform(): string;
45
+ getFullURL(): string;
46
+ getStartParameter(): string | null;
47
+ getTelegramInitDataRaw(): string | null;
48
+ getDeviceID(): string;
49
+ getDeviceModel(): string;
50
+ shareLink(url: string): void;
51
+ openInvoice(url: string): void;
52
+ showAd(blockId: string): Promise<void>;
53
+ copyToClipboard(text: string): Promise<void>;
54
+ }
55
+
56
+ /** No-op adapter for tests and non-browser (SSR) contexts. In-memory storage, no Telegram. */
57
+ declare class NoopPlatformAdapter implements PlatformAdapter {
58
+ readonly storage: KeyValueStorage;
59
+ constructor(storage?: KeyValueStorage);
60
+ getPlatform(): string;
61
+ getFullURL(): string;
62
+ getStartParameter(): string | null;
63
+ getTelegramInitDataRaw(): string | null;
64
+ getDeviceID(): string;
65
+ getDeviceModel(): string;
66
+ shareLink(): void;
67
+ openInvoice(): void;
68
+ showAd(): Promise<void>;
69
+ copyToClipboard(): Promise<void>;
70
+ }
71
+
72
+ interface TelegramInitDataUnsafe {
73
+ start_param?: string;
74
+ [key: string]: unknown;
75
+ }
76
+ interface TelegramWebApp {
77
+ platform?: string;
78
+ initData?: string;
79
+ initDataUnsafe?: TelegramInitDataUnsafe;
80
+ openTelegramLink?: (url: string) => void;
81
+ openInvoice?: (url: string, callback?: (status: string) => void) => void;
82
+ }
83
+ declare function getTelegramWebApp(): TelegramWebApp | null;
84
+
85
+ export { BrowserPlatformAdapter, BrowserStorage, type KeyValueStorage, MemoryStorage, NoopPlatformAdapter, type PlatformAdapter, type TelegramInitDataUnsafe, type TelegramWebApp, getTelegramWebApp };
@@ -0,0 +1 @@
1
+ export{e as BrowserPlatformAdapter,a as BrowserStorage,b as MemoryStorage,f as NoopPlatformAdapter,c as getTelegramWebApp}from'../chunk-QJVWT32O.js';
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@idosgames/core",
3
+ "version": "0.1.0",
4
+ "description": "Engine-agnostic core of the IDosGames SDK (transport, auth, cache, services, events).",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "iDos Games",
8
+ "homepage": "https://github.com/iDos-Games/iDosGamesSDK_TS#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/iDos-Games/iDosGamesSDK_TS.git",
12
+ "directory": "packages/core"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/iDos-Games/iDosGamesSDK_TS/issues"
16
+ },
17
+ "keywords": [
18
+ "idosgames",
19
+ "sdk",
20
+ "game",
21
+ "gamedev",
22
+ "telegram",
23
+ "web3"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "sideEffects": false,
29
+ "main": "./dist/index.cjs",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js",
36
+ "require": "./dist/index.cjs"
37
+ },
38
+ "./platform": {
39
+ "types": "./dist/platform/index.d.ts",
40
+ "import": "./dist/platform/index.js",
41
+ "require": "./dist/platform/index.cjs"
42
+ }
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "README.md",
47
+ "CHANGELOG.md",
48
+ "LICENSE"
49
+ ],
50
+ "scripts": {
51
+ "build": "tsup && node scripts/flatten-dts.mjs",
52
+ "typecheck": "tsc --noEmit -p tsconfig.json"
53
+ },
54
+ "dependencies": {
55
+ "decimal.js": "^10.4.3",
56
+ "zod": "^3.23.8"
57
+ }
58
+ }