@chainstream-io/sdk 0.1.19 → 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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## @chainstream-io/sdk@0.1.19
1
+ ## @chainstream-io/sdk@0.1.21
2
2
 
3
3
  This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
4
4
 
@@ -321,6 +321,10 @@ declare class StreamApi {
321
321
  private realtimeClient;
322
322
  private listenersMap;
323
323
  constructor(context: DexRequestContext);
324
+ /**
325
+ * Build WebSocket URL with token as query parameter
326
+ */
327
+ private buildWsUrl;
324
328
  connect(): void;
325
329
  /**
326
330
  * Start batching commands for efficient bulk operations
@@ -467,7 +471,7 @@ interface DexAggregatorOptions {
467
471
  serverUrl?: string;
468
472
  streamUrl?: string;
469
473
  }
470
- declare const LIB_VERSION = "0.1.19";
474
+ declare const LIB_VERSION = "0.1.20";
471
475
  declare class DexClient {
472
476
  readonly requestCtx: DexRequestContext;
473
477
  readonly _configuration: Configuration;
@@ -321,6 +321,10 @@ declare class StreamApi {
321
321
  private realtimeClient;
322
322
  private listenersMap;
323
323
  constructor(context: DexRequestContext);
324
+ /**
325
+ * Build WebSocket URL with token as query parameter
326
+ */
327
+ private buildWsUrl;
324
328
  connect(): void;
325
329
  /**
326
330
  * Start batching commands for efficient bulk operations
@@ -467,7 +471,7 @@ interface DexAggregatorOptions {
467
471
  serverUrl?: string;
468
472
  streamUrl?: string;
469
473
  }
470
- declare const LIB_VERSION = "0.1.19";
474
+ declare const LIB_VERSION = "0.1.20";
471
475
  declare class DexClient {
472
476
  readonly requestCtx: DexRequestContext;
473
477
  readonly _configuration: Configuration;
package/dist/index.cjs CHANGED
@@ -289,7 +289,7 @@ var StreamApi = class {
289
289
  constructor(context) {
290
290
  __publicField(this, "realtimeClient");
291
291
  __publicField(this, "listenersMap");
292
- const realtimeEndpoint = context.streamUrl;
292
+ const realtimeEndpoint = this.buildWsUrl(context.streamUrl, context.accessToken);
293
293
  this.realtimeClient = new import_centrifuge.Centrifuge(realtimeEndpoint, {
294
294
  getToken: async (_ctx) => {
295
295
  return typeof context.accessToken === "string" ? context.accessToken : await context.accessToken.getToken();
@@ -297,13 +297,23 @@ var StreamApi = class {
297
297
  });
298
298
  this.realtimeClient.on("connected", () => {
299
299
  console.log("[streaming] connected");
300
- }).on("disconnected", (err) => {
301
- console.warn("[streaming] disconnected", err);
300
+ }).on("disconnected", (ctx) => {
301
+ console.warn("[streaming] disconnected", ctx);
302
302
  }).on("error", (err) => {
303
303
  console.error("[streaming] error: ", err);
304
304
  });
305
305
  this.listenersMap = /* @__PURE__ */ new Map();
306
306
  }
307
+ /**
308
+ * Build WebSocket URL with token as query parameter
309
+ */
310
+ buildWsUrl(endpoint, accessToken) {
311
+ const url = new URL(endpoint);
312
+ if (typeof accessToken === "string") {
313
+ url.searchParams.set("token", accessToken);
314
+ }
315
+ return url.toString();
316
+ }
307
317
  connect() {
308
318
  this.realtimeClient.connect();
309
319
  }
@@ -8162,7 +8172,7 @@ var WatchlistApi = class extends BaseAPI {
8162
8172
 
8163
8173
  // src/index.ts
8164
8174
  var import_event_source_polyfill = require("event-source-polyfill");
8165
- var LIB_VERSION = "0.1.19";
8175
+ var LIB_VERSION = "0.1.20";
8166
8176
  var UserAgentMiddleware = class {
8167
8177
  async pre(context) {
8168
8178
  if (!context.init.headers) {