vedatrace 0.1.8 → 0.2.0

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.
@@ -1,4 +1,4 @@
1
- import { c as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-CcdFb-vY.cjs';
1
+ import { e as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-BU0UESs9.cjs';
2
2
 
3
3
  /**
4
4
  * Console transport for development/debugging
@@ -31,17 +31,20 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
31
31
 
32
32
  /**
33
33
  * HTTP transport for sending logs to VedaTrace ingestion endpoint
34
+ *
35
+ * Features:
36
+ * - Timeout support with AbortController
37
+ * - Retry on network failure
38
+ * - Keepalive support for browser final flush
34
39
  */
35
40
 
36
41
  interface HttpTransportConfig {
37
- /** API key for authentication */
38
42
  apiKey: string;
39
- /** Ingestion endpoint URL */
40
43
  endpoint?: string;
41
- /** Request timeout in milliseconds */
42
44
  timeout?: number;
43
- /** Additional headers */
44
45
  headers?: Record<string, string>;
46
+ /** Enable keepalive for browser final flush */
47
+ keepalive?: boolean;
45
48
  }
46
49
  declare class VedaTraceHttpTransport implements VedaTraceTransport {
47
50
  readonly name = "http";
@@ -49,10 +52,24 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
49
52
  private apiKey;
50
53
  private timeout;
51
54
  private headers;
55
+ private keepalive;
52
56
  constructor(config: HttpTransportConfig);
53
57
  /** Send logs via HTTP POST */
54
58
  send(logs: InternalLogEntry[]): Promise<void>;
59
+ /** Flush pending logs - called on page unload */
60
+ flush(): Promise<void>;
61
+ /** Check if keepalive is enabled */
62
+ isKeepaliveEnabled(): boolean;
63
+ /** Enable/disable keepalive */
64
+ setKeepalive(enabled: boolean): void;
65
+ }
66
+ /**
67
+ * Browser-safe HTTP transport that uses keepalive for final flush
68
+ */
69
+ declare class VedaTraceHttpTransportBrowser extends VedaTraceHttpTransport {
70
+ constructor(config: HttpTransportConfig);
71
+ flush(): Promise<void>;
55
72
  }
56
73
 
57
- export { VedaTraceConsoleTransport, VedaTraceHttpTransport };
74
+ export { VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser };
58
75
  export type { ConsoleFormat, ConsoleTransportConfig, HttpTransportConfig };
@@ -1,4 +1,4 @@
1
- import { c as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-CcdFb-vY.mjs';
1
+ import { e as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-BU0UESs9.mjs';
2
2
 
3
3
  /**
4
4
  * Console transport for development/debugging
@@ -31,17 +31,20 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
31
31
 
32
32
  /**
33
33
  * HTTP transport for sending logs to VedaTrace ingestion endpoint
34
+ *
35
+ * Features:
36
+ * - Timeout support with AbortController
37
+ * - Retry on network failure
38
+ * - Keepalive support for browser final flush
34
39
  */
35
40
 
36
41
  interface HttpTransportConfig {
37
- /** API key for authentication */
38
42
  apiKey: string;
39
- /** Ingestion endpoint URL */
40
43
  endpoint?: string;
41
- /** Request timeout in milliseconds */
42
44
  timeout?: number;
43
- /** Additional headers */
44
45
  headers?: Record<string, string>;
46
+ /** Enable keepalive for browser final flush */
47
+ keepalive?: boolean;
45
48
  }
46
49
  declare class VedaTraceHttpTransport implements VedaTraceTransport {
47
50
  readonly name = "http";
@@ -49,10 +52,24 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
49
52
  private apiKey;
50
53
  private timeout;
51
54
  private headers;
55
+ private keepalive;
52
56
  constructor(config: HttpTransportConfig);
53
57
  /** Send logs via HTTP POST */
54
58
  send(logs: InternalLogEntry[]): Promise<void>;
59
+ /** Flush pending logs - called on page unload */
60
+ flush(): Promise<void>;
61
+ /** Check if keepalive is enabled */
62
+ isKeepaliveEnabled(): boolean;
63
+ /** Enable/disable keepalive */
64
+ setKeepalive(enabled: boolean): void;
65
+ }
66
+ /**
67
+ * Browser-safe HTTP transport that uses keepalive for final flush
68
+ */
69
+ declare class VedaTraceHttpTransportBrowser extends VedaTraceHttpTransport {
70
+ constructor(config: HttpTransportConfig);
71
+ flush(): Promise<void>;
55
72
  }
56
73
 
57
- export { VedaTraceConsoleTransport, VedaTraceHttpTransport };
74
+ export { VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser };
58
75
  export type { ConsoleFormat, ConsoleTransportConfig, HttpTransportConfig };
@@ -80,11 +80,13 @@ class VedaTraceHttpTransport {
80
80
  apiKey;
81
81
  timeout;
82
82
  headers;
83
+ keepalive;
83
84
  constructor(config) {
84
85
  this.apiKey = config.apiKey;
85
86
  this.endpoint = config.endpoint ?? "https://ingest.vedatrace.dev/v1/logs";
86
87
  this.timeout = config.timeout ?? 3e4;
87
88
  this.headers = config.headers ?? {};
89
+ this.keepalive = config.keepalive ?? false;
88
90
  }
89
91
  /** Send logs via HTTP POST */
90
92
  async send(logs) {
@@ -106,7 +108,8 @@ class VedaTraceHttpTransport {
106
108
  ...this.headers
107
109
  },
108
110
  body: JSON.stringify(payload),
109
- signal: controller.signal
111
+ signal: controller.signal,
112
+ keepalive: this.keepalive
110
113
  });
111
114
  clearTimeout(timeoutId);
112
115
  if (!response.ok) {
@@ -124,6 +127,27 @@ class VedaTraceHttpTransport {
124
127
  throw new Error(String(error));
125
128
  }
126
129
  }
130
+ /** Flush pending logs - called on page unload */
131
+ async flush() {
132
+ return Promise.resolve();
133
+ }
134
+ /** Check if keepalive is enabled */
135
+ isKeepaliveEnabled() {
136
+ return this.keepalive;
137
+ }
138
+ /** Enable/disable keepalive */
139
+ setKeepalive(enabled) {
140
+ this.keepalive = enabled;
141
+ }
142
+ }
143
+ class VedaTraceHttpTransportBrowser extends VedaTraceHttpTransport {
144
+ constructor(config) {
145
+ super({ ...config, keepalive: true });
146
+ }
147
+ async flush() {
148
+ this.setKeepalive(true);
149
+ return super.flush();
150
+ }
127
151
  }
128
152
 
129
- export { VedaTraceConsoleTransport, VedaTraceHttpTransport };
153
+ export { VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser };
@@ -6,103 +6,79 @@
6
6
  type VedaTraceLevel = "debug" | "info" | "warn" | "error" | "fatal";
7
7
  /** Log entry structure matching ingestion API */
8
8
  interface VedaTraceLog {
9
- /** Log severity level */
10
9
  level: VedaTraceLevel;
11
- /** Log message */
12
10
  message: string;
13
- /** Service name (optional, can override default) */
14
11
  service?: string;
15
- /** Unix timestamp in milliseconds (optional, auto-generated if not provided) */
16
12
  timestamp?: number;
17
- /** Arbitrary metadata object */
18
13
  metadata?: Record<string, unknown>;
19
14
  }
15
+ /**
16
+ * Generic Edge Context interface for Cloudflare Workers / Pages / etc.
17
+ * This avoids importing heavy framework-specific types and works with any
18
+ * environment that provides a waitUntil() method.
19
+ */
20
+ interface VedaTraceEdgeContext {
21
+ waitUntil(promise: Promise<unknown>): void;
22
+ }
20
23
  /** Configuration options for VedaTrace SDK */
21
24
  interface VedaTraceConfig {
22
- /** API key for authentication */
23
25
  apiKey?: string;
24
- /** Default service name for all logs */
25
26
  service?: string;
26
- /** Ingestion endpoint URL */
27
27
  endpoint?: string;
28
- /** Environment identifier */
29
28
  environment?: "production" | "staging" | "development" | string;
30
- /** Batch size before flushing (default: 100) */
31
29
  batchSize?: number;
32
- /** Flush interval in milliseconds (default: 5000) */
33
30
  flushInterval?: number;
34
- /** Maximum retry attempts for failed requests (default: 3) */
35
31
  maxRetries?: number;
36
- /** Delay between retries in milliseconds (default: 1000) */
37
32
  retryDelay?: number;
38
- /** Redaction configuration for PII */
39
33
  redaction?: RedactionConfig;
40
- /** Custom transports (defaults to HTTP if apiKey provided) */
41
34
  transports?: VedaTraceTransport[];
42
- /** Callback for transport errors */
43
35
  onError?: (error: Error) => void;
44
- /** Callback for successful sends */
45
36
  onSuccess?: () => void;
46
- /** Disable logging entirely */
47
37
  disabled?: boolean;
48
- /** Enable debug mode (verbose console output) */
49
38
  debug?: boolean;
50
- /** Flush immediately after each log (for console/dev mode) */
51
39
  immediateFlush?: boolean;
52
- /** Unref the flush timer (Node.js only, default: false) */
53
40
  unrefTimer?: boolean;
41
+ autoStart?: boolean;
42
+ runtime?: RuntimeType;
43
+ /** Cloudflare Workers ExecutionContext - enables waitUntil support */
44
+ executionContext?: VedaTraceEdgeContext;
54
45
  }
55
- /** Redaction configuration */
56
46
  interface RedactionConfig {
57
- /** Field paths to redact (e.g., ['password', 'user.token']) */
58
47
  paths?: string[];
59
- /** Custom redaction mask (default: '[REDACTED]') */
60
48
  mask?: string;
61
- /** Enable automatic PII detection */
62
49
  autoDetectPii?: boolean;
63
50
  }
64
- /** Transport interface for sending logs */
51
+ type RuntimeType = "node" | "browser" | "cloudflare" | "deno" | "bun" | "edge";
65
52
  interface VedaTraceTransport {
66
- /** Transport name */
67
53
  name: string;
68
- /** Send logs to destination */
69
54
  send(logs: InternalLogEntry[]): Promise<void> | void;
70
- /** Flush any pending logs */
71
55
  flush?(): Promise<void>;
72
56
  }
73
- /** Metadata that can be passed to log methods */
74
57
  interface LogMetadata {
75
- /** Override default service name */
76
58
  service?: string;
77
- /** Any other metadata fields */
78
59
  [key: string]: unknown;
79
60
  }
80
- /** Internal log entry with SDK metadata */
81
61
  interface InternalLogEntry extends VedaTraceLog {
82
- /** SDK-generated fields */
83
62
  _sdk?: {
84
- /** Source of the log (node, browser, edge) */
85
63
  source?: string;
86
- /** SDK version */
87
64
  version?: string;
88
- /** Error stack trace if log is an error */
89
65
  stackTrace?: string;
90
- /** Browser info */
91
66
  browser?: {
92
67
  userAgent?: string;
93
68
  url?: string;
94
69
  };
95
70
  };
96
71
  }
97
- /** Batcher configuration */
98
72
  interface BatcherConfig {
99
73
  batchSize: number;
100
74
  flushInterval: number;
101
75
  maxRetries: number;
102
76
  retryDelay: number;
103
77
  unrefTimer?: boolean;
78
+ executionContext?: VedaTraceEdgeContext;
79
+ onError?: (error: Error) => void;
80
+ onSuccess?: () => void;
104
81
  }
105
- /** Logger interface */
106
82
  interface VedaTraceLoggerInterface {
107
83
  debug(message: string, metadata?: LogMetadata): void;
108
84
  info(message: string, metadata?: LogMetadata): void;
@@ -112,6 +88,14 @@ interface VedaTraceLoggerInterface {
112
88
  child(defaults: LogMetadata): VedaTraceLoggerInterface;
113
89
  flush(): Promise<void>;
114
90
  stop(): void;
91
+ start(): void;
92
+ runtime: RuntimeType;
93
+ /** Attach execution context for waitUntil support (Cloudflare Workers) */
94
+ withContext(ctx: VedaTraceEdgeContext): this;
95
+ /** Check if context is attached */
96
+ hasContext(): boolean;
97
+ /** Get current execution context */
98
+ getContext(): VedaTraceEdgeContext | undefined;
115
99
  }
116
100
 
117
- export type { BatcherConfig as B, InternalLogEntry as I, LogMetadata as L, RedactionConfig as R, VedaTraceLoggerInterface as V, VedaTraceConfig as a, VedaTraceTransport as b, VedaTraceLevel as c, VedaTraceLog as d };
101
+ export type { BatcherConfig as B, InternalLogEntry as I, LogMetadata as L, RuntimeType as R, VedaTraceLoggerInterface as V, VedaTraceConfig as a, VedaTraceTransport as b, VedaTraceEdgeContext as c, RedactionConfig as d, VedaTraceLevel as e, VedaTraceLog as f };
@@ -6,103 +6,79 @@
6
6
  type VedaTraceLevel = "debug" | "info" | "warn" | "error" | "fatal";
7
7
  /** Log entry structure matching ingestion API */
8
8
  interface VedaTraceLog {
9
- /** Log severity level */
10
9
  level: VedaTraceLevel;
11
- /** Log message */
12
10
  message: string;
13
- /** Service name (optional, can override default) */
14
11
  service?: string;
15
- /** Unix timestamp in milliseconds (optional, auto-generated if not provided) */
16
12
  timestamp?: number;
17
- /** Arbitrary metadata object */
18
13
  metadata?: Record<string, unknown>;
19
14
  }
15
+ /**
16
+ * Generic Edge Context interface for Cloudflare Workers / Pages / etc.
17
+ * This avoids importing heavy framework-specific types and works with any
18
+ * environment that provides a waitUntil() method.
19
+ */
20
+ interface VedaTraceEdgeContext {
21
+ waitUntil(promise: Promise<unknown>): void;
22
+ }
20
23
  /** Configuration options for VedaTrace SDK */
21
24
  interface VedaTraceConfig {
22
- /** API key for authentication */
23
25
  apiKey?: string;
24
- /** Default service name for all logs */
25
26
  service?: string;
26
- /** Ingestion endpoint URL */
27
27
  endpoint?: string;
28
- /** Environment identifier */
29
28
  environment?: "production" | "staging" | "development" | string;
30
- /** Batch size before flushing (default: 100) */
31
29
  batchSize?: number;
32
- /** Flush interval in milliseconds (default: 5000) */
33
30
  flushInterval?: number;
34
- /** Maximum retry attempts for failed requests (default: 3) */
35
31
  maxRetries?: number;
36
- /** Delay between retries in milliseconds (default: 1000) */
37
32
  retryDelay?: number;
38
- /** Redaction configuration for PII */
39
33
  redaction?: RedactionConfig;
40
- /** Custom transports (defaults to HTTP if apiKey provided) */
41
34
  transports?: VedaTraceTransport[];
42
- /** Callback for transport errors */
43
35
  onError?: (error: Error) => void;
44
- /** Callback for successful sends */
45
36
  onSuccess?: () => void;
46
- /** Disable logging entirely */
47
37
  disabled?: boolean;
48
- /** Enable debug mode (verbose console output) */
49
38
  debug?: boolean;
50
- /** Flush immediately after each log (for console/dev mode) */
51
39
  immediateFlush?: boolean;
52
- /** Unref the flush timer (Node.js only, default: false) */
53
40
  unrefTimer?: boolean;
41
+ autoStart?: boolean;
42
+ runtime?: RuntimeType;
43
+ /** Cloudflare Workers ExecutionContext - enables waitUntil support */
44
+ executionContext?: VedaTraceEdgeContext;
54
45
  }
55
- /** Redaction configuration */
56
46
  interface RedactionConfig {
57
- /** Field paths to redact (e.g., ['password', 'user.token']) */
58
47
  paths?: string[];
59
- /** Custom redaction mask (default: '[REDACTED]') */
60
48
  mask?: string;
61
- /** Enable automatic PII detection */
62
49
  autoDetectPii?: boolean;
63
50
  }
64
- /** Transport interface for sending logs */
51
+ type RuntimeType = "node" | "browser" | "cloudflare" | "deno" | "bun" | "edge";
65
52
  interface VedaTraceTransport {
66
- /** Transport name */
67
53
  name: string;
68
- /** Send logs to destination */
69
54
  send(logs: InternalLogEntry[]): Promise<void> | void;
70
- /** Flush any pending logs */
71
55
  flush?(): Promise<void>;
72
56
  }
73
- /** Metadata that can be passed to log methods */
74
57
  interface LogMetadata {
75
- /** Override default service name */
76
58
  service?: string;
77
- /** Any other metadata fields */
78
59
  [key: string]: unknown;
79
60
  }
80
- /** Internal log entry with SDK metadata */
81
61
  interface InternalLogEntry extends VedaTraceLog {
82
- /** SDK-generated fields */
83
62
  _sdk?: {
84
- /** Source of the log (node, browser, edge) */
85
63
  source?: string;
86
- /** SDK version */
87
64
  version?: string;
88
- /** Error stack trace if log is an error */
89
65
  stackTrace?: string;
90
- /** Browser info */
91
66
  browser?: {
92
67
  userAgent?: string;
93
68
  url?: string;
94
69
  };
95
70
  };
96
71
  }
97
- /** Batcher configuration */
98
72
  interface BatcherConfig {
99
73
  batchSize: number;
100
74
  flushInterval: number;
101
75
  maxRetries: number;
102
76
  retryDelay: number;
103
77
  unrefTimer?: boolean;
78
+ executionContext?: VedaTraceEdgeContext;
79
+ onError?: (error: Error) => void;
80
+ onSuccess?: () => void;
104
81
  }
105
- /** Logger interface */
106
82
  interface VedaTraceLoggerInterface {
107
83
  debug(message: string, metadata?: LogMetadata): void;
108
84
  info(message: string, metadata?: LogMetadata): void;
@@ -112,6 +88,14 @@ interface VedaTraceLoggerInterface {
112
88
  child(defaults: LogMetadata): VedaTraceLoggerInterface;
113
89
  flush(): Promise<void>;
114
90
  stop(): void;
91
+ start(): void;
92
+ runtime: RuntimeType;
93
+ /** Attach execution context for waitUntil support (Cloudflare Workers) */
94
+ withContext(ctx: VedaTraceEdgeContext): this;
95
+ /** Check if context is attached */
96
+ hasContext(): boolean;
97
+ /** Get current execution context */
98
+ getContext(): VedaTraceEdgeContext | undefined;
115
99
  }
116
100
 
117
- export type { BatcherConfig as B, InternalLogEntry as I, LogMetadata as L, RedactionConfig as R, VedaTraceLoggerInterface as V, VedaTraceConfig as a, VedaTraceTransport as b, VedaTraceLevel as c, VedaTraceLog as d };
101
+ export type { BatcherConfig as B, InternalLogEntry as I, LogMetadata as L, RuntimeType as R, VedaTraceLoggerInterface as V, VedaTraceConfig as a, VedaTraceTransport as b, VedaTraceEdgeContext as c, RedactionConfig as d, VedaTraceLevel as e, VedaTraceLog as f };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "vedatrace",
3
3
  "description": "Universal JavaScript logging SDK for VedaTrace - type-safe, lightweight, and developer-friendly",
4
- "version": "0.1.8",
4
+ "version": "0.2.0",
5
5
  "scripts": {
6
6
  "setup": "rm -rf node_modules && npm i && git init && husky",
7
7
  "prepublishOnly": "npm run build",
8
8
  "build": "pkgroll --clean-dist",
9
9
  "test": "vitest --run",
10
- "lint": "npx @biomejs/biome check --write",
10
+ "lint": "bunx @biomejs/biome check --write",
11
11
  "changeset": "changeset",
12
12
  "version": "changeset version",
13
13
  "release": "bun run build && changeset publish",