@abbacchio/transport 0.1.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.
Files changed (42) hide show
  1. package/dist/client.d.ts +66 -0
  2. package/dist/client.d.ts.map +1 -0
  3. package/dist/client.js +123 -0
  4. package/dist/client.js.map +1 -0
  5. package/dist/encrypt.d.ts +53 -0
  6. package/dist/encrypt.d.ts.map +1 -0
  7. package/dist/encrypt.js +97 -0
  8. package/dist/encrypt.js.map +1 -0
  9. package/dist/index.d.ts +12 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +10 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/transports/bunyan.d.ts +58 -0
  14. package/dist/transports/bunyan.d.ts.map +1 -0
  15. package/dist/transports/bunyan.js +84 -0
  16. package/dist/transports/bunyan.js.map +1 -0
  17. package/dist/transports/console.d.ts +21 -0
  18. package/dist/transports/console.d.ts.map +1 -0
  19. package/dist/transports/console.js +119 -0
  20. package/dist/transports/console.js.map +1 -0
  21. package/dist/transports/index.d.ts +9 -0
  22. package/dist/transports/index.d.ts.map +1 -0
  23. package/dist/transports/index.js +9 -0
  24. package/dist/transports/index.js.map +1 -0
  25. package/dist/transports/pino.d.ts +31 -0
  26. package/dist/transports/pino.d.ts.map +1 -0
  27. package/dist/transports/pino.js +42 -0
  28. package/dist/transports/pino.js.map +1 -0
  29. package/dist/transports/winston.d.ts +55 -0
  30. package/dist/transports/winston.d.ts.map +1 -0
  31. package/dist/transports/winston.js +85 -0
  32. package/dist/transports/winston.js.map +1 -0
  33. package/package.json +56 -0
  34. package/src/client.ts +148 -0
  35. package/src/encrypt.ts +112 -0
  36. package/src/index.ts +19 -0
  37. package/src/transports/bunyan.ts +99 -0
  38. package/src/transports/console.ts +147 -0
  39. package/src/transports/index.ts +15 -0
  40. package/src/transports/pino.ts +49 -0
  41. package/src/transports/winston.ts +100 -0
  42. package/tsconfig.json +19 -0
