@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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## @chainstream-io/sdk@0.1.19
1
+ ## @chainstream-io/sdk@0.1.20
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
 
@@ -320,8 +320,9 @@ interface Unsubscrible {
320
320
  declare class StreamApi {
321
321
  private realtimeClient;
322
322
  private listenersMap;
323
+ private getTokenValue;
323
324
  constructor(context: DexRequestContext);
324
- connect(): void;
325
+ connect(): Promise<void>;
325
326
  /**
326
327
  * Start batching commands for efficient bulk operations
327
328
  * All subscription commands after this call will be batched until stopBatching is called
@@ -467,7 +468,7 @@ interface DexAggregatorOptions {
467
468
  serverUrl?: string;
468
469
  streamUrl?: string;
469
470
  }
470
- declare const LIB_VERSION = "0.1.19";
471
+ declare const LIB_VERSION = "0.1.20";
471
472
  declare class DexClient {
472
473
  readonly requestCtx: DexRequestContext;
473
474
  readonly _configuration: Configuration;
@@ -320,8 +320,9 @@ interface Unsubscrible {
320
320
  declare class StreamApi {
321
321
  private realtimeClient;
322
322
  private listenersMap;
323
+ private getTokenValue;
323
324
  constructor(context: DexRequestContext);
324
- connect(): void;
325
+ connect(): Promise<void>;
325
326
  /**
326
327
  * Start batching commands for efficient bulk operations
327
328
  * All subscription commands after this call will be batched until stopBatching is called
@@ -467,7 +468,7 @@ interface DexAggregatorOptions {
467
468
  serverUrl?: string;
468
469
  streamUrl?: string;
469
470
  }
470
- declare const LIB_VERSION = "0.1.19";
471
+ declare const LIB_VERSION = "0.1.20";
471
472
  declare class DexClient {
472
473
  readonly requestCtx: DexRequestContext;
473
474
  readonly _configuration: Configuration;
package/dist/index.cjs CHANGED
@@ -29,6 +29,7 @@ module.exports = __toCommonJS(index_exports);
29
29
 
30
30
  // src/stream/stream.ts
31
31
  var import_centrifuge = require("@chainstream-io/centrifuge");
32
+ var import_module = require("module");
32
33
 
33
34
  // src/stream/stream.fields.ts
34
35
  var CEL_FIELD_MAPPINGS = {
@@ -285,14 +286,36 @@ function replaceFilterFields(filter, methodName) {
285
286
  }
286
287
 
287
288
  // src/stream/stream.ts
289
+ var import_meta = {};
288
290
  var StreamApi = class {
289
291
  constructor(context) {
290
292
  __publicField(this, "realtimeClient");
291
293
  __publicField(this, "listenersMap");
294
+ __publicField(this, "getTokenValue");
292
295
  const realtimeEndpoint = context.streamUrl;
296
+ this.getTokenValue = async () => {
297
+ return typeof context.accessToken === "string" ? context.accessToken : await context.accessToken.getToken();
298
+ };
299
+ let wsImpl = void 0;
300
+ if (typeof process !== "undefined" && process.versions?.node) {
301
+ try {
302
+ const require2 = (0, import_module.createRequire)(import_meta.url);
303
+ wsImpl = require2("ws");
304
+ } catch {
305
+ }
306
+ }
307
+ if (!wsImpl && typeof WebSocket !== "undefined") {
308
+ wsImpl = WebSocket;
309
+ }
293
310
  this.realtimeClient = new import_centrifuge.Centrifuge(realtimeEndpoint, {
311
+ ...wsImpl && { websocket: wsImpl },
294
312
  getToken: async (_ctx) => {
295
- return typeof context.accessToken === "string" ? context.accessToken : await context.accessToken.getToken();
313
+ const token = await this.getTokenValue();
314
+ this.realtimeClient.setHttpHeaders({
315
+ Authorization: `Bearer ${token}`,
316
+ "User-Agent": `chainstream-io/sdk/javascript`
317
+ });
318
+ return token;
296
319
  }
297
320
  });
298
321
  this.realtimeClient.on("connected", () => {
@@ -304,7 +327,11 @@ var StreamApi = class {
304
327
  });
305
328
  this.listenersMap = /* @__PURE__ */ new Map();
306
329
  }
307
- connect() {
330
+ async connect() {
331
+ const token = await this.getTokenValue();
332
+ this.realtimeClient.setHttpHeaders({
333
+ Authorization: `Bearer ${token}`
334
+ });
308
335
  this.realtimeClient.connect();
309
336
  }
310
337
  /**
@@ -8162,7 +8189,7 @@ var WatchlistApi = class extends BaseAPI {
8162
8189
 
8163
8190
  // src/index.ts
8164
8191
  var import_event_source_polyfill = require("event-source-polyfill");
8165
- var LIB_VERSION = "0.1.19";
8192
+ var LIB_VERSION = "0.1.20";
8166
8193
  var UserAgentMiddleware = class {
8167
8194
  async pre(context) {
8168
8195
  if (!context.init.headers) {