@graphty/remote-logger 0.0.1 → 1.1.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.
Files changed (48) hide show
  1. package/README.md +636 -28
  2. package/bin/remote-log-server.js +3 -0
  3. package/dist/client/RemoteLogClient.d.ts +114 -0
  4. package/dist/client/RemoteLogClient.d.ts.map +1 -0
  5. package/dist/client/RemoteLogClient.js +238 -0
  6. package/dist/client/RemoteLogClient.js.map +1 -0
  7. package/dist/client/index.d.ts +7 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +6 -0
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/client/types.d.ts +47 -0
  12. package/dist/client/types.d.ts.map +1 -0
  13. package/dist/client/types.js +6 -0
  14. package/dist/client/types.js.map +1 -0
  15. package/dist/index.d.ts +22 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +23 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/server/index.d.ts +8 -0
  20. package/dist/server/index.d.ts.map +1 -0
  21. package/dist/server/index.js +8 -0
  22. package/dist/server/index.js.map +1 -0
  23. package/dist/server/log-server.d.ts +75 -0
  24. package/dist/server/log-server.d.ts.map +1 -0
  25. package/dist/server/log-server.js +453 -0
  26. package/dist/server/log-server.js.map +1 -0
  27. package/dist/server/self-signed-cert.d.ts +30 -0
  28. package/dist/server/self-signed-cert.d.ts.map +1 -0
  29. package/dist/server/self-signed-cert.js +83 -0
  30. package/dist/server/self-signed-cert.js.map +1 -0
  31. package/dist/ui/ConsoleCaptureUI.d.ts +118 -0
  32. package/dist/ui/ConsoleCaptureUI.d.ts.map +1 -0
  33. package/dist/ui/ConsoleCaptureUI.js +571 -0
  34. package/dist/ui/ConsoleCaptureUI.js.map +1 -0
  35. package/dist/ui/index.d.ts +15 -0
  36. package/dist/ui/index.d.ts.map +1 -0
  37. package/dist/ui/index.js +15 -0
  38. package/dist/ui/index.js.map +1 -0
  39. package/package.json +80 -7
  40. package/src/client/RemoteLogClient.ts +280 -0
  41. package/src/client/index.ts +7 -0
  42. package/src/client/types.ts +49 -0
  43. package/src/index.ts +28 -0
  44. package/src/server/index.ts +17 -0
  45. package/src/server/log-server.ts +571 -0
  46. package/src/server/self-signed-cert.ts +93 -0
  47. package/src/ui/ConsoleCaptureUI.ts +649 -0
  48. package/src/ui/index.ts +15 -0
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Browser client for sending log messages to a remote server.
3
+ * Provides batching and automatic retry with exponential backoff.
4
+ * @module client/RemoteLogClient
5
+ */
6
+ import type { RemoteLogClientOptions } from "./types.js";
7
+ /**
8
+ * Client for sending log messages to a remote logging server.
9
+ *
10
+ * Features:
11
+ * - Batches multiple log entries before sending
12
+ * - Automatic retry with exponential backoff on network failures
13
+ * - Unique session ID for correlating logs
14
+ * @example
15
+ * ```typescript
16
+ * const client = new RemoteLogClient({
17
+ * serverUrl: "http://localhost:9080",
18
+ * sessionPrefix: "myapp",
19
+ * });
20
+ *
21
+ * client.log("INFO", "User logged in", { userId: 123 });
22
+ * client.log("DEBUG", "Loading data...");
23
+ *
24
+ * // Flush immediately when needed
25
+ * await client.flush();
26
+ *
27
+ * // Clean up when done
28
+ * await client.close();
29
+ * ```
30
+ */
31
+ export declare class RemoteLogClient {
32
+ /** Unique identifier for this logging session */
33
+ readonly sessionId: string;
34
+ private readonly serverUrl;
35
+ private readonly batchIntervalMs;
36
+ private readonly maxRetries;
37
+ private readonly retryDelayMs;
38
+ private readonly throttlePatterns;
39
+ private pendingLogs;
40
+ private batchTimer;
41
+ private isClosed;
42
+ private flushPromise;
43
+ /** Tracks when each throttle pattern was last allowed through */
44
+ private throttleLastTimes;
45
+ /**
46
+ * Creates a new RemoteLogClient.
47
+ * @param options - Configuration options
48
+ */
49
+ constructor(options: RemoteLogClientOptions);
50
+ /**
51
+ * Checks if a message should be throttled based on configured patterns.
52
+ * Updates the last time tracking if the message is allowed through.
53
+ * @param message - The message to check
54
+ * @returns true if the message should be dropped (throttled)
55
+ */
56
+ private shouldThrottle;
57
+ /**
58
+ * Logs a message at the specified level.
59
+ * @param level - Log level (e.g., "INFO", "DEBUG", "WARN", "ERROR")
60
+ * @param message - The log message
61
+ * @param data - Optional additional data to include
62
+ */
63
+ log(level: string, message: string, data?: Record<string, unknown>): void;
64
+ /**
65
+ * Schedules a batch send after the configured interval.
66
+ * If a timer is already scheduled, does nothing.
67
+ */
68
+ private scheduleBatchSend;
69
+ /**
70
+ * Sends the current batch of logs to the server.
71
+ * Uses retry logic with exponential backoff on failure.
72
+ */
73
+ private sendBatch;
74
+ /**
75
+ * Sends logs with retry logic using exponential backoff.
76
+ * @param logs - The log entries to send
77
+ */
78
+ private sendWithRetry;
79
+ /**
80
+ * Makes the actual HTTP request to send logs.
81
+ * @param logs - The log entries to send
82
+ * @throws Error if the request fails
83
+ */
84
+ private sendRequest;
85
+ /**
86
+ * Helper to sleep for the specified duration.
87
+ * @param ms - Milliseconds to sleep
88
+ * @returns A promise that resolves after the specified time
89
+ */
90
+ private sleep;
91
+ /**
92
+ * Immediately flushes all pending logs to the server.
93
+ * Useful before page unload or when immediate delivery is needed.
94
+ */
95
+ flush(): Promise<void>;
96
+ /**
97
+ * Closes the client, flushing any pending logs and stopping the batch timer.
98
+ * After calling close(), no more logs will be accepted.
99
+ */
100
+ close(): Promise<void>;
101
+ }
102
+ /**
103
+ * Factory function to create a RemoteLogClient.
104
+ * @param options - Configuration options
105
+ * @returns A new RemoteLogClient instance
106
+ * @example
107
+ * ```typescript
108
+ * const client = createRemoteLogClient({
109
+ * serverUrl: "http://localhost:9080",
110
+ * });
111
+ * ```
112
+ */
113
+ export declare function createRemoteLogClient(options: RemoteLogClientOptions): RemoteLogClient;
114
+ //# sourceMappingURL=RemoteLogClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoteLogClient.d.ts","sourceRoot":"","sources":["../../src/client/RemoteLogClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OA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Provides batching and automatic retry with exponential backoff.
4
+ * @module client/RemoteLogClient
5
+ */
6
+ /** Default configuration values */
7
+ const DEFAULT_BATCH_INTERVAL_MS = 1000;
8
+ const DEFAULT_MAX_RETRIES = 3;
9
+ const DEFAULT_RETRY_DELAY_MS = 1000;
10
+ const DEFAULT_SESSION_PREFIX = "session";
11
+ /**
12
+ * Generates a unique session ID with the given prefix.
13
+ * Format: {prefix}-{timestamp}-{random}
14
+ * @param prefix - The prefix to use for the session ID
15
+ * @returns A unique session ID string
16
+ */
17
+ function generateSessionId(prefix) {
18
+ const timestamp = Date.now().toString(36);
19
+ const random = Math.random().toString(36).substring(2, 8);
20
+ return `${prefix}-${timestamp}-${random}`;
21
+ }
22
+ /**
23
+ * Client for sending log messages to a remote logging server.
24
+ *
25
+ * Features:
26
+ * - Batches multiple log entries before sending
27
+ * - Automatic retry with exponential backoff on network failures
28
+ * - Unique session ID for correlating logs
29
+ * @example
30
+ * ```typescript
31
+ * const client = new RemoteLogClient({
32
+ * serverUrl: "http://localhost:9080",
33
+ * sessionPrefix: "myapp",
34
+ * });
35
+ *
36
+ * client.log("INFO", "User logged in", { userId: 123 });
37
+ * client.log("DEBUG", "Loading data...");
38
+ *
39
+ * // Flush immediately when needed
40
+ * await client.flush();
41
+ *
42
+ * // Clean up when done
43
+ * await client.close();
44
+ * ```
45
+ */
46
+ export class RemoteLogClient {
47
+ /**
48
+ * Creates a new RemoteLogClient.
49
+ * @param options - Configuration options
50
+ */
51
+ constructor(options) {
52
+ this.pendingLogs = [];
53
+ this.batchTimer = null;
54
+ this.isClosed = false;
55
+ this.flushPromise = null;
56
+ /** Tracks when each throttle pattern was last allowed through */
57
+ this.throttleLastTimes = new Map();
58
+ this.serverUrl = options.serverUrl;
59
+ this.sessionId = generateSessionId(options.sessionPrefix ?? DEFAULT_SESSION_PREFIX);
60
+ this.batchIntervalMs = options.batchIntervalMs ?? DEFAULT_BATCH_INTERVAL_MS;
61
+ this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
62
+ this.retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
63
+ this.throttlePatterns = options.throttlePatterns ?? [];
64
+ }
65
+ /**
66
+ * Checks if a message should be throttled based on configured patterns.
67
+ * Updates the last time tracking if the message is allowed through.
68
+ * @param message - The message to check
69
+ * @returns true if the message should be dropped (throttled)
70
+ */
71
+ shouldThrottle(message) {
72
+ const now = Date.now();
73
+ for (const { pattern, intervalMs } of this.throttlePatterns) {
74
+ if (pattern.test(message)) {
75
+ const key = pattern.source;
76
+ const lastTime = this.throttleLastTimes.get(key) ?? 0;
77
+ if (now - lastTime < intervalMs) {
78
+ // Within throttle window, drop this message
79
+ return true;
80
+ }
81
+ // Outside throttle window, update timestamp and allow through
82
+ this.throttleLastTimes.set(key, now);
83
+ return false;
84
+ }
85
+ }
86
+ // No matching pattern, allow through
87
+ return false;
88
+ }
89
+ /**
90
+ * Logs a message at the specified level.
91
+ * @param level - Log level (e.g., "INFO", "DEBUG", "WARN", "ERROR")
92
+ * @param message - The log message
93
+ * @param data - Optional additional data to include
94
+ */
95
+ log(level, message, data) {
96
+ if (this.isClosed) {
97
+ return;
98
+ }
99
+ // Check throttling before adding to buffer
100
+ if (this.shouldThrottle(message)) {
101
+ return;
102
+ }
103
+ const entry = {
104
+ time: new Date().toISOString(),
105
+ level,
106
+ message,
107
+ ...(data !== undefined && { data }),
108
+ };
109
+ this.pendingLogs.push(entry);
110
+ this.scheduleBatchSend();
111
+ }
112
+ /**
113
+ * Schedules a batch send after the configured interval.
114
+ * If a timer is already scheduled, does nothing.
115
+ */
116
+ scheduleBatchSend() {
117
+ if (this.batchTimer !== null || this.isClosed) {
118
+ return;
119
+ }
120
+ this.batchTimer = setTimeout(() => {
121
+ this.batchTimer = null;
122
+ void this.sendBatch();
123
+ }, this.batchIntervalMs);
124
+ }
125
+ /**
126
+ * Sends the current batch of logs to the server.
127
+ * Uses retry logic with exponential backoff on failure.
128
+ */
129
+ async sendBatch() {
130
+ if (this.pendingLogs.length === 0) {
131
+ return;
132
+ }
133
+ // Take the current logs and clear the pending array
134
+ const logsToSend = this.pendingLogs;
135
+ this.pendingLogs = [];
136
+ await this.sendWithRetry(logsToSend);
137
+ }
138
+ /**
139
+ * Sends logs with retry logic using exponential backoff.
140
+ * @param logs - The log entries to send
141
+ */
142
+ async sendWithRetry(logs) {
143
+ let lastError = null;
144
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
145
+ try {
146
+ await this.sendRequest(logs);
147
+ return; // Success!
148
+ }
149
+ catch (error) {
150
+ lastError = error instanceof Error ? error : new Error(String(error));
151
+ if (attempt < this.maxRetries) {
152
+ // Exponential backoff: delay * 2^attempt
153
+ const delay = this.retryDelayMs * Math.pow(2, attempt);
154
+ await this.sleep(delay);
155
+ }
156
+ }
157
+ }
158
+ // All retries exhausted - log the error but don't throw
159
+ // In a browser context, we don't want to break the application
160
+ console.error("[RemoteLogClient] Failed to send logs after retries:", lastError?.message);
161
+ }
162
+ /**
163
+ * Makes the actual HTTP request to send logs.
164
+ * @param logs - The log entries to send
165
+ * @throws Error if the request fails
166
+ */
167
+ async sendRequest(logs) {
168
+ const response = await fetch(`${this.serverUrl}/log`, {
169
+ method: "POST",
170
+ headers: {
171
+ "Content-Type": "application/json",
172
+ },
173
+ body: JSON.stringify({
174
+ sessionId: this.sessionId,
175
+ logs,
176
+ }),
177
+ });
178
+ if (!response.ok) {
179
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
180
+ }
181
+ }
182
+ /**
183
+ * Helper to sleep for the specified duration.
184
+ * @param ms - Milliseconds to sleep
185
+ * @returns A promise that resolves after the specified time
186
+ */
187
+ sleep(ms) {
188
+ return new Promise((resolve) => setTimeout(resolve, ms));
189
+ }
190
+ /**
191
+ * Immediately flushes all pending logs to the server.
192
+ * Useful before page unload or when immediate delivery is needed.
193
+ */
194
+ async flush() {
195
+ // Cancel any scheduled batch
196
+ if (this.batchTimer !== null) {
197
+ clearTimeout(this.batchTimer);
198
+ this.batchTimer = null;
199
+ }
200
+ // Wait for any in-progress flush
201
+ if (this.flushPromise !== null) {
202
+ await this.flushPromise;
203
+ }
204
+ // Send any remaining logs
205
+ if (this.pendingLogs.length > 0) {
206
+ this.flushPromise = this.sendBatch();
207
+ await this.flushPromise;
208
+ this.flushPromise = null;
209
+ }
210
+ }
211
+ /**
212
+ * Closes the client, flushing any pending logs and stopping the batch timer.
213
+ * After calling close(), no more logs will be accepted.
214
+ */
215
+ async close() {
216
+ if (this.isClosed) {
217
+ return;
218
+ }
219
+ this.isClosed = true;
220
+ // Flush remaining logs
221
+ await this.flush();
222
+ }
223
+ }
224
+ /**
225
+ * Factory function to create a RemoteLogClient.
226
+ * @param options - Configuration options
227
+ * @returns A new RemoteLogClient instance
228
+ * @example
229
+ * ```typescript
230
+ * const client = createRemoteLogClient({
231
+ * serverUrl: "http://localhost:9080",
232
+ * });
233
+ * ```
234
+ */
235
+ export function createRemoteLogClient(options) {
236
+ return new RemoteLogClient(options);
237
+ }
238
+ //# sourceMappingURL=RemoteLogClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoteLogClient.js","sourceRoot":"","sources":["../../src/client/RemoteLogClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,mCAAmC;AACnC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AACvC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEzC;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,MAAc;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,OAAO,GAAG,MAAM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,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACjE,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Browser client for remote logging.
3
+ * @module client
4
+ */
5
+ export { createRemoteLogClient, RemoteLogClient } from "./RemoteLogClient.js";
6
+ export type { LogEntry, RemoteLogClientOptions, ThrottlePattern } from "./types.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,YAAY,EAAE,QAAQ,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Browser client for remote logging.
3
+ * @module client
4
+ */
5
+ export { createRemoteLogClient, RemoteLogClient } from "./RemoteLogClient.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Type definitions for the remote logging client.
3
+ * @module client/types
4
+ */
5
+ /**
6
+ * A single log entry to be sent to the remote server.
7
+ */
8
+ export interface LogEntry {
9
+ /** ISO 8601 timestamp when the log was created */
10
+ time: string;
11
+ /** Log level (e.g., "INFO", "DEBUG", "WARN", "ERROR") */
12
+ level: string;
13
+ /** The log message */
14
+ message: string;
15
+ /** Optional additional data to include with the log */
16
+ data?: Record<string, unknown>;
17
+ }
18
+ /**
19
+ * Configuration for throttling specific message patterns.
20
+ */
21
+ export interface ThrottlePattern {
22
+ /** Regular expression pattern to match log messages */
23
+ pattern: RegExp;
24
+ /** Minimum interval in milliseconds between matching messages */
25
+ intervalMs: number;
26
+ }
27
+ /**
28
+ * Configuration options for the RemoteLogClient.
29
+ */
30
+ export interface RemoteLogClientOptions {
31
+ /** URL of the remote log server (e.g., "http://localhost:9080") */
32
+ serverUrl: string;
33
+ /** Prefix for the generated session ID (default: "session") */
34
+ sessionPrefix?: string;
35
+ /** Interval in milliseconds between batch sends (default: 1000) */
36
+ batchIntervalMs?: number;
37
+ /** Maximum number of retry attempts for failed sends (default: 3) */
38
+ maxRetries?: number;
39
+ /** Base delay in milliseconds between retries (uses exponential backoff) (default: 1000) */
40
+ retryDelayMs?: number;
41
+ /**
42
+ * Patterns to throttle to prevent log flooding.
43
+ * Messages matching a pattern will only be sent once per the configured interval.
44
+ */
45
+ throttlePatterns?: ThrottlePattern[];
46
+ }
47
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4FAA4F;IAC5F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;CACxC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Type definitions for the remote logging client.
3
+ * @module client/types
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Remote logging client and server for browser debugging.
3
+ *
4
+ * Client usage (Browser):
5
+ * import { RemoteLogClient } from "@graphty/remote-logger";
6
+ * const client = new RemoteLogClient({ serverUrl: "http://localhost:9080" });
7
+ * client.log("INFO", "Hello from browser");
8
+ *
9
+ * Server usage (Node.js):
10
+ * import { startLogServer } from "@graphty/remote-logger/server";
11
+ * startLogServer({ port: 9080 });
12
+ *
13
+ * Or via CLI:
14
+ * npx remote-log-server --port 9080
15
+ *
16
+ * UI usage (Browser):
17
+ * import { initConsoleCaptureUI } from "@graphty/remote-logger/ui";
18
+ * initConsoleCaptureUI();
19
+ */
20
+ export type { LogEntry, RemoteLogClientOptions, ThrottlePattern } from "./client/index.js";
21
+ export { createRemoteLogClient, RemoteLogClient } from "./client/index.js";
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,YAAY,EAAE,QAAQ,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Remote logging client and server for browser debugging.
3
+ *
4
+ * Client usage (Browser):
5
+ * import { RemoteLogClient } from "@graphty/remote-logger";
6
+ * const client = new RemoteLogClient({ serverUrl: "http://localhost:9080" });
7
+ * client.log("INFO", "Hello from browser");
8
+ *
9
+ * Server usage (Node.js):
10
+ * import { startLogServer } from "@graphty/remote-logger/server";
11
+ * startLogServer({ port: 9080 });
12
+ *
13
+ * Or via CLI:
14
+ * npx remote-log-server --port 9080
15
+ *
16
+ * UI usage (Browser):
17
+ * import { initConsoleCaptureUI } from "@graphty/remote-logger/ui";
18
+ * initConsoleCaptureUI();
19
+ */
20
+ export { createRemoteLogClient, RemoteLogClient } from "./client/index.js";
21
+ // Note: UI components are NOT re-exported here to keep the main entry lightweight.
22
+ // Import from "@graphty/remote-logger/ui" for UI usage.
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE3E,mFAAmF;AACnF,wDAAwD"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Server-side logging utilities.
3
+ * These are only meant to be run in Node.js, not in the browser.
4
+ * @module server
5
+ */
6
+ export { clearLogs, HELP_TEXT, type LogEntry, type LogServerOptions, main, parseArgs, type ParseArgsResult, startLogServer, } from "./log-server.js";
7
+ export { certFilesExist, type GeneratedCert, generateSelfSignedCert, readCertFiles } from "./self-signed-cert.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACH,SAAS,EACT,SAAS,EACT,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,IAAI,EACJ,SAAS,EACT,KAAK,eAAe,EACpB,cAAc,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Server-side logging utilities.
3
+ * These are only meant to be run in Node.js, not in the browser.
4
+ * @module server
5
+ */
6
+ export { clearLogs, HELP_TEXT, main, parseArgs, startLogServer, } from "./log-server.js";
7
+ export { certFilesExist, generateSelfSignedCert, readCertFiles } from "./self-signed-cert.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACH,SAAS,EACT,SAAS,EAGT,IAAI,EACJ,SAAS,EAET,cAAc,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAsB,sBAAsB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Remote Log Server - A standalone HTTP/HTTPS log server for remote debugging.
3
+ *
4
+ * Features:
5
+ * - HTTPS with auto-generated self-signed certs or custom certs
6
+ * - Receives logs from browser via POST /log
7
+ * - Pretty terminal output with colors
8
+ * - REST API for querying logs
9
+ * - Optional file logging for Claude Code to read
10
+ *
11
+ * Usage:
12
+ * npx remote-log-server --port 9080
13
+ * npx remote-log-server --cert /path/to/cert.crt --key /path/to/key.key
14
+ */
15
+ import * as http from "http";
16
+ import * as https from "https";
17
+ export interface LogServerOptions {
18
+ /** Port to listen on (default: 9080) */
19
+ port?: number;
20
+ /** Hostname to bind to (default: localhost) */
21
+ host?: string;
22
+ /** Path to SSL certificate file */
23
+ certPath?: string;
24
+ /** Path to SSL private key file */
25
+ keyPath?: string;
26
+ /** Path to file for writing logs (optional) */
27
+ logFile?: string;
28
+ /** Use HTTP instead of HTTPS (default: false) */
29
+ useHttp?: boolean;
30
+ /** Suppress startup banner (default: false) */
31
+ quiet?: boolean;
32
+ }
33
+ export interface LogEntry {
34
+ time: string;
35
+ level: string;
36
+ message: string;
37
+ }
38
+ /**
39
+ * Clear all stored logs.
40
+ * Useful for testing.
41
+ */
42
+ export declare function clearLogs(): void;
43
+ /**
44
+ * Start the log server.
45
+ * @param options - Server configuration options
46
+ * @returns The HTTP or HTTPS server instance
47
+ */
48
+ export declare function startLogServer(options?: LogServerOptions): http.Server | https.Server;
49
+ /**
50
+ * Help text displayed when --help is passed.
51
+ */
52
+ export declare const HELP_TEXT = "\nRemote Log Server - Remote logging for browser debugging\n\nUsage:\n npx remote-log-server [options]\n npx @graphty/remote-logger [options]\n\nOptions:\n --port, -p <port> Port to listen on (default: 9080)\n --host, -h <host> Hostname to bind to (default: localhost)\n --cert, -c <path> Path to SSL certificate file\n --key, -k <path> Path to SSL private key file\n --log-file, -l <path> Write logs to file\n --http Use HTTP instead of HTTPS\n --quiet, -q Suppress startup banner\n --help Show this help message\n\nExamples:\n npx remote-log-server # Start with defaults (port 9080, self-signed cert)\n npx remote-log-server --port 9085 # Custom port\n npx remote-log-server --http # Use HTTP instead of HTTPS\n npx remote-log-server --cert cert.crt --key key.key # Custom SSL certs\n npx remote-log-server --log-file ./tmp/logs.jsonl # Also write to file\n";
53
+ /**
54
+ * Result of parsing command line arguments.
55
+ */
56
+ export interface ParseArgsResult {
57
+ /** Parsed options for the log server */
58
+ options: LogServerOptions;
59
+ /** Whether --help was requested */
60
+ showHelp: boolean;
61
+ /** Error message if parsing failed */
62
+ error?: string;
63
+ }
64
+ /**
65
+ * Parse command line arguments into LogServerOptions.
66
+ * This is separated from main() to enable testing.
67
+ * @param args - Array of command line arguments (excluding node and script name)
68
+ * @returns ParseArgsResult with options, help flag, or error
69
+ */
70
+ export declare function parseArgs(args: string[]): ParseArgsResult;
71
+ /**
72
+ * Parse command line arguments and start the server.
73
+ */
74
+ export declare function main(): void;
75
+ //# sourceMappingURL=log-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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