@chainstream-io/sdk 0.1.20 → 0.1.21

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.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- export { q as DexAggregatorOptions, r as DexClient, p as DexRequestContext, L as LIB_VERSION, P as PostOptions, o as TokenProvider } from './index-Rg3zipzv.cjs';
1
+ export { q as DexAggregatorOptions, r as DexClient, p as DexRequestContext, L as LIB_VERSION, P as PostOptions, o as TokenProvider } from './index-D3RVUCiG.cjs';
2
2
  import './WatchlistApi-18jD3YH5.cjs';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { q as DexAggregatorOptions, r as DexClient, p as DexRequestContext, L as LIB_VERSION, P as PostOptions, o as TokenProvider } from './index-8REU_oTW.js';
1
+ export { q as DexAggregatorOptions, r as DexClient, p as DexRequestContext, L as LIB_VERSION, P as PostOptions, o as TokenProvider } from './index-BhyMM-wS.js';
2
2
  import './WatchlistApi-18jD3YH5.js';
package/dist/index.mjs CHANGED
@@ -4,7 +4,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4
4
 
5
5
  // src/stream/stream.ts
6
6
  import { Centrifuge } from "@chainstream-io/centrifuge";
7
- import { createRequire } from "module";
8
7
 
9
8
  // src/stream/stream.fields.ts
10
9
  var CEL_FIELD_MAPPINGS = {
@@ -265,47 +264,32 @@ var StreamApi = class {
265
264
  constructor(context) {
266
265
  __publicField(this, "realtimeClient");
267
266
  __publicField(this, "listenersMap");
268
- __publicField(this, "getTokenValue");
269
- const realtimeEndpoint = context.streamUrl;
270
- this.getTokenValue = async () => {
271
- return typeof context.accessToken === "string" ? context.accessToken : await context.accessToken.getToken();
272
- };
273
- let wsImpl = void 0;
274
- if (typeof process !== "undefined" && process.versions?.node) {
275
- try {
276
- const require2 = createRequire(import.meta.url);
277
- wsImpl = require2("ws");
278
- } catch {
279
- }
280
- }
281
- if (!wsImpl && typeof WebSocket !== "undefined") {
282
- wsImpl = WebSocket;
283
- }
267
+ const realtimeEndpoint = this.buildWsUrl(context.streamUrl, context.accessToken);
284
268
  this.realtimeClient = new Centrifuge(realtimeEndpoint, {
285
- ...wsImpl && { websocket: wsImpl },
286
269
  getToken: async (_ctx) => {
287
- const token = await this.getTokenValue();
288
- this.realtimeClient.setHttpHeaders({
289
- Authorization: `Bearer ${token}`,
290
- "User-Agent": `chainstream-io/sdk/javascript`
291
- });
292
- return token;
270
+ return typeof context.accessToken === "string" ? context.accessToken : await context.accessToken.getToken();
293
271
  }
294
272
  });
295
273
  this.realtimeClient.on("connected", () => {
296
274
  console.log("[streaming] connected");
297
- }).on("disconnected", (err) => {
298
- console.warn("[streaming] disconnected", err);
275
+ }).on("disconnected", (ctx) => {
276
+ console.warn("[streaming] disconnected", ctx);
299
277
  }).on("error", (err) => {
300
278
  console.error("[streaming] error: ", err);
301
279
  });
302
280
  this.listenersMap = /* @__PURE__ */ new Map();
303
281
  }
304
- async connect() {
305
- const token = await this.getTokenValue();
306
- this.realtimeClient.setHttpHeaders({
307
- Authorization: `Bearer ${token}`
308
- });
282
+ /**
283
+ * Build WebSocket URL with token as query parameter
284
+ */
285
+ buildWsUrl(endpoint, accessToken) {
286
+ const url = new URL(endpoint);
287
+ if (typeof accessToken === "string") {
288
+ url.searchParams.set("token", accessToken);
289
+ }
290
+ return url.toString();
291
+ }
292
+ connect() {
309
293
  this.realtimeClient.connect();
310
294
  }
311
295
  /**