infinite-games-sdk 0.0.4 → 0.0.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/history/index.d.ts +1 -1
- package/dist/history/index.d.ts.map +1 -1
- package/dist/history/types.d.ts +0 -7
- package/dist/history/types.d.ts.map +1 -1
- package/dist/history/useHistoryClient.d.ts +11 -5
- package/dist/history/useHistoryClient.d.ts.map +1 -1
- package/dist/history/useHistoryClient.js +29 -36
- package/dist/history/useHistoryClient.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/session/SessionClient.d.ts +1 -17
- package/dist/session/SessionClient.d.ts.map +1 -1
- package/dist/session/SessionClient.js +0 -49
- package/dist/session/SessionClient.js.map +1 -1
- package/dist/session/index.d.ts +5 -2
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +4 -1
- package/dist/session/index.js.map +1 -1
- package/dist/session/initializeGame.d.ts +48 -0
- package/dist/session/initializeGame.d.ts.map +1 -0
- package/dist/session/initializeGame.js +59 -0
- package/dist/session/initializeGame.js.map +1 -0
- package/dist/session/tokens.d.ts +6 -0
- package/dist/session/tokens.d.ts.map +1 -1
- package/dist/session/tokens.js +16 -0
- package/dist/session/tokens.js.map +1 -1
- package/dist/session/types.d.ts +0 -6
- package/dist/session/types.d.ts.map +1 -1
- package/package.json +16 -10
package/dist/history/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HistoryConfig } from './types';
|
|
2
2
|
interface UseHistoryClientOptions {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
*/
|
|
6
11
|
config?: HistoryConfig;
|
|
7
12
|
}
|
|
8
13
|
export declare function useHistoryClient(tableId: string | null, coinType: string | null, options?: UseHistoryClientOptions): {
|
|
9
14
|
isConnected: boolean;
|
|
10
|
-
|
|
15
|
+
send: (message: object) => void;
|
|
16
|
+
sendBetUpdate: (bets: Record<string, number>) => void;
|
|
11
17
|
sendGameReset: () => void;
|
|
12
18
|
disconnect: () => void;
|
|
13
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHistoryClient.d.ts","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
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"}
|
|
@@ -6,20 +6,21 @@ const HistoryClient_1 = require("./HistoryClient");
|
|
|
6
6
|
function useHistoryClient(tableId, coinType, options = {}) {
|
|
7
7
|
const [isConnected, setIsConnected] = (0, react_1.useState)(false);
|
|
8
8
|
const clientRef = (0, react_1.useRef)(null);
|
|
9
|
-
// Use
|
|
10
|
-
const
|
|
11
|
-
const onBetUpdateRef = (0, react_1.useRef)(options.onBetUpdate);
|
|
12
|
-
const onGameResetRef = (0, react_1.useRef)(options.onGameReset);
|
|
9
|
+
// Use ref for callback to avoid stale closures
|
|
10
|
+
const onMessageRef = (0, react_1.useRef)(options.onMessage);
|
|
13
11
|
(0, react_1.useEffect)(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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]);
|
|
18
19
|
(0, react_1.useEffect)(() => {
|
|
19
20
|
if (!tableId || !coinType) {
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
|
-
const client = new HistoryClient_1.HistoryClient(
|
|
23
|
+
const client = new HistoryClient_1.HistoryClient(configRef.current);
|
|
23
24
|
clientRef.current = client;
|
|
24
25
|
client.onConnect = () => {
|
|
25
26
|
setIsConnected(true);
|
|
@@ -30,27 +31,17 @@ function useHistoryClient(tableId, coinType, options = {}) {
|
|
|
30
31
|
client.onMessage = (event) => {
|
|
31
32
|
try {
|
|
32
33
|
const message = JSON.parse(event.data);
|
|
33
|
-
//
|
|
34
|
+
// For wrapped events {channel, data}, unwrap and pass the data
|
|
35
|
+
// For relay messages {type, ...}, pass as-is
|
|
34
36
|
if (message.channel && message.data) {
|
|
35
|
-
|
|
36
|
-
onGameEventRef.current(message.data);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Relay messages: {type, ...}
|
|
40
|
-
else if (message.type === 'bet_update') {
|
|
41
|
-
if (onBetUpdateRef.current) {
|
|
42
|
-
const { type, ...bets } = message;
|
|
43
|
-
onBetUpdateRef.current(bets);
|
|
44
|
-
}
|
|
37
|
+
onMessageRef.current?.(message.data);
|
|
45
38
|
}
|
|
46
|
-
else
|
|
47
|
-
|
|
48
|
-
onGameResetRef.current();
|
|
49
|
-
}
|
|
39
|
+
else {
|
|
40
|
+
onMessageRef.current?.(message);
|
|
50
41
|
}
|
|
51
42
|
}
|
|
52
43
|
catch (error) {
|
|
53
|
-
console.error('Failed to parse WebSocket message:', error);
|
|
44
|
+
console.error('[HistoryClient] Failed to parse WebSocket message:', error);
|
|
54
45
|
}
|
|
55
46
|
};
|
|
56
47
|
client.connect(tableId, coinType);
|
|
@@ -58,24 +49,26 @@ function useHistoryClient(tableId, coinType, options = {}) {
|
|
|
58
49
|
client.disconnect();
|
|
59
50
|
clientRef.current = null;
|
|
60
51
|
};
|
|
61
|
-
}, [tableId, coinType
|
|
62
|
-
const
|
|
52
|
+
}, [tableId, coinType]);
|
|
53
|
+
const send = (0, react_1.useCallback)((message) => {
|
|
63
54
|
if (clientRef.current) {
|
|
64
|
-
clientRef.current.send(
|
|
55
|
+
clientRef.current.send(message);
|
|
65
56
|
}
|
|
66
|
-
};
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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)(() => {
|
|
73
65
|
if (clientRef.current) {
|
|
74
66
|
clientRef.current.disconnect();
|
|
75
67
|
}
|
|
76
|
-
};
|
|
68
|
+
}, []);
|
|
77
69
|
return {
|
|
78
70
|
isConnected,
|
|
71
|
+
send,
|
|
79
72
|
sendBetUpdate,
|
|
80
73
|
sendGameReset,
|
|
81
74
|
disconnect,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHistoryClient.js","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":";;
|
|
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,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AAC,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/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export { SessionClient } from './session';
|
|
2
2
|
export { HistoryClient, useHistoryClient } from './history';
|
|
3
|
+
export { initializeGame } from './session';
|
|
3
4
|
export { useGameLauncher } from './launcher';
|
|
4
|
-
export { looksLikeJwt, isOneTimeToken, isTableId } from './session/tokens';
|
|
5
|
+
export { looksLikeJwt, isOneTimeToken, isTableId, getTokenType } from './session/tokens';
|
|
5
6
|
export { toBackendScale, fromBackendScale, SCALE_FACTOR } from './utils/scale';
|
|
6
7
|
export { getCompatibleCoinType, VALID_COINS } from './launcher';
|
|
7
8
|
export { AuthError } from './errors';
|
|
8
|
-
export type {
|
|
9
|
-
export type {
|
|
9
|
+
export type { TokenType } from './session/tokens';
|
|
10
|
+
export type { SessionConfig, LaunchParams, LaunchResult, InitializeGameOptions, InitializeGameResult, TableInfo } from './session';
|
|
11
|
+
export type { HistoryConfig } from './history/types';
|
|
10
12
|
export type { GameLauncherConfig, UseGameLauncherOptions, GameLauncherState, WalletState, LaunchMutation, } from './launcher';
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACnI,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthError = exports.VALID_COINS = exports.getCompatibleCoinType = exports.SCALE_FACTOR = exports.fromBackendScale = exports.toBackendScale = exports.isTableId = exports.isOneTimeToken = exports.looksLikeJwt = exports.useGameLauncher = exports.useHistoryClient = exports.HistoryClient = exports.SessionClient = void 0;
|
|
3
|
+
exports.AuthError = exports.VALID_COINS = exports.getCompatibleCoinType = exports.SCALE_FACTOR = exports.fromBackendScale = exports.toBackendScale = exports.getTokenType = exports.isTableId = exports.isOneTimeToken = exports.looksLikeJwt = exports.useGameLauncher = exports.initializeGame = exports.useHistoryClient = exports.HistoryClient = exports.SessionClient = void 0;
|
|
4
4
|
// Clients
|
|
5
5
|
var session_1 = require("./session");
|
|
6
6
|
Object.defineProperty(exports, "SessionClient", { enumerable: true, get: function () { return session_1.SessionClient; } });
|
|
7
7
|
var history_1 = require("./history");
|
|
8
8
|
Object.defineProperty(exports, "HistoryClient", { enumerable: true, get: function () { return history_1.HistoryClient; } });
|
|
9
9
|
Object.defineProperty(exports, "useHistoryClient", { enumerable: true, get: function () { return history_1.useHistoryClient; } });
|
|
10
|
+
// Functions
|
|
11
|
+
var session_2 = require("./session");
|
|
12
|
+
Object.defineProperty(exports, "initializeGame", { enumerable: true, get: function () { return session_2.initializeGame; } });
|
|
10
13
|
// Hooks
|
|
11
14
|
var launcher_1 = require("./launcher");
|
|
12
15
|
Object.defineProperty(exports, "useGameLauncher", { enumerable: true, get: function () { return launcher_1.useGameLauncher; } });
|
|
@@ -15,6 +18,7 @@ var tokens_1 = require("./session/tokens");
|
|
|
15
18
|
Object.defineProperty(exports, "looksLikeJwt", { enumerable: true, get: function () { return tokens_1.looksLikeJwt; } });
|
|
16
19
|
Object.defineProperty(exports, "isOneTimeToken", { enumerable: true, get: function () { return tokens_1.isOneTimeToken; } });
|
|
17
20
|
Object.defineProperty(exports, "isTableId", { enumerable: true, get: function () { return tokens_1.isTableId; } });
|
|
21
|
+
Object.defineProperty(exports, "getTokenType", { enumerable: true, get: function () { return tokens_1.getTokenType; } });
|
|
18
22
|
var scale_1 = require("./utils/scale");
|
|
19
23
|
Object.defineProperty(exports, "toBackendScale", { enumerable: true, get: function () { return scale_1.toBackendScale; } });
|
|
20
24
|
Object.defineProperty(exports, "fromBackendScale", { enumerable: true, get: function () { return scale_1.fromBackendScale; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,UAAU;AACV,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,qCAA4D;AAAnD,wGAAA,aAAa,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAExC,QAAQ;AACR,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AAExB,YAAY;AACZ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,UAAU;AACV,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,qCAA4D;AAAnD,wGAAA,aAAa,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAExC,YAAY;AACZ,qCAA2C;AAAlC,yGAAA,cAAc,OAAA;AAEvB,QAAQ;AACR,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AAExB,YAAY;AACZ,2CAAyF;AAAhF,sGAAA,YAAY,OAAA;AAAE,wGAAA,cAAc,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA;AAC9D,uCAA+E;AAAtE,uGAAA,cAAc,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,qGAAA,YAAY,OAAA;AACvD,uCAAgE;AAAvD,iHAAA,qBAAqB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAE3C,SAAS;AACT,mCAAqC;AAA5B,mGAAA,SAAS,OAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionConfig, LaunchParams, LaunchResult
|
|
1
|
+
import { SessionConfig, LaunchParams, LaunchResult } from './types';
|
|
2
2
|
export declare class SessionClient {
|
|
3
3
|
private baseUrl;
|
|
4
4
|
constructor(config?: SessionConfig);
|
|
@@ -18,21 +18,5 @@ export declare class SessionClient {
|
|
|
18
18
|
* @throws AuthError if the token is invalid or expired
|
|
19
19
|
*/
|
|
20
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
21
|
}
|
|
38
22
|
//# sourceMappingURL=SessionClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionClient.d.ts","sourceRoot":"","sources":["../../src/session/SessionClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"SessionClient.d.ts","sourceRoot":"","sources":["../../src/session/SessionClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIpE,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;CAuB7D"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SessionClient = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
|
-
const tokens_1 = require("./tokens");
|
|
6
5
|
const DEFAULT_BASE_URL = 'https://sessiondev.infiniteedgers.com';
|
|
7
6
|
class SessionClient {
|
|
8
7
|
constructor(config = {}) {
|
|
@@ -83,54 +82,6 @@ class SessionClient {
|
|
|
83
82
|
}
|
|
84
83
|
return data.token;
|
|
85
84
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Initialize a game session from a URL token.
|
|
88
|
-
* Handles the full flow: detect token type → exchange OTT → return session info.
|
|
89
|
-
*
|
|
90
|
-
* This is the main entry point for game frontends (baccarat, blackjack, range).
|
|
91
|
-
*
|
|
92
|
-
* @param urlToken - Token from URL (can be OTT, session JWT, or table ID)
|
|
93
|
-
* @returns Session initialization result with token type and session token
|
|
94
|
-
* @throws AuthError if authentication fails
|
|
95
|
-
*/
|
|
96
|
-
async initializeSession(urlToken) {
|
|
97
|
-
// Case 1: Token is a table ID (UUID) - spectator or returning player
|
|
98
|
-
if ((0, tokens_1.isTableId)(urlToken)) {
|
|
99
|
-
return {
|
|
100
|
-
tokenType: 'table_id',
|
|
101
|
-
tableId: urlToken,
|
|
102
|
-
sessionToken: null,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
// Case 2: Token is a one-time token - exchange for session JWT
|
|
106
|
-
if ((0, tokens_1.isOneTimeToken)(urlToken)) {
|
|
107
|
-
const sessionToken = await this.getSessionToken(urlToken);
|
|
108
|
-
return {
|
|
109
|
-
tokenType: 'ott',
|
|
110
|
-
tableId: null,
|
|
111
|
-
sessionToken,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
// Case 3: Token looks like a JWT but is not an OTT - likely expired/used
|
|
115
|
-
if ((0, tokens_1.looksLikeJwt)(urlToken)) {
|
|
116
|
-
throw new errors_1.AuthError('This launch link has expired or was already used. Please launch the game again.');
|
|
117
|
-
}
|
|
118
|
-
// Case 4: Unknown token format
|
|
119
|
-
throw new Error('Invalid token format');
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Get the token type without making any network calls.
|
|
123
|
-
* Useful for quick UI decisions before full initialization.
|
|
124
|
-
*/
|
|
125
|
-
getTokenType(token) {
|
|
126
|
-
if ((0, tokens_1.isTableId)(token))
|
|
127
|
-
return 'table_id';
|
|
128
|
-
if ((0, tokens_1.isOneTimeToken)(token))
|
|
129
|
-
return 'ott';
|
|
130
|
-
if ((0, tokens_1.looksLikeJwt)(token))
|
|
131
|
-
return 'expired_jwt';
|
|
132
|
-
return 'unknown';
|
|
133
|
-
}
|
|
134
85
|
}
|
|
135
86
|
exports.SessionClient = SessionClient;
|
|
136
87
|
//# sourceMappingURL=SessionClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionClient.js","sourceRoot":"","sources":["../../src/session/SessionClient.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;
|
|
1
|
+
{"version":3,"file":"SessionClient.js","sourceRoot":"","sources":["../../src/session/SessionClient.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AAGtC,MAAM,gBAAgB,GAAG,uCAAuC,CAAC;AAEjE,MAAa,aAAa;IAGxB,YAAY,SAAwB,EAAE;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,MAAoB;QACrC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,qBAAqB,EAAE;YACjE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B,CAAC;SACH,CAAC,CAA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ACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;aACxC;SACF,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,kBAAS,CAAC,mCAAmC,CAAC,CAAC;QAC3D,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,6BAA6B,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AA1FD,sCA0FC"}
|
package/dist/session/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { SessionClient } from './SessionClient';
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
2
|
+
export { initializeGame } from './initializeGame';
|
|
3
|
+
export { looksLikeJwt, isOneTimeToken, isTableId, getTokenType } from './tokens';
|
|
4
|
+
export type { TokenType } from './tokens';
|
|
5
|
+
export type { SessionConfig, LaunchParams, LaunchResult } from './types';
|
|
6
|
+
export type { InitializeGameOptions, InitializeGameResult, TableInfo } from './initializeGame';
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACjF,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/session/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTableId = exports.isOneTimeToken = exports.looksLikeJwt = exports.SessionClient = void 0;
|
|
3
|
+
exports.getTokenType = exports.isTableId = exports.isOneTimeToken = exports.looksLikeJwt = exports.initializeGame = exports.SessionClient = void 0;
|
|
4
4
|
var SessionClient_1 = require("./SessionClient");
|
|
5
5
|
Object.defineProperty(exports, "SessionClient", { enumerable: true, get: function () { return SessionClient_1.SessionClient; } });
|
|
6
|
+
var initializeGame_1 = require("./initializeGame");
|
|
7
|
+
Object.defineProperty(exports, "initializeGame", { enumerable: true, get: function () { return initializeGame_1.initializeGame; } });
|
|
6
8
|
var tokens_1 = require("./tokens");
|
|
7
9
|
Object.defineProperty(exports, "looksLikeJwt", { enumerable: true, get: function () { return tokens_1.looksLikeJwt; } });
|
|
8
10
|
Object.defineProperty(exports, "isOneTimeToken", { enumerable: true, get: function () { return tokens_1.isOneTimeToken; } });
|
|
9
11
|
Object.defineProperty(exports, "isTableId", { enumerable: true, get: function () { return tokens_1.isTableId; } });
|
|
12
|
+
Object.defineProperty(exports, "getTokenType", { enumerable: true, get: function () { return tokens_1.getTokenType; } });
|
|
10
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,mCAAiF;AAAxE,sGAAA,YAAY,OAAA;AAAE,wGAAA,cAAc,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SessionConfig } from './types';
|
|
2
|
+
export interface TableInfo {
|
|
3
|
+
tableId: string;
|
|
4
|
+
coinType: string;
|
|
5
|
+
}
|
|
6
|
+
export interface InitializeGameOptions {
|
|
7
|
+
/** Token from URL - can be OTT or table_id */
|
|
8
|
+
token: string;
|
|
9
|
+
/** Coin type from URL (required for OTT, ignored for table_id) */
|
|
10
|
+
coinType: string | null;
|
|
11
|
+
/** Existing session token from storage (optional) */
|
|
12
|
+
sessionToken?: string | null;
|
|
13
|
+
/** Game-specific function to create a new table */
|
|
14
|
+
createTable: (sessionToken: string, coinType: string) => Promise<TableInfo>;
|
|
15
|
+
/** Game-specific function to get table info (e.g., via getBalance) */
|
|
16
|
+
getTableInfo: (tableId: string, sessionToken: string | null) => Promise<{
|
|
17
|
+
coinType: string;
|
|
18
|
+
}>;
|
|
19
|
+
/** Session client config (optional) */
|
|
20
|
+
sessionConfig?: SessionConfig;
|
|
21
|
+
}
|
|
22
|
+
export interface InitializeGameResult {
|
|
23
|
+
tableId: string;
|
|
24
|
+
coinType: string;
|
|
25
|
+
sessionToken: string | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Initialize a game session from a URL token.
|
|
29
|
+
*
|
|
30
|
+
* Handles the complete flow:
|
|
31
|
+
* - OTT: exchange for session token → create table → return result
|
|
32
|
+
* - table_id: fetch table info → return result
|
|
33
|
+
* - expired JWT: throw AuthError
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const result = await initializeGame({
|
|
38
|
+
* token: urlParams.get('token'),
|
|
39
|
+
* coinType: urlParams.get('coinType'),
|
|
40
|
+
* sessionToken: sessionStorage.getItem('session_token'),
|
|
41
|
+
* createTable: (session, coin) => baccaratApi.createTable(session, coin),
|
|
42
|
+
* getTableInfo: (tableId, session) => baccaratApi.getBalance(session, tableId),
|
|
43
|
+
* });
|
|
44
|
+
* // result = { tableId, coinType, sessionToken }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function initializeGame(options: InitializeGameOptions): Promise<InitializeGameResult>;
|
|
48
|
+
//# sourceMappingURL=initializeGame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeGame.d.ts","sourceRoot":"","sources":["../../src/session/initializeGame.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mDAAmD;IACnD,WAAW,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5E,sEAAsE;IACtE,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9F,uCAAuC;IACvC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqClG"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeGame = initializeGame;
|
|
4
|
+
const SessionClient_1 = require("./SessionClient");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const tokens_1 = require("./tokens");
|
|
7
|
+
/**
|
|
8
|
+
* Initialize a game session from a URL token.
|
|
9
|
+
*
|
|
10
|
+
* Handles the complete flow:
|
|
11
|
+
* - OTT: exchange for session token → create table → return result
|
|
12
|
+
* - table_id: fetch table info → return result
|
|
13
|
+
* - expired JWT: throw AuthError
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const result = await initializeGame({
|
|
18
|
+
* token: urlParams.get('token'),
|
|
19
|
+
* coinType: urlParams.get('coinType'),
|
|
20
|
+
* sessionToken: sessionStorage.getItem('session_token'),
|
|
21
|
+
* createTable: (session, coin) => baccaratApi.createTable(session, coin),
|
|
22
|
+
* getTableInfo: (tableId, session) => baccaratApi.getBalance(session, tableId),
|
|
23
|
+
* });
|
|
24
|
+
* // result = { tableId, coinType, sessionToken }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async function initializeGame(options) {
|
|
28
|
+
const { token, coinType, sessionToken, createTable, getTableInfo, sessionConfig } = options;
|
|
29
|
+
// Case 1: Token is a table_id - fetch table info
|
|
30
|
+
if ((0, tokens_1.isTableId)(token)) {
|
|
31
|
+
const info = await getTableInfo(token, sessionToken ?? null);
|
|
32
|
+
return {
|
|
33
|
+
tableId: token,
|
|
34
|
+
coinType: info.coinType,
|
|
35
|
+
sessionToken: sessionToken ?? null,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Case 2: Token is a one-time token - exchange and create table
|
|
39
|
+
if ((0, tokens_1.isOneTimeToken)(token)) {
|
|
40
|
+
if (!coinType) {
|
|
41
|
+
throw new Error('Missing coinType for new game');
|
|
42
|
+
}
|
|
43
|
+
const sessionClient = new SessionClient_1.SessionClient(sessionConfig);
|
|
44
|
+
const newSessionToken = await sessionClient.getSessionToken(token);
|
|
45
|
+
const table = await createTable(newSessionToken, coinType);
|
|
46
|
+
return {
|
|
47
|
+
tableId: table.tableId,
|
|
48
|
+
coinType: table.coinType,
|
|
49
|
+
sessionToken: newSessionToken,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// Case 3: Token looks like a JWT but not OTT - likely expired/used
|
|
53
|
+
if ((0, tokens_1.looksLikeJwt)(token)) {
|
|
54
|
+
throw new errors_1.AuthError('This launch link has expired or was already used. Please launch the game again.');
|
|
55
|
+
}
|
|
56
|
+
// Case 4: Unknown token format
|
|
57
|
+
throw new Error('Invalid token format');
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=initializeGame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeGame.js","sourceRoot":"","sources":["../../src/session/initializeGame.ts"],"names":[],"mappings":";;AAmDA,wCAqCC;AAxFD,mDAAgD;AAChD,sCAAsC;AACtC,qCAAmE;AA6BnE;;;;;;;;;;;;;;;;;;;GAmBG;AACI,KAAK,UAAU,cAAc,CAAC,OAA8B;IACjE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE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/
|
|
14
14
|
export declare function isTableId(token: string): boolean;
|
|
15
|
+
export type TokenType = 'ott' | 'table_id' | 'expired_jwt' | 'unknown';
|
|
16
|
+
/**
|
|
17
|
+
* Classify a URL token into its type.
|
|
18
|
+
* Useful for quick UI decisions before making network calls.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getTokenType(token: string | null | undefined): TokenType;
|
|
15
21
|
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/session/tokens.ts"],"names":[],"mappings":"AAyBA;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAItE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAIhD"}
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/session/tokens.ts"],"names":[],"mappings":"AAyBA;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAItE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAIhD;AAED,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,aAAa,GAAG,SAAS,CAAC;AAEvE;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,CAMxE"}
|
package/dist/session/tokens.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.looksLikeJwt = looksLikeJwt;
|
|
4
4
|
exports.isOneTimeToken = isOneTimeToken;
|
|
5
5
|
exports.isTableId = isTableId;
|
|
6
|
+
exports.getTokenType = getTokenType;
|
|
6
7
|
/**
|
|
7
8
|
* Decode a base64url encoded string (used for JWT payloads).
|
|
8
9
|
*/
|
|
@@ -52,4 +53,19 @@ function isTableId(token) {
|
|
|
52
53
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
53
54
|
return uuidRegex.test(token);
|
|
54
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Classify a URL token into its type.
|
|
58
|
+
* Useful for quick UI decisions before making network calls.
|
|
59
|
+
*/
|
|
60
|
+
function getTokenType(token) {
|
|
61
|
+
if (!token)
|
|
62
|
+
return 'unknown';
|
|
63
|
+
if (isTableId(token))
|
|
64
|
+
return 'table_id';
|
|
65
|
+
if (isOneTimeToken(token))
|
|
66
|
+
return 'ott';
|
|
67
|
+
if (looksLikeJwt(token))
|
|
68
|
+
return 'expired_jwt';
|
|
69
|
+
return 'unknown';
|
|
70
|
+
}
|
|
55
71
|
//# sourceMappingURL=tokens.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/session/tokens.ts"],"names":[],"mappings":";;AA4BA,oCAIC;AAMD,wCAEC;AAMD,8BAIC;
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/session/tokens.ts"],"names":[],"mappings":";;AA4BA,oCAIC;AAMD,wCAEC;AAMD,8BAIC;AAQD,oCAMC;AAhED;;GAEG;AACH,SAAS,eAAe,CAAC,KAAa;IACpC,uCAAuC;IACvC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3D,wBAAwB;IACxB,MAAM,M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,YAAY,CAAC,KAAgC;IAC3D,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC;IACxC,IAAI,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,YAAY,CAAC,KAAK,CAAC;QAAE,OAAO,aAAa,CAAC;IAC9C,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/session/types.d.ts
CHANGED
|
@@ -12,10 +12,4 @@ export interface LaunchResult {
|
|
|
12
12
|
origin: string;
|
|
13
13
|
token: string;
|
|
14
14
|
}
|
|
15
|
-
export type TokenType = 'ott' | 'table_id' | 'expired_jwt' | 'unknown';
|
|
16
|
-
export interface InitializeResult {
|
|
17
|
-
tokenType: TokenType;
|
|
18
|
-
tableId: string | null;
|
|
19
|
-
sessionToken: string | null;
|
|
20
|
-
}
|
|
21
15
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "infinite-games-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Infinite Games SDK",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"sdk",
|
|
12
|
+
"typescript",
|
|
13
|
+
"npm"
|
|
14
|
+
],
|
|
13
15
|
"author": "",
|
|
14
16
|
"license": "ISC",
|
|
15
17
|
"devDependencies": {
|
|
@@ -19,5 +21,9 @@
|
|
|
19
21
|
},
|
|
20
22
|
"peerDependencies": {
|
|
21
23
|
"react": "^18.x"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
28
|
}
|
|
23
|
-
}
|
|
29
|
+
}
|