@taphubhq/sdk-core 0.15.0 → 0.15.1

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.cjs CHANGED
@@ -1398,11 +1398,30 @@ function normaliseMyWalletByCurrencyResponse(body) {
1398
1398
  }
1399
1399
  return normaliseWalletNode(body.myWalletByCurrency);
1400
1400
  }
1401
+ function normaliseUserPnL(node) {
1402
+ if (!node) {
1403
+ throw new TaphubServerError("Invalid response from server", {
1404
+ code: "InvalidResponse"
1405
+ });
1406
+ }
1407
+ return {
1408
+ gain: node.gain,
1409
+ totalWagered: node.total_wagered,
1410
+ totalPayout: node.total_payout,
1411
+ totalBids: node.total_bids,
1412
+ totalWins: node.total_wins
1413
+ };
1414
+ }
1401
1415
 
1402
1416
  // src/modules/user/queries.ts
1403
1417
  var ME_QUERY = "query Me { me { id username wallet_address balance is_demo } }";
1404
1418
  var MY_WALLETS_QUERY = "query MyWallets { myWallets { id amount currency isEnable } }";
1405
1419
  var MY_WALLET_BY_CURRENCY_QUERY = "query MyWalletByCurrency($currency: String!) { myWalletByCurrency(currency: $currency) { id amount currency isEnable } }";
1420
+ var USER_PNL_QUERY = `query UserPnL($period: String) {
1421
+ userPnL(period: $period) {
1422
+ gain total_wagered total_payout total_bids total_wins
1423
+ }
1424
+ }`;
1406
1425
 
1407
1426
  // src/modules/user/index.ts
