@unicitylabs/nostr-js-sdk 0.2.2 → 0.2.3

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
@@ -47,8 +47,15 @@ console.log(keyManager.getPublicKeyHex());
47
47
  import { NostrClient, NostrKeyManager } from '@unicitylabs/nostr-sdk';
48
48
 
49
49
  const keyManager = NostrKeyManager.generate();
50
+
51
+ // Create client with default options
50
52
  const client = new NostrClient(keyManager);
51
53
 
54
+ // Or configure with custom options
55
+ const client = new NostrClient(keyManager, {
56
+ queryTimeoutMs: 15000, // Increase timeout for slow relays (default: 5000ms)
57
+ });
58
+
52
59
  // Connect to relays
53
60
  await client.connect(
54
61
  'wss://relay.damus.io',
@@ -58,6 +65,9 @@ await client.connect(
58
65
  // Check connection status
59
66
  console.log(client.isConnected());
60
67
  console.log(client.getConnectedRelays());
68
+
69
+ // You can also adjust timeout dynamically
70
+ client.setQueryTimeout(30000); // 30 seconds
61
71
  ```
62
72
 
63
73
  ### Publishing Events
@@ -5990,8 +5990,8 @@ var nip17 = /*#__PURE__*/Object.freeze({
5990
5990
  const CONNECTION_TIMEOUT_MS = 30000;
5991
5991
  /** Reconnection delay in milliseconds */
5992
5992
  const RECONNECT_DELAY_MS = 5000;
5993
- /** Query timeout in milliseconds */
5994
- const QUERY_TIMEOUT_MS = 5000;
5993
+ /** Default query timeout in milliseconds */
5994
+ const DEFAULT_QUERY_TIMEOUT_MS = 5000;
5995
5995
  /**
5996
5996
  * NostrClient provides the main interface for Nostr protocol operations.
5997
5997
  */
@@ -6003,12 +6003,15 @@ class NostrClient {
6003
6003
  pendingOks = new Map();
6004
6004
  subscriptionCounter = 0;
6005
6005
  closed = false;
6006
+ queryTimeoutMs;
6006
6007
  /**
6007
6008
  * Create a NostrClient instance.
6008
6009
  * @param keyManager Key manager with signing keys
6010
+ * @param options Optional configuration options
6009
6011
  */
6010
- constructor(keyManager) {
6012
+ constructor(keyManager, options) {
6011
6013
  this.keyManager = keyManager;
6014
+ this.queryTimeoutMs = options?.queryTimeoutMs ?? DEFAULT_QUERY_TIMEOUT_MS;
6012
6015
  }
6013
6016
  /**
6014
6017
  * Get the key manager.
@@ -6017,6 +6020,20 @@ class NostrClient {
6017
6020
  getKeyManager() {
6018
6021
  return this.keyManager;
6019
6022
  }
6023
+ /**
6024
+ * Get the current query timeout in milliseconds.
6025
+ * @returns Query timeout in milliseconds
6026
+ */
6027
+ getQueryTimeout() {
6028
+ return this.queryTimeoutMs;
6029
+ }
6030
+ /**
6031
+ * Set the query timeout for nametag lookups and other queries.
6032
+ * @param timeoutMs Timeout in milliseconds
6033
+ */
6034
+ setQueryTimeout(timeoutMs) {
6035
+ this.queryTimeoutMs = timeoutMs;
6036
+ }
6020
6037
  /**
6021
6038
  * Connect to one or more relay WebSocket URLs.
6022
6039
  * @param relayUrls Relay URLs to connect to
@@ -6442,7 +6459,7 @@ class NostrClient {
6442
6459
  const timeoutId = setTimeout(() => {
6443
6460
  this.unsubscribe(subscriptionId);
6444
6461
  resolve(null);
6445
- }, QUERY_TIMEOUT_MS);
6462
+ }, this.queryTimeoutMs);
6446
6463
  let result = null;
6447
6464
  let latestCreatedAt = 0;
6448
6465
  const subscriptionId = this.subscribe(filter, {