@@ -0,0 +1,66 @@
1
+ export interface AbbacchioClientOptions {
2
+ /** Server URL endpoint */
3
+ url?: string;
4
+ /** Secret key for encryption. If provided, logs will be encrypted before sending */
5
+ secretKey?: string;
6
+ /** Channel/app name for multi-app support. Defaults to 'default' */
7
+ channel?: string;
8
+ /** Number of logs to batch before sending. Defaults to 10 */
9
+ batchSize?: number;
10
+ /** Interval in ms between flushes. Defaults to 1000 */
11
+ interval?: number;
12
+ /** Additional headers to send with requests */
13
+ headers?: Record<string, string>;
14
+ }
15
+ /**
16
+ * Shared HTTP client for all Abbacchio transports.
17
+ * Handles batching, encryption, and HTTP communication.
18
+ */
19
+ export declare class AbbacchioClient {
20
+ private url;
21
+ private secretKey?;
22
+ private channel?;
23
+ private batchSize;
24
+ private interval;
25
+ private headers;
26
+ private buffer;
27
+ private timer;
28
+ constructor(options?: AbbacchioClientOptions);
29
+ /**
30
+ * Process a log entry (encrypt if secretKey is provided)
31
+ */
32
+ private processLog;
33
+ /**
34
+ * Add a log to the buffer and trigger send if needed
35
+ */
36
+ add(log: unknown): void;
37
+ /**
38
+ * Add multiple logs at once
39
+ */
40
+ addBatch(logs: unknown[]): void;
41
+ /**
42
+ * Send logs immediately without batching
43
+ */
44
+ send(logs: unknown[]): Promise<void>;
45
+ /**
46
+ * Schedule a send after the interval
47
+ */
48
+ private scheduleSend;
49
+ /**
50
+ * Flush the buffer and send to server
51
+ */
52
+ flush(): Promise<void>;
53
+ /**
54
+ * Send logs to the Abbacchio server
55
+ */
56
+ private sendToServer;
57
+ /**
58
+ * Close the client and flush any remaining logs
59
+ */
60
+ close(): Promise<void>;
61
+ }
62
+ /**
63
+ * Create a new Abbacchio client instance
64
+ */
65
+ export declare function createClient(options?: AbbacchioClientOptions): AbbacchioClient;
66
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC,0BAA0B;IAC1B,GAAG,CA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ared HTTP client for all Abbacchio transports.
4
+ * Handles batching, encryption, and HTTP communication.
5
+ */
6
+ export class AbbacchioClient {
7
+ url;
8
+ secretKey;
9
+ channel;
10
+ batchSize;
11
+ interval;
12
+ headers;
13
+ buffer = [];
14
+ timer = null;
15
+ constructor(options = {}) {
16
+ this.url = options.url || "http://localhost:4000/api/logs";
17
+ this.secretKey = options.secretKey;
18
+ this.channel = options.channel;
19
+ this.batchSize = options.batchSize || 10;
20
+ this.interval = options.interval || 1000;
21
+ this.headers = options.headers || {};
22
+ }
23
+ /**
24
+ * Process a log entry (encrypt if secretKey is provided)
25
+ */
26
+ processLog(log) {
27
+ if (this.secretKey) {
28
+ return { encrypted: encrypt(JSON.stringify(log), this.secretKey) };
29
+ }
30
+ return log;
31
+ }
32
+ /**
33
+ * Add a log to the buffer and trigger send if needed
34
+ */
35
+ add(log) {
36
+ this.buffer.push(this.processLog(log));
37
+ if (this.buffer.length >= this.batchSize) {
38
+ this.flush();
39
+ }
40
+ else {
41
+ this.scheduleSend();
42
+ }
43
+ }
44
+ /**
45
+ * Add multiple logs at once
46
+ */
47
+ addBatch(logs) {
48
+ for (const log of logs) {
49
+ this.buffer.push(this.processLog(log));
50
+ }
51
+ if (this.buffer.length >= this.batchSize) {
52
+ this.flush();
53
+ }
54
+ else {
55
+ this.scheduleSend();
56
+ }
57
+ }
58
+ /**
59
+ * Send logs immediately without batching
60
+ */
61
+ async send(logs) {
62
+ const processedLogs = logs.map(log => this.processLog(log));
63
+ await this.sendToServer(processedLogs);
64
+ }
65
+ /**
66
+ * Schedule a send after the interval
67
+ */
68
+ scheduleSend() {
69
+ if (this.timer)
70
+ return;
71
+ this.timer = setTimeout(() => {
72
+ this.timer = null;
73
+ this.flush();
74
+ }, this.interval);
75
+ }
76
+ /**
77
+ * Flush the buffer and send to server
78
+ */
79
+ async flush() {
80
+ if (this.buffer.length === 0)
81
+ return;
82
+ const toSend = this.buffer;
83
+ this.buffer = [];
84
+ await this.sendToServer(toSend);
85
+ }
86
+ /**
87
+ * Send logs to the Abbacchio server
88
+ */
89
+ async sendToServer(logs) {
90
+ try {
91
+ await fetch(this.url, {
92
+ method: "POST",
93
+ headers: {
94
+ "Content-Type": "application/json",
95
+ "X-Encrypted": this.secretKey ? "true" : "false",
96
+ ...(this.channel ? { "X-Channel": this.channel } : {}),
97
+ ...this.headers,
98
+ },
99
+ body: JSON.stringify({ logs }),
100
+ });
101
+ }
102
+ catch {
103
+ // Silently fail - don't break the app if Abbacchio server is down
104
+ }
105
+ }
106
+ /**
107
+ * Close the client and flush any remaining logs
108
+ */
109
+ async close() {
110
+ if (this.timer) {
111
+ clearTimeout(this.timer);
112
+ this.timer = null;
113
+ }
114
+ await this.flush();
115
+ }
116
+ }
117
+ /**
118
+ * Create a new Abbacchio client instance
119
+ */
120
+ export function createClient(options) {
121
+ return new AbbacchioClient(options);
122
+ }
123
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAiBvC;;;GAGG;AACH,MAAM,OAAO,eAAe;IAClB,GAAG,CAAS;IACZ,SAAS,CAAU;IACnB,OAAO,CAAU;IACjB,SAAS,CAAS;IAClB,QAAQ,CAAS;IACjB,OAAO,CAAyB;IAEhC,MAAM,GAAc,EAAE,CAAC;IACvB,KAAK,GAAyC,IAAI,CAAC;IAE3D,YAAY,UAAkC,EAAE;QAC9C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,gCAAgC,CAAC;QAC3D,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI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IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAAgC;IAC3D,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Generate a cryptographically secure random key for encryption.
3
+ * Use this on the server/producer side to create a key for each channel.
4
+ *
5
+ * @param length - Length of the key in bytes (default: 32 for 256-bit key)
6
+ * @returns A hex-encoded random key
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { generateKey } from "@abbacchio/client";
11
+ *
12
+ * // Generate a key for a channel
13
+ * const key = generateKey();
14
+ *
15
+ * // Use in pino transport
16
+ * const logger = pino({
17
+ * transport: {
18
+ * target: "@abbacchio/client/transports/pino",
19
+ * options: {
20
+ * url: "http://localhost:4000/api/logs",
21
+ * channel: "my-app",
22
+ * secretKey: key,
23
+ * },
24
+ * },
25
+ * });
26
+ *
27
+ * // Share the dashboard URL with the key
28
+ * console.log(`Dashboard: http://localhost:4000?channel=my-app&key=${key}`);
29
+ * ```
30
+ */
31
+ export declare function generateKey(length?: number): string;
32
+ /**
33
+ * Encrypt data with AES-256-GCM
34
+ * Returns base64 encoded string: salt:iv:authTag:ciphertext
35
+ */
36
+ export declare function encrypt(data: string, secretKey: string): string;
37
+ /**
38
+ * Decrypt data encrypted with encrypt()
39
+ */
40
+ export declare function decrypt(encryptedData: string, secretKey: string): string;
41
+ /**
42
+ * Encrypt a log object
43
+ */
44
+ export declare function encryptLog(log: unknown, secretKey: string): {
45
+ encrypted: string;
46
+ };
47
+ /**
48
+ * Decrypt an encrypted log
49
+ */
50
+ export declare function decryptLog<T = unknown>(encryptedLog: {
51
+ encrypted: string;
52
+ }, secretKey: string): T;
53
+ //# sourceMappingURL=encrypt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../src/encrypt.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,WAAW,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAEvD;AAeD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAe/D;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAsBxE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAGjF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,YAAY,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,CAGjG"}
@@ -0,0 +1,97 @@
1
+ import { createCipheriv, createDecipheriv, randomBytes, pbkdf2Sync } from "crypto";
2
+ /**
3
+ * Generate a cryptographically secure random key for encryption.
4
+ * Use this on the server/producer side to create a key for each channel.
5
+ *
6
+ * @param length - Length of the key in bytes (default: 32 for 256-bit key)
7
+ * @returns A hex-encoded random key
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { generateKey } from "@abbacchio/client";
12
+ *
13
+ * // Generate a key for a channel
14
+ * const key = generateKey();
15
+ *
16
+ * // Use in pino transport
17
+ * const logger = pino({
18
+ * transport: {
19
+ * target: "@abbacchio/client/transports/pino",
20
+ * options: {
21
+ * url: "http://localhost:4000/api/logs",
22
+ * channel: "my-app",
23
+ * secretKey: key,
24
+ * },
25
+ * },
26
+ * });
27
+ *
28
+ * // Share the dashboard URL with the key
29
+ * console.log(`Dashboard: http://localhost:4000?channel=my-app&key=${key}`);
30
+ * ```
31
+ */
32
+ export function generateKey(length = 32) {
33
+ return randomBytes(length).toString("hex");
34
+ }
35
+ const ALGORITHM = "aes-256-gcm";
36
+ const IV_LENGTH = 16;
37
+ const AUTH_TAG_LENGTH = 16;
38
+ const SALT_LENGTH = 32;
39
+ const PBKDF2_ITERATIONS = 100000;
40
+ /**
41
+ * Derive a key from a password using PBKDF2 (browser-compatible)
42
+ */
43
+ function deriveKey(password, salt) {
44
+ return pbkdf2Sync(password, salt, PBKDF2_ITERATIONS, 32, "sha256");
45
+ }
46
+ /**
47
+ * Encrypt data with AES-256-GCM
48
+ * Returns base64 encoded string: salt:iv:authTag:ciphertext
49
+ */
50
+ export function encrypt(data, secretKey) {
51
+ const salt = randomBytes(SALT_LENGTH);
52
+ const key = deriveKey(secretKey, salt);
53
+ const iv = randomBytes(IV_LENGTH);
54
+ const cipher = createCipheriv(ALGORITHM, key, iv);
55
+ const encrypted = Buffer.concat([
56
+ cipher.update(data, "utf8"),
57
+ cipher.final(),
58
+ ]);
59
+ const authTag = cipher.getAuthTag();
60
+ // Combine: salt + iv + authTag + ciphertext
61
+ const combined = Buffer.concat([salt, iv, authTag, encrypted]);
62
+ return combined.toString("base64");
63
+ }
64
+ /**
65
+ * Decrypt data encrypted with encrypt()
66
+ */
67
+ export function decrypt(encryptedData, secretKey) {
68
+ const combined = Buffer.from(encryptedData, "base64");
69
+ // Extract components
70
+ const salt = combined.subarray(0, SALT_LENGTH);
71
+ const iv = combined.subarray(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
72
+ const authTag = combined.subarray(SALT_LENGTH + IV_LENGTH, SALT_LENGTH + IV_LENGTH + AUTH_TAG_LENGTH);
73
+ const ciphertext = combined.subarray(SALT_LENGTH + IV_LENGTH + AUTH_TAG_LENGTH);
74
+ const key = deriveKey(secretKey, salt);
75
+ const decipher = createDecipheriv(ALGORITHM, key, iv);
76
+ decipher.setAuthTag(authTag);
77
+ const decrypted = Buffer.concat([
78
+ decipher.update(ciphertext),
79
+ decipher.final(),
80
+ ]);
81
+ return decrypted.toString("utf8");
82
+ }
83
+ /**
84
+ * Encrypt a log object
85
+ */
86
+ export function encryptLog(log, secretKey) {
87
+ const jsonStr = JSON.stringify(log);
88
+ return { encrypted: encrypt(jsonStr, secretKey) };
89
+ }
90
+ /**
91
+ * Decrypt an encrypted log
92
+ */
93
+ export function decryptLog(encryptedLog, secretKey) {
94
+ const jsonStr = decrypt(encryptedLog.encrypted, secretKey);
95
+ return JSON.parse(jsonStr);
96
+ }
97
+ //# sourceMappingURL=encrypt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../src/encrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE;IAC7C,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC;;GAEG;AACH,SAAS,SAAS,CAAC,QAAgB,EAAE,IAAY;IAC/C,OAAO,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;AACrE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,SAAiB;IACrD,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACtC,MAAM,GAAG,GAAG,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC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C,CAAC;IACtD,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAE7B,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;QAC9B,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;QAC3B,QAAQ,CAAC,KAAK,EAAE;KACjB,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,SAAiB;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAc,YAAmC,EAAE,SAAiB;IAC5F,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC3D,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,12 @@
1
+ export { AbbacchioClient, createClient } from "./client.js";
2
+ export type { AbbacchioClientOptions } from "./client.js";
3
+ export { generateKey, encrypt, decrypt, encryptLog, decryptLog } from "./encrypt.js";
4
+ export { default as pinoTransport } from "./transports/pino.js";
5
+ export type { PinoTransportOptions } from "./transports/pino.js";
6
+ export { winstonTransport, AbbacchioWinstonTransport } from "./transports/winston.js";
7
+ export type { WinstonTransportOptions } from "./transports/winston.js";
8
+ export { bunyanStream, AbbacchioBunyanStream } from "./transports/bunyan.js";
9
+ export type { BunyanStreamOptions } from "./transports/bunyan.js";
10
+ export { interceptConsole, restoreConsole, getActiveClient } from "./transports/console.js";
11
+ export type { ConsoleInterceptorOptions } from "./transports/console.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChE,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACtF,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC7E,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC5F,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // Core client
2
+ export { AbbacchioClient, createClient } from "./client.js";
3
+ // Encryption utilities
4
+ export { generateKey, encrypt, decrypt, encryptLog, decryptLog } from "./encrypt.js";
5
+ // Re-export transports for convenience
6
+ export { default as pinoTransport } from "./transports/pino.js";
7
+ export { winstonTransport, AbbacchioWinstonTransport } from "./transports/winston.js";
8
+ export { bunyanStream, AbbacchioBunyanStream } from "./transports/bunyan.js";
9
+ export { interceptConsole, restoreConsole, getActiveClient } from "./transports/console.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG5D,uBAAuB;AACvB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAErF,uCAAuC;AACvC,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAGtF,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAG7E,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { Writable } from "stream";
2
+ import { type AbbacchioClientOptions } from "../client.js";
3
+ export interface BunyanStreamOptions extends AbbacchioClientOptions {
4
+ /** Bunyan log level (optional) */
5
+ level?: number | string;
6
+ }
7
+ /**
8
+ * Bunyan stream for Abbacchio.
9
+ * Implements the Node.js Writable stream interface for Bunyan.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import bunyan from "bunyan";
14
+ * import { bunyanStream } from "@abbacchio/client/transports/bunyan";
15
+ *
16
+ * const logger = bunyan.createLogger({
17
+ * name: "myapp",
18
+ * streams: [
19
+ * { stream: process.stdout },
20
+ * bunyanStream({
21
+ * url: "http://localhost:4000/api/logs",
22
+ * channel: "my-app",
23
+ * secretKey: "optional-encryption-key",
24
+ * }),
25
+ * ],
26
+ * });
27
+ *
28
+ * logger.info("Hello from Bunyan!");
29
+ * ```
30
+ */
31
+ export declare class AbbacchioBunyanStream extends Writable {
32
+ private client;
33
+ level?: number | string;
34
+ constructor(opts?: BunyanStreamOptions);
35
+ /**
36
+ * Writable stream _write method - called for each log entry
37
+ */
38
+ _write(chunk: Record<string, unknown>, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
39
+ /**
40
+ * Transform Bunyan log format to a normalized format
41
+ */
42
+ private transformLog;
43
+ /**
44
+ * Close the stream
45
+ */
46
+ _final(callback: (error?: Error | null) => void): void;
47
+ }
48
+ /**
49
+ * Factory function to create a Bunyan stream
50
+ * Returns an object with stream and optional level for Bunyan's streams array
51
+ */
52
+ export declare function bunyanStream(opts?: BunyanStreamOptions): {
53
+ stream: AbbacchioBunyanStream;
54
+ level?: number | string;
55
+ type: "raw";
56
+ };
57
+ export default bunyanStream;
58
+ //# sourceMappingURL=bunyan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bunyan.d.ts","sourceRoot":"","sources":["../../src/transports/bunyan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE5E,MAAM,WAAW,mBAAoB,SAAQ,sBAAsB;IACjE,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;IACjD,OAAO,CAAC,MAAM,CAAkB;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;gBAEnB,IAAI,GAAE,mBAAwB;IAM1C;;OAEG;IACH,MAAM,CACJ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,SAAS,EAAE,cAAc,EACzB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GACvC,IAAI;IAWP;;OAEG;IACH,OAAO,CAAC,YAAY;IAcpB;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;CAGvD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAOhI;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { Writable } from "stream";
2
+ import { AbbacchioClient } from "../client.js";
3
+ /**
4
+ * Bunyan stream for Abbacchio.
5
+ * Implements the Node.js Writable stream interface for Bunyan.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import bunyan from "bunyan";
10
+ * import { bunyanStream } from "@abbacchio/client/transports/bunyan";
11
+ *
12
+ * const logger = bunyan.createLogger({
13
+ * name: "myapp",
14
+ * streams: [
15
+ * { stream: process.stdout },
16
+ * bunyanStream({
17
+ * url: "http://localhost:4000/api/logs",
18
+ * channel: "my-app",
19
+ * secretKey: "optional-encryption-key",
20
+ * }),
21
+ * ],
22
+ * });
23
+ *
24
+ * logger.info("Hello from Bunyan!");
25
+ * ```
26
+ */
27
+ export class AbbacchioBunyanStream extends Writable {
28
+ client;
29
+ level;
30
+ constructor(opts = {}) {
31
+ super({ objectMode: true });
32
+ this.client = new AbbacchioClient(opts);
33
+ this.level = opts.level;
34
+ }
35
+ /**
36
+ * Writable stream _write method - called for each log entry
37
+ */
38
+ _write(chunk, _encoding, callback) {
39
+ try {
40
+ // Transform Bunyan format to Abbacchio format
41
+ const log = this.transformLog(chunk);
42
+ this.client.add(log);
43
+ callback();
44
+ }
45
+ catch (err) {
46
+ callback(err);
47
+ }
48
+ }
49
+ /**
50
+ * Transform Bunyan log format to a normalized format
51
+ */
52
+ transformLog(record) {
53
+ const { name, hostname, pid, level, msg, time, v, ...rest } = record;
54
+ return {
55
+ level: level,
56
+ msg,
57
+ time: time ? new Date(time).getTime() : Date.now(),
58
+ name,
59
+ hostname,
60
+ pid,
61
+ ...rest,
62
+ };
63
+ }
64
+ /**
65
+ * Close the stream
66
+ */
67
+ _final(callback) {
68
+ this.client.close().then(() => callback()).catch(callback);
69
+ }
70
+ }
71
+ /**
72
+ * Factory function to create a Bunyan stream
73
+ * Returns an object with stream and optional level for Bunyan's streams array
74
+ */
75
+ export function bunyanStream(opts) {
76
+ const stream = new AbbacchioBunyanStream(opts);
77
+ return {
78
+ stream,
79
+ level: opts?.level,
80
+ type: "raw",
81
+ };
82
+ }
83
+ export default bunyanStream;
84
+ //# sourceMappingURL=bunyan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bunyan.js","sourceRoot":"","sources":["../../src/transports/bunyan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,eAAe,EAA+B,MAAM,cAAc,CAAC;AAO5E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,qBAAsB,SAAQ,QAAQ;IACzC,MAAM,CAAkB;IACzB,KAAK,CAAmB;IAE/B,YAAY,OAA4B,EAAE;QACxC,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,MAAM,CACJ,KAA8B,EAC9B,SAAyB,EACzB,QAAwC;QAExC,IAAI,CAAC;YACH,8CAA8C;YAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,QAAQ,EAAE,CAAC;QACb,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CAAC,GAAY,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,MAA+B;QAClD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAErE,OAAO;YACL,KAAK,EAAE,KAAe;YACtB,GAAG;YACH,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAc,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAC5D,IAAI;YACJ,QAAQ;YACR,GAAG;YACH,GAAG,IAAI;SACR,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAwC;QAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAA0B;IACrD,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC/C,OAAO;QACL,MAAM;QACN,KAAK,EAAE,IAAI,EAAE,KAAK;QAClB,IAAI,EAAE,KAAK;KACZ,CAAC;AACJ,CAAC;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { AbbacchioClient, type AbbacchioClientOptions } from "../client.js";
2
+ export interface ConsoleInterceptorOptions extends AbbacchioClientOptions {
3
+ /** Which console methods to intercept. Defaults to all. */
4
+ methods?: ("log" | "info" | "warn" | "error" | "debug")[];
5
+ /** Whether to still output to original console. Defaults to true. */
6
+ passthrough?: boolean;
7
+ }
8
+ /**
9
+ * Start intercepting console calls
10
+ */
11
+ export declare function interceptConsole(opts?: ConsoleInterceptorOptions): void;
12
+ /**
13
+ * Stop intercepting console calls and restore original behavior
14
+ */
15
+ export declare function restoreConsole(): void;
16
+ /**
17
+ * Get the active client (for testing)
18
+ */
19
+ export declare function getActiveClient(): AbbacchioClient | null;
20
+ export default interceptConsole;
21
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/transports/console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE5E,MAAM,WAAW,yBAA0B,SAAQ,sBAAsB;IACvE,2DAA2D;IAC3D,OAAO,CAAC,EAAE,CAAC,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC;IAC1D,qEAAqE;IACrE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AA0FD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,yBAA8B,GAAG,IAAI,CAoB3E;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAYrC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,eAAe,GAAG,IAAI,CAExD;AAED,eAAe,gBAAgB,CAAC"}