1408
1427
  var UserModule = class {
@@ -1419,6 +1438,20 @@ var UserModule = class {
1419
1438
  const body = await this.#graphql.request(ME_QUERY);
1420
1439
  return normaliseMeResponse(body);
1421
1440
  }
1441
+ /**
1442
+ * Fetch the authenticated user's realized PnL (grid-api).
1443
+ * `period` defaults to 'all_time' ('weekly' also accepted). Agency scope is
1444
+ * resolved server-side from the JWT — never passed from the client.
1445
+ */
1446
+ async pnl(args) {
1447
+ const period = args?.period ?? "all_time";
1448
+ const body = await this.#graphql.request(
1449
+ USER_PNL_QUERY,
1450
+ { period },
1451
+ args?.signal ? { signal: args.signal } : void 0
1452
+ );
1453
+ return normaliseUserPnL(body.userPnL);
1454
+ }
1422
1455
  async wallets(opts) {
1423
1456
  const body = await this.#graphqlUser.request(
1424
1457
  MY_WALLETS_QUERY,
package/dist/index.d.mts CHANGED
@@ -701,6 +701,19 @@ interface Wallet {
701
701
  currency: string;
702
702
  isEnable: boolean;
703
703
  }
704
+ type UserPnLPeriod = 'weekly' | 'all_time';
705
+ /**
706
+ * Public, normalised PnL shape (camelCase). The wire shape is the codegen'd
707
+ * `UserPnL` from `@/types/gql/grid`; `normaliseUserPnL` maps wire → this.
708
+ */
709
+ interface UserPnL {
710
+ /** Realized PnL: totalPayout − totalWagered. Decimal string. */
711
+ gain: string;
712
+ totalWagered: string;
713
+ totalPayout: string;
714
+ totalBids: number;
715
+ totalWins: number;
716
+ }
704
717
 
705
718
  interface UserModuleDeps {
706
719
  rest: RestTransport;
@@ -714,6 +727,15 @@ declare class UserModule {
714
727
  #private;
715
728
  constructor(deps: UserModuleDeps);
716
729
  me(): Promise<Me>;
730
+ /**
731
+ * Fetch the authenticated user's realized PnL (grid-api).
732
+ * `period` defaults to 'all_time' ('weekly' also accepted). Agency scope is
733
+ * resolved server-side from the JWT — never passed from the client.
734
+ */
735
+ pnl(args?: {
736
+ period?: UserPnLPeriod;
737
+ signal?: AbortSignal;
738
+ }): Promise<UserPnL>;
717
739
  wallets(opts?: RequestOpts): Promise<Wallet[]>;
718
740
  walletByCurrency(currency: string, opts?: RequestOpts): Promise<Wallet>;
719
741
  get currencies(): Currency[] | null;
@@ -879,4 +901,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
879
901
  declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
880
902
  declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
881
903
 
882
- export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, type Game, GameChannel, type GameConfig, GameModule, type GamePairInfo, type GridConfig, type LeaderboardEntry, LeaderboardModule, type LeaderboardPeriod, type LeaderboardSortBy, LocaleModule, type LocaleRefreshResult, type LocaleResponse, type LocaleTranslations, type LoginResult, type Me, type MqttAcceptedBid, type MqttAgencyPairStatsEvent, type MqttBalanceEvent, type MqttBidAcceptedEvent, type MqttBidLostEvent, type MqttBidWonEvent, type MqttCandleEvent, type MqttConfigEvent, type MqttIdealConfigEvent, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type PlaceBidInput, RealtimeModule, type Sample, type SampleReason, type SignalSource, TaphubAuthError, TaphubClient, type TaphubClientConfig, TaphubError, TaphubEventBus, type TaphubEventMap, TaphubNetworkError, TaphubServerError, TaphubSlippageError, TaphubStorage, type TaphubStorageAdapter, TaphubValidationError, type User, UserModule, type Wallet as UserWallet, type Wallet$1 as Wallet, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
904
+ export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, type Game, GameChannel, type GameConfig, GameModule, type GamePairInfo, type GridConfig, type LeaderboardEntry, LeaderboardModule, type LeaderboardPeriod, type LeaderboardSortBy, LocaleModule, type LocaleRefreshResult, type LocaleResponse, type LocaleTranslations, type LoginResult, type Me, type MqttAcceptedBid, type MqttAgencyPairStatsEvent, type MqttBalanceEvent, type MqttBidAcceptedEvent, type MqttBidLostEvent, type MqttBidWonEvent, type MqttCandleEvent, type MqttConfigEvent, type MqttIdealConfigEvent, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type PlaceBidInput, RealtimeModule, type Sample, type SampleReason, type SignalSource, TaphubAuthError, TaphubClient, type TaphubClientConfig, TaphubError, TaphubEventBus, type TaphubEventMap, TaphubNetworkError, TaphubServerError, TaphubSlippageError, TaphubStorage, type TaphubStorageAdapter, TaphubValidationError, type User, UserModule, type UserPnL, type UserPnLPeriod, type Wallet as UserWallet, type Wallet$1 as Wallet, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
package/dist/index.d.ts CHANGED
@@ -701,6 +701,19 @@ interface Wallet {
701
701
  currency: string;
702
702
  isEnable: boolean;
703
703
  }
704
+ type UserPnLPeriod = 'weekly' | 'all_time';
705
+ /**
706
+ * Public, normalised PnL shape (camelCase). The wire shape is the codegen'd
707
+ * `UserPnL` from `@/types/gql/grid`; `normaliseUserPnL` maps wire → this.
708
+ */
709
+ interface UserPnL {
710
+ /** Realized PnL: totalPayout − totalWagered. Decimal string. */
711
+ gain: string;
712
+ totalWagered: string;
713
+ totalPayout: string;
714
+ totalBids: number;
715
+ totalWins: number;
716
+ }
704
717
 
705
718
  interface UserModuleDeps {
706
719
  rest: RestTransport;
@@ -714,6 +727,15 @@ declare class UserModule {
714
727
  #private;
715
728
  constructor(deps: UserModuleDeps);
716
729
  me(): Promise<Me>;
730
+ /**
731
+ * Fetch the authenticated user's realized PnL (grid-api).
732
+ * `period` defaults to 'all_time' ('weekly' also accepted). Agency scope is
733
+ * resolved server-side from the JWT — never passed from the client.
734
+ */
735
+ pnl(args?: {
736
+ period?: UserPnLPeriod;
737
+ signal?: AbortSignal;
738
+ }): Promise<UserPnL>;
717
739
  wallets(opts?: RequestOpts): Promise<Wallet[]>;
718
740
  walletByCurrency(currency: string, opts?: RequestOpts): Promise<Wallet>;
719
741
  get currencies(): Currency[] | null;
@@ -879,4 +901,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
879
901
  declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
880
902
  declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
881
903
 
882
- export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, type Game, GameChannel, type GameConfig, GameModule, type GamePairInfo, type GridConfig, type LeaderboardEntry, LeaderboardModule, type LeaderboardPeriod, type LeaderboardSortBy, LocaleModule, type LocaleRefreshResult, type LocaleResponse, type LocaleTranslations, type LoginResult, type Me, type MqttAcceptedBid, type MqttAgencyPairStatsEvent, type MqttBalanceEvent, type MqttBidAcceptedEvent, type MqttBidLostEvent, type MqttBidWonEvent, type MqttCandleEvent, type MqttConfigEvent, type MqttIdealConfigEvent, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type PlaceBidInput, RealtimeModule, type Sample, type SampleReason, type SignalSource, TaphubAuthError, TaphubClient, type TaphubClientConfig, TaphubError, TaphubEventBus, type TaphubEventMap, TaphubNetworkError, TaphubServerError, TaphubSlippageError, TaphubStorage, type TaphubStorageAdapter, TaphubValidationError, type User, UserModule, type Wallet as UserWallet, type Wallet$1 as Wallet, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
904
+ export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, type Game, GameChannel, type GameConfig, GameModule, type GamePairInfo, type GridConfig, type LeaderboardEntry, LeaderboardModule, type LeaderboardPeriod, type LeaderboardSortBy, LocaleModule, type LocaleRefreshResult, type LocaleResponse, type LocaleTranslations, type LoginResult, type Me, type MqttAcceptedBid, type MqttAgencyPairStatsEvent, type MqttBalanceEvent, type MqttBidAcceptedEvent, type MqttBidLostEvent, type MqttBidWonEvent, type MqttCandleEvent, type MqttConfigEvent, type MqttIdealConfigEvent, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type PlaceBidInput, RealtimeModule, type Sample, type SampleReason, type SignalSource, TaphubAuthError, TaphubClient, type TaphubClientConfig, TaphubError, TaphubEventBus, type TaphubEventMap, TaphubNetworkError, TaphubServerError, TaphubSlippageError, TaphubStorage, type TaphubStorageAdapter, TaphubValidationError, type User, UserModule, type UserPnL, type UserPnLPeriod, type Wallet as UserWallet, type Wallet$1 as Wallet, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
package/dist/index.js CHANGED
@@ -1333,11 +1333,30 @@ function normaliseMyWalletByCurrencyResponse(body) {
1333
1333
  }
1334
1334
  return normaliseWalletNode(body.myWalletByCurrency);
1335
1335
  }
1336
+ function normaliseUserPnL(node) {
1337
+ if (!node) {
1338
+ throw new TaphubServerError("Invalid response from server", {
1339
+ code: "InvalidResponse"
1340
+ });
1341
+ }
1342
+ return {
1343
+ gain: node.gain,
1344
+ totalWagered: node.total_wagered,
1345
+ totalPayout: node.total_payout,
1346
+ totalBids: node.total_bids,
1347
+ totalWins: node.total_wins
1348
+ };
1349
+ }
1336
1350
 
1337
1351
  // src/modules/user/queries.ts
1338
1352
  var ME_QUERY = "query Me { me { id username wallet_address balance is_demo } }";
1339
1353
  var MY_WALLETS_QUERY = "query MyWallets { myWallets { id amount currency isEnable } }";
1340
1354
  var MY_WALLET_BY_CURRENCY_QUERY = "query MyWalletByCurrency($currency: String!) { myWalletByCurrency(currency: $currency) { id amount currency isEnable } }";
1355
+ var USER_PNL_QUERY = `query UserPnL($period: String) {
1356
+ userPnL(period: $period) {
1357
+ gain total_wagered total_payout total_bids total_wins
1358
+ }
1359
+ }`;
1341
1360
 
1342
1361
  // src/modules/user/index.ts
1343
1362
  var UserModule = class {
@@ -1354,6 +1373,20 @@ var UserModule = class {
1354
1373
  const body = await this.#graphql.request(ME_QUERY);
1355
1374
  return normaliseMeResponse(body);
1356
1375
  }
1376
+ /**
1377
+ * Fetch the authenticated user's realized PnL (grid-api).
1378
+ * `period` defaults to 'all_time' ('weekly' also accepted). Agency scope is
1379
+ * resolved server-side from the JWT — never passed from the client.
1380
+ */
1381
+ async pnl(args) {
1382
+ const period = args?.period ?? "all_time";
1383
+ const body = await this.#graphql.request(
1384
+ USER_PNL_QUERY,
1385
+ { period },
1386
+ args?.signal ? { signal: args.signal } : void 0
1387
+ );
1388
+ return normaliseUserPnL(body.userPnL);
1389
+ }
1357
1390
  async wallets(opts) {
1358
1391
  const body = await this.#graphqlUser.request(
1359
1392
  MY_WALLETS_QUERY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taphubhq/sdk-core",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Core SDK for building on the TabHub platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",