@taphubhq/sdk-core 0.22.0 → 0.22.2

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
@@ -1047,7 +1047,7 @@ function createMqttTransport(endpoint, opts = {}) {
1047
1047
  const candleSubscriptions = /* @__PURE__ */ new Map();
1048
1048
  const statsSubscriptions = /* @__PURE__ */ new Map();
1049
1049
  const walletSubscriptions = /* @__PURE__ */ new Map();
1050
- const { onLifecycle } = opts;
1050
+ const { onLifecycle, auth } = opts;
1051
1051
  let connectStartedAt = 0;
1052
1052
  function fireLifecycle(event) {
1053
1053
  if (!onLifecycle) return;
@@ -1063,7 +1063,12 @@ function createMqttTransport(endpoint, opts = {}) {
1063
1063
  clean: true,
1064
1064
  reconnectPeriod: 2e3,
1065
1065
  connectTimeout: 1e4,
1066
- keepalive: 6
1066
+ keepalive: 6,
1067
+ // Forwarded once at connect time (no refresh on reconnect). When `auth`
1068
+ // is absent both are `undefined`, which mqtt.js omits from the CONNECT
1069
+ // packet — i.e. an anonymous connection, identical to prior behaviour.
1070
+ username: auth?.username,
1071
+ password: auth?.password
1067
1072
  });
1068
1073
  let lastPingreqAt = 0;
1069
1074
  client.on("packetsend", (packet) => {
@@ -1422,7 +1427,8 @@ var RealtimeModule = class extends import_eventemitter33.default {
1422
1427
  } else {
1423
1428
  this.#agencyId = mqttEndpointOrOptions.agencyId;
1424
1429
  this.#transport = mqttEndpointOrOptions.transport ?? createMqttTransport(mqttEndpointOrOptions.mqttEndpoint, {
1425
- onLifecycle: mqttEndpointOrOptions.onMqttLifecycle
1430
+ onLifecycle: mqttEndpointOrOptions.onMqttLifecycle,
1431
+ auth: mqttEndpointOrOptions.mqttAuth
1426
1432
  });
1427
1433
  }
1428
1434
  }
@@ -1816,10 +1822,8 @@ var RTT_FAIR_TO_POOR = 450;
1816
1822
  var RTT_POOR_TO_FAIR = 350;
1817
1823
  var JITTER_POOR = 150;
1818
1824
  var JITTER_LEAVE_POOR = 120;
1819
- var LOSS_POOR = 0.05;
1820
- var LOSS_LEAVE_POOR = 0.03;
1821
- var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR || m.lossRate > LOSS_POOR;
1822
- var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR && m.lossRate < LOSS_LEAVE_POOR;
1825
+ var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR;
1826
+ var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR;
1823
1827
  var isFairUpper = (rtt) => rtt > RTT_GOOD_TO_FAIR;
1824
1828
  var canReachGood = (rtt) => rtt < RTT_FAIR_TO_GOOD;
