@taphubhq/sdk-core 0.18.0 → 0.19.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.cjs +21 -8
- package/dist/index.d.mts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +21 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -420,6 +420,18 @@ var AuthModule = class {
|
|
|
420
420
|
};
|
|
421
421
|
|
|
422
422
|
// src/modules/bid/normalise.ts
|
|
423
|
+
function parseMeta(raw) {
|
|
424
|
+
if (!raw) return null;
|
|
425
|
+
try {
|
|
426
|
+
const obj = JSON.parse(raw);
|
|
427
|
+
return {
|
|
428
|
+
userName: typeof obj.userName === "string" ? obj.userName : "",
|
|
429
|
+
pairName: typeof obj.pairName === "string" ? obj.pairName : ""
|
|
430
|
+
};
|
|
431
|
+
} catch {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
423
435
|
var VALID_STATUSES = /* @__PURE__ */ new Set(["pending", "win", "lose", "cancelled"]);
|
|
424
436
|
var PAST_TENSE_MAP = {
|
|
425
437
|
won: "win",
|
|
@@ -442,7 +454,7 @@ function toWireStatus(status) {
|
|
|
442
454
|
return SDK_TO_WIRE_STATUS[status];
|
|
443
455
|
}
|
|
444
456
|
function normaliseBid(node) {
|
|
445
|
-
if (typeof node.id !== "string" || node.id === "" || typeof node.user_id !== "string" || node.user_id === "" || typeof node.
|
|
457
|
+
if (typeof node.id !== "string" || node.id === "" || typeof node.user_id !== "string" || node.user_id === "" || typeof node.pair_id !== "string" || node.pair_id === "" || typeof node.status !== "string" || node.status === "") {
|
|
446
458
|
throw new TaphubServerError("Invalid response from server", {
|
|
447
459
|
code: "InvalidResponse"
|
|
448
460
|
});
|
|
@@ -450,7 +462,7 @@ function normaliseBid(node) {
|
|
|
450
462
|
return {
|
|
451
463
|
id: node.id,
|
|
452
464
|
userId: node.user_id,
|
|
453
|
-
|
|
465
|
+
pairId: node.pair_id,
|
|
454
466
|
currency: node.currency,
|
|
455
467
|
amount: node.amount,
|
|
456
468
|
coefficient: node.coefficient,
|
|
@@ -461,7 +473,8 @@ function normaliseBid(node) {
|
|
|
461
473
|
status: coerceStatus(node.status),
|
|
462
474
|
payout: node.payout || null,
|
|
463
475
|
slippage: node.slippage,
|
|
464
|
-
createdAt: node.created_at || null
|
|
476
|
+
createdAt: node.created_at || null,
|
|
477
|
+
meta: parseMeta(node.meta)
|
|
465
478
|
};
|
|
466
479
|
}
|
|
467
480
|
function normaliseBids(list) {
|
|
@@ -476,17 +489,17 @@ function normaliseBids(list) {
|
|
|
476
489
|
// src/modules/bid/queries.ts
|
|
477
490
|
var PLACE_BID_MUTATION = `mutation PlaceBid($input: PlaceBidInput!) {
|
|
478
491
|
placeBid(input: $input) {
|
|
479
|
-
id user_id
|
|
492
|
+
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout slippage created_at meta
|
|
480
493
|
}
|
|
481
494
|
}`;
|
|
482
495
|
var MY_BIDS_QUERY = `query MyBids($statuses: [BidStatus!], $limit: Int, $offset: Int, $pairId: ID) {
|
|
483
496
|
myBids(statuses: $statuses, limit: $limit, offset: $offset, pairId: $pairId) {
|
|
484
|
-
id user_id
|
|
497
|
+
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout slippage created_at meta
|
|
485
498
|
}
|
|
486
499
|
}`;
|
|
487
500
|
var CANCEL_BID_MUTATION = `mutation CancelBid($input: CancelBidInput!) {
|
|
488
501
|
cancelBid(input: $input) {
|
|
489
|
-
bid { id user_id
|
|
502
|
+
bid { id user_id pair_id currency amount coefficient time1 time2 price1 price2 status cancelled payout slippage created_at meta }
|
|
490
503
|
refund_amount
|
|
491
504
|
new_balance
|
|
492
505
|
}
|
|
@@ -901,7 +914,7 @@ function subKey(gameId, userId) {
|
|
|
901
914
|
var GAME_SCOPED_SUFFIXES = ["config", "ideal_config"];
|
|
902
915
|
var USER_SCOPED_SUFFIXES = ["bid_result", "balance_update"];
|
|
903
916
|
var TOPIC_PREFIX = "game";
|
|
904
|
-
var MARKET_TOPIC_PREFIX = "market";
|
|
917
|
+
var MARKET_TOPIC_PREFIX = "public/market";
|
|
905
918
|
var WALLET_TOPIC_PREFIX = "wallet";
|
|
906
919
|
var PUBLIC_PREFIX = "public";
|
|
907
920
|
function walletBalanceTopic(userId) {
|
|
@@ -1069,7 +1082,7 @@ function createMqttTransport(endpoint, opts = {}) {
|
|
|
1069
1082
|
}
|
|
1070
1083
|
},
|
|
1071
1084
|
subscribeCandle(pairId, onCandle) {
|
|
1072
|
-
const topic = `${
|
|
1085
|
+
const topic = `${MARKET_TOPIC_PREFIX}/${pairId}/candle`;
|
|
1073
1086
|
if (candleSubscriptions.has(pairId)) return;
|
|
1074
1087
|
const mqttClient = ensureConnected();
|
|
1075
1088
|
candleSubscriptions.set(pairId, { topic, onCandle });
|
package/dist/index.d.mts
CHANGED
|
@@ -171,10 +171,22 @@ declare class AuthModule {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
type BidStatus = 'pending' | 'win' | 'lose' | 'cancelled';
|
|
174
|
+
/** Denormalised display data frozen onto the bid at placement time. */
|
|
175
|
+
interface BidMeta {
|
|
176
|
+
/** Display name of the user who placed the bid. */
|
|
177
|
+
userName: string;
|
|
178
|
+
/** Display pair, e.g. "ETH/USD". */
|
|
179
|
+
pairName: string;
|
|
180
|
+
}
|
|
174
181
|
interface Bid {
|
|
175
182
|
id: string;
|
|
176
183
|
userId: string;
|
|
177
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Pair id, e.g. "grid-ETH-USD" (slash-free system id).
|
|
186
|
+
* Renamed from `gameId` in bid-260601 — the value is now the bare pair id,
|
|
187
|
+
* not the agency-scoped composite.
|
|
188
|
+
*/
|
|
189
|
+
pairId: string;
|
|
178
190
|
currency: string;
|
|
179
191
|
amount: string;
|
|
180
192
|
coefficient: string;
|
|
@@ -187,6 +199,12 @@ interface Bid {
|
|
|
187
199
|
slippage: number;
|
|
188
200
|
/** ISO-8601 string passthrough from the server. */
|
|
189
201
|
createdAt: string | null;
|
|
202
|
+
/**
|
|
203
|
+
* Parsed display metadata. Null for bids placed before meta shipped, or when
|
|
204
|
+
* the server sends malformed/absent meta. Read `meta.pairName` for the
|
|
205
|
+
* display pair instead of mapping `pairId` yourself.
|
|
206
|
+
*/
|
|
207
|
+
meta?: BidMeta | null;
|
|
190
208
|
}
|
|
191
209
|
interface CancelBidResult {
|
|
192
210
|
bid: Bid;
|
|
@@ -449,7 +467,10 @@ interface MqttWireCandle {
|
|
|
449
467
|
interface MqttWireAcceptedBid {
|
|
450
468
|
id: string;
|
|
451
469
|
userId: string;
|
|
470
|
+
/** @deprecated server now also sends `pairId`; both carry the bare pair id. */
|
|
452
471
|
gameUuid: string;
|
|
472
|
+
/** Pair id, e.g. "grid-ETH-USD". */
|
|
473
|
+
pairId?: string;
|
|
453
474
|
currency: string;
|
|
454
475
|
amount: string;
|
|
455
476
|
coefficient: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -171,10 +171,22 @@ declare class AuthModule {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
type BidStatus = 'pending' | 'win' | 'lose' | 'cancelled';
|
|
174
|
+
/** Denormalised display data frozen onto the bid at placement time. */
|
|
175
|
+
interface BidMeta {
|
|
176
|
+
/** Display name of the user who placed the bid. */
|
|
177
|
+
userName: string;
|
|
178
|
+
/** Display pair, e.g. "ETH/USD". */
|
|
179
|
+
pairName: string;
|
|
180
|
+
}
|
|
174
181
|
interface Bid {
|
|
175
182
|
id: string;
|
|
176
183
|
userId: string;
|
|
177
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Pair id, e.g. "grid-ETH-USD" (slash-free system id).
|
|
186
|
+
* Renamed from `gameId` in bid-260601 — the value is now the bare pair id,
|
|
187
|
+
* not the agency-scoped composite.
|
|
188
|
+
*/
|
|
189
|
+
pairId: string;
|
|
178
190
|
currency: string;
|
|
179
191
|
amount: string;
|
|
180
192
|
coefficient: string;
|
|
@@ -187,6 +199,12 @@ interface Bid {
|
|
|
187
199
|
slippage: number;
|
|
188
200
|
/** ISO-8601 string passthrough from the server. */
|
|
189
201
|
createdAt: string | null;
|
|
202
|
+
/**
|
|
203
|
+
* Parsed display metadata. Null for bids placed before meta shipped, or when
|
|
204
|
+
* the server sends malformed/absent meta. Read `meta.pairName` for the
|
|
205
|
+
* display pair instead of mapping `pairId` yourself.
|
|
206
|
+
*/
|
|
207
|
+
meta?: BidMeta | null;
|
|
190
208
|
}
|
|
191
209
|
interface CancelBidResult {
|
|
192
210
|
bid: Bid;
|
|
@@ -449,7 +467,10 @@ interface MqttWireCandle {
|
|
|
449
467
|
interface MqttWireAcceptedBid {
|
|
450
468
|
id: string;
|
|
451
469
|
userId: string;
|
|
470
|
+
/** @deprecated server now also sends `pairId`; both carry the bare pair id. */
|
|
452
471
|
gameUuid: string;
|
|
472
|
+
/** Pair id, e.g. "grid-ETH-USD". */
|
|
473
|
+
pairId?: string;
|
|
453
474
|
currency: string;
|
|
454
475
|
amount: string;
|
|
455
476
|
coefficient: number;
|
package/dist/index.js
CHANGED
|
@@ -355,6 +355,18 @@ var AuthModule = class {
|
|
|
355
355
|
};
|
|
356
356
|
|
|
357
357
|
// src/modules/bid/normalise.ts
|
|
358
|
+
function parseMeta(raw) {
|
|
359
|
+
if (!raw) return null;
|
|
360
|
+
try {
|
|
361
|
+
const obj = JSON.parse(raw);
|
|
362
|
+
return {
|
|
363
|
+
userName: typeof obj.userName === "string" ? obj.userName : "",
|
|
364
|
+
pairName: typeof obj.pairName === "string" ? obj.pairName : ""
|
|
365
|
+
};
|
|
366
|
+
} catch {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
358
370
|
var VALID_STATUSES = /* @__PURE__ */ new Set(["pending", "win", "lose", "cancelled"]);
|
|
359
371
|
var PAST_TENSE_MAP = {
|
|
360
372
|
won: "win",
|
|
@@ -377,7 +389,7 @@ function toWireStatus(status) {
|
|
|
377
389
|
return SDK_TO_WIRE_STATUS[status];
|
|
378
390
|
}
|
|
379
391
|
function normaliseBid(node) {
|
|
380
|
-
if (typeof node.id !== "string" || node.id === "" || typeof node.user_id !== "string" || node.user_id === "" || typeof node.
|
|
392
|
+
if (typeof node.id !== "string" || node.id === "" || typeof node.user_id !== "string" || node.user_id === "" || typeof node.pair_id !== "string" || node.pair_id === "" || typeof node.status !== "string" || node.status === "") {
|
|
381
393
|
throw new TaphubServerError("Invalid response from server", {
|
|
382
394
|
code: "InvalidResponse"
|
|
383
395
|
});
|
|
@@ -385,7 +397,7 @@ function normaliseBid(node) {
|
|
|
385
397
|
return {
|
|
386
398
|
id: node.id,
|
|
387
399
|
userId: node.user_id,
|
|
388
|
-
|
|
400
|
+
pairId: node.pair_id,
|
|
389
401
|
currency: node.currency,
|
|
390
402
|
amount: node.amount,
|
|
391
403
|
coefficient: node.coefficient,
|
|
@@ -396,7 +408,8 @@ function normaliseBid(node) {
|
|
|
396
408
|
status: coerceStatus(node.status),
|
|
397
409
|
payout: node.payout || null,
|
|
398
410
|
slippage: node.slippage,
|
|
399
|
-
createdAt: node.created_at || null
|
|
411
|
+
createdAt: node.created_at || null,
|
|
412
|
+
meta: parseMeta(node.meta)
|
|
400
413
|
};
|
|
401
414
|
}
|
|
402
415
|
function normaliseBids(list) {
|
|
@@ -411,17 +424,17 @@ function normaliseBids(list) {
|
|
|
411
424
|
// src/modules/bid/queries.ts
|
|
412
425
|
var PLACE_BID_MUTATION = `mutation PlaceBid($input: PlaceBidInput!) {
|
|
413
426
|
placeBid(input: $input) {
|
|
414
|
-
id user_id
|
|
427
|
+
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout slippage created_at meta
|
|
415
428
|
}
|
|
416
429
|
}`;
|
|
417
430
|
var MY_BIDS_QUERY = `query MyBids($statuses: [BidStatus!], $limit: Int, $offset: Int, $pairId: ID) {
|
|
418
431
|
myBids(statuses: $statuses, limit: $limit, offset: $offset, pairId: $pairId) {
|
|
419
|
-
id user_id
|
|
432
|
+
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout slippage created_at meta
|
|
420
433
|
}
|
|
421
434
|
}`;
|
|
422
435
|
var CANCEL_BID_MUTATION = `mutation CancelBid($input: CancelBidInput!) {
|
|
423
436
|
cancelBid(input: $input) {
|
|
424
|
-
bid { id user_id
|
|
437
|
+
bid { id user_id pair_id currency amount coefficient time1 time2 price1 price2 status cancelled payout slippage created_at meta }
|
|
425
438
|
refund_amount
|
|
426
439
|
new_balance
|
|
427
440
|
}
|
|
@@ -836,7 +849,7 @@ function subKey(gameId, userId) {
|
|
|
836
849
|
var GAME_SCOPED_SUFFIXES = ["config", "ideal_config"];
|
|
837
850
|
var USER_SCOPED_SUFFIXES = ["bid_result", "balance_update"];
|
|
838
851
|
var TOPIC_PREFIX = "game";
|
|
839
|
-
var MARKET_TOPIC_PREFIX = "market";
|
|
852
|
+
var MARKET_TOPIC_PREFIX = "public/market";
|
|
840
853
|
var WALLET_TOPIC_PREFIX = "wallet";
|
|
841
854
|
var PUBLIC_PREFIX = "public";
|
|
842
855
|
function walletBalanceTopic(userId) {
|
|
@@ -1004,7 +1017,7 @@ function createMqttTransport(endpoint, opts = {}) {
|
|
|
1004
1017
|
}
|
|
1005
1018
|
},
|
|
1006
1019
|
subscribeCandle(pairId, onCandle) {
|
|
1007
|
-
const topic = `${
|
|
1020
|
+
const topic = `${MARKET_TOPIC_PREFIX}/${pairId}/candle`;
|
|
1008
1021
|
if (candleSubscriptions.has(pairId)) return;
|
|
1009
1022
|
const mqttClient = ensureConnected();
|
|
1010
1023
|
candleSubscriptions.set(pairId, { topic, onCandle });
|