@abbacchio/browser-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.
- package/README.md +220 -0
- package/dist/auto.d.ts +37 -0
- package/dist/auto.d.ts.map +1 -0
- package/dist/auto.js +41 -0
- package/dist/auto.js.map +1 -0
- package/dist/client.d.ts +74 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +132 -0
- package/dist/client.js.map +1 -0
- package/dist/console.d.ts +61 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +257 -0
- package/dist/console.js.map +1 -0
- package/dist/crypto.d.ts +35 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +96 -0
- package/dist/crypto.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +98 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +126 -0
- package/dist/logger.js.map +1 -0
- package/dist/react/AbbacchioProvider.d.ts +83 -0
- package/dist/react/AbbacchioProvider.d.ts.map +1 -0
- package/dist/react/AbbacchioProvider.js +113 -0
- package/dist/react/AbbacchioProvider.js.map +1 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +5 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +64 -0
package/dist/console.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console interceptor for Abbacchio
|
|
3
|
+
* Intercepts console.log, console.error, etc. and sends them to Abbacchio server
|
|
4
|
+
*/
|
|
5
|
+
import { AbbacchioClient } from './client.js';
|
|
6
|
+
// Map console methods to Pino log levels
|
|
7
|
+
const LEVEL_MAP = {
|
|
8
|
+
debug: 20,
|
|
9
|
+
log: 30,
|
|
10
|
+
info: 30,
|
|
11
|
+
warn: 40,
|
|
12
|
+
error: 50,
|
|
13
|
+
};
|
|
14
|
+
// Store original console methods
|
|
15
|
+
const originalConsole = {
|
|
16
|
+
log: console.log.bind(console),
|
|
17
|
+
info: console.info.bind(console),
|
|
18
|
+
warn: console.warn.bind(console),
|
|
19
|
+
error: console.error.bind(console),
|
|
20
|
+
debug: console.debug.bind(console),
|
|
21
|
+
};
|
|
22
|
+
let client = null;
|
|
23
|
+
let options = {};
|
|
24
|
+
let isIntercepting = false;
|
|
25
|
+
/**
|
|
26
|
+
* Safely serialize a value for logging
|
|
27
|
+
*/
|
|
28
|
+
function safeSerialize(value, seen = new WeakSet()) {
|
|
29
|
+
if (value === null)
|
|
30
|
+
return null;
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (typeof value === 'function') {
|
|
34
|
+
return `[Function: ${value.name || 'anonymous'}]`;
|
|
35
|
+
}
|
|
36
|
+
if (typeof value !== 'object') {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
// Handle circular references
|
|
40
|
+
if (seen.has(value)) {
|
|
41
|
+
return '[Circular]';
|
|
42
|
+
}
|
|
43
|
+
seen.add(value);
|
|
44
|
+
// Handle special objects
|
|
45
|
+
if (value instanceof Error) {
|
|
46
|
+
return {
|
|
47
|
+
__type: 'Error',
|
|
48
|
+
name: value.name,
|
|
49
|
+
message: value.message,
|
|
50
|
+
stack: value.stack,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (value instanceof Date) {
|
|
54
|
+
return value.toISOString();
|
|
55
|
+
}
|
|
56
|
+
if (value instanceof RegExp) {
|
|
57
|
+
return value.toString();
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
return value.map(item => safeSerialize(item, seen));
|
|
61
|
+
}
|
|
62
|
+
// Handle DOM elements
|
|
63
|
+
if (typeof Element !== 'undefined' && value instanceof Element) {
|
|
64
|
+
return `[Element: ${value.tagName.toLowerCase()}${value.id ? '#' + value.id : ''}]`;
|
|
65
|
+
}
|
|
66
|
+
// Handle plain objects
|
|
67
|
+
const result = {};
|
|
68
|
+
for (const key of Object.keys(value)) {
|
|
69
|
+
try {
|
|
70
|
+
result[key] = safeSerialize(value[key], seen);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
result[key] = '[Unserializable]';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Format console arguments into a message and extra data
|
|
80
|
+
*/
|
|
81
|
+
function formatArgs(args) {
|
|
82
|
+
const serialized = args.map(arg => safeSerialize(arg));
|
|
83
|
+
const msgParts = [];
|
|
84
|
+
const dataObjects = [];
|
|
85
|
+
for (const item of serialized) {
|
|
86
|
+
if (typeof item === 'string') {
|
|
87
|
+
msgParts.push(item);
|
|
88
|
+
}
|
|
89
|
+
else if (typeof item === 'number' || typeof item === 'boolean') {
|
|
90
|
+
msgParts.push(String(item));
|
|
91
|
+
}
|
|
92
|
+
else if (item === null) {
|
|
93
|
+
msgParts.push('null');
|
|
94
|
+
}
|
|
95
|
+
else if (item === undefined) {
|
|
96
|
+
msgParts.push('undefined');
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
dataObjects.push(item);
|
|
100
|
+
msgParts.push(JSON.stringify(item));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
msg: msgParts.join(' '),
|
|
105
|
+
data: dataObjects.length > 0 ? (dataObjects.length === 1 ? dataObjects[0] : dataObjects) : null,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get caller location from stack trace
|
|
110
|
+
*/
|
|
111
|
+
function getCallerLocation() {
|
|
112
|
+
if (!options.captureStackTrace)
|
|
113
|
+
return null;
|
|
114
|
+
try {
|
|
115
|
+
const stack = new Error().stack;
|
|
116
|
+
if (!stack)
|
|
117
|
+
return null;
|
|
118
|
+
const lines = stack.split('\n');
|
|
119
|
+
// Find the first line that's not from this file
|
|
120
|
+
for (const line of lines) {
|
|
121
|
+
if (line.includes('console.ts') ||
|
|
122
|
+
line.includes('createInterceptor') ||
|
|
123
|
+
line.includes('at console.') ||
|
|
124
|
+
line.includes('at Object.') ||
|
|
125
|
+
line.trim() === 'Error') {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const match = line.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
|
|
129
|
+
if (match) {
|
|
130
|
+
return {
|
|
131
|
+
function: match[1] || 'anonymous',
|
|
132
|
+
file: match[2],
|
|
133
|
+
line: parseInt(match[3], 10),
|
|
134
|
+
column: parseInt(match[4], 10),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Ignore errors
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a log entry from console arguments
|
|
146
|
+
*/
|
|
147
|
+
function createLogEntry(method, args) {
|
|
148
|
+
const { msg, data } = formatArgs(args);
|
|
149
|
+
const location = getCallerLocation();
|
|
150
|
+
const entry = {
|
|
151
|
+
level: LEVEL_MAP[method] || 30,
|
|
152
|
+
time: Date.now(),
|
|
153
|
+
name: options.appName || 'browser',
|
|
154
|
+
msg,
|
|
155
|
+
};
|
|
156
|
+
if (options.includeUrl !== false && typeof window !== 'undefined') {
|
|
157
|
+
entry.url = window.location.href;
|
|
158
|
+
}
|
|
159
|
+
if (options.includeUserAgent && typeof navigator !== 'undefined') {
|
|
160
|
+
entry.userAgent = navigator.userAgent;
|
|
161
|
+
}
|
|
162
|
+
if (location) {
|
|
163
|
+
entry.caller = location;
|
|
164
|
+
}
|
|
165
|
+
if (data) {
|
|
166
|
+
if (typeof data === 'object' && !Array.isArray(data)) {
|
|
167
|
+
Object.assign(entry, data);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
entry.data = data;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return entry;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create an interceptor for a console method
|
|
177
|
+
*/
|
|
178
|
+
function createInterceptor(method) {
|
|
179
|
+
return function (...args) {
|
|
180
|
+
// Pass through to original console if enabled
|
|
181
|
+
if (options.passthrough !== false) {
|
|
182
|
+
originalConsole[method](...args);
|
|
183
|
+
}
|
|
184
|
+
// Send to Abbacchio if intercepting
|
|
185
|
+
if (isIntercepting && client) {
|
|
186
|
+
try {
|
|
187
|
+
const entry = createLogEntry(method, args);
|
|
188
|
+
client.add(entry);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// Don't let logging errors break the app
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Start intercepting console methods
|
|
198
|
+
*/
|
|
199
|
+
export function interceptConsole(opts = {}) {
|
|
200
|
+
if (isIntercepting) {
|
|
201
|
+
// Update options and client config
|
|
202
|
+
options = { ...options, ...opts };
|
|
203
|
+
if (client) {
|
|
204
|
+
client.configure(opts);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
options = opts;
|
|
209
|
+
client = new AbbacchioClient(opts);
|
|
210
|
+
isIntercepting = true;
|
|
211
|
+
// Replace console methods
|
|
212
|
+
console.log = createInterceptor('log');
|
|
213
|
+
console.info = createInterceptor('info');
|
|
214
|
+
console.warn = createInterceptor('warn');
|
|
215
|
+
console.error = createInterceptor('error');
|
|
216
|
+
console.debug = createInterceptor('debug');
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Stop intercepting console methods
|
|
220
|
+
*/
|
|
221
|
+
export function stopInterceptConsole() {
|
|
222
|
+
if (!isIntercepting)
|
|
223
|
+
return;
|
|
224
|
+
isIntercepting = false;
|
|
225
|
+
// Restore original console methods
|
|
226
|
+
console.log = originalConsole.log;
|
|
227
|
+
console.info = originalConsole.info;
|
|
228
|
+
console.warn = originalConsole.warn;
|
|
229
|
+
console.error = originalConsole.error;
|
|
230
|
+
console.debug = originalConsole.debug;
|
|
231
|
+
// Flush and close client
|
|
232
|
+
if (client) {
|
|
233
|
+
client.close();
|
|
234
|
+
client = null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Flush any buffered logs
|
|
239
|
+
*/
|
|
240
|
+
export async function flushConsole() {
|
|
241
|
+
if (client) {
|
|
242
|
+
await client.flush();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Check if console is currently being intercepted
|
|
247
|
+
*/
|
|
248
|
+
export function isConsoleIntercepted() {
|
|
249
|
+
return isIntercepting;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get the original console methods (for internal use when passthrough is false)
|
|
253
|
+
*/
|
|
254
|
+
export function getOriginalConsole() {
|
|
255
|
+
return originalConsole;
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAA8C,MAAM,aAAa,CAAC;AAe1F,yCAAyC;AACzC,MAAM,SAAS,GAA2B;IACxC,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,iCAAiC;AACjC,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;IAC9B,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAChC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC,KAAK,CA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kBAAkB;IAChC,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible AES-256-GCM encryption/decryption
|
|
3
|
+
* Uses Web Crypto API with PBKDF2 key derivation
|
|
4
|
+
*
|
|
5
|
+
* Wire format: base64(salt + iv + authTag + ciphertext)
|
|
6
|
+
* - salt: 32 bytes (for PBKDF2 key derivation)
|
|
7
|
+
* - iv: 16 bytes (initialization vector)
|
|
8
|
+
* - authTag: 16 bytes (GCM authentication tag)
|
|
9
|
+
* - ciphertext: variable length
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Encrypt data using AES-256-GCM with PBKDF2 key derivation
|
|
13
|
+
* @param data - The string data to encrypt
|
|
14
|
+
* @param secretKey - The encryption password/key
|
|
15
|
+
* @returns Base64-encoded encrypted data
|
|
16
|
+
*/
|
|
17
|
+
export declare function encrypt(data: string, secretKey: string): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Decrypt data that was encrypted with the encrypt function
|
|
20
|
+
* @param encryptedData - Base64-encoded encrypted data
|
|
21
|
+
* @param secretKey - The encryption password/key
|
|
22
|
+
* @returns Decrypted string
|
|
23
|
+
*/
|
|
24
|
+
export declare function decrypt(encryptedData: string, secretKey: string): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if Web Crypto API is available
|
|
27
|
+
*/
|
|
28
|
+
export declare function isCryptoAvailable(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a random encryption key
|
|
31
|
+
* @param length - Length in bytes (default: 32)
|
|
32
|
+
* @returns Base64url-encoded random key
|
|
33
|
+
*/
|
|
34
|
+
export declare function generateKey(length?: number): string;
|
|
35
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAuCH;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B9E;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA6BvF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAK,GAAG,MAAM,CAK/C"}
|
package/dist/crypto.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible AES-256-GCM encryption/decryption
|
|
3
|
+
* Uses Web Crypto API with PBKDF2 key derivation
|
|
4
|
+
*
|
|
5
|
+
* Wire format: base64(salt + iv + authTag + ciphertext)
|
|
6
|
+
* - salt: 32 bytes (for PBKDF2 key derivation)
|
|
7
|
+
* - iv: 16 bytes (initialization vector)
|
|
8
|
+
* - authTag: 16 bytes (GCM authentication tag)
|
|
9
|
+
* - ciphertext: variable length
|
|
10
|
+
*/
|
|
11
|
+
const ALGORITHM = 'AES-GCM';
|
|
12
|
+
const SALT_LENGTH = 32;
|
|
13
|
+
const IV_LENGTH = 16;
|
|
14
|
+
const AUTH_TAG_LENGTH = 16;
|
|
15
|
+
const PBKDF2_ITERATIONS = 100000;
|
|
16
|
+
/**
|
|
17
|
+
* Derive a key from password using PBKDF2
|
|
18
|
+
*/
|
|
19
|
+
async function deriveKey(password, salt, usage) {
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
const passwordKey = await crypto.subtle.importKey('raw', encoder.encode(password), 'PBKDF2', false, ['deriveKey']);
|
|
22
|
+
return crypto.subtle.deriveKey({
|
|
23
|
+
name: 'PBKDF2',
|
|
24
|
+
salt: salt.buffer,
|
|
25
|
+
iterations: PBKDF2_ITERATIONS,
|
|
26
|
+
hash: 'SHA-256',
|
|
27
|
+
}, passwordKey, { name: ALGORITHM, length: 256 }, false, [usage]);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encrypt data using AES-256-GCM with PBKDF2 key derivation
|
|
31
|
+
* @param data - The string data to encrypt
|
|
32
|
+
* @param secretKey - The encryption password/key
|
|
33
|
+
* @returns Base64-encoded encrypted data
|
|
34
|
+
*/
|
|
35
|
+
export async function encrypt(data, secretKey) {
|
|
36
|
+
const encoder = new TextEncoder();
|
|
37
|
+
const salt = crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
|
|
38
|
+
const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));
|
|
39
|
+
const key = await deriveKey(secretKey, salt, 'encrypt');
|
|
40
|
+
// Web Crypto AES-GCM encrypt returns ciphertext with authTag appended
|
|
41
|
+
const encrypted = await crypto.subtle.encrypt({ name: ALGORITHM, iv }, key, encoder.encode(data));
|
|
42
|
+
const encryptedArray = new Uint8Array(encrypted);
|
|
43
|
+
// Split ciphertext and authTag (tag is last 16 bytes)
|
|
44
|
+
const ciphertext = encryptedArray.slice(0, -AUTH_TAG_LENGTH);
|
|
45
|
+
const authTag = encryptedArray.slice(-AUTH_TAG_LENGTH);
|
|
46
|
+
// Combine in wire format: salt + iv + authTag + ciphertext
|
|
47
|
+
const combined = new Uint8Array(SALT_LENGTH + IV_LENGTH + AUTH_TAG_LENGTH + ciphertext.length);
|
|
48
|
+
combined.set(salt, 0);
|
|
49
|
+
combined.set(iv, SALT_LENGTH);
|
|
50
|
+
combined.set(authTag, SALT_LENGTH + IV_LENGTH);
|
|
51
|
+
combined.set(ciphertext, SALT_LENGTH + IV_LENGTH + AUTH_TAG_LENGTH);
|
|
52
|
+
// Convert to base64
|
|
53
|
+
return btoa(String.fromCharCode(...combined));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Decrypt data that was encrypted with the encrypt function
|
|
57
|
+
* @param encryptedData - Base64-encoded encrypted data
|
|
58
|
+
* @param secretKey - The encryption password/key
|
|
59
|
+
* @returns Decrypted string
|
|
60
|
+
*/
|
|
61
|
+
export async function decrypt(encryptedData, secretKey) {
|
|
62
|
+
// Decode base64
|
|
63
|
+
const combined = Uint8Array.from(atob(encryptedData), c => c.charCodeAt(0));
|
|
64
|
+
// Extract components
|
|
65
|
+
const salt = combined.slice(0, SALT_LENGTH);
|
|
66
|
+
const iv = combined.slice(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
|
|
67
|
+
const authTag = combined.slice(SALT_LENGTH + IV_LENGTH, SALT_LENGTH + IV_LENGTH + AUTH_TAG_LENGTH);
|
|
68
|
+
const ciphertext = combined.slice(SALT_LENGTH + IV_LENGTH + AUTH_TAG_LENGTH);
|
|
69
|
+
// Combine ciphertext and authTag for WebCrypto (it expects them together)
|
|
70
|
+
const ciphertextWithTag = new Uint8Array(ciphertext.length + authTag.length);
|
|
71
|
+
ciphertextWithTag.set(ciphertext);
|
|
72
|
+
ciphertextWithTag.set(authTag, ciphertext.length);
|
|
73
|
+
// Derive key
|
|
74
|
+
const key = await deriveKey(secretKey, salt, 'decrypt');
|
|
75
|
+
// Decrypt
|
|
76
|
+
const decrypted = await crypto.subtle.decrypt({ name: ALGORITHM, iv }, key, ciphertextWithTag);
|
|
77
|
+
return new TextDecoder().decode(decrypted);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if Web Crypto API is available
|
|
81
|
+
*/
|
|
82
|
+
export function isCryptoAvailable() {
|
|
83
|
+
return typeof crypto !== 'undefined' && typeof crypto.subtle !== 'undefined';
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generate a random encryption key
|
|
87
|
+
* @param length - Length in bytes (default: 32)
|
|
88
|
+
* @returns Base64url-encoded random key
|
|
89
|
+
*/
|
|
90
|
+
export function generateKey(length = 32) {
|
|
91
|
+
const bytes = crypto.getRandomValues(new Uint8Array(length));
|
|
92
|
+
// Convert to base64url (URL-safe base64)
|
|
93
|
+
const base64 = btoa(String.fromCharCode(...bytes));
|
|
94
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,SAAS,GAAG,SAAS,CAAC;AAC5B,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC;;GAEG;AACH,KAAK,UAAU,SAAS,CACtB,QAAgB,EAChB,IAAgB,EAChB,KAA4B;IAE5B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC/C,KAAK,EACL,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EACxB,QAAQ,EACR,KAAK,EACL,CAAC,WAAW,CAAC,CACd,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAC5B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,IAAI,CAAC,MAAqB;QAChC,UAAU,EAAE,iBAAiB;QAC7B,IAAI,EAAE,SAAS;KAChB,EACD,WAAW,EACX,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,EAChC,KAAK,EACL,CAAC,KAAK,CAAC,CACR,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAY,EAAE,SAAiB;IAC3D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,U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AAM,KAAK,WAAW,CAAC;AAC/E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,MAAM,GAAG,EAAE;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,yCAAyC;IACzC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @abbacchio/browser-transport - Browser and React logging client for Abbacchio
|
|
3
|
+
*
|
|
4
|
+
* @example Basic usage
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { createLogger } from '@abbacchio/browser-transport'
|
|
7
|
+
*
|
|
8
|
+
* const log = createLogger({
|
|
9
|
+
* url: 'http://localhost:4000/api/logs',
|
|
10
|
+
* channel: 'my-app',
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* log.info('Hello from browser!')
|
|
14
|
+
* log.error('Something went wrong', { error: 'details' })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example Intercept console.log
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { interceptConsole } from '@abbacchio/browser-transport'
|
|
20
|
+
*
|
|
21
|
+
* interceptConsole({
|
|
22
|
+
* url: 'http://localhost:4000/api/logs',
|
|
23
|
+
* channel: 'my-app',
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // Now all console.log calls go to Abbacchio
|
|
27
|
+
* console.log('This goes to Abbacchio!')
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example React usage
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { AbbacchioProvider, useLogger } from '@abbacchio/browser-transport/react'
|
|
33
|
+
*
|
|
34
|
+
* function App() {
|
|
35
|
+
* return (
|
|
36
|
+
* <AbbacchioProvider channel="my-app" captureConsole>
|
|
37
|
+
* <MyApp />
|
|
38
|
+
* </AbbacchioProvider>
|
|
39
|
+
* )
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* function MyComponent() {
|
|
43
|
+
* const log = useLogger()
|
|
44
|
+
* return <button onClick={() => log.info('clicked')}>Click</button>
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export { AbbacchioClient, createClient, type AbbacchioClientOptions, type LogEntry } from './client.js';
|
|
49
|
+
export { Logger, createLogger, LOG_LEVELS, type LoggerOptions } from './logger.js';
|
|
50
|
+
export { interceptConsole, stopInterceptConsole, flushConsole, isConsoleIntercepted, getOriginalConsole, type ConsoleInterceptorOptions, } from './console.js';
|
|
51
|
+
export { encrypt, decrypt, generateKey, isCryptoAvailable } from './crypto.js';
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAGH,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,sBAAsB,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGxG,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAGnF,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @abbacchio/browser-transport - Browser and React logging client for Abbacchio
|
|
3
|
+
*
|
|
4
|
+
* @example Basic usage
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { createLogger } from '@abbacchio/browser-transport'
|
|
7
|
+
*
|
|
8
|
+
* const log = createLogger({
|
|
9
|
+
* url: 'http://localhost:4000/api/logs',
|
|
10
|
+
* channel: 'my-app',
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* log.info('Hello from browser!')
|
|
14
|
+
* log.error('Something went wrong', { error: 'details' })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example Intercept console.log
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { interceptConsole } from '@abbacchio/browser-transport'
|
|
20
|
+
*
|
|
21
|
+
* interceptConsole({
|
|
22
|
+
* url: 'http://localhost:4000/api/logs',
|
|
23
|
+
* channel: 'my-app',
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // Now all console.log calls go to Abbacchio
|
|
27
|
+
* console.log('This goes to Abbacchio!')
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example React usage
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { AbbacchioProvider, useLogger } from '@abbacchio/browser-transport/react'
|
|
33
|
+
*
|
|
34
|
+
* function App() {
|
|
35
|
+
* return (
|
|
36
|
+
* <AbbacchioProvider channel="my-app" captureConsole>
|
|
37
|
+
* <MyApp />
|
|
38
|
+
* </AbbacchioProvider>
|
|
39
|
+
* )
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* function MyComponent() {
|
|
43
|
+
* const log = useLogger()
|
|
44
|
+
* return <button onClick={() => log.info('clicked')}>Click</button>
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
// Client
|
|
49
|
+
export { AbbacchioClient, createClient } from './client.js';
|
|
50
|
+
// Logger
|
|
51
|
+
export { Logger, createLogger, LOG_LEVELS } from './logger.js';
|
|
52
|
+
// Console interceptor
|
|
53
|
+
export { interceptConsole, stopInterceptConsole, flushConsole, isConsoleIntercepted, getOriginalConsole, } from './console.js';
|
|
54
|
+
// Crypto utilities
|
|
55
|
+
export { encrypt, decrypt, generateKey, isCryptoAvailable } from './crypto.js';
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,SAAS;AACT,OAAO,EAAE,eAAe,EAAE,YAAY,EAA8C,MAAM,aAAa,CAAC;AAExG,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAC;AAEnF,sBAAsB;AACtB,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,GAEnB,MAAM,cAAc,CAAC;AAEtB,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger class for Abbacchio
|
|
3
|
+
* Provides a structured logging API similar to Pino
|
|
4
|
+
*/
|
|
5
|
+
import { type AbbacchioClientOptions } from './client.js';
|
|
6
|
+
export interface LoggerOptions extends AbbacchioClientOptions {
|
|
7
|
+
/** Logger name (namespace). Defaults to 'app' */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Minimum log level. Defaults to 'debug' (20) */
|
|
10
|
+
level?: number | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
11
|
+
/** Include the current URL in log data. Defaults to false */
|
|
12
|
+
includeUrl?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const LOG_LEVELS: {
|
|
15
|
+
readonly trace: 10;
|
|
16
|
+
readonly debug: 20;
|
|
17
|
+
readonly info: 30;
|
|
18
|
+
readonly warn: 40;
|
|
19
|
+
readonly error: 50;
|
|
20
|
+
readonly fatal: 60;
|
|
21
|
+
};
|
|
22
|
+
type LogLevel = keyof typeof LOG_LEVELS;
|
|
23
|
+
/**
|
|
24
|
+
* Browser logger for Abbacchio
|
|
25
|
+
* Provides structured logging with automatic batching and optional encryption
|
|
26
|
+
*/
|
|
27
|
+
export declare class Logger {
|
|
28
|
+
private client;
|
|
29
|
+
private name;
|
|
30
|
+
private minLevel;
|
|
31
|
+
private includeUrl;
|
|
32
|
+
private bindings;
|
|
33
|
+
constructor(options?: LoggerOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Parse level string or number to numeric level
|
|
36
|
+
*/
|
|
37
|
+
private parseLevel;
|
|
38
|
+
/**
|
|
39
|
+
* Create a log entry
|
|
40
|
+
*/
|
|
41
|
+
private createEntry;
|
|
42
|
+
/**
|
|
43
|
+
* Internal log method
|
|
44
|
+
*/
|
|
45
|
+
private log;
|
|
46
|
+
/**
|
|
47
|
+
* Log at trace level (10)
|
|
48
|
+
*/
|
|
49
|
+
trace(msg: string, data?: Record<string, unknown>): void;
|
|
50
|
+
trace(data: Record<string, unknown>, msg?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Log at debug level (20)
|
|
53
|
+
*/
|
|
54
|
+
debug(msg: string, data?: Record<string, unknown>): void;
|
|
55
|
+
debug(data: Record<string, unknown>, msg?: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Log at info level (30)
|
|
58
|
+
*/
|
|
59
|
+
info(msg: string, data?: Record<string, unknown>): void;
|
|
60
|
+
info(data: Record<string, unknown>, msg?: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Log at warn level (40)
|
|
63
|
+
*/
|
|
64
|
+
warn(msg: string, data?: Record<string, unknown>): void;
|
|
65
|
+
warn(data: Record<string, unknown>, msg?: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Log at error level (50)
|
|
68
|
+
*/
|
|
69
|
+
error(msg: string, data?: Record<string, unknown>): void;
|
|
70
|
+
error(data: Record<string, unknown>, msg?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Log at fatal level (60)
|
|
73
|
+
*/
|
|
74
|
+
fatal(msg: string, data?: Record<string, unknown>): void;
|
|
75
|
+
fatal(data: Record<string, unknown>, msg?: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Create a child logger with additional bindings
|
|
78
|
+
*/
|
|
79
|
+
child(bindings: Record<string, unknown>): Logger;
|
|
80
|
+
/**
|
|
81
|
+
* Flush buffered logs
|
|
82
|
+
*/
|
|
83
|
+
flush(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Close the logger and flush remaining logs
|
|
86
|
+
*/
|
|
87
|
+
close(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Set the minimum log level
|
|
90
|
+
*/
|
|
91
|
+
setLevel(level: number | LogLevel): void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a new logger instance
|
|
95
|
+
*/
|
|
96
|
+
export declare function createLogger(options?: LoggerOptions): Logger;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAmB,KAAK,sBAAsB,EAAiB,MAAM,aAAa,CAAC;AAE1F,MAAM,WAAW,aAAc,SAAQ,sBAAsB;IAC3D,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,O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