1825
1829
  function classifyNetworkLevel(metrics, current) {
@@ -1867,10 +1871,7 @@ var RttSmoother = class {
1867
1871
  this.consecutiveOutliers = 0;
1868
1872
  }
1869
1873
  this.ema = this.ema === 0 ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
1870
- const next = classifyNetworkLevel(
1871
- { rtt, jitter: metrics.jitter, lossRate: metrics.lossRate },
1872
- this.committed
1873
- );
1874
+ const next = classifyNetworkLevel({ rtt, jitter: metrics.jitter }, this.committed);
1874
1875
  if (next === this.candidate) {
1875
1876
  this.candidateCount += 1;
1876
1877
  } else {
@@ -1929,7 +1930,6 @@ var NetworkQualityMonitor = class {
1929
1930
  smoother = new RttSmoother();
1930
1931
  mqttConnected = false;
1931
1932
  mqttDisconnectedAt = null;
1932
- lastSuccessfulHttpAt = null;
1933
1933
  committedNetwork = "good";
1934
1934
  committedBackend = "ok";
1935
1935
  tickHandle = null;
@@ -1948,9 +1948,6 @@ var NetworkQualityMonitor = class {
1948
1948
  if (bucket.length > WINDOW_MAX_SAMPLES_PER_SOURCE) {
1949
1949
  bucket.shift();
1950
1950
  }
1951
- if (sample.reason === "ok" && sample.source !== "connection" && sample.source !== "browser") {
1952
- this.lastSuccessfulHttpAt = sample.ts;
1953
- }
1954
1951
  if (sample.source === "mqtt" && sample.reason === "ok") {
1955
1952
  this.smoother.add(sample.rtt, this.deriveMetrics());
1956
1953
  }
@@ -2014,7 +2011,6 @@ var NetworkQualityMonitor = class {
2014
2011
  this.smoother.reset();
2015
2012
  this.mqttConnected = false;
2016
2013
  this.mqttDisconnectedAt = null;
2017
- this.lastSuccessfulHttpAt = null;
2018
2014
  this.committedNetwork = "good";
2019
2015
  this.committedBackend = "ok";
2020
2016
  const current = this.snapshot();
@@ -2086,7 +2082,7 @@ var NetworkQualityMonitor = class {
2086
2082
  const backend = classifyBackendHealth(httpSamples);
2087
2083
  const metrics = this.deriveMetricsFrom(effectiveSamples);
2088
2084
  const candidate = classifyNetworkLevel(
2089
- { rtt: metrics.emaForLevel, jitter: metrics.jitter, lossRate: metrics.lossRate },
2085
+ { rtt: metrics.emaForLevel, jitter: metrics.jitter },
2090
2086
  this.committedNetwork
2091
2087
  );
2092
2088
  let nextNetwork = this.smoother.level;
@@ -2139,15 +2135,7 @@ var NetworkQualityMonitor = class {
2139
2135
  return true;
2140
2136
  }
2141
2137
  const now = this.now();
2142
- const recent = this.allHttpAndMqttSamples().filter(
2143
- (s) => s.ts >= now - OFFLINE_HOLD_MS && (s.source === "graphql" || s.source === "rest")
2144
- );
2145
- if (recent.length >= 3 && recent.every(
2146
- (s) => s.reason === "network" || s.reason === "timeout" || s.reason === "offline"
2147
- )) {
2148
- return true;
2149
- }
2150
- if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS && (this.lastSuccessfulHttpAt === null || now - this.lastSuccessfulHttpAt > OFFLINE_HOLD_MS)) {
2138
+ if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS) {
2151
2139
  return true;
2152
2140
  }
2153
2141
  return false;
@@ -2783,6 +2771,7 @@ var TaphubClient = class {
2783
2771
  this.realtime = config.mqttEndpoint ? new RealtimeModule({
2784
2772
  mqttEndpoint: config.mqttEndpoint,
2785
2773
  agencyId: this.agencyId,
2774
+ mqttAuth: config.mqttAuth,
2786
2775
  onMqttLifecycle: createMqttProbe(this.network)
2787
2776
  }) : void 0;
2788
2777
  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
  }
@@ -850,6 +864,15 @@ interface RealtimeModuleOptions {
850
864
  * the caller (tenant-scoping mirror of the GQL resolver).
851
865
  */
852
866
  agencyId?: string;
867
+ /**
868
+ * Optional MQTT broker credentials, forwarded to the transport connection
869
+ * (read once at connect time, no refresh). Ignored when an explicit
870
+ * `transport` override is supplied.
871
+ */
872
+ mqttAuth?: {
873
+ username?: string;
874
+ password?: string;
875
+ };
853
876
  /** @internal For testing only */
854
877
  transport?: MqttTransport;
855
878
  /**
@@ -984,7 +1007,6 @@ declare class NetworkQualityMonitor {
984
1007
  private readonly smoother;
985
1008
  private mqttConnected;
986
1009
  private mqttDisconnectedAt;
987
- private lastSuccessfulHttpAt;
988
1010
  private committedNetwork;
989
1011
  private committedBackend;
990
1012
  private tickHandle;
@@ -1124,4 +1146,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
1124
1146
  declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1125
1147
  declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1126
1148
 
1127
- 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 };
1149
+ 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
  }
@@ -850,6 +864,15 @@ interface RealtimeModuleOptions {
850
864
  * the caller (tenant-scoping mirror of the GQL resolver).
851
865
  */
852
866
  agencyId?: string;
867
+ /**
868
+ * Optional MQTT broker credentials, forwarded to the transport connection
869
+ * (read once at connect time, no refresh). Ignored when an explicit
870
+ * `transport` override is supplied.
871
+ */
872
+ mqttAuth?: {
873
+ username?: string;
874
+ password?: string;
875
+ };
853
876
  /** @internal For testing only */
854
877
  transport?: MqttTransport;
855
878
  /**
@@ -984,7 +1007,6 @@ declare class NetworkQualityMonitor {
984
1007
  private readonly smoother;
985
1008
  private mqttConnected;
986
1009
  private mqttDisconnectedAt;
987
- private lastSuccessfulHttpAt;
988
1010
  private committedNetwork;
989
1011
  private committedBackend;
990
1012
  private tickHandle;
@@ -1124,4 +1146,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
1124
1146
  declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1125
1147
  declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
1126
1148
 
1127
- 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 };
1149
+ 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
@@ -982,7 +982,7 @@ function createMqttTransport(endpoint, opts = {}) {
982
982
  const candleSubscriptions = /* @__PURE__ */ new Map();
983
983
  const statsSubscriptions = /* @__PURE__ */ new Map();
984
984
  const walletSubscriptions = /* @__PURE__ */ new Map();
985
- const { onLifecycle } = opts;
985
+ const { onLifecycle, auth } = opts;
986
986
  let connectStartedAt = 0;
987
987
  function fireLifecycle(event) {
988
988
  if (!onLifecycle) return;
@@ -998,7 +998,12 @@ function createMqttTransport(endpoint, opts = {}) {
998
998
  clean: true,
999
999
  reconnectPeriod: 2e3,
1000
1000
  connectTimeout: 1e4,
1001
- keepalive: 6
1001
+ keepalive: 6,
1002
+ // Forwarded once at connect time (no refresh on reconnect). When `auth`
1003
+ // is absent both are `undefined`, which mqtt.js omits from the CONNECT
1004
+ // packet — i.e. an anonymous connection, identical to prior behaviour.
1005
+ username: auth?.username,
1006
+ password: auth?.password
1002
1007
  });
1003
1008
  let lastPingreqAt = 0;
1004
1009
  client.on("packetsend", (packet) => {
@@ -1357,7 +1362,8 @@ var RealtimeModule = class extends EventEmitter3 {
1357
1362
  } else {
1358
1363
  this.#agencyId = mqttEndpointOrOptions.agencyId;
1359
1364
  this.#transport = mqttEndpointOrOptions.transport ?? createMqttTransport(mqttEndpointOrOptions.mqttEndpoint, {
1360
- onLifecycle: mqttEndpointOrOptions.onMqttLifecycle
1365
+ onLifecycle: mqttEndpointOrOptions.onMqttLifecycle,
1366
+ auth: mqttEndpointOrOptions.mqttAuth
1361
1367
  });
1362
1368
  }
1363
1369
  }
@@ -1751,10 +1757,8 @@ var RTT_FAIR_TO_POOR = 450;
1751
1757
  var RTT_POOR_TO_FAIR = 350;
1752
1758
  var JITTER_POOR = 150;
1753
1759
  var JITTER_LEAVE_POOR = 120;
1754
- var LOSS_POOR = 0.05;
1755
- var LOSS_LEAVE_POOR = 0.03;
1756
- var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR || m.lossRate > LOSS_POOR;
1757
- var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR && m.lossRate < LOSS_LEAVE_POOR;
1760
+ var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR;
1761
+ var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR;
1758
1762
  var isFairUpper = (rtt) => rtt > RTT_GOOD_TO_FAIR;
1759
1763
  var canReachGood = (rtt) => rtt < RTT_FAIR_TO_GOOD;
1760
1764
  function classifyNetworkLevel(metrics, current) {
@@ -1802,10 +1806,7 @@ var RttSmoother = class {
1802
1806
  this.consecutiveOutliers = 0;
1803
1807
  }
1804
1808
  this.ema = this.ema === 0 ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
1805
- const next = classifyNetworkLevel(
1806
- { rtt, jitter: metrics.jitter, lossRate: metrics.lossRate },
1807
- this.committed
1808
- );
1809
+ const next = classifyNetworkLevel({ rtt, jitter: metrics.jitter }, this.committed);
1809
1810
  if (next === this.candidate) {
1810
1811
  this.candidateCount += 1;
1811
1812
  } else {
@@ -1864,7 +1865,6 @@ var NetworkQualityMonitor = class {
1864
1865
  smoother = new RttSmoother();
1865
1866
  mqttConnected = false;
1866
1867
  mqttDisconnectedAt = null;
1867
- lastSuccessfulHttpAt = null;
1868
1868
  committedNetwork = "good";
1869
1869
  committedBackend = "ok";
1870
1870
  tickHandle = null;
@@ -1883,9 +1883,6 @@ var NetworkQualityMonitor = class {
1883
1883
  if (bucket.length > WINDOW_MAX_SAMPLES_PER_SOURCE) {
1884
1884
  bucket.shift();
1885
1885
  }
1886
- if (sample.reason === "ok" && sample.source !== "connection" && sample.source !== "browser") {
1887
- this.lastSuccessfulHttpAt = sample.ts;
1888
- }
1889
1886
  if (sample.source === "mqtt" && sample.reason === "ok") {
1890
1887
  this.smoother.add(sample.rtt, this.deriveMetrics());
1891
1888
  }
@@ -1949,7 +1946,6 @@ var NetworkQualityMonitor = class {
1949
1946
  this.smoother.reset();
1950
1947
  this.mqttConnected = false;
1951
1948
  this.mqttDisconnectedAt = null;
1952
- this.lastSuccessfulHttpAt = null;
1953
1949
  this.committedNetwork = "good";
1954
1950
  this.committedBackend = "ok";
1955
1951
  const current = this.snapshot();
@@ -2021,7 +2017,7 @@ var NetworkQualityMonitor = class {
2021
2017
  const backend = classifyBackendHealth(httpSamples);
2022
2018
  const metrics = this.deriveMetricsFrom(effectiveSamples);
2023
2019
  const candidate = classifyNetworkLevel(
2024
- { rtt: metrics.emaForLevel, jitter: metrics.jitter, lossRate: metrics.lossRate },
2020
+ { rtt: metrics.emaForLevel, jitter: metrics.jitter },
2025
2021
  this.committedNetwork
2026
2022
  );
2027
2023
  let nextNetwork = this.smoother.level;
@@ -2074,15 +2070,7 @@ var NetworkQualityMonitor = class {
2074
2070
  return true;
2075
2071
  }
2076
2072
  const now = this.now();
2077
- const recent = this.allHttpAndMqttSamples().filter(
2078
- (s) => s.ts >= now - OFFLINE_HOLD_MS && (s.source === "graphql" || s.source === "rest")
2079
- );
2080
- if (recent.length >= 3 && recent.every(
2081
- (s) => s.reason === "network" || s.reason === "timeout" || s.reason === "offline"
2082
- )) {
2083
- return true;
2084
- }
2085
- if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS && (this.lastSuccessfulHttpAt === null || now - this.lastSuccessfulHttpAt > OFFLINE_HOLD_MS)) {
2073
+ if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS) {
2086
2074
  return true;
2087
2075
  }
2088
2076
  return false;
@@ -2718,6 +2706,7 @@ var TaphubClient = class {
2718
2706
  this.realtime = config.mqttEndpoint ? new RealtimeModule({
2719
2707
  mqttEndpoint: config.mqttEndpoint,
2720
2708
  agencyId: this.agencyId,
2709
+ mqttAuth: config.mqttAuth,
2721
2710
  onMqttLifecycle: createMqttProbe(this.network)
2722
2711
  }) : void 0;
2723
2712
  attachConnectionProbe(this.network);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taphubhq/sdk-core",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "description": "Core SDK for building on the TabHub platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",