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