infinite-games-sdk 0.0.5 → 0.0.7
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/README.md +126 -113
- package/dist/index.d.ts +208 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +561 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/errors.d.ts +0 -4
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -11
- package/dist/errors.js.map +0 -1
- package/dist/history/HistoryClient.d.ts +0 -20
- package/dist/history/HistoryClient.d.ts.map +0 -1
- package/dist/history/HistoryClient.js +0 -96
- package/dist/history/HistoryClient.js.map +0 -1
- package/dist/history/index.d.ts +0 -4
- package/dist/history/index.d.ts.map +0 -1
- package/dist/history/index.js +0 -8
- package/dist/history/index.js.map +0 -1
- package/dist/history/types.d.ts +0 -7
- package/dist/history/types.d.ts.map +0 -1
- package/dist/history/types.js +0 -3
- package/dist/history/types.js.map +0 -1
- package/dist/history/useHistoryClient.d.ts +0 -21
- package/dist/history/useHistoryClient.d.ts.map +0 -1
- package/dist/history/useHistoryClient.js +0 -77
- package/dist/history/useHistoryClient.js.map +0 -1
- package/dist/launcher/index.d.ts +0 -4
- package/dist/launcher/index.d.ts.map +0 -1
- package/dist/launcher/index.js +0 -9
- package/dist/launcher/index.js.map +0 -1
- package/dist/launcher/types.d.ts +0 -59
- package/dist/launcher/types.d.ts.map +0 -1
- package/dist/launcher/types.js +0 -20
- package/dist/launcher/types.js.map +0 -1
- package/dist/launcher/useGameLauncher.d.ts +0 -3
- package/dist/launcher/useGameLauncher.d.ts.map +0 -1
- package/dist/launcher/useGameLauncher.js +0 -144
- package/dist/launcher/useGameLauncher.js.map +0 -1
- package/dist/session/SessionClient.d.ts +0 -38
- package/dist/session/SessionClient.d.ts.map +0 -1
- package/dist/session/SessionClient.js +0 -136
- package/dist/session/SessionClient.js.map +0 -1
- package/dist/session/index.d.ts +0 -4
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -10
- package/dist/session/index.js.map +0 -1
- package/dist/session/tokens.d.ts +0 -15
- package/dist/session/tokens.d.ts.map +0 -1
- package/dist/session/tokens.js +0 -55
- package/dist/session/tokens.js.map +0 -1
- package/dist/session/types.d.ts +0 -21
- package/dist/session/types.d.ts.map +0 -1
- package/dist/session/types.js +0 -3
- package/dist/session/types.js.map +0 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -8
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/scale.d.ts +0 -4
- package/dist/utils/scale.d.ts.map +0 -1
- package/dist/utils/scale.js +0 -13
- package/dist/utils/scale.js.map +0 -1
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { HistoryConfig } from './types';
|
|
2
|
-
export declare class HistoryClient {
|
|
3
|
-
private ws;
|
|
4
|
-
private config;
|
|
5
|
-
private keepAliveInterval;
|
|
6
|
-
private reconnectTimeout;
|
|
7
|
-
private tableId;
|
|
8
|
-
private coinType;
|
|
9
|
-
onMessage: ((event: MessageEvent) => void) | null;
|
|
10
|
-
onConnect: (() => void) | null;
|
|
11
|
-
onDisconnect: (() => void) | null;
|
|
12
|
-
onError: ((error: Event) => void) | null;
|
|
13
|
-
constructor(config?: HistoryConfig);
|
|
14
|
-
connect(tableId: string, coinType: string): void;
|
|
15
|
-
disconnect(): void;
|
|
16
|
-
send(message: object): void;
|
|
17
|
-
private startKeepAlive;
|
|
18
|
-
private cleanup;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=HistoryClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryClient.d.ts","sourceRoot":"","sources":["../../src/history/HistoryClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMxC,qBAAa,aAAa;IACxB,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,iBAAiB,CAAuB;IAChD,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,QAAQ,CAAuB;IAEhC,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI,CAAQ;IACzD,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IACtC,YAAY,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IACzC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAAQ;gBAE3C,MAAM,GAAE,aAAkB;IAStC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IA0ChD,UAAU,IAAI,IAAI;IASlB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAM3B,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,OAAO;CAUhB"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HistoryClient = void 0;
|
|
4
|
-
const DEFAULT_BASE_URL = 'historydev.infiniteedgers.com';
|
|
5
|
-
const DEFAULT_KEEP_ALIVE_INTERVAL_MS = 30000;
|
|
6
|
-
const DEFAULT_RECONNECT_DELAY_MS = 3000;
|
|
7
|
-
class HistoryClient {
|
|
8
|
-
constructor(config = {}) {
|
|
9
|
-
this.ws = null;
|
|
10
|
-
this.keepAliveInterval = null;
|
|
11
|
-
this.reconnectTimeout = null;
|
|
12
|
-
this.tableId = null;
|
|
13
|
-
this.coinType = null;
|
|
14
|
-
this.onMessage = null;
|
|
15
|
-
this.onConnect = null;
|
|
16
|
-
this.onDisconnect = null;
|
|
17
|
-
this.onError = null;
|
|
18
|
-
this.config = {
|
|
19
|
-
baseUrl: config.baseUrl || DEFAULT_BASE_URL,
|
|
20
|
-
keepAliveIntervalMs: config.keepAliveIntervalMs || DEFAULT_KEEP_ALIVE_INTERVAL_MS,
|
|
21
|
-
reconnectDelayMs: config.reconnectDelayMs || DEFAULT_RECONNECT_DELAY_MS,
|
|
22
|
-
autoReconnect: config.autoReconnect !== false,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
connect(tableId, coinType) {
|
|
26
|
-
this.tableId = tableId;
|
|
27
|
-
this.coinType = coinType;
|
|
28
|
-
// Convert coin_type from "sui/sui" to "sui-sui" for URL
|
|
29
|
-
const coinTypeUrl = coinType.replace('/', '-');
|
|
30
|
-
const url = `wss://${this.config.baseUrl}/api/ws/${encodeURIComponent(tableId)}/${encodeURIComponent(coinTypeUrl)}`;
|
|
31
|
-
this.ws = new WebSocket(url);
|
|
32
|
-
this.ws.onopen = () => {
|
|
33
|
-
this.startKeepAlive();
|
|
34
|
-
if (this.onConnect) {
|
|
35
|
-
this.onConnect();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
this.ws.onmessage = (event) => {
|
|
39
|
-
if (this.onMessage) {
|
|
40
|
-
this.onMessage(event);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
this.ws.onclose = () => {
|
|
44
|
-
this.cleanup();
|
|
45
|
-
if (this.onDisconnect) {
|
|
46
|
-
this.onDisconnect();
|
|
47
|
-
}
|
|
48
|
-
if (this.config.autoReconnect && this.tableId && this.coinType) {
|
|
49
|
-
this.reconnectTimeout = window.setTimeout(() => {
|
|
50
|
-
this.connect(this.tableId, this.coinType);
|
|
51
|
-
}, this.config.reconnectDelayMs);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
this.ws.onerror = (error) => {
|
|
55
|
-
if (this.onError) {
|
|
56
|
-
this.onError(error);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
disconnect() {
|
|
61
|
-
this.config.autoReconnect = false;
|
|
62
|
-
this.cleanup();
|
|
63
|
-
if (this.ws) {
|
|
64
|
-
this.ws.close();
|
|
65
|
-
this.ws = null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
send(message) {
|
|
69
|
-
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
70
|
-
this.ws.send(JSON.stringify(message));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
startKeepAlive() {
|
|
74
|
-
if (this.keepAliveInterval !== null) {
|
|
75
|
-
clearInterval(this.keepAliveInterval);
|
|
76
|
-
}
|
|
77
|
-
this.keepAliveInterval = window.setInterval(() => {
|
|
78
|
-
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
79
|
-
// Send plain 'ping' string - history service expects this format
|
|
80
|
-
this.ws.send('ping');
|
|
81
|
-
}
|
|
82
|
-
}, this.config.keepAliveIntervalMs);
|
|
83
|
-
}
|
|
84
|
-
cleanup() {
|
|
85
|
-
if (this.keepAliveInterval !== null) {
|
|
86
|
-
clearInterval(this.keepAliveInterval);
|
|
87
|
-
this.keepAliveInterval = null;
|
|
88
|
-
}
|
|
89
|
-
if (this.reconnectTimeout !== null) {
|
|
90
|
-
clearTimeout(this.reconnectTimeout);
|
|
91
|
-
this.reconnectTimeout = null;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.HistoryClient = HistoryClient;
|
|
96
|
-
//# sourceMappingURL=HistoryClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryClient.js","sourceRoot":"","sources":["../../src/history/HistoryClient.ts"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AACzD,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAC7C,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAExC,MAAa,aAAa;IAaxB,YAAY,SAAwB,EAAE;QAZ9B,OAAE,GAAqB,IAAI,CAAC;QAE5B,sBAA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CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAEO,cAAc;QACpB,IAAI,IAAI,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE;YAC/C,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;gBACrD,iEAAiE;gBACjE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACtC,CAAC;IAEO,OAAO;QACb,IAAI,IAAI,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YACtC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAChC,CAAC;QACD,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;YACnC,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACpC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;CACF;AAtGD,sCAsGC"}
|
package/dist/history/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/history/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useHistoryClient = exports.HistoryClient = void 0;
|
|
4
|
-
var HistoryClient_1 = require("./HistoryClient");
|
|
5
|
-
Object.defineProperty(exports, "HistoryClient", { enumerable: true, get: function () { return HistoryClient_1.HistoryClient; } });
|
|
6
|
-
var useHistoryClient_1 = require("./useHistoryClient");
|
|
7
|
-
Object.defineProperty(exports, "useHistoryClient", { enumerable: true, get: function () { return useHistoryClient_1.useHistoryClient; } });
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
|
package/dist/history/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/history/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB"}
|
package/dist/history/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/history/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { HistoryConfig } from './types';
|
|
2
|
-
interface UseHistoryClientOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Callback for all incoming WebSocket messages.
|
|
5
|
-
* Receives the parsed JSON message.
|
|
6
|
-
*/
|
|
7
|
-
onMessage?: (message: any) => void;
|
|
8
|
-
/**
|
|
9
|
-
* History client configuration (baseUrl, reconnect settings, etc.)
|
|
10
|
-
*/
|
|
11
|
-
config?: HistoryConfig;
|
|
12
|
-
}
|
|
13
|
-
export declare function useHistoryClient(tableId: string | null, coinType: string | null, options?: UseHistoryClientOptions): {
|
|
14
|
-
isConnected: boolean;
|
|
15
|
-
send: (message: object) => void;
|
|
16
|
-
sendBetUpdate: (bets: Record<string, number>) => void;
|
|
17
|
-
sendGameReset: () => void;
|
|
18
|
-
disconnect: () => void;
|
|
19
|
-
};
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=useHistoryClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHistoryClient.d.ts","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,UAAU,uBAAuB;IAC/B;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,OAAO,GAAE,uBAA4B;;oBAyDF,MAAM;0BAMA,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;EAqBhE"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useHistoryClient = useHistoryClient;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const HistoryClient_1 = require("./HistoryClient");
|
|
6
|
-
function useHistoryClient(tableId, coinType, options = {}) {
|
|
7
|
-
const [isConnected, setIsConnected] = (0, react_1.useState)(false);
|
|
8
|
-
const clientRef = (0, react_1.useRef)(null);
|
|
9
|
-
// Use ref for callback to avoid stale closures
|
|
10
|
-
const onMessageRef = (0, react_1.useRef)(options.onMessage);
|
|
11
|
-
(0, react_1.useEffect)(() => {
|
|
12
|
-
onMessageRef.current = options.onMessage;
|
|
13
|
-
}, [options.onMessage]);
|
|
14
|
-
// Stable config ref to avoid reconnects on config object identity changes
|
|
15
|
-
const configRef = (0, react_1.useRef)(options.config);
|
|
16
|
-
(0, react_1.useEffect)(() => {
|
|
17
|
-
configRef.current = options.config;
|
|
18
|
-
}, [options.config]);
|
|
19
|
-
(0, react_1.useEffect)(() => {
|
|
20
|
-
if (!tableId || !coinType) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const client = new HistoryClient_1.HistoryClient(configRef.current);
|
|
24
|
-
clientRef.current = client;
|
|
25
|
-
client.onConnect = () => {
|
|
26
|
-
setIsConnected(true);
|
|
27
|
-
};
|
|
28
|
-
client.onDisconnect = () => {
|
|
29
|
-
setIsConnected(false);
|
|
30
|
-
};
|
|
31
|
-
client.onMessage = (event) => {
|
|
32
|
-
try {
|
|
33
|
-
const message = JSON.parse(event.data);
|
|
34
|
-
// For wrapped events {channel, data}, unwrap and pass the data
|
|
35
|
-
// For relay messages {type, ...}, pass as-is
|
|
36
|
-
if (message.channel && message.data) {
|
|
37
|
-
onMessageRef.current?.(message.data);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
onMessageRef.current?.(message);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
console.error('[HistoryClient] Failed to parse WebSocket message:', error);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
client.connect(tableId, coinType);
|
|
48
|
-
return () => {
|
|
49
|
-
client.disconnect();
|
|
50
|
-
clientRef.current = null;
|
|
51
|
-
};
|
|
52
|
-
}, [tableId, coinType]);
|
|
53
|
-
const send = (0, react_1.useCallback)((message) => {
|
|
54
|
-
if (clientRef.current) {
|
|
55
|
-
clientRef.current.send(message);
|
|
56
|
-
}
|
|
57
|
-
}, []);
|
|
58
|
-
const sendBetUpdate = (0, react_1.useCallback)((bets) => {
|
|
59
|
-
send({ type: 'bet_update', ...bets });
|
|
60
|
-
}, [send]);
|
|
61
|
-
const sendGameReset = (0, react_1.useCallback)(() => {
|
|
62
|
-
send({ type: 'game_reset' });
|
|
63
|
-
}, [send]);
|
|
64
|
-
const disconnect = (0, react_1.useCallback)(() => {
|
|
65
|
-
if (clientRef.current) {
|
|
66
|
-
clientRef.current.disconnect();
|
|
67
|
-
}
|
|
68
|
-
}, []);
|
|
69
|
-
return {
|
|
70
|
-
isConnected,
|
|
71
|
-
send,
|
|
72
|
-
sendBetUpdate,
|
|
73
|
-
sendGameReset,
|
|
74
|
-
disconnect,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=useHistoryClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHistoryClient.js","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":";;AAgBA,4CAuFC;AAvGD,iCAAiE;AACjE,mDAAgD;AAehD,SAAgB,gBAAgB,CAC9B,OAAsB,EACtB,QAAuB,EACvB,UAAmC,EAAE;IAErC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,IAAA,cAAM,EAAuB,IAAI,CAAC,CAAC;IAErD,+CAA+C;IAC/C,MAAM,YAAY,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;IAC3C,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IAExB,0EAA0E;IAC1E,MAAM,SAAS,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,IAAA,iBAAS,EAAC,GA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,OAAO,GAAG,IAAI,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAExB,MAAM,IAAI,GAAG,IAAA,mBAAW,EAAC,CAAC,OAAe,EAAE,EAAE;QAC3C,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,IAA4B,EAAE,EAAE;QACjE,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QACrC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/B,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAClC,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QACjC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,WAAW;QACX,IAAI;QACJ,aAAa;QACb,aAAa;QACb,UAAU;KACX,CAAC;AACJ,CAAC"}
|
package/dist/launcher/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { useGameLauncher } from './useGameLauncher';
|
|
2
|
-
export type { GameLauncherConfig, UseGameLauncherOptions, GameLauncherState, WalletState, LaunchMutation, } from './types';
|
|
3
|
-
export { getCompatibleCoinType, VALID_COINS } from './types';
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/launcher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/launcher/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VALID_COINS = exports.getCompatibleCoinType = exports.useGameLauncher = void 0;
|
|
4
|
-
var useGameLauncher_1 = require("./useGameLauncher");
|
|
5
|
-
Object.defineProperty(exports, "useGameLauncher", { enumerable: true, get: function () { return useGameLauncher_1.useGameLauncher; } });
|
|
6
|
-
var types_1 = require("./types");
|
|
7
|
-
Object.defineProperty(exports, "getCompatibleCoinType", { enumerable: true, get: function () { return types_1.getCompatibleCoinType; } });
|
|
8
|
-
Object.defineProperty(exports, "VALID_COINS", { enumerable: true, get: function () { return types_1.VALID_COINS; } });
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/launcher/index.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAQxB,iCAA6D;AAApD,8GAAA,qBAAqB,OAAA;AAAE,oGAAA,WAAW,OAAA"}
|
package/dist/launcher/types.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export interface WalletState {
|
|
2
|
-
address: string | null;
|
|
3
|
-
connected: boolean;
|
|
4
|
-
chain: string | null;
|
|
5
|
-
}
|
|
6
|
-
export interface LaunchMutation {
|
|
7
|
-
mutateAsync: (params: {
|
|
8
|
-
gameType: string;
|
|
9
|
-
}) => Promise<{
|
|
10
|
-
origin: string;
|
|
11
|
-
token: string;
|
|
12
|
-
chain: string;
|
|
13
|
-
}>;
|
|
14
|
-
reset: () => void;
|
|
15
|
-
}
|
|
16
|
-
export interface GameLauncherConfig {
|
|
17
|
-
/** Game type identifier (e.g., 'baccarat', 'blackjack', 'range') */
|
|
18
|
-
gameType: string;
|
|
19
|
-
/** Default game origin URL (used when no token in URL) */
|
|
20
|
-
defaultOrigin: string;
|
|
21
|
-
/** Optional local development origin */
|
|
22
|
-
localOrigin?: string;
|
|
23
|
-
/** Use local origin instead of production */
|
|
24
|
-
useLocal?: boolean;
|
|
25
|
-
/** Message type for table creation events (e.g., 'baccarat-table-created') */
|
|
26
|
-
tableCreatedMessageType?: string;
|
|
27
|
-
}
|
|
28
|
-
export interface UseGameLauncherOptions {
|
|
29
|
-
/** Wallet state from useWallet() */
|
|
30
|
-
wallet: WalletState;
|
|
31
|
-
/** Launch mutation from useAuth() */
|
|
32
|
-
launch: LaunchMutation;
|
|
33
|
-
/** Function to get current URL search params */
|
|
34
|
-
getSearchParams: () => URLSearchParams;
|
|
35
|
-
/** Function to set URL search params */
|
|
36
|
-
setSearchParams: (params: Record<string, string>, options?: {
|
|
37
|
-
replace?: boolean;
|
|
38
|
-
}) => void;
|
|
39
|
-
}
|
|
40
|
-
export interface GameLauncherState {
|
|
41
|
-
/** Ready-to-use iframe src URL, or null if not ready */
|
|
42
|
-
iframeSrc: string | null;
|
|
43
|
-
/** Current iframe height from postMessage, or null */
|
|
44
|
-
iframeHeight: number | null;
|
|
45
|
-
/** Current iframe origin for security checks */
|
|
46
|
-
iframeOrigin: string | null;
|
|
47
|
-
/** Error message if launch failed */
|
|
48
|
-
error: string | null;
|
|
49
|
-
/** Whether the game is currently loading */
|
|
50
|
-
isLoading: boolean;
|
|
51
|
-
/** Whether the user needs to connect their wallet */
|
|
52
|
-
showConnectPrompt: boolean;
|
|
53
|
-
/** Retry the launch after an error */
|
|
54
|
-
retry: () => void;
|
|
55
|
-
}
|
|
56
|
-
export declare const VALID_COINS: Record<string, string[]>;
|
|
57
|
-
/** Get coin type: use URL param if compatible with chain, otherwise default */
|
|
58
|
-
export declare function getCompatibleCoinType(chain: string, urlCoinType: string | null): string;
|
|
59
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/launcher/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;QACrD,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,aAAa,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8EAA8E;IAC9E,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,sBAAsB;IACrC,oCAAoC;IACpC,MAAM,EAAE,WAAW,CAAC;IACpB,qCAAqC;IACrC,MAAM,EAAE,cAAc,CAAC;IACvB,gDAAgD;IAChD,eAAe,EAAE,MAAM,eAAe,CAAC;IACvC,wCAAwC;IACxC,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;CAC5F;AAED,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sDAAsD;IACtD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gDAAgD;IAChD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,qCAAqC;IACrC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,4CAA4C;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sCAAsC;IACtC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAGD,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAGhD,CAAC;AAEF,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAMvF"}
|
package/dist/launcher/types.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VALID_COINS = void 0;
|
|
4
|
-
exports.getCompatibleCoinType = getCompatibleCoinType;
|
|
5
|
-
// Valid coin types per chain
|
|
6
|
-
exports.VALID_COINS = {
|
|
7
|
-
sui: ['sui/sui', 'sui/usdc'],
|
|
8
|
-
solana: ['solana/sol', 'solana/usdc'],
|
|
9
|
-
};
|
|
10
|
-
/** Get coin type: use URL param if compatible with chain, otherwise default */
|
|
11
|
-
function getCompatibleCoinType(chain, urlCoinType) {
|
|
12
|
-
const defaultCoin = chain === 'solana' ? 'solana/sol' : 'sui/sui';
|
|
13
|
-
if (!urlCoinType)
|
|
14
|
-
return defaultCoin;
|
|
15
|
-
const validCoins = exports.VALID_COINS[chain] ?? [];
|
|
16
|
-
if (validCoins.includes(urlCoinType))
|
|
17
|
-
return urlCoinType;
|
|
18
|
-
return defaultCoin;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/launcher/types.ts"],"names":[],"mappings":";;;AA+DA,sDAMC;AAbD,6BAA6B;AAChB,QAAA,WAAW,GAA6B;IACnD,GAAG,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC;IAC5B,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC;CACtC,CAAC;AAEF,+EAA+E;AAC/E,SAAgB,qBAAqB,CAAC,KAAa,EAAE,WAA0B;IAC7E,MAAM,WAAW,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,IAAI,CAAC,WAAW;QAAE,OAAO,WAAW,CAAC;IACrC,MAAM,UAAU,GAAG,mBAAW,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC5C,IAAI,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,WAAW,CAAC;IACzD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGameLauncher.d.ts","sourceRoot":"","sources":["../../src/launcher/useGameLauncher.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EAElB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,eAAe,CAC7B,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,sBAAsB,GAC9B,iBAAiB,CA+InB"}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useGameLauncher = useGameLauncher;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
function useGameLauncher(config, options) {
|
|
7
|
-
const { gameType, defaultOrigin, localOrigin, useLocal = false, tableCreatedMessageType } = config;
|
|
8
|
-
const { wallet, launch, getSearchParams, setSearchParams } = options;
|
|
9
|
-
const { mutateAsync: launchGame, reset } = launch;
|
|
10
|
-
// Derive the message type from gameType if not provided
|
|
11
|
-
const tableCreatedType = tableCreatedMessageType ?? `${gameType}-table-created`;
|
|
12
|
-
// Get URL params
|
|
13
|
-
const searchParams = getSearchParams();
|
|
14
|
-
const tokenParam = searchParams.get('token');
|
|
15
|
-
const urlCoinType = searchParams.get('coinType');
|
|
16
|
-
const [iframeOrigin, setIframeOrigin] = (0, react_1.useState)(null);
|
|
17
|
-
const [sessionToken, setSessionToken] = (0, react_1.useState)(null);
|
|
18
|
-
const [launchError, setLaunchError] = (0, react_1.useState)(null);
|
|
19
|
-
const [launchCoinType, setLaunchCoinType] = (0, react_1.useState)(null);
|
|
20
|
-
const [iframeHeight, setIframeHeight] = (0, react_1.useState)(null);
|
|
21
|
-
const launchInProgress = (0, react_1.useRef)(false);
|
|
22
|
-
// Determine the origin to use
|
|
23
|
-
const resolvedOrigin = useLocal && localOrigin ? localOrigin : defaultOrigin;
|
|
24
|
-
// Main launch effect
|
|
25
|
-
(0, react_1.useEffect)(() => {
|
|
26
|
-
async function run() {
|
|
27
|
-
// Load directly from URL token (shareable link or spectator)
|
|
28
|
-
if (tokenParam) {
|
|
29
|
-
if (sessionToken === tokenParam)
|
|
30
|
-
return;
|
|
31
|
-
setLaunchError(null);
|
|
32
|
-
setSessionToken(tokenParam);
|
|
33
|
-
setIframeOrigin(resolvedOrigin);
|
|
34
|
-
setLaunchCoinType(null); // Will be set by iframe message
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// Need wallet to launch
|
|
38
|
-
if (!wallet.address || !wallet.connected || !wallet.chain) {
|
|
39
|
-
setSessionToken(null);
|
|
40
|
-
setIframeOrigin(null);
|
|
41
|
-
setLaunchError(null);
|
|
42
|
-
setLaunchCoinType(null);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
// Skip if already have session, error, or launch in progress
|
|
46
|
-
if (sessionToken || launchError || launchInProgress.current)
|
|
47
|
-
return;
|
|
48
|
-
launchInProgress.current = true;
|
|
49
|
-
try {
|
|
50
|
-
const { origin, token, chain } = await launchGame({ gameType });
|
|
51
|
-
setSessionToken(token);
|
|
52
|
-
setIframeOrigin(useLocal && localOrigin ? localOrigin : origin);
|
|
53
|
-
// Use selected coin type if compatible, otherwise default
|
|
54
|
-
setLaunchCoinType((0, types_1.getCompatibleCoinType)(chain, urlCoinType));
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
setLaunchError(error instanceof Error ? error.message : String(error));
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
launchInProgress.current = false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
run();
|
|
64
|
-
}, [
|
|
65
|
-
wallet.address,
|
|
66
|
-
wallet.connected,
|
|
67
|
-
wallet.chain,
|
|
68
|
-
sessionToken,
|
|
69
|
-
launchError,
|
|
70
|
-
launchGame,
|
|
71
|
-
tokenParam,
|
|
72
|
-
urlCoinType,
|
|
73
|
-
gameType,
|
|
74
|
-
resolvedOrigin,
|
|
75
|
-
useLocal,
|
|
76
|
-
localOrigin,
|
|
77
|
-
]);
|
|
78
|
-
// Handle iframe messages
|
|
79
|
-
(0, react_1.useEffect)(() => {
|
|
80
|
-
const handleMessage = (event) => {
|
|
81
|
-
if (!iframeOrigin || event.origin !== iframeOrigin)
|
|
82
|
-
return;
|
|
83
|
-
if (event.data?.type === tableCreatedType && event.data.tableId) {
|
|
84
|
-
// Table created - include coinType so selector shows correct coin (disabled)
|
|
85
|
-
const coinType = event.data.coinType || launchCoinType;
|
|
86
|
-
const newParams = { token: event.data.tableId };
|
|
87
|
-
if (coinType)
|
|
88
|
-
newParams.coinType = coinType;
|
|
89
|
-
setSessionToken(event.data.tableId);
|
|
90
|
-
setLaunchCoinType(null);
|
|
91
|
-
setSearchParams(newParams, { replace: true });
|
|
92
|
-
}
|
|
93
|
-
if (event.data?.type === 'table-info' && event.data.coinType) {
|
|
94
|
-
// Existing table loaded - set coinType in URL so selector shows correct coin
|
|
95
|
-
const currentToken = getSearchParams().get('token');
|
|
96
|
-
if (currentToken) {
|
|
97
|
-
setSearchParams({ token: currentToken, coinType: event.data.coinType }, { replace: true });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (event.data?.type === 'iframe-height' && event.data.height) {
|
|
101
|
-
setIframeHeight(event.data.height);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
window.addEventListener('message', handleMessage);
|
|
105
|
-
return () => window.removeEventListener('message', handleMessage);
|
|
106
|
-
}, [iframeOrigin, launchCoinType, tableCreatedType, getSearchParams, setSearchParams]);
|
|
107
|
-
const retry = (0, react_1.useCallback)(() => {
|
|
108
|
-
launchInProgress.current = false;
|
|
109
|
-
setSessionToken(null);
|
|
110
|
-
setIframeOrigin(null);
|
|
111
|
-
setLaunchError(null);
|
|
112
|
-
setLaunchCoinType(null);
|
|
113
|
-
reset();
|
|
114
|
-
}, [reset]);
|
|
115
|
-
const iframeSrc = (0, react_1.useMemo)(() => {
|
|
116
|
-
if (!iframeOrigin || !sessionToken)
|
|
117
|
-
return null;
|
|
118
|
-
try {
|
|
119
|
-
const url = new URL('/', iframeOrigin);
|
|
120
|
-
url.searchParams.set('token', sessionToken);
|
|
121
|
-
if (launchCoinType)
|
|
122
|
-
url.searchParams.set('coinType', launchCoinType);
|
|
123
|
-
return url.toString();
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
// Invalid origin URL - this will be caught and surfaced via error state
|
|
127
|
-
console.error('Invalid iframe origin:', iframeOrigin, e);
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
}, [iframeOrigin, sessionToken, launchCoinType]);
|
|
131
|
-
// Determine UI state
|
|
132
|
-
const showConnectPrompt = !tokenParam && !wallet.connected;
|
|
133
|
-
const isLoading = !showConnectPrompt && !launchError && !iframeSrc;
|
|
134
|
-
return {
|
|
135
|
-
iframeSrc,
|
|
136
|
-
iframeHeight,
|
|
137
|
-
iframeOrigin,
|
|
138
|
-
error: launchError,
|
|
139
|
-
isLoading,
|
|
140
|
-
showConnectPrompt,
|
|
141
|
-
retry,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=useGameLauncher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGameLauncher.js","sourceRoot":"","sources":["../../src/launcher/useGameLauncher.ts"],"names":[],"mappings":";;AAQA,0CAkJC;AA1JD,iCAA0E;AAC1E,mCAKiB;AAEjB,SAAgB,eAAe,CAC7B,MAA0B,EAC1B,OAA+B;IAE/B,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,GAAG,KAAK,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IACnG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACrE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAElD,wDAAwD;IACxD,MAAM,gBAAgB,GAAG,uBAAuB,IAAI,GAAG,QAAQ,gBAAgB,CAAC;IAEhF,iBAAiB;IACjB,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAEjD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAAgB,IAAI,CAAC,CAAC;IACtE,MAAM,CAAC,YAAY,EAAE,eAAe,CA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B,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { SessionConfig, LaunchParams, LaunchResult, InitializeResult, TokenType } from './types';
|
|
2
|
-
export declare class SessionClient {
|
|
3
|
-
private baseUrl;
|
|
4
|
-
constructor(config?: SessionConfig);
|
|
5
|
-
/**
|
|
6
|
-
* Get a launch URL with one-time token for a game.
|
|
7
|
-
* Used by the parent site (e.g., doubleup-io) to launch games.
|
|
8
|
-
*
|
|
9
|
-
* @param params - Wallet address, signature, chain, and game type
|
|
10
|
-
* @returns Launch URL containing the one-time token
|
|
11
|
-
*/
|
|
12
|
-
getLaunchUrl(params: LaunchParams): Promise<LaunchResult>;
|
|
13
|
-
/**
|
|
14
|
-
* Exchange a one-time token (OTT) for a session JWT.
|
|
15
|
-
*
|
|
16
|
-
* @param oneTimeToken - The one-time token from the launch URL
|
|
17
|
-
* @returns The session JWT token
|
|
18
|
-
* @throws AuthError if the token is invalid or expired
|
|
19
|
-
*/
|
|
20
|
-
getSessionToken(oneTimeToken: string): Promise<string>;
|
|
21
|
-
/**
|
|
22
|
-
* Initialize a game session from a URL token.
|
|
23
|
-
* Handles the full flow: detect token type → exchange OTT → return session info.
|
|
24
|
-
*
|
|
25
|
-
* This is the main entry point for game frontends (baccarat, blackjack, range).
|
|
26
|
-
*
|
|
27
|
-
* @param urlToken - Token from URL (can be OTT, session JWT, or table ID)
|
|
28
|
-
* @returns Session initialization result with token type and session token
|
|
29
|
-
* @throws AuthError if authentication fails
|
|
30
|
-
*/
|
|
31
|
-
initializeSession(urlToken: string): Promise<InitializeResult>;
|
|
32
|
-
/**
|
|
33
|
-
* Get the token type without making any network calls.
|
|
34
|
-
* Useful for quick UI decisions before full initialization.
|
|
35
|
-
*/
|
|
36
|
-
getTokenType(token: string): TokenType;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=SessionClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SessionClient.d.ts","sourceRoot":"","sources":["../../src/session/SessionClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKjG,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,GAAE,aAAkB;IAItC;;;;;;OAMG;IACG,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IA8C/D;;;;;;OAMG;IACG,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwB5D;;;;;;;;;OASG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA6BpE;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS;CAMvC"}
|