@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/README.md +1 -1
- package/dist/{index-8REU_oTW.d.ts → index-BhyMM-wS.d.ts} +5 -2
- package/dist/{index-Rg3zipzv.d.cts → index-D3RVUCiG.d.cts} +5 -2
- package/dist/index.cjs +15 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +15 -31
- package/dist/index.mjs.map +1 -1
- package/dist/stream/index.cjs +15 -32
- package/dist/stream/index.cjs.map +1 -1
- package/dist/stream/index.d.cts +1 -1
- package/dist/stream/index.d.ts +1 -1
- package/dist/stream/index.mjs +15 -31
- package/dist/stream/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -320,9 +320,12 @@ interface Unsubscrible {
|
|
|
320
320
|
declare class StreamApi {
|
|
321
321
|
private realtimeClient;
|
|
322
322
|
private listenersMap;
|
|
323
|
-
private getTokenValue;
|
|
324
323
|
constructor(context: DexRequestContext);
|
|
325
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Build WebSocket URL with token as query parameter
|
|
326
|
+
*/
|
|
327
|
+
private buildWsUrl;
|
|
328
|
+
connect(): void;
|
|
326
329
|
/**
|
|
327
330
|
* Start batching commands for efficient bulk operations
|
|
328
331
|
* All subscription commands after this call will be batched until stopBatching is called
|
|
@@ -320,9 +320,12 @@ interface Unsubscrible {
|
|
|
320
320
|
declare class StreamApi {
|
|
321
321
|
private realtimeClient;
|
|
322
322
|
private listenersMap;
|
|
323
|
-
private getTokenValue;
|
|
324
323
|
constructor(context: DexRequestContext);
|
|
325
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Build WebSocket URL with token as query parameter
|
|
326
|
+
*/
|
|
327
|
+
private buildWsUrl;
|
|
328
|
+
connect(): void;
|
|
326
329
|
/**
|
|
327
330
|
* Start batching commands for efficient bulk operations
|
|
328
331
|
* All subscription commands after this call will be batched until stopBatching is called
|
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,6 @@ 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");
|
|
33
32
|
|
|
34
33
|
// src/stream/stream.fields.ts
|
|
35
34
|
var CEL_FIELD_MAPPINGS = {
|
|
@@ -286,52 +285,36 @@ function replaceFilterFields(filter, methodName) {
|
|
|
286
285
|
}
|
|
287
286
|
|
|
288
287
|
// src/stream/stream.ts
|
|
289
|
-
var import_meta = {};
|
|
290
288
|
var StreamApi = class {
|
|
291
289
|
constructor(context) {
|
|
292
290
|
__publicField(this, "realtimeClient");
|
|
293
291
|
__publicField(this, "listenersMap");
|
|
294
|
-
|
|
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
|
-
}
|
|
292
|
+
const realtimeEndpoint = this.buildWsUrl(context.streamUrl, context.accessToken);
|
|
310
293
|
this.realtimeClient = new import_centrifuge.Centrifuge(realtimeEndpoint, {
|
|
311
|
-
...wsImpl && { websocket: wsImpl },
|
|
312
294
|
getToken: async (_ctx) => {
|
|
313
|
-
|
|
314
|
-
this.realtimeClient.setHttpHeaders({
|
|
315
|
-
Authorization: `Bearer ${token}`,
|
|
316
|
-
"User-Agent": `chainstream-io/sdk/javascript`
|
|
317
|
-
});
|
|
318
|
-
return token;
|
|
295
|
+
return typeof context.accessToken === "string" ? context.accessToken : await context.accessToken.getToken();
|
|
319
296
|
}
|
|
320
297
|
});
|
|
321
298
|
this.realtimeClient.on("connected", () => {
|
|
322
299
|
console.log("[streaming] connected");
|
|
323
|
-
}).on("disconnected", (
|
|
324
|
-
console.warn("[streaming] disconnected",
|
|
300
|
+
}).on("disconnected", (ctx) => {
|
|
301
|
+
console.warn("[streaming] disconnected", ctx);
|
|
325
302
|
}).on("error", (err) => {
|
|
326
303
|
console.error("[streaming] error: ", err);
|
|
327
304
|
});
|
|
328
305
|
this.listenersMap = /* @__PURE__ */ new Map();
|
|
329
306
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
+
}
|
|
317
|
+
connect() {
|
|
335
318
|
this.realtimeClient.connect();
|
|
336
319
|
}
|
|
337
320
|
/**
|