@stxapp/stx-typescript 0.6.1 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.3 (2026-09-28)
4
+
5
+ - `placeOrders()` checks the whole list before placing any order on every exchange: an over-long list or a malformed order is refused with nothing placed.
6
+
7
+ ## 0.6.2 (2026-09-28)
8
+
9
+ - `balance()`, `positions()` and `placeOrders()` now work on every STX exchange, with the same results everywhere.
10
+
3
11
  ## 0.6.1 (2026-09-28)
4
12
 
5
13
  Documentation only; no change to the API.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5;// src/enums.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5;// src/enums.ts
2
2
  var Region = {
3
3
  US: "us",
4
4
  ONTARIO: "ontario"
@@ -809,7 +809,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
809
809
  }
810
810
 
811
811
  // src/version.ts
812
- var VERSION = "0.6.1";
812
+ var VERSION = "0.6.3";
813
813
  var USER_AGENT = `stx-typescript/${VERSION}`;
814
814
  var ASYNC_DISPOSE = _nullishCoalesce(Symbol.asyncDispose, () => ( /* @__PURE__ */ Symbol.for("Symbol.asyncDispose")));
815
815
 
@@ -1187,6 +1187,160 @@ function toBatchOrderResult(raw) {
1187
1187
  return { ...obj, order, errors, ok: order !== null && !_optionalChain([errors, 'optionalAccess', _16 => _16.length]) };
1188
1188
  }
1189
1189
 
