@pokertools/sdk 1.0.11 → 1.0.16
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 +194 -43
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.cjs +58 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.js +58 -1
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +107 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +74 -2
- package/dist/react/index.d.ts +74 -2
- package/dist/react/index.js +106 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -2
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as _pokertools_types from '@pokertools/types';
|
|
4
|
-
import { LoginRequest, LoginResponse, TableListItem, CreateTableRequest, PublicState, BuyInRequest, GameActionRequest, AddChipsRequest } from '@pokertools/types';
|
|
4
|
+
import { LoginRequest, LoginResponse, TableListItem, CreateTableRequest, PublicState, BuyInRequest, GameActionRequest, AddChipsRequest, TournamentListItem, CreateTournamentRequest, TournamentDetails, RegisterTournamentRequest, StartTournamentResponse, ReconcileTournamentResponse, SettleTournamentResponse } from '@pokertools/types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* SDK-specific types and configuration
|
|
@@ -40,6 +40,7 @@ interface PokerSDKConfig {
|
|
|
40
40
|
interface UserBalances {
|
|
41
41
|
main: number;
|
|
42
42
|
inPlay: number;
|
|
43
|
+
pendingWithdrawal: number;
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* User profile with balances
|
|
@@ -104,6 +105,7 @@ interface WithdrawalRequest {
|
|
|
104
105
|
address: string;
|
|
105
106
|
message: string;
|
|
106
107
|
signature: `0x${string}`;
|
|
108
|
+
idempotencyKey?: string;
|
|
107
109
|
}
|
|
108
110
|
/**
|
|
109
111
|
* Withdrawal record
|
|
@@ -262,6 +264,48 @@ declare class PokerClient {
|
|
|
262
264
|
* Stand from table (leave and cash out)
|
|
263
265
|
*/
|
|
264
266
|
stand(tableId: string): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Get active and registering tournaments.
|
|
269
|
+
*/
|
|
270
|
+
getTournaments(): Promise<TournamentListItem[]>;
|
|
271
|
+
/**
|
|
272
|
+
* Create a tournament lobby and backing tournament table.
|
|
273
|
+
*/
|
|
274
|
+
createTournament(request: CreateTournamentRequest): Promise<{
|
|
275
|
+
tournamentId: string;
|
|
276
|
+
tableId: string;
|
|
277
|
+
}>;
|
|
278
|
+
/**
|
|
279
|
+
* Get tournament lobby details, entries, prize pool, and table reference.
|
|
280
|
+
*/
|
|
281
|
+
getTournament(tournamentId: string): Promise<TournamentDetails>;
|
|
282
|
+
/**
|
|
283
|
+
* Register for a tournament. Debits buy-in and fee from MAIN balance.
|
|
284
|
+
*/
|
|
285
|
+
registerTournament(tournamentId: string, request: RegisterTournamentRequest): Promise<{
|
|
286
|
+
success: boolean;
|
|
287
|
+
}>;
|
|
288
|
+
/**
|
|
289
|
+
* Start a tournament once at least two players are registered.
|
|
290
|
+
*/
|
|
291
|
+
startTournament(tournamentId: string): Promise<StartTournamentResponse>;
|
|
292
|
+
/**
|
|
293
|
+
* Reconcile a running multi-table tournament after completed hands.
|
|
294
|
+
*/
|
|
295
|
+
reconcileTournament(tournamentId: string): Promise<ReconcileTournamentResponse>;
|
|
296
|
+
/**
|
|
297
|
+
* Manually advance tournament blind level.
|
|
298
|
+
*/
|
|
299
|
+
advanceTournamentBlinds(tournamentId: string): Promise<{
|
|
300
|
+
results: Record<string, {
|
|
301
|
+
blindLevel?: number;
|
|
302
|
+
error?: string;
|
|
303
|
+
}>;
|
|
304
|
+
}>;
|
|
305
|
+
/**
|
|
306
|
+
* Settle a completed tournament and pay the configured prize distribution.
|
|
307
|
+
*/
|
|
308
|
+
settleTournament(tournamentId: string): Promise<SettleTournamentResponse>;
|
|
265
309
|
/**
|
|
266
310
|
* Fold hand
|
|
267
311
|
*/
|
|
@@ -673,6 +717,34 @@ interface UseTablesResult {
|
|
|
673
717
|
* Hook to get list of active tables
|
|
674
718
|
*/
|
|
675
719
|
declare function useTables(): UseTablesResult;
|
|
720
|
+
interface UseTournamentsResult {
|
|
721
|
+
/** Active and registering tournament lobbies */
|
|
722
|
+
tournaments: TournamentListItem[];
|
|
723
|
+
/** Loading state */
|
|
724
|
+
isLoading: boolean;
|
|
725
|
+
/** Error if any */
|
|
726
|
+
error: Error | null;
|
|
727
|
+
/** Refresh tournament list */
|
|
728
|
+
refresh: () => Promise<void>;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Hook to get active and registering tournaments.
|
|
732
|
+
*/
|
|
733
|
+
declare function useTournaments(): UseTournamentsResult;
|
|
734
|
+
interface UseTournamentResult {
|
|
735
|
+
/** Tournament lobby details */
|
|
736
|
+
tournament: TournamentDetails | null;
|
|
737
|
+
/** Loading state */
|
|
738
|
+
isLoading: boolean;
|
|
739
|
+
/** Error if any */
|
|
740
|
+
error: Error | null;
|
|
741
|
+
/** Refresh tournament details */
|
|
742
|
+
refresh: () => Promise<void>;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Hook to get a tournament lobby and its entries/tables.
|
|
746
|
+
*/
|
|
747
|
+
declare function useTournament(tournamentId: string | null): UseTournamentResult;
|
|
676
748
|
/**
|
|
677
749
|
* Hook to manage WebSocket connection
|
|
678
750
|
*/
|
|
@@ -687,4 +759,4 @@ declare function useConnection(): {
|
|
|
687
759
|
ping: () => Promise<number | null>;
|
|
688
760
|
};
|
|
689
761
|
|
|
690
|
-
export { type PokerContextValue, PokerProvider, type PokerProviderProps, type UseTableOptions, type UseTableResult, type UseTablesResult, type UseUserResult, useConnection, usePoker, usePokerClient, usePokerSocket, useTable, useTables, useUser };
|
|
762
|
+
export { type PokerContextValue, PokerProvider, type PokerProviderProps, type UseTableOptions, type UseTableResult, type UseTablesResult, type UseTournamentResult, type UseTournamentsResult, type UseUserResult, useConnection, usePoker, usePokerClient, usePokerSocket, useTable, useTables, useTournament, useTournaments, useUser };
|
package/dist/react/index.js
CHANGED
|
@@ -158,6 +158,62 @@ var PokerClient = class {
|
|
|
158
158
|
async stand(tableId) {
|
|
159
159
|
await this.request("POST", `/tables/${tableId}/stand`);
|
|
160
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Get active and registering tournaments.
|
|
163
|
+
*/
|
|
164
|
+
async getTournaments() {
|
|
165
|
+
const response = await this.request(
|
|
166
|
+
"GET",
|
|
167
|
+
"/tournaments"
|
|
168
|
+
);
|
|
169
|
+
return response.tournaments;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a tournament lobby and backing tournament table.
|
|
173
|
+
*/
|
|
174
|
+
async createTournament(request) {
|
|
175
|
+
return this.request("POST", "/tournaments", request);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get tournament lobby details, entries, prize pool, and table reference.
|
|
179
|
+
*/
|
|
180
|
+
async getTournament(tournamentId) {
|
|
181
|
+
const response = await this.request(
|
|
182
|
+
"GET",
|
|
183
|
+
`/tournaments/${tournamentId}`
|
|
184
|
+
);
|
|
185
|
+
return response.tournament;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Register for a tournament. Debits buy-in and fee from MAIN balance.
|
|
189
|
+
*/
|
|
190
|
+
async registerTournament(tournamentId, request) {
|
|
191
|
+
return this.request("POST", `/tournaments/${tournamentId}/register`, request);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Start a tournament once at least two players are registered.
|
|
195
|
+
*/
|
|
196
|
+
async startTournament(tournamentId) {
|
|
197
|
+
return this.request("POST", `/tournaments/${tournamentId}/start`);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Reconcile a running multi-table tournament after completed hands.
|
|
201
|
+
*/
|
|
202
|
+
async reconcileTournament(tournamentId) {
|
|
203
|
+
return this.request("POST", `/tournaments/${tournamentId}/reconcile`);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Manually advance tournament blind level.
|
|
207
|
+
*/
|
|
208
|
+
async advanceTournamentBlinds(tournamentId) {
|
|
209
|
+
return this.request("POST", `/tournaments/${tournamentId}/advance-blinds`);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Settle a completed tournament and pay the configured prize distribution.
|
|
213
|
+
*/
|
|
214
|
+
async settleTournament(tournamentId) {
|
|
215
|
+
return this.request("POST", `/tournaments/${tournamentId}/settle`);
|
|
216
|
+
}
|
|
161
217
|
// ============================================================================
|
|
162
218
|
// Convenience Action Methods
|
|
163
219
|
// ============================================================================
|
|
@@ -1100,6 +1156,55 @@ function useTables() {
|
|
|
1100
1156
|
}, [refresh]);
|
|
1101
1157
|
return { tables, isLoading, error, refresh };
|
|
1102
1158
|
}
|
|
1159
|
+
function useTournaments() {
|
|
1160
|
+
const { client } = usePoker();
|
|
1161
|
+
const [tournaments, setTournaments] = useState([]);
|
|
1162
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
1163
|
+
const [error, setError] = useState(null);
|
|
1164
|
+
const refresh = useCallback(async () => {
|
|
1165
|
+
try {
|
|
1166
|
+
setIsLoading(true);
|
|
1167
|
+
const data = await client.getTournaments();
|
|
1168
|
+
setTournaments(data);
|
|
1169
|
+
setError(null);
|
|
1170
|
+
} catch (err) {
|
|
1171
|
+
setError(err);
|
|
1172
|
+
} finally {
|
|
1173
|
+
setIsLoading(false);
|
|
1174
|
+
}
|
|
1175
|
+
}, [client]);
|
|
1176
|
+
useEffect(() => {
|
|
1177
|
+
void refresh();
|
|
1178
|
+
}, [refresh]);
|
|
1179
|
+
return { tournaments, isLoading, error, refresh };
|
|
1180
|
+
}
|
|
1181
|
+
function useTournament(tournamentId) {
|
|
1182
|
+
const { client } = usePoker();
|
|
1183
|
+
const [tournament, setTournament] = useState(null);
|
|
1184
|
+
const [isLoading, setIsLoading] = useState(Boolean(tournamentId));
|
|
1185
|
+
const [error, setError] = useState(null);
|
|
1186
|
+
const refresh = useCallback(async () => {
|
|
1187
|
+
if (!tournamentId) {
|
|
1188
|
+
setTournament(null);
|
|
1189
|
+
setIsLoading(false);
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
try {
|
|
1193
|
+
setIsLoading(true);
|
|
1194
|
+
const data = await client.getTournament(tournamentId);
|
|
1195
|
+
setTournament(data);
|
|
1196
|
+
setError(null);
|
|
1197
|
+
} catch (err) {
|
|
1198
|
+
setError(err);
|
|
1199
|
+
} finally {
|
|
1200
|
+
setIsLoading(false);
|
|
1201
|
+
}
|
|
1202
|
+
}, [client, tournamentId]);
|
|
1203
|
+
useEffect(() => {
|
|
1204
|
+
void refresh();
|
|
1205
|
+
}, [refresh]);
|
|
1206
|
+
return { tournament, isLoading, error, refresh };
|
|
1207
|
+
}
|
|
1103
1208
|
function useConnection() {
|
|
1104
1209
|
const { socket, connectionState, connect, disconnect } = usePoker();
|
|
1105
1210
|
const [latency, setLatency] = useState(null);
|
|
@@ -1125,6 +1230,6 @@ function useConnection() {
|
|
|
1125
1230
|
};
|
|
1126
1231
|
}
|
|
1127
1232
|
|
|
1128
|
-
export { PokerProvider, useConnection, usePoker, usePokerClient, usePokerSocket, useTable, useTables, useUser };
|
|
1233
|
+
export { PokerProvider, useConnection, usePoker, usePokerClient, usePokerSocket, useTable, useTables, useTournament, useTournaments, useUser };
|
|
1129
1234
|
//# sourceMappingURL=index.js.map
|
|
1130
1235
|
//# sourceMappingURL=index.js.map
|