@visibe.ai/node 0.1.7 → 0.1.8
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/dist/cjs/api.js +24 -0
- package/dist/cjs/client.js +7 -0
- package/dist/esm/api.js +24 -0
- package/dist/esm/client.js +7 -0
- package/dist/types/api.d.ts +2 -1
- package/package.json +1 -1
package/dist/cjs/api.js
CHANGED
|
@@ -13,6 +13,30 @@ class APIClient {
|
|
|
13
13
|
process.emitWarning('[Visibe] No API key provided — tracing is disabled. Set VISIBE_API_KEY or pass apiKey= to enable.', { type: 'VisibleSDKWarning', code: 'VISIBE_NO_API_KEY' });
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// validateKey() — called once at startup in the background.
|
|
18
|
+
// Hits GET /api/auth/validate with the API key.
|
|
19
|
+
// On 401 (invalid/revoked key): disables tracing and prints a clear warning.
|
|
20
|
+
// On network error or non-401 failure: stays enabled (lenient — don't punish
|
|
21
|
+
// users for flaky networks at startup).
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
async validateKey() {
|
|
24
|
+
try {
|
|
25
|
+
const response = await fetch(`${this.apiUrl}/api/auth/validate`, {
|
|
26
|
+
method: 'GET',
|
|
27
|
+
headers: { 'Authorization': `Bearer ${this.apiKey}` },
|
|
28
|
+
signal: AbortSignal.timeout(5000),
|
|
29
|
+
});
|
|
30
|
+
if (response.status === 401) {
|
|
31
|
+
this._enabled = false;
|
|
32
|
+
process.emitWarning('[Visibe] Invalid API key — tracing is disabled. Check your VISIBE_API_KEY.', { type: 'VisibleSDKWarning', code: 'VISIBE_INVALID_API_KEY' });
|
|
33
|
+
}
|
|
34
|
+
// 200 → valid, stay enabled. Other status codes → lenient, stay enabled.
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Network error / timeout → lenient, stay enabled.
|
|
38
|
+
}
|
|
39
|
+
}
|
|
16
40
|
async _request(method, path, body) {
|
|
17
41
|
if (!this._enabled)
|
|
18
42
|
return false;
|
package/dist/cjs/client.js
CHANGED
|
@@ -20,6 +20,13 @@ class Visibe {
|
|
|
20
20
|
this.debug = debug;
|
|
21
21
|
this.apiClient = new api_1.APIClient({ apiKey, apiUrl });
|
|
22
22
|
this.batcher = new api_1.SpanBatcher(this.apiClient);
|
|
23
|
+
// Fire-and-forget background key validation.
|
|
24
|
+
// Runs ~80ms after startup — well before the 2s batcher flush window.
|
|
25
|
+
// On invalid key: disables tracing and prints a warning.
|
|
26
|
+
// On network error: stays enabled (lenient).
|
|
27
|
+
if (this.apiClient._enabled) {
|
|
28
|
+
this.apiClient.validateKey().catch(() => { });
|
|
29
|
+
}
|
|
23
30
|
}
|
|
24
31
|
// ---------------------------------------------------------------------------
|
|
25
32
|
// instrument() — wrap a client so each call creates its own trace.
|
package/dist/esm/api.js
CHANGED
|
@@ -10,6 +10,30 @@ export class APIClient {
|
|
|
10
10
|
process.emitWarning('[Visibe] No API key provided — tracing is disabled. Set VISIBE_API_KEY or pass apiKey= to enable.', { type: 'VisibleSDKWarning', code: 'VISIBE_NO_API_KEY' });
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// validateKey() — called once at startup in the background.
|
|
15
|
+
// Hits GET /api/auth/validate with the API key.
|
|
16
|
+
// On 401 (invalid/revoked key): disables tracing and prints a clear warning.
|
|
17
|
+
// On network error or non-401 failure: stays enabled (lenient — don't punish
|
|
18
|
+
// users for flaky networks at startup).
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
async validateKey() {
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(`${this.apiUrl}/api/auth/validate`, {
|
|
23
|
+
method: 'GET',
|
|
24
|
+
headers: { 'Authorization': `Bearer ${this.apiKey}` },
|
|
25
|
+
signal: AbortSignal.timeout(5000),
|
|
26
|
+
});
|
|
27
|
+
if (response.status === 401) {
|
|
28
|
+
this._enabled = false;
|
|
29
|
+
process.emitWarning('[Visibe] Invalid API key — tracing is disabled. Check your VISIBE_API_KEY.', { type: 'VisibleSDKWarning', code: 'VISIBE_INVALID_API_KEY' });
|
|
30
|
+
}
|
|
31
|
+
// 200 → valid, stay enabled. Other status codes → lenient, stay enabled.
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Network error / timeout → lenient, stay enabled.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
13
37
|
async _request(method, path, body) {
|
|
14
38
|
if (!this._enabled)
|
|
15
39
|
return false;
|
package/dist/esm/client.js
CHANGED
|
@@ -17,6 +17,13 @@ export class Visibe {
|
|
|
17
17
|
this.debug = debug;
|
|
18
18
|
this.apiClient = new APIClient({ apiKey, apiUrl });
|
|
19
19
|
this.batcher = new SpanBatcher(this.apiClient);
|
|
20
|
+
// Fire-and-forget background key validation.
|
|
21
|
+
// Runs ~80ms after startup — well before the 2s batcher flush window.
|
|
22
|
+
// On invalid key: disables tracing and prints a warning.
|
|
23
|
+
// On network error: stays enabled (lenient).
|
|
24
|
+
if (this.apiClient._enabled) {
|
|
25
|
+
this.apiClient.validateKey().catch(() => { });
|
|
26
|
+
}
|
|
20
27
|
}
|
|
21
28
|
// ---------------------------------------------------------------------------
|
|
22
29
|
// instrument() — wrap a client so each call creates its own trace.
|
package/dist/types/api.d.ts
CHANGED
|
@@ -2,12 +2,13 @@ export declare class APIClient {
|
|
|
2
2
|
readonly apiUrl: string;
|
|
3
3
|
private readonly apiKey;
|
|
4
4
|
private readonly timeout;
|
|
5
|
-
|
|
5
|
+
_enabled: boolean;
|
|
6
6
|
constructor(options: {
|
|
7
7
|
apiUrl?: string;
|
|
8
8
|
apiKey?: string;
|
|
9
9
|
timeout?: number;
|
|
10
10
|
});
|
|
11
|
+
validateKey(): Promise<void>;
|
|
11
12
|
private _request;
|
|
12
13
|
createTrace(data: object): Promise<boolean>;
|
|
13
14
|
sendSpan(traceId: string, span: object): Promise<boolean>;
|
package/package.json
CHANGED