1190
+ // src/legacy-routes.ts
1191
+ function isRouteMissing(err) {
1192
+ return err instanceof STXNotFoundException && err.statusCode === 404 && typeof err.body === "string";
1193
+ }
1194
+ var QUIET = { debug() {
1195
+ }, info() {
1196
+ }, warn() {
1197
+ }, error() {
1198
+ } };
1199
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1200
+ async function channelSnapshot(client, join3, event) {
1201
+ const me = await client._identity();
1202
+ const ws = client.websocket({
1203
+ userId: me.user_id,
1204
+ reconnect: false,
1205
+ channelPingIntervalMs: null,
1206
+ joinTimeoutMs: client.timeoutMs,
1207
+ logger: QUIET
1208
+ });
1209
+ try {
1210
+ const channel = await join3(ws, me);
1211
+ const snapshot = await channel.waitSnapshot(client.timeoutMs);
1212
+ return snapshot[event];
1213
+ } finally {
1214
+ await ws.close();
1215
+ }
1216
+ }
1217
+ async function balanceFromChannel(client) {
1218
+ const payload = await channelSnapshot(
1219
+ client,
1220
+ (ws, me) => ws.balances(me.account_id ? { accountId: me.account_id } : {}),
1221
+ "balances"
1222
+ );
1223
+ if (!payload || typeof payload !== "object") {
1224
+ throw new STXException("The balances channel sent no balance", { path: "/api/v1/account/balance" });
1225
+ }
1226
+ return payload;
1227
+ }
1228
+ function positionsFilter(marketIds) {
1229
+ if (marketIds === void 0 || marketIds === null) return null;
1230
+ const list = typeof marketIds === "string" ? [marketIds] : [...marketIds];
1231
+ if (list.length === 0) return null;
1232
+ const joined = list.join(",");
1233
+ if (joined === "") return null;
1234
+ const ids2 = joined.split(",").map((s) => s.trim());
1235
+ for (const id of ids2) {
1236
+ if (!UUID.test(id)) {
1237
+ throw new STXValidationException(`${id} is not a valid UUID`, {
1238
+ statusCode: 400,
1239
+ body: { error: `${id} is not a valid UUID` },
1240
+ method: "GET",
1241
+ path: "/api/v1/positions"
1242
+ });
1243
+ }
1244
+ }
1245
+ return new Set(ids2.map((id) => id.toLowerCase()));
1246
+ }
1247
+ async function positionsFromChannel(client, query = {}) {
1248
+ const filter = positionsFilter(query.marketIds);
1249
+ const payload = await channelSnapshot(client, (ws) => ws.positions(), "all_positions");
1250
+ const rows = payload && Array.isArray(payload.positions) ? payload.positions : null;
1251
+ if (!rows) throw new STXException("The positions channel sent no positions", { path: "/api/v1/positions" });
1252
+ return filter ? rows.filter((p) => filter.has(String(p.market_id).toLowerCase())) : rows;
1253
+ }
1254
+ var MAX_BATCH_ORDERS = 100;
1255
+ var ORDER_TYPES = ["limit", "market"];
1256
+ var ACTIONS = ["buy", "sell"];
1257
+ var EXPIRATIONS = ["good_till_start", "good_till_time"];
1258
+ function batchRefusal(message) {
1259
+ return new STXValidationException(message, {
1260
+ statusCode: 400,
1261
+ body: { error: message },
1262
+ method: "POST",
1263
+ path: "/api/v1/orders/batched"
1264
+ });
1265
+ }
1266
+ function enumError(field, value, allowed, required) {
1267
+ if (value === void 0 || value === null) return required ? `${field} is required` : void 0;
1268
+ if (typeof value !== "string") return `${field} is invalid`;
1269
+ return allowed.includes(value) ? void 0 : `${field} has invalid value: ${value}`;
1270
+ }
1271
+ function parseDecimal(text) {
1272
+ if (/^[+-]?(inf|infinity|nan)$/i.test(text)) return { special: true };
1273
+ const m = /^([+-]?)(?:(\d+)\.?(\d*)|\.(\d+))(?:[eE]([+-]?\d+))?$/.exec(text);
1274
+ if (!m) return void 0;
1275
+ const int = _nullishCoalesce(m[2], () => ( ""));
1276
+ const frac = _nullishCoalesce(_nullishCoalesce(m[3], () => ( m[4])), () => ( ""));
1277
+ return { special: false, sign: m[1] === "-" ? -1 : 1, digits: int + frac, exp: Number(_nullishCoalesce(m[5], () => ( 0))) - frac.length };
1278
+ }
1279
+ var scaleOf = (exp) => Math.max(0, -exp);
1280
+ function priceError(value) {
1281
+ if (value === void 0 || value === null) return void 0;
1282
+ const format2 = 'price must be a dollar amount as a string, e.g. "30.00"';
1283
+ if (typeof value !== "string") return format2;
1284
+ const d = parseDecimal(value);
1285
+ if (!d || d.special) return format2;
1286
+ if (scaleOf(d.exp) > 7) return "price supports at most 7 decimal places";
1287
+ const trailingZeros = /0*$/.exec(d.digits)[0].length;
1288
+ const significant = /^0*$/.test(d.digits) ? 0 : scaleOf(d.exp + trailingZeros);
1289
+ if (significant > 2) {
1290
+ return `price must be a whole number of cents \u2014 at most 2 decimal places, not counting trailing zeros (got ${JSON.stringify(value)})`;
1291
+ }
1292
+ if (d.sign < 0 || /^0*$/.test(d.digits)) return "price must be greater than 0";
1293
+ return void 0;
1294
+ }
1295
+ function marketIdError(value) {
1296
+ if (value === void 0 || value === null) return "market_id is required";
1297
+ return typeof value === "string" && UUID.test(value) ? void 0 : "market_id is not a valid UUID";
1298
+ }
1299
+ function quantityError(value) {
1300
+ if (value === void 0 || value === null) return "quantity is required";
1301
+ const d = typeof value === "string" ? parseDecimal(value) : void 0;
1302
+ return d && !d.special ? void 0 : 'quantity must be a decimal string, e.g. "10" or "10.00"';
1303
+ }
1304
+ function validateBatch(orders) {
1305
+ if (orders.length === 0) throw batchRefusal("orders must not be empty");
1306
+ if (orders.length > MAX_BATCH_ORDERS) {
1307
+ throw batchRefusal(`orders may contain at most ${MAX_BATCH_ORDERS} orders per batch`);
1308
+ }
1309
+ for (const order of orders) {
1310
+ const { marketId, action, orderType, ...fields } = order;
1311
+ const body = orderBody(marketId, action, orderType, fields);
1312
+ const message = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(marketIdError(body.market_id), () => ( enumError("order_type", body.order_type, ORDER_TYPES, true))), () => ( enumError("action", body.action, ACTIONS, true))), () => ( priceError(body.price))), () => ( quantityError(body.quantity))), () => ( enumError("expiration", body.expiration, EXPIRATIONS, false))), () => ( (body.expiration !== void 0 && body.order_type !== "limit" ? "Order expiration is only supported for limit orders." : void 0)));
1313
+ if (message) throw batchRefusal(message);
1314
+ }
1315
+ }
1316
+ async function placeOrdersOneByOne(client, orders, opts) {
1317
+ validateBatch(orders);
1318
+ const packet = _optionalChain([opts, 'optionalAccess', _17 => _17.geoLocation]) !== void 0 ? opts.geoLocation : await _asyncNullishCoalesce(await resolveGeoLocation(client.geoLocation), async () => ( null));
1319
+ const results = [];
1320
+ let placed = 0;
1321
+ for (let i = 0; i < orders.length; i++) {
1322
+ const { marketId, action, orderType, ...fields } = orders[i];
1323
+ try {
1324
+ const order = await client.placeOrder(marketId, action, orderType, { ...fields, geoLocation: packet });
1325
+ results.push(toBatchOrderResult({ order }));
1326
+ placed += 1;
1327
+ } catch (err) {
1328
+ if (!(err instanceof STXException)) throw err;
1329
+ if (err instanceof STXRejectedException && !(err instanceof STXGeoLocationException)) {
1330
+ results.push(toBatchOrderResult({ errors: [err.message] }));
1331
+ continue;
1332
+ }
1333
+ if (err instanceof STXServerException || err instanceof STXTransportException) throw err;
1334
+ if (placed === 0) throw err;
1335
+ results.push(toBatchOrderResult({ errors: [err.message] }));
1336
+ if (err instanceof STXValidationException) continue;
1337
+ for (let j = i + 1; j < orders.length; j++) results.push(toBatchOrderResult({ errors: [err.message] }));
1338
+ break;
1339
+ }
1340
+ }
1341
+ return results;
1342
+ }
1343
+
1190
1344
  // src/client.ts
