@taphubhq/sdk-core 0.22.1 → 0.22.3

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
@@ -533,7 +533,10 @@ var BidModule = class {
533
533
  price2: input.price2,
534
534
  coefficient: input.coefficient,
535
535
  amount: input.amount,
536
- slippage: input.slippage
536
+ slippage: input.slippage,
537
+ // QA-only late-bid passthrough (bid-260610). Omitted entirely when absent
538
+ // so no `bidToken: null` is sent. sdk-react sets it from localStorage.
539
+ ...input.bidToken ? { bidToken: input.bidToken } : {}
537
540
  }
538
541
  };
539
542
  try {
@@ -1047,7 +1050,7 @@ function createMqttTransport(endpoint, opts = {}) {
1047
1050
  const candleSubscriptions = /* @__PURE__ */ new Map();
1048
1051
  const statsSubscriptions = /* @__PURE__ */ new Map();
1049
1052
  const walletSubscriptions = /* @__PURE__ */ new Map();
1050
- const { onLifecycle } = opts;
1053
+ const { onLifecycle, auth } = opts;
1051
1054
  let connectStartedAt = 0;
1052
1055
  function fireLifecycle(event) {
1053
1056
  if (!onLifecycle) return;
@@ -1063,7 +1066,12 @@ function createMqttTransport(endpoint, opts = {}) {
1063
1066
  clean: true,
1064
1067
  reconnectPeriod: 2e3,
1065
1068
  connectTimeout: 1e4,
1066
- keepalive: 6
1069
+ keepalive: 6,
1070
+ // Forwarded once at connect time (no refresh on reconnect). When `auth`
1071
+ // is absent both are `undefined`, which mqtt.js omits from the CONNECT
1072
+ // packet — i.e. an anonymous connection, identical to prior behaviour.
1073
+ username: auth?.username,
1074
+ password: auth?.password
1067
1075
  });
1068
1076
  let lastPingreqAt = 0;
1069
1077
  client.on("packetsend", (packet) => {
@@ -1422,7 +1430,8 @@ var RealtimeModule = class extends import_eventemitter33.default {
1422
1430
  } else {
1423
1431
  this.#agencyId = mqttEndpointOrOptions.agencyId;
1424
1432
  this.#transport = mqttEndpointOrOptions.transport ?? createMqttTransport(mqttEndpointOrOptions.mqttEndpoint, {
1425
- onLifecycle: mqttEndpointOrOptions.onMqttLifecycle
1433
+ onLifecycle: mqttEndpointOrOptions.onMqttLifecycle,
1434
+ auth: mqttEndpointOrOptions.mqttAuth
1426
1435
  });
1427
1436
  }
1428
1437
  }
@@ -2765,6 +2774,7 @@ var TaphubClient = class {
2765
2774
  this.realtime = config.mqttEndpoint ? new RealtimeModule({
2766
2775
  mqttEndpoint: config.mqttEndpoint,
2767
2776
  agencyId: this.agencyId,
2777
+ mqttAuth: config.mqttAuth,
2768
2778
  onMqttLifecycle: createMqttProbe(this.network)
2769
2779
  }) : void 0;
2770
2780
  attachConnectionProbe(this.network);
package/dist/index.d.mts CHANGED
@@ -12,10 +12,24 @@ declare const TaphubStorage: {
12
12
  sessionStorage(): TaphubStorageAdapter;
13
13
  };
14
14
 
15
+ /**
16
+ * MQTT broker credentials. Forwarded verbatim to the MQTT connection when
17
+ * `mqttEndpoint` is set, and ignored otherwise. Read once when the connection
18
+ * first opens (no refresh on reconnect).
19
+ *
20
+ * For brokers using JWT-in-username auth (the TapHub/EMQX default), pass the
21
+ * session token as `username` and leave `password` empty (`''`).
22
+ */
23
+ interface MqttAuthConfig {
24
+ username?: string;
25
+ password?: string;
26
+ }
15
27
  interface TaphubClientConfig {
16
28
  agencyId: string;
17
29
  endpoint: string;
18
30
  mqttEndpoint?: string;
31
+ /** Optional MQTT broker credentials. Ignored when `mqttEndpoint` is absent. */
32
+ mqttAuth?: MqttAuthConfig;
19
33
  storage?: TaphubStorageAdapter;
20
34
  fetch?: typeof globalThis.fetch;
21
35
  }
@@ -229,6 +243,13 @@ interface PlaceBidInput {
229
243
  coefficient: string;
230
244
  amount: string;
231
245
  slippage: number;
246
+ /**
247
+ * QA-only late-bid token (dev/local). Forwarded verbatim to grid-api, which
248
+ * honours it only when it matches its env secret on a dev/local stage. sdk-core
249
+ * is environment-agnostic and never reads it from storage — the browser-only
250
+ * sdk-react reads `localStorage["bidToken"]` and injects it. Omit when absent.
251
+ */
252
+ bidToken?: string;
232
253
  }
233
254
 
234
255
  declare const isPending: (bid: Bid) => boolean;
@@ -850,6 +871,15 @@ interface RealtimeModuleOptions {
850
871
  * the caller (tenant-scoping mirror of the GQL resolver).
851
872
  */
852
873
  agencyId?: string;
874
+ /**
875
+ * Optional MQTT broker credentials, forwarded to the transport connection
876
+ * (read once at connect time, no refresh). Ignored when an explicit
877
+ * `transport` override is supplied.
878
+ */
879
+ mqttAuth?: {
880
+ username?: string;
881
+ password?: string;
882
+ };
853
883
  /** @internal For testing only */
854
884
  transport?: MqttTransport;
855
885
  /**
@@ -1123,4 +1153,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
1123
1153
  declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1124
1154
  declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1125
1155
 
1126
- export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, GameChannel, type GameConfig, 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 MqttWalletBalanceEvent, type MyRank, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type Pair, type PairInfo, PairModule, type PlaceBidInput, type RankBoard, type RankEntry, type RankPeriod, type RankSort, RealtimeModule, type Sample, type SampleReason, type SignalSource, type SortDir, 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, type WalletBalanceReason, WalletChannel, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
1156
+ export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, GameChannel, type GameConfig, 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 MqttAuthConfig, type MqttBalanceEvent, type MqttBidAcceptedEvent, type MqttBidLostEvent, type MqttBidWonEvent, type MqttCandleEvent, type MqttConfigEvent, type MqttIdealConfigEvent, type MqttWalletBalanceEvent, type MyRank, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type Pair, type PairInfo, PairModule, type PlaceBidInput, type RankBoard, type RankEntry, type RankPeriod, type RankSort, RealtimeModule, type Sample, type SampleReason, type SignalSource, type SortDir, 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, type WalletBalanceReason, WalletChannel, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
package/dist/index.d.ts CHANGED
@@ -12,10 +12,24 @@ declare const TaphubStorage: {
12
12
  sessionStorage(): TaphubStorageAdapter;
13
13
  };
14
14
 
15
+ /**
16
+ * MQTT broker credentials. Forwarded verbatim to the MQTT connection when
17
+ * `mqttEndpoint` is set, and ignored otherwise. Read once when the connection
18
+ * first opens (no refresh on reconnect).
19
+ *
20
+ * For brokers using JWT-in-username auth (the TapHub/EMQX default), pass the
21
+ * session token as `username` and leave `password` empty (`''`).
22
+ */
23
+ interface MqttAuthConfig {
24
+ username?: string;
25
+ password?: string;
26
+ }
15
27
  interface TaphubClientConfig {
16
28
  agencyId: string;
17
29
  endpoint: string;
18
30
  mqttEndpoint?: string;
31
+ /** Optional MQTT broker credentials. Ignored when `mqttEndpoint` is absent. */
32
+ mqttAuth?: MqttAuthConfig;
19
33
  storage?: TaphubStorageAdapter;
20
34
  fetch?: typeof globalThis.fetch;
21
35
  }
@@ -229,6 +243,13 @@ interface PlaceBidInput {
229
243
  coefficient: string;
230
244
  amount: string;
231
245
  slippage: number;
246
+ /**
247
+ * QA-only late-bid token (dev/local). Forwarded verbatim to grid-api, which
248
+ * honours it only when it matches its env secret on a dev/local stage. sdk-core
249
+ * is environment-agnostic and never reads it from storage — the browser-only
250
+ * sdk-react reads `localStorage["bidToken"]` and injects it. Omit when absent.
251
+ */
252
+ bidToken?: string;
232
253
  }
233
254
 
234
255
  declare const isPending: (bid: Bid) => boolean;
@@ -850,6 +871,15 @@ interface RealtimeModuleOptions {
850
871
  * the caller (tenant-scoping mirror of the GQL resolver).
851
872
  */
852
873
  agencyId?: string;
874
+ /**
875
+ * Optional MQTT broker credentials, forwarded to the transport connection
876
+ * (read once at connect time, no refresh). Ignored when an explicit
877
+ * `transport` override is supplied.
878
+ */
879
+ mqttAuth?: {
880
+ username?: string;
881
+ password?: string;
882
+ };
853
883
  /** @internal For testing only */
854
884
  transport?: MqttTransport;
855
885
  /**
@@ -1123,4 +1153,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
1123
1153
  declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1124
1154
  declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1125
1155
 
1126
- export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, GameChannel, type GameConfig, 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 MqttWalletBalanceEvent, type MyRank, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type Pair, type PairInfo, PairModule, type PlaceBidInput, type RankBoard, type RankEntry, type RankPeriod, type RankSort, RealtimeModule, type Sample, type SampleReason, type SignalSource, type SortDir, 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, type WalletBalanceReason, WalletChannel, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
1156
+ export { type AgencyPairFilter, AgencyPairModule, type AgencyPairStats, type AgencyPairStatus, AuthModule, type BackendHealth, type Bid, BidModule, type BidStatus, type CancelBidResult, type Candle, type Constraints, type Currency, GameChannel, type GameConfig, 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 MqttAuthConfig, type MqttBalanceEvent, type MqttBidAcceptedEvent, type MqttBidLostEvent, type MqttBidWonEvent, type MqttCandleEvent, type MqttConfigEvent, type MqttIdealConfigEvent, type MqttWalletBalanceEvent, type MyRank, type NetworkLevel, type NetworkQuality, NetworkQualityMonitor, type Pair, type PairInfo, PairModule, type PlaceBidInput, type RankBoard, type RankEntry, type RankPeriod, type RankSort, RealtimeModule, type Sample, type SampleReason, type SignalSource, type SortDir, 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, type WalletBalanceReason, WalletChannel, adaptiveSimpson, autoDetectStorage, calculateProbWin, calculateProbWin_v2, errorFunction, isCancelled, isLoss, isPending, isTerminal, isWin, normalCDF, normalPDF };
package/dist/index.js CHANGED
@@ -468,7 +468,10 @@ var BidModule = class {
468
468
  price2: input.price2,
469
469
  coefficient: input.coefficient,
470
470
  amount: input.amount,
471
- slippage: input.slippage
471
+ slippage: input.slippage,
472
+ // QA-only late-bid passthrough (bid-260610). Omitted entirely when absent
473
+ // so no `bidToken: null` is sent. sdk-react sets it from localStorage.
474
+ ...input.bidToken ? { bidToken: input.bidToken } : {}
472
475
  }
473
476
  };
474
477
  try {
@@ -982,7 +985,7 @@ function createMqttTransport(endpoint, opts = {}) {
982
985
  const candleSubscriptions = /* @__PURE__ */ new Map();
983
986
  const statsSubscriptions = /* @__PURE__ */ new Map();
984
987
  const walletSubscriptions = /* @__PURE__ */ new Map();
985
- const { onLifecycle } = opts;
988
+ const { onLifecycle, auth } = opts;
986
989
  let connectStartedAt = 0;
987
990
  function fireLifecycle(event) {
988
991
  if (!onLifecycle) return;
@@ -998,7 +1001,12 @@ function createMqttTransport(endpoint, opts = {}) {
998
1001
  clean: true,
999
1002
  reconnectPeriod: 2e3,
1000
1003
  connectTimeout: 1e4,
1001
- keepalive: 6
1004
+ keepalive: 6,
1005
+ // Forwarded once at connect time (no refresh on reconnect). When `auth`
1006
+ // is absent both are `undefined`, which mqtt.js omits from the CONNECT
1007
+ // packet — i.e. an anonymous connection, identical to prior behaviour.
1008
+ username: auth?.username,
1009
+ password: auth?.password
1002
1010
  });
1003
1011
  let lastPingreqAt = 0;
1004
1012
  client.on("packetsend", (packet) => {
@@ -1357,7 +1365,8 @@ var RealtimeModule = class extends EventEmitter3 {
1357
1365
  } else {
1358
1366
  this.#agencyId = mqttEndpointOrOptions.agencyId;
1359
1367
  this.#transport = mqttEndpointOrOptions.transport ?? createMqttTransport(mqttEndpointOrOptions.mqttEndpoint, {
1360
- onLifecycle: mqttEndpointOrOptions.onMqttLifecycle
1368
+ onLifecycle: mqttEndpointOrOptions.onMqttLifecycle,
1369
+ auth: mqttEndpointOrOptions.mqttAuth
1361
1370
  });
1362
1371
  }
1363
1372
  }
@@ -2700,6 +2709,7 @@ var TaphubClient = class {
2700
2709
  this.realtime = config.mqttEndpoint ? new RealtimeModule({
2701
2710
  mqttEndpoint: config.mqttEndpoint,
2702
2711
  agencyId: this.agencyId,
2712
+ mqttAuth: config.mqttAuth,
2703
2713
  onMqttLifecycle: createMqttProbe(this.network)
2704
2714
  }) : void 0;
2705
2715
  attachConnectionProbe(this.network);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taphubhq/sdk-core",
3
- "version": "0.22.1",
3
+ "version": "0.22.3",
4
4
  "description": "Core SDK for building on the TabHub platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",