@glideidentity/web-client-sdk 4.4.8-beta.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.
- package/README.md +938 -0
- package/dist/adapters/angular/client.service.d.ts +7 -0
- package/dist/adapters/angular/client.service.js +30 -0
- package/dist/adapters/angular/index.d.ts +3 -0
- package/dist/adapters/angular/index.js +18 -0
- package/dist/adapters/angular/phone-auth.service.d.ts +38 -0
- package/dist/adapters/angular/phone-auth.service.js +130 -0
- package/dist/adapters/react/index.d.ts +9 -0
- package/dist/adapters/react/index.js +28 -0
- package/dist/adapters/react/useClient.d.ts +26 -0
- package/dist/adapters/react/useClient.js +121 -0
- package/dist/adapters/react/usePhoneAuth.d.ts +23 -0
- package/dist/adapters/react/usePhoneAuth.js +95 -0
- package/dist/adapters/vanilla/client.d.ts +8 -0
- package/dist/adapters/vanilla/client.js +33 -0
- package/dist/adapters/vanilla/index.d.ts +3 -0
- package/dist/adapters/vanilla/index.js +18 -0
- package/dist/adapters/vanilla/phone-auth.d.ts +46 -0
- package/dist/adapters/vanilla/phone-auth.js +138 -0
- package/dist/adapters/vue/index.d.ts +10 -0
- package/dist/adapters/vue/index.js +36 -0
- package/dist/adapters/vue/useClient.d.ts +115 -0
- package/dist/adapters/vue/useClient.js +131 -0
- package/dist/adapters/vue/usePhoneAuth.d.ts +94 -0
- package/dist/adapters/vue/usePhoneAuth.js +103 -0
- package/dist/browser/web-client-sdk.min.js +2 -0
- package/dist/browser/web-client-sdk.min.js.LICENSE.txt +1 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +31 -0
- package/dist/core/client.d.ts +22 -0
- package/dist/core/client.js +77 -0
- package/dist/core/logger.d.ts +130 -0
- package/dist/core/logger.js +370 -0
- package/dist/core/phone-auth/api-types.d.ts +525 -0
- package/dist/core/phone-auth/api-types.js +215 -0
- package/dist/core/phone-auth/client.d.ts +187 -0
- package/dist/core/phone-auth/client.js +1353 -0
- package/dist/core/phone-auth/error-utils.d.ts +110 -0
- package/dist/core/phone-auth/error-utils.js +350 -0
- package/dist/core/phone-auth/index.d.ts +7 -0
- package/dist/core/phone-auth/index.js +47 -0
- package/dist/core/phone-auth/status-types.d.ts +107 -0
- package/dist/core/phone-auth/status-types.js +31 -0
- package/dist/core/phone-auth/strategies/desktop.d.ts +113 -0
- package/dist/core/phone-auth/strategies/desktop.js +502 -0
- package/dist/core/phone-auth/strategies/index.d.ts +11 -0
- package/dist/core/phone-auth/strategies/index.js +15 -0
- package/dist/core/phone-auth/strategies/link.d.ts +81 -0
- package/dist/core/phone-auth/strategies/link.js +265 -0
- package/dist/core/phone-auth/strategies/ts43.d.ts +32 -0
- package/dist/core/phone-auth/strategies/ts43.js +146 -0
- package/dist/core/phone-auth/strategies/types.d.ts +18 -0
- package/dist/core/phone-auth/strategies/types.js +6 -0
- package/dist/core/phone-auth/type-guards.d.ts +125 -0
- package/dist/core/phone-auth/type-guards.js +160 -0
- package/dist/core/phone-auth/types.d.ts +232 -0
- package/dist/core/phone-auth/types.js +93 -0
- package/dist/core/phone-auth/ui/mobile-debug-console.d.ts +25 -0
- package/dist/core/phone-auth/ui/mobile-debug-console.js +288 -0
- package/dist/core/phone-auth/ui/modal.d.ts +84 -0
- package/dist/core/phone-auth/ui/modal.js +574 -0
- package/dist/core/phone-auth/validation-utils.d.ts +66 -0
- package/dist/core/phone-auth/validation-utils.js +182 -0
- package/dist/core/types.d.ts +62 -0
- package/dist/core/types.js +2 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/esm/adapters/angular/client.service.d.ts +7 -0
- package/dist/esm/adapters/angular/client.service.js +27 -0
- package/dist/esm/adapters/angular/index.d.ts +3 -0
- package/dist/esm/adapters/angular/index.js +4 -0
- package/dist/esm/adapters/angular/phone-auth.service.d.ts +38 -0
- package/dist/esm/adapters/angular/phone-auth.service.js +127 -0
- package/dist/esm/adapters/react/index.d.ts +9 -0
- package/dist/esm/adapters/react/index.js +8 -0
- package/dist/esm/adapters/react/useClient.d.ts +26 -0
- package/dist/esm/adapters/react/useClient.js +116 -0
- package/dist/esm/adapters/react/usePhoneAuth.d.ts +23 -0
- package/dist/esm/adapters/react/usePhoneAuth.js +92 -0
- package/dist/esm/adapters/vanilla/client.d.ts +8 -0
- package/dist/esm/adapters/vanilla/client.js +29 -0
- package/dist/esm/adapters/vanilla/index.d.ts +3 -0
- package/dist/esm/adapters/vanilla/index.js +4 -0
- package/dist/esm/adapters/vanilla/phone-auth.d.ts +46 -0
- package/dist/esm/adapters/vanilla/phone-auth.js +134 -0
- package/dist/esm/adapters/vue/index.d.ts +10 -0
- package/dist/esm/adapters/vue/index.js +11 -0
- package/dist/esm/adapters/vue/useClient.d.ts +115 -0
- package/dist/esm/adapters/vue/useClient.js +127 -0
- package/dist/esm/adapters/vue/usePhoneAuth.d.ts +94 -0
- package/dist/esm/adapters/vue/usePhoneAuth.js +100 -0
- package/dist/esm/browser.d.ts +7 -0
- package/dist/esm/browser.js +11 -0
- package/dist/esm/core/client.d.ts +22 -0
- package/dist/esm/core/client.js +70 -0
- package/dist/esm/core/logger.d.ts +130 -0
- package/dist/esm/core/logger.js +359 -0
- package/dist/esm/core/phone-auth/api-types.d.ts +525 -0
- package/dist/esm/core/phone-auth/api-types.js +203 -0
- package/dist/esm/core/phone-auth/client.d.ts +187 -0
- package/dist/esm/core/phone-auth/client.js +1316 -0
- package/dist/esm/core/phone-auth/error-utils.d.ts +110 -0
- package/dist/esm/core/phone-auth/error-utils.js +338 -0
- package/dist/esm/core/phone-auth/index.d.ts +7 -0
- package/dist/esm/core/phone-auth/index.js +6 -0
- package/dist/esm/core/phone-auth/status-types.d.ts +107 -0
- package/dist/esm/core/phone-auth/status-types.js +26 -0
- package/dist/esm/core/phone-auth/strategies/desktop.d.ts +113 -0
- package/dist/esm/core/phone-auth/strategies/desktop.js +496 -0
- package/dist/esm/core/phone-auth/strategies/index.d.ts +11 -0
- package/dist/esm/core/phone-auth/strategies/index.js +7 -0
- package/dist/esm/core/phone-auth/strategies/link.d.ts +81 -0
- package/dist/esm/core/phone-auth/strategies/link.js +261 -0
- package/dist/esm/core/phone-auth/strategies/ts43.d.ts +32 -0
- package/dist/esm/core/phone-auth/strategies/ts43.js +142 -0
- package/dist/esm/core/phone-auth/strategies/types.d.ts +18 -0
- package/dist/esm/core/phone-auth/strategies/types.js +5 -0
- package/dist/esm/core/phone-auth/type-guards.d.ts +125 -0
- package/dist/esm/core/phone-auth/type-guards.js +150 -0
- package/dist/esm/core/phone-auth/types.d.ts +232 -0
- package/dist/esm/core/phone-auth/types.js +76 -0
- package/dist/esm/core/phone-auth/ui/mobile-debug-console.d.ts +25 -0
- package/dist/esm/core/phone-auth/ui/mobile-debug-console.js +284 -0
- package/dist/esm/core/phone-auth/ui/modal.d.ts +84 -0
- package/dist/esm/core/phone-auth/ui/modal.js +570 -0
- package/dist/esm/core/phone-auth/validation-utils.d.ts +66 -0
- package/dist/esm/core/phone-auth/validation-utils.js +174 -0
- package/dist/esm/core/types.d.ts +62 -0
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/core/version.d.ts +1 -0
- package/dist/esm/core/version.js +2 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +15 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +52 -0
- package/package.json +92 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Industry-grade logging for Glide Web SDK
|
|
3
|
+
* Following best practices from Stripe, Auth0, Twilio, and AWS Amplify
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export var LogLevel;
|
|
15
|
+
(function (LogLevel) {
|
|
16
|
+
LogLevel[LogLevel["SILENT"] = 0] = "SILENT";
|
|
17
|
+
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
18
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
19
|
+
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
20
|
+
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
|
|
21
|
+
})(LogLevel || (LogLevel = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Default browser console logger with automatic data sanitization
|
|
24
|
+
*/
|
|
25
|
+
export class ConsoleLogger {
|
|
26
|
+
constructor(level = LogLevel.SILENT, prefix = '[Glide]', enableGrouping = false) {
|
|
27
|
+
this.level = level;
|
|
28
|
+
this.prefix = prefix;
|
|
29
|
+
this.enableGrouping = enableGrouping;
|
|
30
|
+
}
|
|
31
|
+
debug(message, fields) {
|
|
32
|
+
if (this.level >= LogLevel.DEBUG) {
|
|
33
|
+
this.log('debug', message, fields);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
info(message, fields) {
|
|
37
|
+
if (this.level >= LogLevel.INFO) {
|
|
38
|
+
this.log('info', message, fields);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
warn(message, fields) {
|
|
42
|
+
if (this.level >= LogLevel.WARN) {
|
|
43
|
+
this.log('warn', message, fields);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
error(message, fields) {
|
|
47
|
+
if (this.level >= LogLevel.ERROR) {
|
|
48
|
+
this.log('error', message, fields);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
log(level, message, fields) {
|
|
52
|
+
const timestamp = new Date().toISOString();
|
|
53
|
+
const sanitizedFields = fields ? this.sanitizeFields(fields) : {};
|
|
54
|
+
// Format the message
|
|
55
|
+
const formattedMessage = `${this.prefix} ${timestamp} [${level.toUpperCase()}] ${message}`;
|
|
56
|
+
// Use console grouping for better readability if enabled
|
|
57
|
+
if (this.enableGrouping && Object.keys(sanitizedFields).length > 0) {
|
|
58
|
+
console.groupCollapsed(formattedMessage);
|
|
59
|
+
Object.entries(sanitizedFields).forEach(([key, value]) => {
|
|
60
|
+
console.log(`${key}:`, value);
|
|
61
|
+
});
|
|
62
|
+
console.groupEnd();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Standard logging with or without fields
|
|
66
|
+
if (Object.keys(sanitizedFields).length > 0) {
|
|
67
|
+
console[level](formattedMessage, sanitizedFields);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
console[level](formattedMessage);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sanitize sensitive data from log fields
|
|
76
|
+
*/
|
|
77
|
+
sanitizeFields(fields) {
|
|
78
|
+
const sanitized = {};
|
|
79
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
80
|
+
sanitized[key] = this.sanitizeValue(key, value);
|
|
81
|
+
}
|
|
82
|
+
return sanitized;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Redact sensitive information based on field name and value patterns
|
|
86
|
+
*/
|
|
87
|
+
sanitizeValue(key, value) {
|
|
88
|
+
// List of sensitive field patterns
|
|
89
|
+
const sensitiveFields = [
|
|
90
|
+
'apikey', 'api_key', 'apiKey',
|
|
91
|
+
'token', 'accesstoken', 'access_token', 'accessToken',
|
|
92
|
+
'password', 'passwd', 'pwd',
|
|
93
|
+
'secret', 'credential',
|
|
94
|
+
'authorization', 'auth',
|
|
95
|
+
'cookie', 'session',
|
|
96
|
+
];
|
|
97
|
+
const lowerKey = key.toLowerCase();
|
|
98
|
+
// Check if field name indicates sensitive data
|
|
99
|
+
for (const sensitive of sensitiveFields) {
|
|
100
|
+
if (lowerKey.includes(sensitive.toLowerCase())) {
|
|
101
|
+
if (typeof value === 'string' && value.length > 4) {
|
|
102
|
+
return value.substring(0, 4) + '****[REDACTED]';
|
|
103
|
+
}
|
|
104
|
+
return '****[REDACTED]';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Handle specific value patterns
|
|
108
|
+
if (typeof value === 'string') {
|
|
109
|
+
// Phone number pattern - show area code only
|
|
110
|
+
const phoneRegex = /^\+?[1-9]\d{6,14}$/;
|
|
111
|
+
if (phoneRegex.test(value)) {
|
|
112
|
+
return value.substring(0, 6) + '****';
|
|
113
|
+
}
|
|
114
|
+
// Email pattern - show domain only
|
|
115
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
116
|
+
if (emailRegex.test(value)) {
|
|
117
|
+
const [, domain] = value.split('@');
|
|
118
|
+
return '****@' + domain;
|
|
119
|
+
}
|
|
120
|
+
// URL with credentials
|
|
121
|
+
if (value.includes('://') && value.includes('@')) {
|
|
122
|
+
return value.replace(/\/\/([^:]+):([^@]+)@/, '//****:****@');
|
|
123
|
+
}
|
|
124
|
+
// JWT tokens
|
|
125
|
+
if (value.startsWith('eyJ') && value.split('.').length === 3) {
|
|
126
|
+
return value.substring(0, 10) + '****[JWT]';
|
|
127
|
+
}
|
|
128
|
+
// Credit card numbers
|
|
129
|
+
const creditCardRegex = /\b\d{13,19}\b/;
|
|
130
|
+
if (creditCardRegex.test(value)) {
|
|
131
|
+
return value.substring(0, 4) + '****' + value.substring(value.length - 4);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Recursively sanitize objects
|
|
135
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
136
|
+
return this.sanitizeFields(value);
|
|
137
|
+
}
|
|
138
|
+
// Sanitize arrays
|
|
139
|
+
if (Array.isArray(value)) {
|
|
140
|
+
return value.map((item, index) => this.sanitizeValue(`${key}[${index}]`, item));
|
|
141
|
+
}
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* No-op logger for when logging is disabled
|
|
147
|
+
*/
|
|
148
|
+
export class NoopLogger {
|
|
149
|
+
debug(message, fields) { }
|
|
150
|
+
info(message, fields) { }
|
|
151
|
+
warn(message, fields) { }
|
|
152
|
+
error(message, fields) { }
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Remote logger for sending logs to a backend service
|
|
156
|
+
* Useful for debugging production issues
|
|
157
|
+
*/
|
|
158
|
+
export class RemoteLogger {
|
|
159
|
+
constructor(endpoint, apiKey, fallbackLogger) {
|
|
160
|
+
this.buffer = [];
|
|
161
|
+
this.flushInterval = 5000; // 5 seconds
|
|
162
|
+
this.maxBufferSize = 100;
|
|
163
|
+
this.endpoint = endpoint;
|
|
164
|
+
this.apiKey = apiKey;
|
|
165
|
+
this.localLogger = fallbackLogger || new ConsoleLogger(LogLevel.ERROR);
|
|
166
|
+
// Set up automatic flushing
|
|
167
|
+
if (typeof window !== 'undefined') {
|
|
168
|
+
setInterval(() => this.flush(), this.flushInterval);
|
|
169
|
+
// Flush on page unload
|
|
170
|
+
window.addEventListener('beforeunload', () => this.flush());
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
debug(message, fields) {
|
|
174
|
+
this.log('debug', message, fields);
|
|
175
|
+
}
|
|
176
|
+
info(message, fields) {
|
|
177
|
+
this.log('info', message, fields);
|
|
178
|
+
}
|
|
179
|
+
warn(message, fields) {
|
|
180
|
+
this.log('warn', message, fields);
|
|
181
|
+
}
|
|
182
|
+
error(message, fields) {
|
|
183
|
+
this.log('error', message, fields);
|
|
184
|
+
}
|
|
185
|
+
log(level, message, fields) {
|
|
186
|
+
const logEntry = {
|
|
187
|
+
timestamp: new Date().toISOString(),
|
|
188
|
+
level,
|
|
189
|
+
message,
|
|
190
|
+
fields,
|
|
191
|
+
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,
|
|
192
|
+
url: typeof window !== 'undefined' ? window.location.href : undefined,
|
|
193
|
+
};
|
|
194
|
+
this.buffer.push(logEntry);
|
|
195
|
+
// Also log locally for immediate feedback
|
|
196
|
+
this.localLogger[level](message, fields);
|
|
197
|
+
// Flush if buffer is full
|
|
198
|
+
if (this.buffer.length >= this.maxBufferSize) {
|
|
199
|
+
this.flush();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
flush() {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
if (this.buffer.length === 0)
|
|
205
|
+
return;
|
|
206
|
+
const logs = [...this.buffer];
|
|
207
|
+
this.buffer = [];
|
|
208
|
+
try {
|
|
209
|
+
yield fetch(this.endpoint, {
|
|
210
|
+
method: 'POST',
|
|
211
|
+
headers: {
|
|
212
|
+
'Content-Type': 'application/json',
|
|
213
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
214
|
+
},
|
|
215
|
+
body: JSON.stringify({ logs }),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
// Failed to send logs, log locally
|
|
220
|
+
this.localLogger.error('Failed to send logs to remote server', { error });
|
|
221
|
+
// Optionally, put logs back in buffer for retry
|
|
222
|
+
// this.buffer.unshift(...logs);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Parse log level from string
|
|
229
|
+
*/
|
|
230
|
+
export function parseLogLevel(level) {
|
|
231
|
+
switch (level.toLowerCase()) {
|
|
232
|
+
case 'debug':
|
|
233
|
+
return LogLevel.DEBUG;
|
|
234
|
+
case 'info':
|
|
235
|
+
return LogLevel.INFO;
|
|
236
|
+
case 'warn':
|
|
237
|
+
case 'warning':
|
|
238
|
+
return LogLevel.WARN;
|
|
239
|
+
case 'error':
|
|
240
|
+
return LogLevel.ERROR;
|
|
241
|
+
case 'silent':
|
|
242
|
+
case 'none':
|
|
243
|
+
case 'off':
|
|
244
|
+
return LogLevel.SILENT;
|
|
245
|
+
default:
|
|
246
|
+
return LogLevel.SILENT;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get log level from browser environment
|
|
251
|
+
*/
|
|
252
|
+
export function getLogLevelFromEnv() {
|
|
253
|
+
// Check localStorage
|
|
254
|
+
if (typeof localStorage !== 'undefined') {
|
|
255
|
+
const storedLevel = localStorage.getItem('GLIDE_LOG_LEVEL');
|
|
256
|
+
if (storedLevel) {
|
|
257
|
+
return parseLogLevel(storedLevel);
|
|
258
|
+
}
|
|
259
|
+
const debugFlag = localStorage.getItem('GLIDE_DEBUG');
|
|
260
|
+
if (debugFlag === 'true' || debugFlag === '1') {
|
|
261
|
+
return LogLevel.DEBUG;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Check URL parameters
|
|
265
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
266
|
+
const params = new URLSearchParams(window.location.search);
|
|
267
|
+
const urlLogLevel = params.get('glide_log_level');
|
|
268
|
+
if (urlLogLevel) {
|
|
269
|
+
return parseLogLevel(urlLogLevel);
|
|
270
|
+
}
|
|
271
|
+
if (params.has('glide_debug')) {
|
|
272
|
+
return LogLevel.DEBUG;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return LogLevel.SILENT;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Performance timer for measuring operation duration
|
|
279
|
+
*/
|
|
280
|
+
export class PerformanceTimer {
|
|
281
|
+
constructor(logger) {
|
|
282
|
+
this.marks = new Map();
|
|
283
|
+
this.startTime = performance.now();
|
|
284
|
+
this.logger = logger;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Mark a point in time
|
|
288
|
+
*/
|
|
289
|
+
mark(name) {
|
|
290
|
+
this.marks.set(name, performance.now());
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Log elapsed time with optional fields
|
|
294
|
+
*/
|
|
295
|
+
logElapsed(message, fields) {
|
|
296
|
+
const elapsed = performance.now() - this.startTime;
|
|
297
|
+
this.logger.debug(message, Object.assign(Object.assign({}, fields), { elapsedMs: elapsed, elapsed: `${elapsed.toFixed(2)}ms` }));
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Log time between marks
|
|
301
|
+
*/
|
|
302
|
+
logMarkDuration(fromMark, toMark, message, fields) {
|
|
303
|
+
const from = this.marks.get(fromMark);
|
|
304
|
+
const to = this.marks.get(toMark);
|
|
305
|
+
if (from && to) {
|
|
306
|
+
const duration = to - from;
|
|
307
|
+
this.logger.debug(message, Object.assign(Object.assign({}, fields), { durationMs: duration, duration: `${duration.toFixed(2)}ms`, fromMark,
|
|
308
|
+
toMark }));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Generate a unique request ID for distributed tracing
|
|
314
|
+
*/
|
|
315
|
+
export function generateRequestId() {
|
|
316
|
+
return `req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Logger factory for creating loggers with consistent configuration
|
|
320
|
+
*/
|
|
321
|
+
export class LoggerFactory {
|
|
322
|
+
/**
|
|
323
|
+
* Set the default log level for all new loggers
|
|
324
|
+
*/
|
|
325
|
+
static setDefaultLevel(level) {
|
|
326
|
+
this.defaultLevel = level;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Set a default logger instance to use
|
|
330
|
+
*/
|
|
331
|
+
static setDefaultLogger(logger) {
|
|
332
|
+
this.defaultLogger = logger;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Create a logger instance based on configuration
|
|
336
|
+
*/
|
|
337
|
+
static create(options) {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
// Use custom logger if provided
|
|
340
|
+
if (options === null || options === void 0 ? void 0 : options.custom) {
|
|
341
|
+
return options.custom;
|
|
342
|
+
}
|
|
343
|
+
// Use default logger if set
|
|
344
|
+
if (this.defaultLogger) {
|
|
345
|
+
return this.defaultLogger;
|
|
346
|
+
}
|
|
347
|
+
// Determine log level
|
|
348
|
+
const level = (_b = (_a = options === null || options === void 0 ? void 0 : options.level) !== null && _a !== void 0 ? _a : getLogLevelFromEnv()) !== null && _b !== void 0 ? _b : this.defaultLevel;
|
|
349
|
+
// Create remote logger if configured
|
|
350
|
+
if (options === null || options === void 0 ? void 0 : options.remote) {
|
|
351
|
+
const fallbackLogger = new ConsoleLogger(level, options === null || options === void 0 ? void 0 : options.prefix);
|
|
352
|
+
return new RemoteLogger(options.remote.endpoint, options.remote.apiKey, fallbackLogger);
|
|
353
|
+
}
|
|
354
|
+
// Create console logger
|
|
355
|
+
return new ConsoleLogger(level, options === null || options === void 0 ? void 0 : options.prefix);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
LoggerFactory.defaultLevel = LogLevel.SILENT;
|
|
359
|
+
LoggerFactory.defaultLogger = null;
|