@taphubhq/sdk-core 0.22.1 → 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 +10 -3
- package/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +10 -3
- package/package.json +1 -1
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
|
}
|
|
@@ -2765,6 +2771,7 @@ var TaphubClient = class {
|
|
|
2765
2771
|
this.realtime = config.mqttEndpoint ? new RealtimeModule({
|
|
2766
2772
|
mqttEndpoint: config.mqttEndpoint,
|
|
2767
2773
|
agencyId: this.agencyId,
|
|
2774
|
+
mqttAuth: config.mqttAuth,
|
|
2768
2775
|
onMqttLifecycle: createMqttProbe(this.network)
|
|
2769
2776
|
}) : void 0;
|
|
2770
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
|
/**
|
|
@@ -1123,4 +1146,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
|
|
|
1123
1146
|
declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
|
|
1124
1147
|
declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
|
|
1125
1148
|
|
|
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 };
|
|
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
|
/**
|
|
@@ -1123,4 +1146,4 @@ declare function adaptiveSimpson(f: (x: number) => number, a: number, b: number,
|
|
|
1123
1146
|
declare function calculateProbWin(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
|
|
1124
1147
|
declare function calculateProbWin_v2(time1: number, time2: number, _price1: number, price2: number, creationTime: number, currentPrice: number, volatility: number): number;
|
|
1125
1148
|
|
|
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 };
|
|
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
|
}
|
|
@@ -2700,6 +2706,7 @@ var TaphubClient = class {
|
|
|
2700
2706
|
this.realtime = config.mqttEndpoint ? new RealtimeModule({
|
|
2701
2707
|
mqttEndpoint: config.mqttEndpoint,
|
|
2702
2708
|
agencyId: this.agencyId,
|
|
2709
|
+
mqttAuth: config.mqttAuth,
|
|
2703
2710
|
onMqttLifecycle: createMqttProbe(this.network)
|
|
2704
2711
|
}) : void 0;
|
|
2705
2712
|
attachConnectionProbe(this.network);
|