@debros/network-ts-sdk 0.4.3 → 0.6.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) [year] [fullname]
3
+ Copyright (c) 2026 DeBrosOfficial
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -367,6 +367,7 @@ interface ClientConfig {
367
367
  timeout?: number; // Request timeout in ms (default: 30000)
368
368
  maxRetries?: number; // Max retry attempts (default: 3)
369
369
  retryDelayMs?: number; // Delay between retries (default: 1000)
370
+ debug?: boolean; // Enable debug logging with full SQL queries (default: false)
370
371
  storage?: StorageAdapter; // For persisting JWT/API key (default: MemoryStorage)
371
372
  wsConfig?: Partial<WSClientConfig>; // WebSocket configuration
372
373
  fetch?: typeof fetch; // Custom fetch implementation
package/dist/index.d.ts CHANGED
@@ -35,6 +35,10 @@ interface HttpClientConfig {
35
35
  maxRetries?: number;
36
36
  retryDelayMs?: number;
37
37
  fetch?: typeof fetch;
38
+ /**
39
+ * Enable debug logging (includes full SQL queries and args). Default: false
40
+ */
41
+ debug?: boolean;
38
42
  /**
39
43
  * Callback invoked on network errors (after all retries exhausted).
40
44
  * Use this to trigger gateway failover at the application layer.
@@ -49,6 +53,7 @@ declare class HttpClient {
49
53
  private fetch;
50
54
  private apiKey?;
51
55
  private jwt?;
56
+ private debug;
52
57
  private onNetworkError?;
53
58
  constructor(config: HttpClientConfig);
54
59
  /**
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ var HttpClient = class {
40
40
  this.maxRetries = config.maxRetries ?? 3;
41
41
  this.retryDelayMs = config.retryDelayMs ?? 1e3;
42
42
  this.fetch = config.fetch ?? createFetchWithTLSConfig();
43
+ this.debug = config.debug ?? false;
43
44
  this.onNetworkError = config.onNetworkError;
44
45
  }
45
46
  /**
@@ -174,7 +175,7 @@ var HttpClient = class {
174
175
  const logMessage = `[HttpClient] ${method} ${path} completed in ${duration.toFixed(
175
176
  2
176
177
  )}ms`;
177
- if (queryDetails) {
178
+ if (queryDetails && this.debug) {
178
179
  console.log(logMessage);
179
180
  console.log(`[HttpClient] ${queryDetails}`);
180
181
  } else {
@@ -197,7 +198,7 @@ var HttpClient = class {
197
198
  2
198
199
  )}ms:`;
199
200
  console.error(errorMessage, error);
200
- if (queryDetails) {
201
+ if (queryDetails && this.debug) {
201
202
  console.error(`[HttpClient] ${queryDetails}`);
202
203
  }
203
204
  }
@@ -938,7 +939,8 @@ var WSClient = class {
938
939
  if (this.authToken) {
939
940
  const separator = url.includes("?") ? "&" : "?";
940
941
  const paramName = this.authToken.startsWith("ak_") ? "api_key" : "token";
941
- url += `${separator}${paramName}=${encodeURIComponent(this.authToken)}`;
942
+ const encodedToken = this.authToken.startsWith("ak_") ? this.authToken : encodeURIComponent(this.authToken);
943
+ url += `${separator}${paramName}=${encodedToken}`;
942
944
  }
943
945
  return url;
944
946
  }
@@ -1600,7 +1602,7 @@ var StorageClient = class {
1600
1602
  if (!isNotFound || attempt === maxAttempts) {
1601
1603
  throw error;
1602
1604
  }
1603
- const backoffMs = attempt * 2500;
1605
+ const backoffMs = Math.min(attempt * 1e3, 3e3);
1604
1606
  await new Promise((resolve) => setTimeout(resolve, backoffMs));
1605
1607
  }
1606
1608
  }
@@ -1639,7 +1641,7 @@ var StorageClient = class {
1639
1641
  if (!isNotFound || attempt === maxAttempts) {
1640
1642
  throw error;
1641
1643
  }
1642
- const backoffMs = attempt * 2500;
1644
+ const backoffMs = Math.min(attempt * 1e3, 3e3);
1643
1645
  await new Promise((resolve) => setTimeout(resolve, backoffMs));
1644
1646
  }
1645
1647
  }
@@ -1694,6 +1696,7 @@ function createClient(config) {
1694
1696
  timeout: config.timeout,
1695
1697
  maxRetries: config.maxRetries,
1696
1698
  retryDelayMs: config.retryDelayMs,
1699
+ debug: config.debug,
1697
1700
  fetch: config.fetch,
1698
1701
  onNetworkError: config.onNetworkError
1699
1702
  });