@effectstream/frontend-sdk 0.100.13 → 0.100.14

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.
Files changed (2) hide show
  1. package/dist/mod.js +116 -104
  2. package/package.json +2 -2
package/dist/mod.js CHANGED
@@ -1412,7 +1412,7 @@ __export(exports_util, {
1412
1412
  callbackify: () => callbackify,
1413
1413
  _extend: () => _extend,
1414
1414
  TextEncoder: () => TextEncoder2,
1415
- TextDecoder: () => TextDecoder
1415
+ TextDecoder: () => TextDecoder2
1416
1416
  });
1417
1417
  function format(f, ...args) {
1418
1418
  if (!isString(f)) {
@@ -1723,7 +1723,7 @@ function callbackify(original) {
1723
1723
  }
1724
1724
  return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, Object.getOwnPropertyDescriptors(original)), callbackified;
1725
1725
  }
1726
- var formatRegExp, debuglog, inspect, types = () => {}, months, promisify, TextEncoder2, TextDecoder, util_default;
1726
+ var formatRegExp, debuglog, inspect, types = () => {}, months, promisify, TextEncoder2, TextDecoder2, util_default;
1727
1727
  var init_util = __esm(() => {
1728
1728
  formatRegExp = /%[sdj%]/g;
1729
1729
  debuglog = ((debugs = {}, debugEnvRegex = {}, debugEnv) => ((debugEnv = typeof process < "u" && false) && (debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, "\\$&").replace(/\*/g, ".*").replace(/,/g, "$|^").toUpperCase()), debugEnvRegex = new RegExp("^" + debugEnv + "$", "i"), (set) => {
@@ -1787,8 +1787,8 @@ var init_util = __esm(() => {
1787
1787
  Object.defineProperty(fn, kCustomPromisifiedSymbol, { value: fn, enumerable: false, writable: false, configurable: true });
1788
1788
  return Object.defineProperties(fn, Object.getOwnPropertyDescriptors(original));
1789
1789
  });
1790
- ({ TextEncoder: TextEncoder2, TextDecoder } = globalThis);
1791
- util_default = { TextEncoder: TextEncoder2, TextDecoder, promisify, log, inherits, _extend, callbackifyOnRejected, callbackify };
1790
+ ({ TextEncoder: TextEncoder2, TextDecoder: TextDecoder2 } = globalThis);
1791
+ util_default = { TextEncoder: TextEncoder2, TextDecoder: TextDecoder2, promisify, log, inherits, _extend, callbackifyOnRejected, callbackify };
1792
1792
  });
1793
1793
 
1794
1794
  // node:events
@@ -20640,7 +20640,7 @@ function addHashes(event) {
20640
20640
  return {
20641
20641
  name: event.name,
20642
20642
  fields: event.fields.flatMap((field) => {
20643
- if (field.indexed === false)
20643
+ if (field.indexed !== true)
20644
20644
  return field;
20645
20645
  const isString2 = Type5.Extends(field.type, Type5.String(), Type5.Literal(true), Type5.Literal(false)).const;
20646
20646
  const isNumber2 = Type5.Extends(field.type, Type5.Number(), Type5.Literal(true), Type5.Literal(false)).const;
@@ -20664,7 +20664,13 @@ function addHashes(event) {
20664
20664
  }
20665
20665
 
20666
20666
  // ../effectstream-sdk/events/src/app-events.ts
20667
+ import { Type as Type6 } from "@sinclair/typebox";
20667
20668
  import sha32 from "js-sha3";
20669
+ var BLOCK_HEIGHT_FIELD = {
20670
+ name: "blockHeight",
20671
+ type: Type6.Integer(),
20672
+ indexed: true
20673
+ };
20668
20674
  // ../effectstream-sdk/events/src/utils.ts
20669
20675
  function fillPath(path, args) {
20670
20676
  const keys = new Set(Object.keys(args));
@@ -20723,11 +20729,8 @@ function keysForPath(path) {
20723
20729
  return path.filter((p) => typeof p !== "string").map((p) => p.name);
20724
20730
  }
20725
20731
 
20726
- // ../effectstream-sdk/events/src/event-connect.ts
20727
- import mqtt from "mqtt";
20728
-
20729
20732
  // ../effectstream-sdk/events/src/builtin-events.ts
20730
- import { Type as Type6 } from "@sinclair/typebox";
20733
+ import { Type as Type7 } from "@sinclair/typebox";
20731
20734
  var BatcherStatus;
20732
20735
  ((BatcherStatus2) => {
20733
20736
  BatcherStatus2["Posting"] = "posting";
@@ -20740,21 +20743,21 @@ var BatcherHash = genEvent({
20740
20743
  fields: [
20741
20744
  {
20742
20745
  name: "batch",
20743
- type: Type6.String(),
20746
+ type: Type7.String(),
20744
20747
  indexed: true
20745
20748
  },
20746
20749
  {
20747
20750
  name: "status",
20748
- type: Type6.Enum(BatcherStatus),
20751
+ type: Type7.Enum(BatcherStatus),
20749
20752
  indexed: true
20750
20753
  },
20751
20754
  {
20752
20755
  name: "blockHeight",
20753
- type: Type6.Optional(Type6.Integer())
20756
+ type: Type7.Optional(Type7.Integer())
20754
20757
  },
20755
20758
  {
20756
20759
  name: "transactionHash",
20757
- type: Type6.String()
20760
+ type: Type7.String()
20758
20761
  }
20759
20762
  ]
20760
20763
  });
@@ -20763,12 +20766,12 @@ var RollupBlock = genEvent({
20763
20766
  fields: [
20764
20767
  {
20765
20768
  name: "block",
20766
- type: Type6.Integer(),
20769
+ type: Type7.Integer(),
20767
20770
  indexed: true
20768
20771
  },
20769
20772
  {
20770
20773
  name: "timestamp",
20771
- type: Type6.Optional(Type6.Integer())
20774
+ type: Type7.Optional(Type7.Integer())
20772
20775
  }
20773
20776
  ]
20774
20777
  });
@@ -20777,17 +20780,17 @@ var SyncChains = genEvent({
20777
20780
  fields: [
20778
20781
  {
20779
20782
  name: "chain",
20780
- type: Type6.String(),
20783
+ type: Type7.String(),
20781
20784
  indexed: true
20782
20785
  },
20783
20786
  {
20784
20787
  name: "block",
20785
- type: Type6.Integer(),
20788
+ type: Type7.Integer(),
20786
20789
  indexed: true
20787
20790
  },
20788
20791
  {
20789
20792
  name: "rollup",
20790
- type: Type6.Integer(),
20793
+ type: Type7.Integer(),
20791
20794
  indexed: false
20792
20795
  }
20793
20796
  ]
@@ -20827,69 +20830,115 @@ async function setupInitialListeners(_broker) {
20827
20830
 
20828
20831
  // ../effectstream-sdk/events/src/event-connect.ts
20829
20832
  import { extract, matches } from "mqtt-pattern";
20833
+ var utf8Encoder = new TextEncoder;
20834
+ var utf8Decoder = new TextDecoder;
20835
+ function dispatchMessage(topic, payload) {
20836
+ const message = utf8Decoder.decode(payload);
20837
+ for (const [_broker, info] of Object.entries(EventManager.Instance.callbacksForTopic)) {
20838
+ for (const [pattern, callbacks] of Object.entries(info)) {
20839
+ if (matches(pattern, topic)) {
20840
+ for (const callbackInfo of Object.getOwnPropertySymbols(callbacks).map((sym) => callbacks[sym])) {
20841
+ const data = JSON.parse(message);
20842
+ const resolved = extract(toPattern(callbackInfo.event.path), topic);
20843
+ callbackInfo.callback({
20844
+ val: data,
20845
+ resolvedPath: resolved
20846
+ });
20847
+ }
20848
+ }
20849
+ }
20850
+ }
20851
+ }
20852
+ async function createOpifexClient(url) {
20853
+ const opifexPath = "@seriousme/opifex" + "/tcpClient";
20854
+ const { TcpClient } = await import(opifexPath);
20855
+ const client = new TcpClient;
20856
+ await client.connect({ url: new URL(url), numberOfRetries: 3 });
20857
+ (async () => {
20858
+ for await (const msg of client.messages()) {
20859
+ dispatchMessage(msg.topic, new Uint8Array(msg.payload));
20860
+ }
20861
+ })();
20862
+ const adapter = {
20863
+ connected: true,
20864
+ async subscribe(topic, qos) {
20865
+ await client.subscribe({
20866
+ subscriptions: [{ topicFilter: topic, qos }]
20867
+ });
20868
+ },
20869
+ async publish(topic, payload, qos) {
20870
+ await client.publish({
20871
+ topic,
20872
+ payload: utf8Encoder.encode(payload),
20873
+ qos
20874
+ });
20875
+ }
20876
+ };
20877
+ client.onConnected = () => {
20878
+ adapter.connected = true;
20879
+ };
20880
+ client.onDisconnected = () => {
20881
+ adapter.connected = false;
20882
+ };
20883
+ return adapter;
20884
+ }
20885
+ async function createMqttJsClient(url) {
20886
+ const mqtt = await import("mqtt");
20887
+ const client = await mqtt.default.connectAsync(url);
20888
+ client.on("message", (topic, message) => {
20889
+ dispatchMessage(topic, new Uint8Array(message));
20890
+ });
20891
+ return {
20892
+ get connected() {
20893
+ return client.connected;
20894
+ },
20895
+ async subscribe(topic, qos) {
20896
+ await client.subscribeAsync(topic, { qos });
20897
+ },
20898
+ async publish(topic, payload, qos) {
20899
+ await client.publishAsync(topic, payload, { qos });
20900
+ }
20901
+ };
20902
+ }
20830
20903
  var ENV = {
20831
- MQTT_ENGINE_BROKER_URL: "ws://localhost:8883",
20832
- MQTT_BATCHER_BROKER_URL: "ws://localhost:8884"
20904
+ MQTT_ENGINE_BROKER_URL: "mqtt://localhost:8883",
20905
+ MQTT_BATCHER_BROKER_URL: "mqtt://localhost:8884",
20906
+ MQTT_ENGINE_BROKER_WS_URL: "ws://localhost:9883",
20907
+ MQTT_BATCHER_BROKER_WS_URL: "ws://localhost:9884"
20833
20908
  };
20834
20909
 
20835
20910
  class EventConnect {
20836
20911
  static clients = {};
20837
- constructor() {
20838
- this.getClient.bind(this);
20839
- this.setupClient.bind(this);
20840
- this.connectEngine.bind(this);
20841
- this.connectBatcher.bind(this);
20842
- }
20843
- static _bunMqttWarned = false;
20844
20912
  async getClient(broker) {
20845
- if (getRuntime().runtime === "bun") {
20846
- if (!EventConnect._bunMqttWarned) {
20847
- EventConnect._bunMqttWarned = true;
20848
- console.warn("[MQTT] WebSocket-based MQTT is not supported in Bun (ws.createWebSocketStream is unimplemented). " + "See: https://github.com/oven-sh/bun/pull/24304");
20849
- }
20850
- return null;
20851
- }
20852
20913
  switch (broker) {
20853
- case "effectstream-engine" /* Engine */: {
20914
+ case "effectstream-engine" /* Engine */:
20854
20915
  return await this.connectEngine();
20855
- }
20856
20916
  case "batcher" /* Batcher */:
20857
20917
  return await this.connectBatcher();
20858
20918
  }
20859
20919
  }
20860
20920
  async setupClient(url) {
20861
- const client = await mqtt.connectAsync(url);
20862
- client.on("message", (topic, message) => {
20863
- for (const [_broker, info] of Object.entries(EventManager.Instance.callbacksForTopic)) {
20864
- for (const [pattern, callbacks] of Object.entries(info)) {
20865
- if (matches(pattern, topic)) {
20866
- for (const callbackInfo of Object.getOwnPropertySymbols(callbacks).map((sym) => callbacks[sym])) {
20867
- const data = JSON.parse(message.toString());
20868
- const resolved = extract(toPattern(callbackInfo.event.path), topic);
20869
- callbackInfo.callback({
20870
- val: data,
20871
- resolvedPath: resolved
20872
- });
20873
- }
20874
- }
20875
- }
20876
- }
20877
- });
20878
- return client;
20921
+ const runtime2 = getRuntime();
20922
+ if (runtime2.environment === "frontend") {
20923
+ return await createMqttJsClient(url);
20924
+ }
20925
+ return await createOpifexClient(url);
20879
20926
  }
20880
20927
  async connectEngine() {
20881
20928
  if (!EventConnect.clients.engine) {
20882
- const broker = "effectstream-engine" /* Engine */;
20883
- EventConnect.clients.engine = await this.setupClient(ENV.MQTT_ENGINE_BROKER_URL);
20884
- await setupInitialListeners(broker);
20929
+ const runtime2 = getRuntime();
20930
+ const url = runtime2.environment === "frontend" ? ENV.MQTT_ENGINE_BROKER_WS_URL : ENV.MQTT_ENGINE_BROKER_URL;
20931
+ EventConnect.clients.engine = await this.setupClient(url);
20932
+ await setupInitialListeners("effectstream-engine" /* Engine */);
20885
20933
  }
20886
20934
  return EventConnect.clients.engine;
20887
20935
  }
20888
20936
  async connectBatcher() {
20889
20937
  if (!EventConnect.clients.batcher) {
20890
- const broker = "batcher" /* Batcher */;
20891
- EventConnect.clients.batcher = await this.setupClient(ENV.MQTT_BATCHER_BROKER_URL);
20892
- await setupInitialListeners(broker);
20938
+ const runtime2 = getRuntime();
20939
+ const url = runtime2.environment === "frontend" ? ENV.MQTT_BATCHER_BROKER_WS_URL : ENV.MQTT_BATCHER_BROKER_URL;
20940
+ EventConnect.clients.batcher = await this.setupClient(url);
20941
+ await setupInitialListeners("batcher" /* Batcher */);
20893
20942
  }
20894
20943
  return EventConnect.clients.batcher;
20895
20944
  }
@@ -20903,13 +20952,6 @@ class EventManager {
20903
20952
  };
20904
20953
  symbolToSubscription = {};
20905
20954
  static Instance = new EventManager;
20906
- constructor() {
20907
- this.subscribe.bind(this);
20908
- this.subscribeExplicit.bind(this);
20909
- this.unsubscribe.bind(this);
20910
- this.sendMessage.bind(this);
20911
- this.sendMessageExplicit.bind(this);
20912
- }
20913
20955
  async subscribe(args, callback) {
20914
20956
  return await this.subscribeExplicit({
20915
20957
  topic: args.topic,
@@ -20921,22 +20963,11 @@ class EventManager {
20921
20963
  if (!client)
20922
20964
  return Symbol("noop");
20923
20965
  const topic = fillPath(args.topic.path, args.filter);
20924
- const clientSubscribe = async () => {
20925
- try {
20926
- await client.subscribeAsync(topic, { qos: 2 });
20927
- } catch (err) {
20928
- console.log(`MQTT[${args.topic.broker}] ERROR`, err);
20929
- }
20930
- };
20931
- if (client.connected)
20932
- await clientSubscribe();
20933
- else
20934
- await new Promise((resolve) => {
20935
- client.on("connect", async () => {
20936
- await clientSubscribe();
20937
- resolve();
20938
- });
20939
- });
20966
+ try {
20967
+ await client.subscribe(topic, 2);
20968
+ } catch (err) {
20969
+ console.log(`MQTT[${args.topic.broker}] ERROR`, err);
20970
+ }
20940
20971
  const symbol = Symbol(topic);
20941
20972
  this.symbolToSubscription[symbol] = {
20942
20973
  broker: args.topic.broker,
@@ -20961,26 +20992,7 @@ class EventManager {
20961
20992
  delete callbacks[event];
20962
20993
  const numCallbacks = Object.keys(callbacks).length - 1;
20963
20994
  if (numCallbacks === 0) {
20964
- const client = await new EventConnect().getClient(broker);
20965
20995
  delete this.callbacksForTopic[broker][topic];
20966
- if (!client)
20967
- return;
20968
- const clientUnsubscribe = async () => {
20969
- try {
20970
- await client.unsubscribeAsync(topic);
20971
- } catch (err) {
20972
- console.log(`MQTT[${broker}] ERROR`, err);
20973
- }
20974
- };
20975
- if (client.connected)
20976
- await clientUnsubscribe();
20977
- else
20978
- await new Promise((resolve) => {
20979
- client.on("connect", async () => {
20980
- await clientUnsubscribe();
20981
- resolve();
20982
- });
20983
- });
20984
20996
  }
20985
20997
  }
20986
20998
  async sendMessage(topic, event) {
@@ -20994,11 +21006,11 @@ class EventManager {
20994
21006
  if (!client)
20995
21007
  return;
20996
21008
  const topicPath = fillPath(args.topic.path, args.filter);
20997
- await client.publishAsync(topicPath, JSON.stringify(message), { qos: 2 });
21009
+ await client.publish(topicPath, JSON.stringify(message), 2);
20998
21010
  }
20999
21011
  }
21000
21012
  // ../effectstream-sdk/events/src/evm.ts
21001
- import { Kind, Type as Type7 } from "@sinclair/typebox";
21013
+ import { Kind, Type as Type8 } from "@sinclair/typebox";
21002
21014
  // ../effectstream-sdk/wallets/src/effectstream.ts
21003
21015
  class EffectstreamConfig {
21004
21016
  appName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/frontend-sdk",
3
- "version": "0.100.13",
3
+ "version": "0.100.14",
4
4
  "license": "MIT",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "build": "bun run build.ts"
28
28
  },
29
29
  "dependencies": {
30
- "@effectstream/wallets": "0.100.13"
30
+ "@effectstream/wallets": "0.100.14"
31
31
  },
32
32
  "description": "React frontend SDK for EffectStream"
33
33
  }