@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 +1 -1
- package/README.md +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/package.json +26 -3
- package/src/auth/index.ts +3 -0
- package/src/cache/index.ts +14 -0
- package/src/core/http.ts +8 -2
- package/src/core/index.ts +10 -0
- package/src/core/interfaces/IAuthStrategy.ts +28 -0
- package/src/core/interfaces/IHttpTransport.ts +73 -0
- package/src/core/interfaces/IRetryPolicy.ts +20 -0
- package/src/core/interfaces/IWebSocketClient.ts +60 -0
- package/src/core/interfaces/index.ts +4 -0
- package/src/core/transport/AuthHeaderStrategy.ts +108 -0
- package/src/core/transport/RequestLogger.ts +116 -0
- package/src/core/transport/RequestRetryPolicy.ts +53 -0
- package/src/core/transport/TLSConfiguration.ts +53 -0
- package/src/core/transport/index.ts +4 -0
- package/src/core/ws.ts +5 -1
- package/src/db/index.ts +13 -0
- package/src/functions/index.ts +2 -0
- package/src/index.ts +1 -0
- package/src/network/index.ts +7 -0
- package/src/pubsub/index.ts +12 -0
- package/src/storage/client.ts +8 -6
- package/src/storage/index.ts +7 -0
- package/src/utils/codec.ts +68 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/platform.ts +44 -0
- package/src/utils/retry.ts +58 -0
package/LICENSE
CHANGED
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
|
-
|
|
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 *
|
|
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 *
|
|
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
|
});
|