1191
1345
  var NEW_ORDER_FIELDS = {
1192
1346
  marketId: "market_id",
@@ -1263,6 +1417,8 @@ var STX = (_class3 = class _STX {
1263
1417
 
1264
1418
  #fetch;
1265
1419
  #me;
1420
+ // Exchanges older than v3.3.172: the routes this exchange turned out not to serve.
1421
+ #missingRoutes = /* @__PURE__ */ new Set();
1266
1422
  /** Test hook: how retries wait. */
1267
1423
  __init4() {this._sleep = sleep}
1268
1424
  constructor(opts = {}) {;_class3.prototype.__init4.call(this);
@@ -1314,7 +1470,7 @@ var STX = (_class3 = class _STX {
1314
1470
  this.#fetch = fetchImpl;
1315
1471
  }
1316
1472
  toString() {
1317
- return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access', _17 => _17.credentials, 'optionalAccess', _18 => _18.keyId]), () => ( null)))})`;
1473
+ return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access', _18 => _18.credentials, 'optionalAccess', _19 => _19.keyId]), () => ( null)))})`;
1318
1474
  }
1319
1475
  /** Nothing to release (fetch pools connections itself); present so `await using` and explicit cleanup work. */
1320
1476
  async close() {
@@ -1349,7 +1505,7 @@ var STX = (_class3 = class _STX {
1349
1505
  status,
1350
1506
  attempt,
1351
1507
  durationMs: Date.now() - started,
1352
- authKind: _optionalChain([this, 'access', _19 => _19.auth, 'optionalAccess', _20 => _20.kind]),
1508
+ authKind: _optionalChain([this, 'access', _20 => _20.auth, 'optionalAccess', _21 => _21.kind]),
1353
1509
  requestBody: request.body,
1354
1510
  responseBody
1355
1511
  });
@@ -1381,7 +1537,7 @@ var STX = (_class3 = class _STX {
1381
1537
  });
1382
1538
  }
1383
1539
  throw new STXTransportException(
1384
- `${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _21 => _21.message]), () => ( String(err)))}`,
1540
+ `${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _22 => _22.message]), () => ( String(err)))}`,
1385
1541
  { method: request.method, path: request.path, cause: err }
1386
1542
  );
1387
1543
  } finally {
@@ -1403,7 +1559,7 @@ var STX = (_class3 = class _STX {
1403
1559
  return await this.#sendOnce(request, sent);
1404
1560
  } catch (err) {
1405
1561
  if (!(err instanceof STXException)) throw err;
1406
- if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access', _22 => _22.auth, 'optionalAccess', _23 => _23.onUnauthorized])) {
1562
+ if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access', _23 => _23.auth, 'optionalAccess', _24 => _24.onUnauthorized])) {
1407
1563
  reauthenticated = true;
1408
1564
  if (await this.auth.onUnauthorized()) continue;
1409
1565
  }
@@ -1439,7 +1595,7 @@ var STX = (_class3 = class _STX {
1439
1595
  }
1440
1596
  }
1441
1597
  async #geoBody(body, opts) {
1442
- const packet = _optionalChain([opts, 'optionalAccess', _24 => _24.geoLocation]) !== void 0 ? _nullishCoalesce(opts.geoLocation, () => ( void 0)) : await resolveGeoLocation(this.geoLocation);
1598
+ const packet = _optionalChain([opts, 'optionalAccess', _25 => _25.geoLocation]) !== void 0 ? _nullishCoalesce(opts.geoLocation, () => ( void 0)) : await resolveGeoLocation(this.geoLocation);
1443
1599
  return packet === void 0 ? body : { ...body, geo_location: packet };
1444
1600
  }
1445
1601
  // ------------------------------------------------------------------
@@ -1455,12 +1611,20 @@ var STX = (_class3 = class _STX {
1455
1611
  return this.#me;
1456
1612
  }
1457
1613
  /**
1458
- * The user id from `me()`, fetched once and cached. An OAuth token granted
1459
- * without `profile.read` cannot call `me()`; the id then comes from
1460
- * `balance()` (`balance.read`), which carries the same `user_id`.
1614
+ * @internal The cached `me()` when it has both ids, else a fresh `me()`.
1615
+ * Never falls back to `balance()`, so the channel fallbacks can use it.
1616
+ */
1617
+ async _identity() {
1618
+ if (_optionalChain([this, 'access', _26 => _26.#me, 'optionalAccess', _27 => _27.user_id]) && this.#me.account_id) return this.#me;
1619
+ return this.me();
1620
+ }
1621
+ /**
1622
+ * The user id from `me()`, fetched once and cached. If `me()` is not
1623
+ * permitted, the id comes from `balance()`, which carries the same
1624
+ * `user_id`.
1461
1625
  */
1462
1626
  async userId() {
1463
- if (_optionalChain([this, 'access', _25 => _25.#me, 'optionalAccess', _26 => _26.user_id])) return this.#me.user_id;
1627
+ if (_optionalChain([this, 'access', _28 => _28.#me, 'optionalAccess', _29 => _29.user_id])) return this.#me.user_id;
1464
1628
  try {
1465
1629
  await this.me();
1466
1630
  } catch (err) {
@@ -1471,7 +1635,7 @@ var STX = (_class3 = class _STX {
1471
1635
  if (!balance.user_id) throw err;
1472
1636
  this.#me = { ..._nullishCoalesce(this.#me, () => ( {})), user_id: balance.user_id };
1473
1637
  }
1474
- if (!_optionalChain([this, 'access', _27 => _27.#me, 'optionalAccess', _28 => _28.user_id])) throw new STXException("GET /api/v1/me returned no user_id");
1638
+ if (!_optionalChain([this, 'access', _30 => _30.#me, 'optionalAccess', _31 => _31.user_id])) throw new STXException("GET /api/v1/me returned no user_id");
1475
1639
  return this.#me.user_id;
1476
1640
  }
1477
1641
  // ------------------------------------------------------------------
@@ -1586,7 +1750,15 @@ var STX = (_class3 = class _STX {
1586
1750
  */
1587
1751
  async placeOrders(orders, opts) {
1588
1752
  const body = { orders: orders.map(normalizeOrder) };
1589
- const raw = await this.#list("orders_batched_post", { body: await this.#geoBody(body, opts) });
1753
+ if (this.#missingRoutes.has("batch")) return placeOrdersOneByOne(this, orders, opts);
1754
+ let raw;
1755
+ try {
1756
+ raw = await this.#list("orders_batched_post", { body: await this.#geoBody(body, opts) });
1757
+ } catch (err) {
1758
+ if (!isRouteMissing(err)) throw err;
1759
+ this.#missingRoutes.add("batch");
1760
+ return placeOrdersOneByOne(this, orders, opts);
1761
+ }
1590
1762
  return raw.map(toBatchOrderResult);
1591
1763
  }
1592
1764
  /**
@@ -1670,15 +1842,29 @@ var STX = (_class3 = class _STX {
1670
1842
  * `positions` channel sends on join. `position` is positive when long,
1671
1843
  * negative when short.
1672
1844
  */
1673
- positions(query = {}) {
1674
- return this.#list("positions_get", { query: { market_ids: ids(query.marketIds) } });
1845
+ async positions(query = {}) {
1846
+ if (this.#missingRoutes.has("positions")) return positionsFromChannel(this, query);
1847
+ try {
1848
+ return await this.#list("positions_get", { query: { market_ids: ids(query.marketIds) } });
1849
+ } catch (err) {
1850
+ if (!isRouteMissing(err)) throw err;
1851
+ this.#missingRoutes.add("positions");
1852
+ return positionsFromChannel(this, query);
1853
+ }
1675
1854
  }
1676
1855
  /**
1677
1856
  * `GET /api/v1/account/balance`: balance, liabilities and fee schedule.
1678
1857
  * The same object the `balances` channel pushes.
1679
1858
  */
1680
- balance() {
1681
- return this.#one("account_balance_get");
1859
+ async balance() {
1860
+ if (this.#missingRoutes.has("balance")) return balanceFromChannel(this);
1861
+ try {
1862
+ return await this.#one("account_balance_get");
1863
+ } catch (err) {
1864
+ if (!isRouteMissing(err)) throw err;
1865
+ this.#missingRoutes.add("balance");
1866
+ return balanceFromChannel(this);
1867
+ }
1682
1868
  }
1683
1869
  static #marketStatsQuery(q) {
1684
1870
  return {
@@ -2061,7 +2247,7 @@ var Channel = (_class4 = class {
2061
2247
  _startPinger() {
2062
2248
  this._stopPinger();
2063
2249
  let interval = this.pingIntervalMs;
2064
- const granted = _optionalChain([this, 'access', _29 => _29.reply, 'optionalAccess', _30 => _30.ping_timeout]);
2250
+ const granted = _optionalChain([this, 'access', _32 => _32.reply, 'optionalAccess', _33 => _33.ping_timeout]);
2065
2251
  if (typeof granted === "number" && this.joinPayload.cancel_on_disconnect) {
2066
2252
  const cod = granted * 0.6;
2067
2253
  interval = interval === null ? cod : Math.min(interval, cod);
@@ -2074,7 +2260,7 @@ var Channel = (_class4 = class {
2074
2260
  (err) => this.#ws.logger.warn(`${this.topic} ping failed: ${err.message}`)
2075
2261
  );
2076
2262
  }, every);
2077
- _optionalChain([this, 'access', _31 => _31.#pingTimer, 'access', _32 => _32.unref, 'optionalCall', _33 => _33()]);
2263
+ _optionalChain([this, 'access', _34 => _34.#pingTimer, 'access', _35 => _35.unref, 'optionalCall', _36 => _36()]);
2078
2264
  }
2079
2265
  }
2080
2266
  /** @internal */
@@ -2269,7 +2455,7 @@ var STXWebSocket = (_class5 = class {
2269
2455
  */
2270
2456
  async marketUpdates(opts = {}) {
2271
2457
  const channel = await this.join("market_updates", {}, opts.onMessage);
2272
- if (_optionalChain([opts, 'access', _34 => _34.watch, 'optionalAccess', _35 => _35.length])) await channel.watch(opts.watch);
2458
+ if (_optionalChain([opts, 'access', _37 => _37.watch, 'optionalAccess', _38 => _38.length])) await channel.watch(opts.watch);
2273
2459
  return channel;
2274
2460
  }
2275
2461
  /**
@@ -2426,12 +2612,12 @@ var STXWebSocket = (_class5 = class {
2426
2612
  if (!(err instanceof STXTransportException)) return false;
2427
2613
  if (err.statusCode !== 401 && err.statusCode !== 403) return false;
2428
2614
  const auth = this.rest.auth;
2429
- if (!_optionalChain([auth, 'optionalAccess', _36 => _36.onUnauthorized])) return false;
2615
+ if (!_optionalChain([auth, 'optionalAccess', _39 => _39.onUnauthorized])) return false;
2430
2616
  return auth.onUnauthorized();
2431
2617
  }
2432
2618
  async #open(reconnect = false) {
2433
2619
  const headers = { "User-Agent": USER_AGENT };
2434
- if (_optionalChain([this, 'access', _37 => _37.rest, 'access', _38 => _38.auth, 'optionalAccess', _39 => _39.websocketHeaders])) Object.assign(headers, await this.rest.auth.websocketHeaders({ reconnect }));
2620
+ if (_optionalChain([this, 'access', _40 => _40.rest, 'access', _41 => _41.auth, 'optionalAccess', _42 => _42.websocketHeaders])) Object.assign(headers, await this.rest.auth.websocketHeaders({ reconnect }));
2435
2621
  const conn = new (0, _ws2.default)(this.url, {
2436
2622
  headers,
2437
2623
  rejectUnauthorized: this.rest.verifyTls,
@@ -2445,7 +2631,7 @@ var STXWebSocket = (_class5 = class {
2445
2631
  const onUnexpected = (_req, res) => {
2446
2632
  cleanup();
2447
2633
  conn.terminate();
2448
- const reason = _optionalChain([res, 'access', _40 => _40.headers, 'optionalAccess', _41 => _41["x-stx-error"]]);
2634
+ const reason = _optionalChain([res, 'access', _43 => _43.headers, 'optionalAccess', _44 => _44["x-stx-error"]]);
2449
2635
  reject(
2450
2636
  new STXTransportException(
2451
2637
  `Could not open ${this.url}: HTTP ${res.statusCode}${reason ? ` (${String(reason)})` : ""}`,
@@ -2590,7 +2776,7 @@ var STXWebSocket = (_class5 = class {
2590
2776
  } catch (err) {
2591
2777
  this.logger.error(`rejoin ${channel.topic} failed: ${err.message}`);
2592
2778
  const reply = err instanceof STXChannelException ? err.reply : void 0;
2593
- if (_optionalChain([reply, 'optionalAccess', _42 => _42.reason]) === "unauthorized") {
2779
+ if (_optionalChain([reply, 'optionalAccess', _45 => _45.reason]) === "unauthorized") {
2594
2780
  channel._close();
2595
2781
  return;
2596
2782
  }
@@ -2604,7 +2790,7 @@ var STXWebSocket = (_class5 = class {
2604
2790
  if (!this.connected) return;
2605
2791
  if (this.#pendingHeartbeat !== null) {
2606
2792
  this.logger.warn("heartbeat unanswered; reconnecting");
2607
- _optionalChain([this, 'access', _43 => _43.#conn, 'optionalAccess', _44 => _44.terminate, 'call', _45 => _45()]);
2793
+ _optionalChain([this, 'access', _46 => _46.#conn, 'optionalAccess', _47 => _47.terminate, 'call', _48 => _48()]);
2608
2794
  return;
2609
2795
  }
2610
2796
  const ref = this.#nextRef();
@@ -2612,7 +2798,7 @@ var STXWebSocket = (_class5 = class {
2612
2798
  try {
2613
2799
  this.#send([null, ref, PHOENIX_TOPIC, "heartbeat", {}]);
2614
2800
  } catch (e10) {
2615
- _optionalChain([this, 'access', _46 => _46.#conn, 'optionalAccess', _47 => _47.terminate, 'call', _48 => _48()]);
2801
+ _optionalChain([this, 'access', _49 => _49.#conn, 'optionalAccess', _50 => _50.terminate, 'call', _51 => _51()]);
2616
2802
  }
2617
2803
  }, this.heartbeatIntervalMs);
2618
2804
  }
@@ -2688,7 +2874,7 @@ var STXWebSocket = (_class5 = class {
2688
2874
  this.error = err;
2689
2875
  this.#shutdownAfterDrop();
2690
2876
  try {
2691
- _optionalChain([this, 'access', _49 => _49.onAuthError, 'optionalCall', _50 => _50(err)]);
2877
+ _optionalChain([this, 'access', _52 => _52.onAuthError, 'optionalCall', _53 => _53(err)]);
2692
2878
  } catch (hookErr) {
2693
2879
  this.logger.error("onAuthError threw", hookErr);
2694
2880
  }
@@ -2771,4 +2957,4 @@ function dropUndefined(payload) {
2771
2957
 
2772
2958
 
2773
2959
  exports.Region = Region; exports.Environment = Environment; exports.geoRejection = geoRejection; exports.STXException = STXException; exports.STXConfigException = STXConfigException; exports.STXAPIException = STXAPIException; exports.STXValidationException = STXValidationException; exports.STXAuthenticationException = STXAuthenticationException; exports.STXForbiddenException = STXForbiddenException; exports.STXInvalidTokenException = STXInvalidTokenException; exports.STXInsufficientScopeException = STXInsufficientScopeException; exports.STXNotFoundException = STXNotFoundException; exports.STXRejectedException = STXRejectedException; exports.STXGeoLocationException = STXGeoLocationException; exports.STXRateLimitException = STXRateLimitException; exports.STXServerException = STXServerException; exports.STXTransportException = STXTransportException; exports.STXChannelException = STXChannelException; exports.STXTimeoutException = STXTimeoutException; exports.errorForStatus = errorForStatus; exports.Environments = Environments; exports.HOSTS = HOSTS; exports.environmentNamed = environmentNamed; exports.resolveHost = resolveHost; exports.baseUrlFor = baseUrlFor; exports.socketUrlFor = socketUrlFor; exports.OPERATIONS = OPERATIONS; exports.Page = Page; exports.RetryPolicy = RetryPolicy; exports.NO_RETRY = NO_RETRY; exports.resolveSettings = resolveSettings; exports.KEY_HEADER = KEY_HEADER; exports.TIMESTAMP_HEADER = TIMESTAMP_HEADER; exports.SIGNATURE_HEADER = SIGNATURE_HEADER; exports.buildMessage = buildMessage; exports.requestPath = requestPath; exports.handshakePath = handshakePath; exports.loadPrivateKey = loadPrivateKey; exports.signerFromPrivateKey = signerFromPrivateKey; exports.ApiKeyCredentials = ApiKeyCredentials; exports.VERSION = VERSION; exports.USER_AGENT = USER_AGENT; exports.TERMINAL_ORDER_STATUSES = TERMINAL_ORDER_STATUSES; exports.AccountView = AccountView; exports.centsToDollars = centsToDollars; exports.toDollarString = toDollarString; exports.toQuantity = toQuantity; exports.convertMarketPayload = convertMarketPayload; exports.convertMarketsFrame = convertMarketsFrame; exports.convertBook = convertBook; exports.convertMarketChannelPayload = convertMarketChannelPayload; exports.SNAPSHOT_EVENTS = SNAPSHOT_EVENTS; exports.ChannelMessage = ChannelMessage; exports.ReconnectPolicy = ReconnectPolicy; exports.Channel = Channel; exports.STXWebSocket = STXWebSocket; exports.orderBody = orderBody; exports.STX = STX;
2774
- //# sourceMappingURL=chunk-7O5ZGZQI.cjs.map
2960
+ //# sourceMappingURL=chunk-CSHPFQ2V.cjs.map