@toromarket/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.
package/dist/index.js ADDED
@@ -0,0 +1,849 @@
1
+ // src/client.ts
2
+ import { randomUUID } from "crypto";
3
+
4
+ // src/errors.ts
5
+ var ToromarketError = class extends Error {
6
+ statusCode;
7
+ code;
8
+ details;
9
+ constructor(message, statusCode = 500, code, details) {
10
+ super(message);
11
+ this.name = "ToromarketError";
12
+ this.statusCode = statusCode;
13
+ this.code = code;
14
+ this.details = details;
15
+ }
16
+ };
17
+
18
+ // src/resources/auth.ts
19
+ var AuthResource = class {
20
+ constructor(client) {
21
+ this.client = client;
22
+ }
23
+ async register(input) {
24
+ const secret = this.client.getAgentSecret();
25
+ const headers = {};
26
+ if (secret) {
27
+ headers["x-agent-secret"] = secret;
28
+ headers["x-toromarket-client"] = "mcp-server/0.1.0";
29
+ }
30
+ const response = await this.client.request(
31
+ "POST",
32
+ "/api/v1/auth/register",
33
+ { ...input, terms: true },
34
+ Object.keys(headers).length > 0 ? { headers } : void 0
35
+ );
36
+ this.client.setToken(response.token);
37
+ return response;
38
+ }
39
+ async login(input) {
40
+ const response = await this.client.request(
41
+ "POST",
42
+ "/api/v1/auth/login",
43
+ input
44
+ );
45
+ this.client.setToken(response.token);
46
+ return response;
47
+ }
48
+ async me() {
49
+ const response = await this.client.request("GET", "/api/v1/auth/me");
50
+ return response.user;
51
+ }
52
+ };
53
+
54
+ // src/resources/chat.ts
55
+ var ChatResource = class {
56
+ constructor(client) {
57
+ this.client = client;
58
+ }
59
+ async post(symbol, input) {
60
+ return this.client.request(
61
+ "POST",
62
+ `/api/v1/chat/${encodeURIComponent(symbol)}`,
63
+ input
64
+ );
65
+ }
66
+ async list(symbol) {
67
+ return this.client.request(
68
+ "GET",
69
+ `/api/v1/chat/${encodeURIComponent(symbol)}`
70
+ );
71
+ }
72
+ };
73
+
74
+ // src/resources/funds.ts
75
+ var FundsResource = class {
76
+ constructor(client) {
77
+ this.client = client;
78
+ }
79
+ async list(params) {
80
+ const query = new URLSearchParams();
81
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
82
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
83
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
84
+ return this.client.request("GET", `/api/v1/funds${suffix}`);
85
+ }
86
+ async create(input) {
87
+ return this.client.request("POST", "/api/v1/funds", input);
88
+ }
89
+ async join(fundId, input) {
90
+ return this.client.request(
91
+ "POST",
92
+ `/api/v1/funds/${encodeURIComponent(fundId)}/join`,
93
+ input
94
+ );
95
+ }
96
+ async chat(fundId, input) {
97
+ return this.client.request(
98
+ "POST",
99
+ `/api/v1/funds/${encodeURIComponent(fundId)}/chat`,
100
+ input
101
+ );
102
+ }
103
+ async members(fundId) {
104
+ return this.client.request(
105
+ "GET",
106
+ `/api/v1/funds/${encodeURIComponent(fundId)}/members`
107
+ );
108
+ }
109
+ async updateMemberRole(fundId, input) {
110
+ return this.client.request(
111
+ "PATCH",
112
+ `/api/v1/funds/${encodeURIComponent(fundId)}/members`,
113
+ input
114
+ );
115
+ }
116
+ async removeMember(fundId, userId) {
117
+ return this.client.request(
118
+ "DELETE",
119
+ `/api/v1/funds/${encodeURIComponent(fundId)}/members/${encodeURIComponent(userId)}`
120
+ );
121
+ }
122
+ async transferOwnership(fundId, input) {
123
+ return this.client.request(
124
+ "POST",
125
+ `/api/v1/funds/${encodeURIComponent(fundId)}/transfer-ownership`,
126
+ input
127
+ );
128
+ }
129
+ async leave(fundId) {
130
+ return this.client.request(
131
+ "POST",
132
+ `/api/v1/funds/${encodeURIComponent(fundId)}/leave`
133
+ );
134
+ }
135
+ async get(fundId) {
136
+ return this.client.request(
137
+ "GET",
138
+ `/api/v1/funds/${encodeURIComponent(fundId)}`
139
+ );
140
+ }
141
+ async cancelPredictionOrder(fundId, orderId) {
142
+ return this.client.request(
143
+ "DELETE",
144
+ `/api/v1/funds/${encodeURIComponent(fundId)}/predictions/orders/${encodeURIComponent(orderId)}`
145
+ );
146
+ }
147
+ async chatHistory(fundId, params = {}) {
148
+ const query = new URLSearchParams();
149
+ if (params.cursor) {
150
+ query.set("cursor", params.cursor);
151
+ }
152
+ if (params.limit !== void 0) {
153
+ query.set("limit", String(params.limit));
154
+ }
155
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
156
+ return this.client.request(
157
+ "GET",
158
+ `/api/v1/funds/${encodeURIComponent(fundId)}/chat${suffix}`
159
+ );
160
+ }
161
+ // --- Fund trading ---
162
+ async positions(fundId) {
163
+ return this.client.request(
164
+ "GET",
165
+ `/api/v1/funds/${encodeURIComponent(fundId)}/positions`
166
+ );
167
+ }
168
+ async predictionPositions(fundId) {
169
+ return this.client.request(
170
+ "GET",
171
+ `/api/v1/funds/${encodeURIComponent(fundId)}/predictions/positions`
172
+ );
173
+ }
174
+ async predictionOrders(fundId) {
175
+ return this.client.request(
176
+ "GET",
177
+ `/api/v1/funds/${encodeURIComponent(fundId)}/predictions/orders`
178
+ );
179
+ }
180
+ async trades(fundId, params) {
181
+ const query = new URLSearchParams();
182
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
183
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
184
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
185
+ return this.client.request(
186
+ "GET",
187
+ `/api/v1/funds/${encodeURIComponent(fundId)}/trades${suffix}`
188
+ );
189
+ }
190
+ async placePredictionOrder(fundId, input) {
191
+ return this.client.request(
192
+ "POST",
193
+ `/api/v1/funds/${encodeURIComponent(fundId)}/predictions/orders`,
194
+ input
195
+ );
196
+ }
197
+ async tradeCrypto(fundId, input) {
198
+ return this.client.request(
199
+ "POST",
200
+ `/api/v1/funds/${encodeURIComponent(fundId)}/trades`,
201
+ input
202
+ );
203
+ }
204
+ async getStrategy(fundId) {
205
+ return this.client.request(
206
+ "GET",
207
+ `/api/v1/funds/${encodeURIComponent(fundId)}/strategy`
208
+ );
209
+ }
210
+ async setStrategy(fundId, strategy) {
211
+ return this.client.request(
212
+ "PUT",
213
+ `/api/v1/funds/${encodeURIComponent(fundId)}/strategy`,
214
+ strategy
215
+ );
216
+ }
217
+ async requestJoin(fundId) {
218
+ return this.client.request(
219
+ "POST",
220
+ `/api/v1/funds/${encodeURIComponent(fundId)}/request`
221
+ );
222
+ }
223
+ async approveRequest(fundId, requestId) {
224
+ return this.client.request(
225
+ "POST",
226
+ `/api/v1/funds/${encodeURIComponent(fundId)}/requests/${encodeURIComponent(requestId)}/approve`
227
+ );
228
+ }
229
+ async rejectRequest(fundId, requestId) {
230
+ return this.client.request(
231
+ "POST",
232
+ `/api/v1/funds/${encodeURIComponent(fundId)}/requests/${encodeURIComponent(requestId)}/reject`
233
+ );
234
+ }
235
+ };
236
+
237
+ // src/resources/leaderboards.ts
238
+ var LeaderboardsResource = class {
239
+ constructor(client) {
240
+ this.client = client;
241
+ }
242
+ async get(params = {}) {
243
+ const query = new URLSearchParams();
244
+ if (params.category) {
245
+ query.set("category", params.category);
246
+ }
247
+ if (params.sort) {
248
+ query.set("sort", params.sort);
249
+ }
250
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
251
+ return this.client.request(
252
+ "GET",
253
+ `/api/v1/leaderboards${suffix}`
254
+ );
255
+ }
256
+ };
257
+
258
+ // src/resources/markets.ts
259
+ var MarketsResource = class {
260
+ constructor(client) {
261
+ this.client = client;
262
+ }
263
+ async list(params) {
264
+ const query = new URLSearchParams();
265
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
266
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
267
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
268
+ return this.client.request("GET", `/api/v1/markets${suffix}`);
269
+ }
270
+ async get(symbol) {
271
+ return this.client.request(
272
+ "GET",
273
+ `/api/v1/markets/${encodeURIComponent(symbol)}`
274
+ );
275
+ }
276
+ async getKlines(symbol, params) {
277
+ const query = new URLSearchParams();
278
+ if (params?.interval) query.set("interval", params.interval);
279
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
280
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
281
+ return this.client.request(
282
+ "GET",
283
+ `/api/v1/markets/${encodeURIComponent(symbol)}/klines${suffix}`
284
+ );
285
+ }
286
+ async getMovers() {
287
+ return this.client.request("GET", "/api/v1/markets/movers");
288
+ }
289
+ async getTrending() {
290
+ return this.client.request("GET", "/api/v1/markets/trending");
291
+ }
292
+ async getInfo(symbol) {
293
+ return this.client.request(
294
+ "GET",
295
+ `/api/v1/markets/${encodeURIComponent(symbol)}/info`
296
+ );
297
+ }
298
+ };
299
+
300
+ // src/resources/portfolio.ts
301
+ var PortfolioResource = class {
302
+ constructor(client) {
303
+ this.client = client;
304
+ }
305
+ async get() {
306
+ return this.client.request("GET", "/api/v1/portfolio");
307
+ }
308
+ async getTrades(params) {
309
+ const query = new URLSearchParams();
310
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
311
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
312
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
313
+ return this.client.request(
314
+ "GET",
315
+ `/api/v1/portfolio/trades${suffix}`
316
+ );
317
+ }
318
+ async trade(input) {
319
+ return this.client.request("POST", "/api/v1/portfolio/trades", input);
320
+ }
321
+ async getMetrics() {
322
+ return this.client.request("GET", "/api/v1/portfolio/metrics");
323
+ }
324
+ async getOpenOrders() {
325
+ return this.client.request("GET", "/api/v1/portfolio/open-orders");
326
+ }
327
+ };
328
+
329
+ // src/resources/predictions.ts
330
+ var PredictionsResource = class {
331
+ constructor(client) {
332
+ this.client = client;
333
+ }
334
+ async listMarkets(params) {
335
+ const query = new URLSearchParams();
336
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
337
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
338
+ if (params?.category) query.set("category", params.category);
339
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
340
+ return this.client.request("GET", `/api/v1/predictions/markets${suffix}`);
341
+ }
342
+ async getMarket(marketId) {
343
+ return this.client.request(
344
+ "GET",
345
+ `/api/v1/predictions/markets/${encodeURIComponent(marketId)}`
346
+ );
347
+ }
348
+ async placeOrder(marketId, input) {
349
+ return this.client.request(
350
+ "POST",
351
+ `/api/v1/predictions/markets/${encodeURIComponent(marketId)}/orders`,
352
+ input
353
+ );
354
+ }
355
+ async cancelOrder(marketId, orderId) {
356
+ return this.client.request(
357
+ "DELETE",
358
+ `/api/v1/predictions/markets/${encodeURIComponent(
359
+ marketId
360
+ )}/orders/${encodeURIComponent(orderId)}`
361
+ );
362
+ }
363
+ async getPositions() {
364
+ return this.client.request(
365
+ "GET",
366
+ "/api/v1/predictions/positions"
367
+ );
368
+ }
369
+ async getMarketTrades(marketId, params) {
370
+ const query = new URLSearchParams();
371
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
372
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
373
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
374
+ return this.client.request(
375
+ "GET",
376
+ `/api/v1/predictions/markets/${encodeURIComponent(marketId)}/trades${suffix}`
377
+ );
378
+ }
379
+ async getMarketPositions(marketId) {
380
+ return this.client.request(
381
+ "GET",
382
+ `/api/v1/predictions/markets/${encodeURIComponent(marketId)}/positions`
383
+ );
384
+ }
385
+ async getMarketOrders(marketId) {
386
+ return this.client.request(
387
+ "GET",
388
+ `/api/v1/predictions/markets/${encodeURIComponent(marketId)}/my-orders`
389
+ );
390
+ }
391
+ async getEventMarkets(eventSlug) {
392
+ return this.client.request(
393
+ "GET",
394
+ `/api/v1/predictions/markets/event/${encodeURIComponent(eventSlug)}`
395
+ );
396
+ }
397
+ };
398
+
399
+ // src/resources/profiles.ts
400
+ var ProfilesResource = class {
401
+ constructor(client) {
402
+ this.client = client;
403
+ }
404
+ async get(username) {
405
+ return this.client.request(
406
+ "GET",
407
+ `/api/v1/profile/${encodeURIComponent(username)}`
408
+ );
409
+ }
410
+ };
411
+
412
+ // src/resources/intelligence.ts
413
+ var IntelligenceResource = class {
414
+ constructor(client) {
415
+ this.client = client;
416
+ }
417
+ async getSummary(params) {
418
+ const query = new URLSearchParams();
419
+ if (params?.include?.length) {
420
+ query.set("include", params.include.join(","));
421
+ }
422
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
423
+ return this.client.request("GET", `/api/v1/intelligence${suffix}`);
424
+ }
425
+ async getSignals(marketId) {
426
+ return this.client.request(
427
+ "GET",
428
+ `/api/v1/intelligence/${encodeURIComponent(marketId)}`
429
+ );
430
+ }
431
+ };
432
+
433
+ // src/resources/performance.ts
434
+ var PerformanceResource = class {
435
+ constructor(client) {
436
+ this.client = client;
437
+ }
438
+ async get(params = {}) {
439
+ const query = new URLSearchParams();
440
+ if (params.period) query.set("period", params.period);
441
+ if (params.category) query.set("category", params.category);
442
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
443
+ return this.client.request("GET", `/api/v1/performance${suffix}`);
444
+ }
445
+ async getResolved(params = {}) {
446
+ const query = new URLSearchParams();
447
+ if (params.cursor) query.set("cursor", params.cursor);
448
+ if (params.limit !== void 0) query.set("limit", String(params.limit));
449
+ if (params.outcome) query.set("outcome", params.outcome);
450
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
451
+ return this.client.request(
452
+ "GET",
453
+ `/api/v1/performance/resolved${suffix}`
454
+ );
455
+ }
456
+ async getBenchmarks(params = {}) {
457
+ const query = new URLSearchParams();
458
+ if (params.period) query.set("period", params.period);
459
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
460
+ return this.client.request("GET", `/api/v1/performance/benchmarks${suffix}`);
461
+ }
462
+ };
463
+
464
+ // src/resources/wars.ts
465
+ var WarsResource = class {
466
+ constructor(client) {
467
+ this.client = client;
468
+ }
469
+ async list() {
470
+ return this.client.request("GET", "/api/v1/wars");
471
+ }
472
+ async active() {
473
+ return this.client.request("GET", "/api/v1/wars/active");
474
+ }
475
+ async get(warId) {
476
+ return this.client.request(
477
+ "GET",
478
+ `/api/v1/wars/${encodeURIComponent(warId)}`
479
+ );
480
+ }
481
+ async enterQueue(input) {
482
+ return this.client.request("POST", "/api/v1/wars/queue", input);
483
+ }
484
+ async cancelQueue() {
485
+ return this.client.request("DELETE", "/api/v1/wars/queue");
486
+ }
487
+ async getQueueStatus() {
488
+ return this.client.request("GET", "/api/v1/wars/queue");
489
+ }
490
+ async results(warId) {
491
+ return this.client.request(
492
+ "GET",
493
+ `/api/v1/wars/${encodeURIComponent(warId)}/results`
494
+ );
495
+ }
496
+ async history() {
497
+ return this.client.request("GET", "/api/v1/wars/history");
498
+ }
499
+ async leaderboard() {
500
+ return this.client.request(
501
+ "GET",
502
+ "/api/v1/wars/leaderboard"
503
+ );
504
+ }
505
+ async currentAutoLeague() {
506
+ return this.client.request("GET", "/api/v1/wars/auto-league");
507
+ }
508
+ async startIntraWar(input) {
509
+ return this.client.request("POST", "/api/v1/wars/intra", input);
510
+ }
511
+ async live() {
512
+ return this.client.request("GET", "/api/v1/wars/live");
513
+ }
514
+ };
515
+
516
+ // src/resources/search.ts
517
+ var SearchResource = class {
518
+ constructor(client) {
519
+ this.client = client;
520
+ }
521
+ async query(q, params) {
522
+ const query = new URLSearchParams({ q });
523
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
524
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
525
+ return this.client.request(
526
+ "GET",
527
+ `/api/v1/search?${query.toString()}`
528
+ );
529
+ }
530
+ async searchGifs(q) {
531
+ return this.client.request(
532
+ "GET",
533
+ `/api/v1/gifs/search?q=${encodeURIComponent(q)}`
534
+ );
535
+ }
536
+ };
537
+
538
+ // src/resources/watchlist.ts
539
+ var WatchlistResource = class {
540
+ constructor(client) {
541
+ this.client = client;
542
+ }
543
+ async list() {
544
+ return this.client.request("GET", "/api/v1/watchlist");
545
+ }
546
+ async add(symbol) {
547
+ return this.client.request(
548
+ "POST",
549
+ "/api/v1/watchlist",
550
+ { symbol }
551
+ );
552
+ }
553
+ async remove(symbol) {
554
+ return this.client.request(
555
+ "DELETE",
556
+ `/api/v1/watchlist/${encodeURIComponent(symbol)}`
557
+ );
558
+ }
559
+ };
560
+
561
+ // src/resources/social.ts
562
+ var SocialResource = class {
563
+ constructor(client) {
564
+ this.client = client;
565
+ }
566
+ async followers() {
567
+ return this.client.request("GET", "/api/v1/social/followers");
568
+ }
569
+ async following() {
570
+ return this.client.request("GET", "/api/v1/social/following");
571
+ }
572
+ async follow(userId) {
573
+ return this.client.request(
574
+ "POST",
575
+ `/api/v1/social/follow/${encodeURIComponent(userId)}`
576
+ );
577
+ }
578
+ async unfollow(userId) {
579
+ return this.client.request(
580
+ "DELETE",
581
+ `/api/v1/social/follow/${encodeURIComponent(userId)}`
582
+ );
583
+ }
584
+ };
585
+
586
+ // src/resources/billing.ts
587
+ var BillingResource = class {
588
+ constructor(client) {
589
+ this.client = client;
590
+ }
591
+ async createCheckout(tier) {
592
+ return this.client.request(
593
+ "POST",
594
+ "/api/v1/billing/checkout",
595
+ { tier }
596
+ );
597
+ }
598
+ async getSubscription() {
599
+ return this.client.request(
600
+ "GET",
601
+ "/api/v1/billing/subscription"
602
+ );
603
+ }
604
+ async createPortalSession() {
605
+ return this.client.request(
606
+ "POST",
607
+ "/api/v1/billing/portal"
608
+ );
609
+ }
610
+ };
611
+
612
+ // src/resources/operators.ts
613
+ var OperatorsResource = class {
614
+ constructor(client) {
615
+ this.client = client;
616
+ }
617
+ async getMe(operatorToken) {
618
+ return this.client.request(
619
+ "GET",
620
+ "/api/v1/operators/me",
621
+ void 0,
622
+ { headers: { "Authorization": `Bearer ${operatorToken}` } }
623
+ );
624
+ }
625
+ };
626
+
627
+ // src/resources/stake.ts
628
+ var StakeResource = class {
629
+ constructor(client) {
630
+ this.client = client;
631
+ }
632
+ async topup(amount) {
633
+ return this.client.request(
634
+ "POST",
635
+ "/api/v1/stake/topup",
636
+ { amount }
637
+ );
638
+ }
639
+ };
640
+
641
+ // src/resources/traces.ts
642
+ var TracesResource = class {
643
+ constructor(client) {
644
+ this.client = client;
645
+ }
646
+ async create(input) {
647
+ return this.client.request("POST", "/api/v1/traces", input);
648
+ }
649
+ async list(params) {
650
+ const query = new URLSearchParams();
651
+ if (params?.limit !== void 0) query.set("limit", String(params.limit));
652
+ if (params?.offset !== void 0) query.set("offset", String(params.offset));
653
+ if (params?.trigger) query.set("trigger", params.trigger);
654
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
655
+ return this.client.request("GET", `/api/v1/traces/me${suffix}`);
656
+ }
657
+ async get(traceId) {
658
+ return this.client.request("GET", `/api/v1/traces/me/${encodeURIComponent(traceId)}`);
659
+ }
660
+ };
661
+
662
+ // src/client.ts
663
+ var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
664
+ var DEFAULT_TIMEOUT_MS = 3e4;
665
+ var MAX_RETRY_ATTEMPTS = 2;
666
+ var RETRY_DELAY_MS = 1e3;
667
+ var ToromarketClient = class {
668
+ baseUrl;
669
+ clientId;
670
+ apiKey;
671
+ agentSecret;
672
+ timeoutMs;
673
+ token;
674
+ auth;
675
+ predictions;
676
+ portfolio;
677
+ markets;
678
+ chat;
679
+ funds;
680
+ leaderboards;
681
+ profiles;
682
+ intelligence;
683
+ performance;
684
+ wars;
685
+ search;
686
+ watchlist;
687
+ social;
688
+ billing;
689
+ traces;
690
+ operators;
691
+ stake;
692
+ constructor(config) {
693
+ this.baseUrl = config.baseUrl.replace(/\/+$/, "");
694
+ this.token = config.token ?? null;
695
+ this.apiKey = config.apiKey ?? null;
696
+ this.clientId = config.clientId ?? null;
697
+ this.agentSecret = config.agentSecret ?? null;
698
+ this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
699
+ this.auth = new AuthResource(this);
700
+ this.predictions = new PredictionsResource(this);
701
+ this.portfolio = new PortfolioResource(this);
702
+ this.markets = new MarketsResource(this);
703
+ this.chat = new ChatResource(this);
704
+ this.funds = new FundsResource(this);
705
+ this.leaderboards = new LeaderboardsResource(this);
706
+ this.profiles = new ProfilesResource(this);
707
+ this.intelligence = new IntelligenceResource(this);
708
+ this.performance = new PerformanceResource(this);
709
+ this.wars = new WarsResource(this);
710
+ this.search = new SearchResource(this);
711
+ this.watchlist = new WatchlistResource(this);
712
+ this.social = new SocialResource(this);
713
+ this.billing = new BillingResource(this);
714
+ this.traces = new TracesResource(this);
715
+ this.operators = new OperatorsResource(this);
716
+ this.stake = new StakeResource(this);
717
+ }
718
+ setToken(token) {
719
+ this.token = token;
720
+ }
721
+ getToken() {
722
+ return this.token;
723
+ }
724
+ getAgentSecret() {
725
+ return this.agentSecret;
726
+ }
727
+ isRetryableStatus(status) {
728
+ return status >= 500;
729
+ }
730
+ async request(method, path, body, options) {
731
+ const upperMethod = method.toUpperCase();
732
+ const idempotencyKey = MUTATING_METHODS.has(upperMethod) ? randomUUID() : void 0;
733
+ for (let attempt = 0; attempt < MAX_RETRY_ATTEMPTS; attempt++) {
734
+ const isLastAttempt = attempt === MAX_RETRY_ATTEMPTS - 1;
735
+ const controller = new AbortController();
736
+ const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
737
+ const init = {
738
+ method,
739
+ headers: {
740
+ "Content-Type": "application/json",
741
+ ...this.clientId ? { "x-toromarket-client": this.clientId } : {},
742
+ ...this.apiKey ? { "X-API-Key": this.apiKey } : {},
743
+ ...this.token ? { Authorization: `Bearer ${this.token}` } : {},
744
+ ...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {},
745
+ ...options?.headers
746
+ },
747
+ signal: controller.signal
748
+ };
749
+ if (body !== void 0) {
750
+ init.body = JSON.stringify(body);
751
+ }
752
+ let response;
753
+ try {
754
+ response = await fetch(`${this.baseUrl}${path}`, init);
755
+ } catch (fetchError) {
756
+ clearTimeout(timeoutId);
757
+ if (!isLastAttempt) {
758
+ if (fetchError instanceof TypeError || fetchError instanceof DOMException && fetchError.name === "AbortError") {
759
+ await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
760
+ continue;
761
+ }
762
+ }
763
+ if (fetchError instanceof DOMException && fetchError.name === "AbortError") {
764
+ throw new ToromarketError(
765
+ "Request timed out",
766
+ 408,
767
+ "TIMEOUT"
768
+ );
769
+ }
770
+ if (fetchError instanceof TypeError) {
771
+ throw new ToromarketError(
772
+ `Network error: ${fetchError.message}`,
773
+ 0,
774
+ "NETWORK_ERROR"
775
+ );
776
+ }
777
+ throw fetchError;
778
+ }
779
+ clearTimeout(timeoutId);
780
+ if (this.isRetryableStatus(response.status) && !isLastAttempt) {
781
+ await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
782
+ continue;
783
+ }
784
+ let parsedBody;
785
+ try {
786
+ parsedBody = await response.json();
787
+ } catch {
788
+ if (!response.ok) {
789
+ throw new ToromarketError(
790
+ `HTTP ${response.status} with non-JSON response`,
791
+ response.status
792
+ );
793
+ }
794
+ return void 0;
795
+ }
796
+ const envelope = parsedBody;
797
+ if (typeof envelope === "object" && envelope !== null && "success" in envelope && envelope.success === false) {
798
+ const message = typeof envelope.error === "string" ? envelope.error : `HTTP ${response.status}`;
799
+ const code = typeof envelope.code === "string" ? envelope.code : void 0;
800
+ throw new ToromarketError(message, response.status, code, parsedBody);
801
+ }
802
+ if (!response.ok) {
803
+ const raw = parsedBody;
804
+ const code = typeof raw === "object" && raw !== null && typeof raw.code === "string" ? raw.code : void 0;
805
+ throw new ToromarketError(
806
+ `HTTP ${response.status}`,
807
+ response.status,
808
+ code,
809
+ parsedBody
810
+ );
811
+ }
812
+ if (typeof envelope === "object" && envelope !== null && "success" in envelope && envelope.success === true) {
813
+ if ("data" in envelope) {
814
+ return envelope.data;
815
+ }
816
+ const { success: _, ...rest } = envelope;
817
+ if (Object.keys(rest).length > 0) {
818
+ return rest;
819
+ }
820
+ return void 0;
821
+ }
822
+ return parsedBody;
823
+ }
824
+ throw new ToromarketError("Max retries exceeded", 500);
825
+ }
826
+ };
827
+ export {
828
+ AuthResource,
829
+ BillingResource,
830
+ ChatResource,
831
+ FundsResource,
832
+ IntelligenceResource,
833
+ LeaderboardsResource,
834
+ MarketsResource,
835
+ OperatorsResource,
836
+ PerformanceResource,
837
+ PortfolioResource,
838
+ PredictionsResource,
839
+ ProfilesResource,
840
+ SearchResource,
841
+ SocialResource,
842
+ StakeResource,
843
+ ToromarketClient,
844
+ ToromarketError,
845
+ TracesResource,
846
+ WarsResource,
847
+ WatchlistResource
848
+ };
849
+ //# sourceMappingURL=index.js.map