@chainstream-io/sdk 0.1.19 → 0.1.20

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-QdKN_FKu.cjs';
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';
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-D2eCYuwV.js';
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';
2
2
  import './WatchlistApi-18jD3YH5.js';
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ 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";
7
8
 
8
9
  // src/stream/stream.fields.ts
9
10
  var CEL_FIELD_MAPPINGS = {
@@ -264,10 +265,31 @@ var StreamApi = class {
264
265
  constructor(context) {
265
266
  __publicField(this, "realtimeClient");
266
267
  __publicField(this, "listenersMap");
268
+ __publicField(this, "getTokenValue");
267
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
+ }
268
284
  this.realtimeClient = new Centrifuge(realtimeEndpoint, {
285
+ ...wsImpl && { websocket: wsImpl },
269
286
  getToken: async (_ctx) => {
270
- return typeof context.accessToken === "string" ? context.accessToken : await context.accessToken.getToken();
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;
271
293
  }
272
294
  });
273
295
  this.realtimeClient.on("connected", () => {
@@ -279,7 +301,11 @@ var StreamApi = class {
279
301
  });
280
302
  this.listenersMap = /* @__PURE__ */ new Map();
281
303
  }
282
- connect() {
304
+ async connect() {
305
+ const token = await this.getTokenValue();
306
+ this.realtimeClient.setHttpHeaders({
307
+ Authorization: `Bearer ${token}`
308
+ });
283
309
  this.realtimeClient.connect();
284
310
  }
285
311
  /**
@@ -8137,7 +8163,7 @@ var WatchlistApi = class extends BaseAPI {
8137
8163
 
8138
8164
  // src/index.ts
8139
8165
  import { EventSourcePolyfill } from "event-source-polyfill";
8140
- var LIB_VERSION = "0.1.19";
8166
+ var LIB_VERSION = "0.1.20";
8141
8167
  var UserAgentMiddleware = class {
8142
8168
  async pre(context) {
8143
8169
  if (!context.init.headers) {