clarityxo-sdk 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,117 @@
1
+ type Network = 'mainnet' | 'testnet';
2
+ type CellValue = 'X' | 'O' | null;
3
+ type Board = [
4
+ [
5
+ CellValue,
6
+ CellValue,
7
+ CellValue
8
+ ],
9
+ [
10
+ CellValue,
11
+ CellValue,
12
+ CellValue
13
+ ],
14
+ [
15
+ CellValue,
16
+ CellValue,
17
+ CellValue
18
+ ]
19
+ ];
20
+ type GameStatus = 'active' | 'finished' | 'not-started';
21
+ type Turn = 'player' | 'ai';
22
+ interface GameState {
23
+ board: Board;
24
+ status: GameStatus;
25
+ winner: 'player' | 'ai' | 'draw' | null;
26
+ currentTurn: Turn;
27
+ }
28
+ interface LeaderboardEntry {
29
+ player: string;
30
+ wins: number;
31
+ losses: number;
32
+ draws: number;
33
+ points: number;
34
+ rank: number;
35
+ }
36
+ interface LeaderboardMonth {
37
+ month: string;
38
+ entries: LeaderboardEntry[];
39
+ }
40
+ interface GameResult {
41
+ player: string;
42
+ outcome: 'win' | 'loss' | 'draw';
43
+ month: string;
44
+ }
45
+ interface ClarityXOConfig {
46
+ network: Network;
47
+ contractAddress?: string;
48
+ contractName?: string;
49
+ leaderboardApiUrl?: string;
50
+ senderAddress?: string;
51
+ senderKey?: string;
52
+ }
53
+
54
+ declare class ClarityXOClient {
55
+ private config;
56
+ constructor(config: ClarityXOConfig);
57
+ getBoardState(): Promise<Board>;
58
+ getGameStatus(): Promise<GameStatus>;
59
+ getWinner(): Promise<GameState['winner']>;
60
+ getCurrentTurn(): Promise<Turn>;
61
+ isValidMove(row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<boolean>;
62
+ getFullGameState(): Promise<GameState>;
63
+ startNewGame(): Promise<{
64
+ txId: string;
65
+ }>;
66
+ makeMove(row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<{
67
+ txId: string;
68
+ }>;
69
+ resignGame(): Promise<{
70
+ txId: string;
71
+ }>;
72
+ getLeaderboard(month: string): Promise<LeaderboardMonth>;
73
+ submitResult(result: GameResult): Promise<void>;
74
+ syncLeaderboard(): Promise<void>;
75
+ healthCheck(): Promise<boolean>;
76
+ }
77
+ declare function createClient(config: ClarityXOConfig): ClarityXOClient;
78
+
79
+ declare const CONTRACT_NAME = "tictactoe";
80
+ declare const CONTRACT_ADDRESS = "SP30VGN68PSGVWGNMD0HH2WQMM5T486EK3YGP7Z3Y.clarity-xo-game";
81
+ declare const MAINNET_API = "https://api.mainnet.hiro.so";
82
+ declare const TESTNET_API = "https://api.testnet.hiro.so";
83
+ declare const DEFAULT_LEADERBOARD_API = "https://clarityxo.onrender.com";
84
+ declare const CONTRACT_FUNCTIONS: {
85
+ readonly START_NEW_GAME: "start-new-game";
86
+ readonly MAKE_MOVE: "make-move";
87
+ readonly RESIGN_GAME: "resign-game";
88
+ readonly GET_BOARD_STATE: "get-board-state";
89
+ readonly GET_GAME_STATUS: "get-game-status";
90
+ readonly GET_WINNER: "get-winner";
91
+ readonly GET_CURRENT_TURN: "get-current-turn";
92
+ readonly IS_VALID_MOVE: "is-valid-move";
93
+ };
94
+
95
+ declare function getBoardState(config: ClarityXOConfig): Promise<Board>;
96
+ declare function getGameStatus(config: ClarityXOConfig): Promise<GameStatus>;
97
+ declare function getWinner(config: ClarityXOConfig): Promise<GameState['winner']>;
98
+ declare function getCurrentTurn(config: ClarityXOConfig): Promise<Turn>;
99
+ declare function isValidMove(config: ClarityXOConfig, row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<boolean>;
100
+ declare function getFullGameState(config: ClarityXOConfig): Promise<GameState>;
101
+
102
+ declare function startNewGame(config: ClarityXOConfig): Promise<{
103
+ txId: string;
104
+ }>;
105
+ declare function makeMove(config: ClarityXOConfig, row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<{
106
+ txId: string;
107
+ }>;
108
+ declare function resignGame(config: ClarityXOConfig): Promise<{
109
+ txId: string;
110
+ }>;
111
+
112
+ declare function getLeaderboard(config: ClarityXOConfig, month: string): Promise<LeaderboardMonth>;
113
+ declare function submitResult(config: ClarityXOConfig, result: GameResult): Promise<void>;
114
+ declare function syncLeaderboard(config: ClarityXOConfig): Promise<void>;
115
+ declare function healthCheck(config: ClarityXOConfig): Promise<boolean>;
116
+
117
+ export { type Board, CONTRACT_ADDRESS, CONTRACT_FUNCTIONS, CONTRACT_NAME, type CellValue, ClarityXOClient, type ClarityXOConfig, DEFAULT_LEADERBOARD_API, type GameResult, type GameState, type GameStatus, type LeaderboardEntry, type LeaderboardMonth, MAINNET_API, type Network, TESTNET_API, type Turn, createClient, getBoardState, getCurrentTurn, getFullGameState, getGameStatus, getLeaderboard, getWinner, healthCheck, isValidMove, makeMove, resignGame, startNewGame, submitResult, syncLeaderboard };
@@ -0,0 +1,117 @@
1
+ type Network = 'mainnet' | 'testnet';
2
+ type CellValue = 'X' | 'O' | null;
3
+ type Board = [
4
+ [
5
+ CellValue,
6
+ CellValue,
7
+ CellValue
8
+ ],
9
+ [
10
+ CellValue,
11
+ CellValue,
12
+ CellValue
13
+ ],
14
+ [
15
+ CellValue,
16
+ CellValue,
17
+ CellValue
18
+ ]
19
+ ];
20
+ type GameStatus = 'active' | 'finished' | 'not-started';
21
+ type Turn = 'player' | 'ai';
22
+ interface GameState {
23
+ board: Board;
24
+ status: GameStatus;
25
+ winner: 'player' | 'ai' | 'draw' | null;
26
+ currentTurn: Turn;
27
+ }
28
+ interface LeaderboardEntry {
29
+ player: string;
30
+ wins: number;
31
+ losses: number;
32
+ draws: number;
33
+ points: number;
34
+ rank: number;
35
+ }
36
+ interface LeaderboardMonth {
37
+ month: string;
38
+ entries: LeaderboardEntry[];
39
+ }
40
+ interface GameResult {
41
+ player: string;
42
+ outcome: 'win' | 'loss' | 'draw';
43
+ month: string;
44
+ }
45
+ interface ClarityXOConfig {
46
+ network: Network;
47
+ contractAddress?: string;
48
+ contractName?: string;
49
+ leaderboardApiUrl?: string;
50
+ senderAddress?: string;
51
+ senderKey?: string;
52
+ }
53
+
54
+ declare class ClarityXOClient {
55
+ private config;
56
+ constructor(config: ClarityXOConfig);
57
+ getBoardState(): Promise<Board>;
58
+ getGameStatus(): Promise<GameStatus>;
59
+ getWinner(): Promise<GameState['winner']>;
60
+ getCurrentTurn(): Promise<Turn>;
61
+ isValidMove(row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<boolean>;
62
+ getFullGameState(): Promise<GameState>;
63
+ startNewGame(): Promise<{
64
+ txId: string;
65
+ }>;
66
+ makeMove(row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<{
67
+ txId: string;
68
+ }>;
69
+ resignGame(): Promise<{
70
+ txId: string;
71
+ }>;
72
+ getLeaderboard(month: string): Promise<LeaderboardMonth>;
73
+ submitResult(result: GameResult): Promise<void>;
74
+ syncLeaderboard(): Promise<void>;
75
+ healthCheck(): Promise<boolean>;
76
+ }
77
+ declare function createClient(config: ClarityXOConfig): ClarityXOClient;
78
+
79
+ declare const CONTRACT_NAME = "tictactoe";
80
+ declare const CONTRACT_ADDRESS = "SP30VGN68PSGVWGNMD0HH2WQMM5T486EK3YGP7Z3Y.clarity-xo-game";
81
+ declare const MAINNET_API = "https://api.mainnet.hiro.so";
82
+ declare const TESTNET_API = "https://api.testnet.hiro.so";
83
+ declare const DEFAULT_LEADERBOARD_API = "https://clarityxo.onrender.com";
84
+ declare const CONTRACT_FUNCTIONS: {
85
+ readonly START_NEW_GAME: "start-new-game";
86
+ readonly MAKE_MOVE: "make-move";
87
+ readonly RESIGN_GAME: "resign-game";
88
+ readonly GET_BOARD_STATE: "get-board-state";
89
+ readonly GET_GAME_STATUS: "get-game-status";
90
+ readonly GET_WINNER: "get-winner";
91
+ readonly GET_CURRENT_TURN: "get-current-turn";
92
+ readonly IS_VALID_MOVE: "is-valid-move";
93
+ };
94
+
95
+ declare function getBoardState(config: ClarityXOConfig): Promise<Board>;
96
+ declare function getGameStatus(config: ClarityXOConfig): Promise<GameStatus>;
97
+ declare function getWinner(config: ClarityXOConfig): Promise<GameState['winner']>;
98
+ declare function getCurrentTurn(config: ClarityXOConfig): Promise<Turn>;
99
+ declare function isValidMove(config: ClarityXOConfig, row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<boolean>;
100
+ declare function getFullGameState(config: ClarityXOConfig): Promise<GameState>;
101
+
102
+ declare function startNewGame(config: ClarityXOConfig): Promise<{
103
+ txId: string;
104
+ }>;
105
+ declare function makeMove(config: ClarityXOConfig, row: 0 | 1 | 2, col: 0 | 1 | 2): Promise<{
106
+ txId: string;
107
+ }>;
108
+ declare function resignGame(config: ClarityXOConfig): Promise<{
109
+ txId: string;
110
+ }>;
111
+
112
+ declare function getLeaderboard(config: ClarityXOConfig, month: string): Promise<LeaderboardMonth>;
113
+ declare function submitResult(config: ClarityXOConfig, result: GameResult): Promise<void>;
114
+ declare function syncLeaderboard(config: ClarityXOConfig): Promise<void>;
115
+ declare function healthCheck(config: ClarityXOConfig): Promise<boolean>;
116
+
117
+ export { type Board, CONTRACT_ADDRESS, CONTRACT_FUNCTIONS, CONTRACT_NAME, type CellValue, ClarityXOClient, type ClarityXOConfig, DEFAULT_LEADERBOARD_API, type GameResult, type GameState, type GameStatus, type LeaderboardEntry, type LeaderboardMonth, MAINNET_API, type Network, TESTNET_API, type Turn, createClient, getBoardState, getCurrentTurn, getFullGameState, getGameStatus, getLeaderboard, getWinner, healthCheck, isValidMove, makeMove, resignGame, startNewGame, submitResult, syncLeaderboard };
package/dist/index.js ADDED
@@ -0,0 +1,374 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CONTRACT_ADDRESS: () => CONTRACT_ADDRESS,
24
+ CONTRACT_FUNCTIONS: () => CONTRACT_FUNCTIONS,
25
+ CONTRACT_NAME: () => CONTRACT_NAME,
26
+ ClarityXOClient: () => ClarityXOClient,
27
+ DEFAULT_LEADERBOARD_API: () => DEFAULT_LEADERBOARD_API,
28
+ MAINNET_API: () => MAINNET_API,
29
+ TESTNET_API: () => TESTNET_API,
30
+ createClient: () => createClient,
31
+ getBoardState: () => getBoardState,
32
+ getCurrentTurn: () => getCurrentTurn,
33
+ getFullGameState: () => getFullGameState,
34
+ getGameStatus: () => getGameStatus,
35
+ getLeaderboard: () => getLeaderboard,
36
+ getWinner: () => getWinner,
37
+ healthCheck: () => healthCheck,
38
+ isValidMove: () => isValidMove,
39
+ makeMove: () => makeMove,
40
+ resignGame: () => resignGame,
41
+ startNewGame: () => startNewGame,
42
+ submitResult: () => submitResult,
43
+ syncLeaderboard: () => syncLeaderboard
44
+ });
45
+ module.exports = __toCommonJS(index_exports);
46
+
47
+ // src/contract/read.ts
48
+ var import_transactions = require("@stacks/transactions");
49
+
50
+ // src/constants.ts
51
+ var CONTRACT_NAME = "tictactoe";
52
+ var CONTRACT_ADDRESS = "SP30VGN68PSGVWGNMD0HH2WQMM5T486EK3YGP7Z3Y.clarity-xo-game";
53
+ var MAINNET_API = "https://api.mainnet.hiro.so";
54
+ var TESTNET_API = "https://api.testnet.hiro.so";
55
+ var DEFAULT_LEADERBOARD_API = "https://clarityxo.onrender.com";
56
+ var CONTRACT_FUNCTIONS = {
57
+ START_NEW_GAME: "start-new-game",
58
+ MAKE_MOVE: "make-move",
59
+ RESIGN_GAME: "resign-game",
60
+ GET_BOARD_STATE: "get-board-state",
61
+ GET_GAME_STATUS: "get-game-status",
62
+ GET_WINNER: "get-winner",
63
+ GET_CURRENT_TURN: "get-current-turn",
64
+ IS_VALID_MOVE: "is-valid-move"
65
+ };
66
+
67
+ // src/utils/network.ts
68
+ var import_network = require("@stacks/network");
69
+ function getStacksNetwork(network) {
70
+ return network === "mainnet" ? new import_network.StacksMainnet() : new import_network.StacksTestnet();
71
+ }
72
+
73
+ // src/utils/cv.ts
74
+ function parseBoardCV(cv) {
75
+ const rows = cv;
76
+ const board = [
77
+ [null, null, null],
78
+ [null, null, null],
79
+ [null, null, null]
80
+ ];
81
+ for (let i = 0; i < 3; i++) {
82
+ const row = rows.list[i].list;
83
+ for (let j = 0; j < 3; j++) {
84
+ const cell = row[j];
85
+ if (cell.type === "some") {
86
+ board[i][j] = cell.value.value;
87
+ } else {
88
+ board[i][j] = null;
89
+ }
90
+ }
91
+ }
92
+ return board;
93
+ }
94
+ function parseGameStatusCV(cv) {
95
+ const value = cv.value;
96
+ if (value === "active") return "active";
97
+ if (value === "finished") return "finished";
98
+ if (value === "not-started") return "not-started";
99
+ throw new Error(`Invalid game status: ${value}`);
100
+ }
101
+ function parseWinnerCV(cv) {
102
+ const value = cv.value;
103
+ if (value === "player") return "player";
104
+ if (value === "ai") return "ai";
105
+ if (value === "draw") return "draw";
106
+ return null;
107
+ }
108
+ function parseTurnCV(cv) {
109
+ const value = cv.value;
110
+ if (value === "player") return "player";
111
+ if (value === "ai") return "ai";
112
+ throw new Error(`Invalid turn: ${value}`);
113
+ }
114
+
115
+ // src/contract/read.ts
116
+ async function getBoardState(config) {
117
+ const network = getStacksNetwork(config.network);
118
+ const contractName = config.contractName || CONTRACT_NAME;
119
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
120
+ const cv = await (0, import_transactions.callReadOnlyFunction)({
121
+ network,
122
+ contractAddress,
123
+ contractName,
124
+ functionName: CONTRACT_FUNCTIONS.GET_BOARD_STATE,
125
+ functionArgs: [],
126
+ senderAddress: contractAddress
127
+ // arbitrary
128
+ });
129
+ return parseBoardCV(cv);
130
+ }
131
+ async function getGameStatus(config) {
132
+ const network = getStacksNetwork(config.network);
133
+ const contractName = config.contractName || CONTRACT_NAME;
134
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
135
+ const cv = await (0, import_transactions.callReadOnlyFunction)({
136
+ network,
137
+ contractAddress,
138
+ contractName,
139
+ functionName: CONTRACT_FUNCTIONS.GET_GAME_STATUS,
140
+ functionArgs: [],
141
+ senderAddress: contractAddress
142
+ });
143
+ return parseGameStatusCV(cv);
144
+ }
145
+ async function getWinner(config) {
146
+ const network = getStacksNetwork(config.network);
147
+ const contractName = config.contractName || CONTRACT_NAME;
148
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
149
+ const cv = await (0, import_transactions.callReadOnlyFunction)({
150
+ network,
151
+ contractAddress,
152
+ contractName,
153
+ functionName: CONTRACT_FUNCTIONS.GET_WINNER,
154
+ functionArgs: [],
155
+ senderAddress: contractAddress
156
+ });
157
+ return parseWinnerCV(cv);
158
+ }
159
+ async function getCurrentTurn(config) {
160
+ const network = getStacksNetwork(config.network);
161
+ const contractName = config.contractName || CONTRACT_NAME;
162
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
163
+ const cv = await (0, import_transactions.callReadOnlyFunction)({
164
+ network,
165
+ contractAddress,
166
+ contractName,
167
+ functionName: CONTRACT_FUNCTIONS.GET_CURRENT_TURN,
168
+ functionArgs: [],
169
+ senderAddress: contractAddress
170
+ });
171
+ return parseTurnCV(cv);
172
+ }
173
+ async function isValidMove(config, row, col) {
174
+ const network = getStacksNetwork(config.network);
175
+ const contractName = config.contractName || CONTRACT_NAME;
176
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
177
+ const cv = await (0, import_transactions.callReadOnlyFunction)({
178
+ network,
179
+ contractAddress,
180
+ contractName,
181
+ functionName: CONTRACT_FUNCTIONS.IS_VALID_MOVE,
182
+ functionArgs: [(0, import_transactions.uintCV)(row), (0, import_transactions.uintCV)(col)],
183
+ senderAddress: contractAddress
184
+ });
185
+ return cv.value;
186
+ }
187
+ async function getFullGameState(config) {
188
+ const [board, status, winner, currentTurn] = await Promise.all([
189
+ getBoardState(config),
190
+ getGameStatus(config),
191
+ getWinner(config),
192
+ getCurrentTurn(config)
193
+ ]);
194
+ return { board, status, winner, currentTurn };
195
+ }
196
+
197
+ // src/contract/write.ts
198
+ var import_transactions2 = require("@stacks/transactions");
199
+ async function startNewGame(config) {
200
+ if (!config.senderKey || !config.senderAddress) {
201
+ throw new Error("senderKey and senderAddress are required for write operations");
202
+ }
203
+ const network = getStacksNetwork(config.network);
204
+ const contractName = config.contractName || CONTRACT_NAME;
205
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
206
+ const tx = await (0, import_transactions2.makeContractCall)({
207
+ network,
208
+ contractAddress,
209
+ contractName,
210
+ functionName: CONTRACT_FUNCTIONS.START_NEW_GAME,
211
+ functionArgs: [],
212
+ senderKey: config.senderKey,
213
+ anchorMode: "any"
214
+ });
215
+ const broadcastResponse = await (0, import_transactions2.broadcastTransaction)(tx, network);
216
+ return { txId: broadcastResponse.txid };
217
+ }
218
+ async function makeMove(config, row, col) {
219
+ if (!config.senderKey || !config.senderAddress) {
220
+ throw new Error("senderKey and senderAddress are required for write operations");
221
+ }
222
+ const network = getStacksNetwork(config.network);
223
+ const contractName = config.contractName || CONTRACT_NAME;
224
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
225
+ const tx = await (0, import_transactions2.makeContractCall)({
226
+ network,
227
+ contractAddress,
228
+ contractName,
229
+ functionName: CONTRACT_FUNCTIONS.MAKE_MOVE,
230
+ functionArgs: [(0, import_transactions2.uintCV)(row), (0, import_transactions2.uintCV)(col)],
231
+ senderKey: config.senderKey,
232
+ anchorMode: "any"
233
+ });
234
+ const broadcastResponse = await (0, import_transactions2.broadcastTransaction)(tx, network);
235
+ return { txId: broadcastResponse.txid };
236
+ }
237
+ async function resignGame(config) {
238
+ if (!config.senderKey || !config.senderAddress) {
239
+ throw new Error("senderKey and senderAddress are required for write operations");
240
+ }
241
+ const network = getStacksNetwork(config.network);
242
+ const contractName = config.contractName || CONTRACT_NAME;
243
+ const contractAddress = config.contractAddress || CONTRACT_ADDRESS;
244
+ const tx = await (0, import_transactions2.makeContractCall)({
245
+ network,
246
+ contractAddress,
247
+ contractName,
248
+ functionName: CONTRACT_FUNCTIONS.RESIGN_GAME,
249
+ functionArgs: [],
250
+ senderKey: config.senderKey,
251
+ anchorMode: "any"
252
+ });
253
+ const broadcastResponse = await (0, import_transactions2.broadcastTransaction)(tx, network);
254
+ return { txId: broadcastResponse.txid };
255
+ }
256
+
257
+ // src/leaderboard/api.ts
258
+ function getBaseUrl(config) {
259
+ return config.leaderboardApiUrl || DEFAULT_LEADERBOARD_API;
260
+ }
261
+ async function getLeaderboard(config, month) {
262
+ const baseUrl = getBaseUrl(config);
263
+ const response = await fetch(`${baseUrl}/api/leaderboard?month=${month}`);
264
+ if (!response.ok) {
265
+ throw new Error(`Failed to fetch leaderboard: ${response.statusText}`);
266
+ }
267
+ return response.json();
268
+ }
269
+ async function submitResult(config, result) {
270
+ const baseUrl = getBaseUrl(config);
271
+ const response = await fetch(`${baseUrl}/api/leaderboard/result`, {
272
+ method: "POST",
273
+ headers: { "Content-Type": "application/json" },
274
+ body: JSON.stringify(result)
275
+ });
276
+ if (!response.ok) {
277
+ throw new Error(`Failed to submit result: ${response.statusText}`);
278
+ }
279
+ }
280
+ async function syncLeaderboard(config) {
281
+ const baseUrl = getBaseUrl(config);
282
+ const response = await fetch(`${baseUrl}/api/sync`, {
283
+ method: "POST"
284
+ });
285
+ if (!response.ok) {
286
+ throw new Error(`Failed to sync leaderboard: ${response.statusText}`);
287
+ }
288
+ }
289
+ async function healthCheck(config) {
290
+ const baseUrl = getBaseUrl(config);
291
+ try {
292
+ const response = await fetch(`${baseUrl}/health`);
293
+ return response.ok;
294
+ } catch {
295
+ return false;
296
+ }
297
+ }
298
+
299
+ // src/client.ts
300
+ var ClarityXOClient = class {
301
+ constructor(config) {
302
+ this.config = config;
303
+ }
304
+ config;
305
+ // Game state
306
+ getBoardState() {
307
+ return getBoardState(this.config);
308
+ }
309
+ getGameStatus() {
310
+ return getGameStatus(this.config);
311
+ }
312
+ getWinner() {
313
+ return getWinner(this.config);
314
+ }
315
+ getCurrentTurn() {
316
+ return getCurrentTurn(this.config);
317
+ }
318
+ isValidMove(row, col) {
319
+ return isValidMove(this.config, row, col);
320
+ }
321
+ getFullGameState() {
322
+ return getFullGameState(this.config);
323
+ }
324
+ // Transactions
325
+ startNewGame() {
326
+ return startNewGame(this.config);
327
+ }
328
+ makeMove(row, col) {
329
+ return makeMove(this.config, row, col);
330
+ }
331
+ resignGame() {
332
+ return resignGame(this.config);
333
+ }
334
+ // Leaderboard
335
+ getLeaderboard(month) {
336
+ return getLeaderboard(this.config, month);
337
+ }
338
+ submitResult(result) {
339
+ return submitResult(this.config, result);
340
+ }
341
+ syncLeaderboard() {
342
+ return syncLeaderboard(this.config);
343
+ }
344
+ healthCheck() {
345
+ return healthCheck(this.config);
346
+ }
347
+ };
348
+ function createClient(config) {
349
+ return new ClarityXOClient(config);
350
+ }
351
+ // Annotate the CommonJS export names for ESM import in node:
352
+ 0 && (module.exports = {
353
+ CONTRACT_ADDRESS,
354
+ CONTRACT_FUNCTIONS,
355
+ CONTRACT_NAME,
356
+ ClarityXOClient,
357
+ DEFAULT_LEADERBOARD_API,
358
+ MAINNET_API,
359
+ TESTNET_API,
360
+ createClient,
361
+ getBoardState,
362
+ getCurrentTurn,
363
+ getFullGameState,
364
+ getGameStatus,
365
+ getLeaderboard,
366
+ getWinner,
367
+ healthCheck,
368
+ isValidMove,
369
+ makeMove,
370
+ resignGame,
371
+ startNewGame,
372
+ submitResult,
373
+ syncLeaderboard
374
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,46 @@
1
+ import {
2
+ CONTRACT_ADDRESS,
3
+ CONTRACT_FUNCTIONS,
4
+ CONTRACT_NAME,
5
+ ClarityXOClient,
6
+ DEFAULT_LEADERBOARD_API,
7
+ MAINNET_API,
8
+ TESTNET_API,
9
+ createClient,
10
+ getBoardState,
11
+ getCurrentTurn,
12
+ getFullGameState,
13
+ getGameStatus,
14
+ getLeaderboard,
15
+ getWinner,
16
+ healthCheck,
17
+ isValidMove,
18
+ makeMove,
19
+ resignGame,
20
+ startNewGame,
21
+ submitResult,
22
+ syncLeaderboard
23
+ } from "./chunk-Z5L3H7VV.mjs";
24
+ export {
25
+ CONTRACT_ADDRESS,
26
+ CONTRACT_FUNCTIONS,
27
+ CONTRACT_NAME,
28
+ ClarityXOClient,
29
+ DEFAULT_LEADERBOARD_API,
30
+ MAINNET_API,
31
+ TESTNET_API,
32
+ createClient,
33
+ getBoardState,
34
+ getCurrentTurn,
35
+ getFullGameState,
36
+ getGameStatus,
37
+ getLeaderboard,
38
+ getWinner,
39
+ healthCheck,
40
+ isValidMove,
41
+ makeMove,
42
+ resignGame,
43
+ startNewGame,
44
+ submitResult,
45
+ syncLeaderboard
46
+ };