@oxyhq/core 10.2.0 → 11.0.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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/boot/sessionColdBoot.js +3 -3
- package/dist/cjs/crypto/keyManager.js +68 -69
- package/dist/cjs/crypto/signatureService.js +2 -2
- package/dist/cjs/index.js +17 -20
- package/dist/cjs/logger/index.js +149 -0
- package/dist/cjs/mixins/OxyServices.assets.js +4 -4
- package/dist/cjs/mixins/OxyServices.auth.js +104 -2
- package/dist/cjs/mixins/OxyServices.language.js +3 -5
- package/dist/cjs/mixins/OxyServices.privacy.js +2 -4
- package/dist/cjs/mixins/OxyServices.security.js +7 -11
- package/dist/cjs/mixins/OxyServices.topics.js +25 -15
- package/dist/cjs/mixins/OxyServices.user.js +4 -4
- package/dist/cjs/mixins/OxyServices.utility.js +18 -18
- package/dist/cjs/session/SessionClient.js +17 -17
- package/dist/cjs/session/accountDialogController.js +12 -12
- package/dist/cjs/session/authStateStore.js +5 -5
- package/dist/cjs/session/refresh.js +4 -4
- package/dist/cjs/session/socketLoader.js +2 -2
- package/dist/cjs/utils/asyncUtils.js +2 -2
- package/dist/cjs/utils/avatarUtils.js +2 -1
- package/dist/cjs/utils/deviceManager.js +7 -5
- package/dist/cjs/utils/errorUtils.js +3 -3
- package/dist/cjs/utils/oauthPkce.js +3 -3
- package/dist/cjs/utils/requestUtils.js +1 -1
- package/dist/cjs/utils/webauthnOrigin.js +51 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/boot/sessionColdBoot.js +1 -1
- package/dist/esm/crypto/keyManager.js +1 -2
- package/dist/esm/crypto/signatureService.js +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/logger/index.js +140 -0
- package/dist/esm/mixins/OxyServices.assets.js +2 -2
- package/dist/esm/mixins/OxyServices.auth.js +103 -1
- package/dist/esm/mixins/OxyServices.language.js +3 -5
- package/dist/esm/mixins/OxyServices.privacy.js +2 -4
- package/dist/esm/mixins/OxyServices.security.js +7 -11
- package/dist/esm/mixins/OxyServices.topics.js +25 -15
- package/dist/esm/mixins/OxyServices.user.js +1 -1
- package/dist/esm/mixins/OxyServices.utility.js +1 -1
- package/dist/esm/session/SessionClient.js +1 -1
- package/dist/esm/session/accountDialogController.js +1 -1
- package/dist/esm/session/authStateStore.js +1 -1
- package/dist/esm/session/refresh.js +1 -1
- package/dist/esm/session/socketLoader.js +1 -1
- package/dist/esm/utils/asyncUtils.js +1 -1
- package/dist/esm/utils/avatarUtils.js +2 -1
- package/dist/esm/utils/deviceManager.js +7 -5
- package/dist/esm/utils/errorUtils.js +1 -1
- package/dist/esm/utils/oauthPkce.js +1 -1
- package/dist/esm/utils/requestUtils.js +1 -1
- package/dist/esm/utils/webauthnOrigin.js +48 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/logger/index.d.ts +104 -0
- package/dist/types/mixins/OxyServices.auth.d.ts +58 -0
- package/dist/types/mixins/OxyServices.topics.d.ts +3 -3
- package/dist/types/models/Topic.d.ts +10 -0
- package/dist/types/utils/requestUtils.d.ts +1 -1
- package/dist/types/utils/webauthnOrigin.d.ts +32 -0
- package/package.json +17 -2
- package/src/boot/sessionColdBoot.ts +1 -1
- package/src/crypto/keyManager.ts +1 -2
- package/src/crypto/signatureService.ts +1 -1
- package/src/index.ts +22 -19
- package/src/logger/__tests__/logger.test.ts +207 -0
- package/src/logger/index.ts +217 -0
- package/src/mixins/OxyServices.assets.ts +3 -3
- package/src/mixins/OxyServices.auth.ts +134 -1
- package/src/mixins/OxyServices.language.ts +3 -5
- package/src/mixins/OxyServices.privacy.ts +2 -4
- package/src/mixins/OxyServices.security.ts +7 -11
- package/src/mixins/OxyServices.topics.ts +47 -17
- package/src/mixins/OxyServices.user.ts +1 -1
- package/src/mixins/OxyServices.utility.ts +1 -1
- package/src/mixins/__tests__/discoveryErrorHandling.test.ts +1 -1
- package/src/mixins/__tests__/topics.test.ts +156 -0
- package/src/mixins/__tests__/webauthnAuth.test.ts +206 -0
- package/src/models/Topic.ts +11 -0
- package/src/session/SessionClient.ts +1 -1
- package/src/session/__tests__/SessionClient.diagnostics.test.ts +1 -1
- package/src/session/__tests__/accountDialogController.test.ts +1 -1
- package/src/session/accountDialogController.ts +1 -1
- package/src/session/authStateStore.ts +1 -1
- package/src/session/refresh.ts +1 -1
- package/src/session/socketLoader.ts +1 -1
- package/src/utils/__tests__/webauthnOrigin.test.ts +83 -0
- package/src/utils/asyncUtils.ts +1 -1
- package/src/utils/avatarUtils.ts +3 -1
- package/src/utils/deviceManager.ts +8 -5
- package/src/utils/errorUtils.ts +1 -1
- package/src/utils/oauthPkce.ts +1 -1
- package/src/utils/requestUtils.ts +1 -1
- package/src/utils/webauthnOrigin.ts +52 -0
- package/dist/cjs/shared/utils/debugUtils.js +0 -80
- package/dist/cjs/utils/loggerUtils.js +0 -126
- package/dist/esm/shared/utils/debugUtils.js +0 -72
- package/dist/esm/utils/loggerUtils.js +0 -115
- package/dist/types/shared/utils/debugUtils.d.ts +0 -48
- package/dist/types/utils/loggerUtils.d.ts +0 -48
- package/src/shared/utils/__tests__/debugUtils.test.ts +0 -55
- package/src/shared/utils/debugUtils.ts +0 -78
- package/src/utils/loggerUtils.ts +0 -153
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebAuthn relying-party origin guard (client side).
|
|
3
|
+
*
|
|
4
|
+
* The passkey ceremonies (`OxyServices.webauthn*`) are only meaningful when the
|
|
5
|
+
* page is served from a first-party Oxy web origin: a credential minted with
|
|
6
|
+
* `WEBAUTHN_RP_ID=oxy.so` can only be created/asserted from `oxy.so`, one of its
|
|
7
|
+
* subdomains, or a loopback dev server. This is the browser-side mirror of the
|
|
8
|
+
* server's `isOxyApexOrigin` (`packages/api/src/utils/origin.ts`), which forms
|
|
9
|
+
* the server's `expectedOrigin` allow-set — consumers use it to decide whether to
|
|
10
|
+
* even offer the passkey UI on the current page.
|
|
11
|
+
*
|
|
12
|
+
* It reads `globalThis.location` directly (no argument) because that is the only
|
|
13
|
+
* origin the browser will let a WebAuthn ceremony run against. On native / SSR /
|
|
14
|
+
* any environment without a DOM `location`, it returns `false` (there is no
|
|
15
|
+
* relying-party origin, so passkeys are not applicable).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* True iff the current page's host is a first-party Oxy relying-party origin:
|
|
20
|
+
* `oxy.so`, any `*.oxy.so` subdomain, or a loopback dev host
|
|
21
|
+
* (`localhost` / `127.0.0.1` / `[::1]`).
|
|
22
|
+
*
|
|
23
|
+
* Fails closed: no `location` (native/SSR), a non-string/empty hostname, or a
|
|
24
|
+
* host that merely ends in the literal `oxy.so` without the dot boundary
|
|
25
|
+
* (`evil-oxy.so`, `oxy.so.evil.com`) all return `false`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* isOxyRpOrigin() // true on https://accounts.oxy.so
|
|
29
|
+
* isOxyRpOrigin() // true on http://localhost:8081
|
|
30
|
+
* isOxyRpOrigin() // false on https://evil.com
|
|
31
|
+
* isOxyRpOrigin() // false in a React Native / SSR context (no location)
|
|
32
|
+
*/
|
|
33
|
+
export function isOxyRpOrigin(): boolean {
|
|
34
|
+
// `globalThis.location` is typed `Location` by the DOM lib, but is genuinely
|
|
35
|
+
// `undefined` on native/SSR — widen to a nullable local so the guard is a real
|
|
36
|
+
// runtime check, not a type-level no-op.
|
|
37
|
+
const location: Location | undefined = globalThis.location;
|
|
38
|
+
if (!location || typeof location.hostname !== 'string') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const hostname = location.hostname.toLowerCase();
|
|
43
|
+
if (hostname.length === 0) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (hostname === 'oxy.so' || hostname.endsWith('.oxy.so')) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
|
|
52
|
+
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Debug Utilities
|
|
4
|
-
*
|
|
5
|
-
* Provides safe logging functions that only output in development mode.
|
|
6
|
-
* All logs are stripped in production builds.
|
|
7
|
-
*
|
|
8
|
-
* @module shared/utils/debugUtils
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.createDebugLogger = exports.debugError = exports.debugWarn = exports.debugLog = exports.isDev = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Check if running in development mode
|
|
14
|
-
*/
|
|
15
|
-
const isDev = () => {
|
|
16
|
-
if (typeof __DEV__ !== 'undefined')
|
|
17
|
-
return __DEV__;
|
|
18
|
-
try {
|
|
19
|
-
return typeof process !== 'undefined' && process.env?.NODE_ENV === 'development';
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
exports.isDev = isDev;
|
|
26
|
-
/**
|
|
27
|
-
* Log a debug message (only in development)
|
|
28
|
-
* @param prefix - Log prefix (e.g., '[ColdBoot]')
|
|
29
|
-
* @param args - Arguments to log
|
|
30
|
-
*/
|
|
31
|
-
const debugLog = (prefix, ...args) => {
|
|
32
|
-
if ((0, exports.isDev)()) {
|
|
33
|
-
console.log(prefix, ...args);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
exports.debugLog = debugLog;
|
|
37
|
-
/**
|
|
38
|
-
* Log a debug warning (only in development)
|
|
39
|
-
* @param prefix - Log prefix
|
|
40
|
-
* @param args - Arguments to log
|
|
41
|
-
*/
|
|
42
|
-
const debugWarn = (prefix, ...args) => {
|
|
43
|
-
if ((0, exports.isDev)()) {
|
|
44
|
-
console.warn(prefix, ...args);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
exports.debugWarn = debugWarn;
|
|
48
|
-
/**
|
|
49
|
-
* Log a debug error (only in development)
|
|
50
|
-
* @param prefix - Log prefix
|
|
51
|
-
* @param args - Arguments to log
|
|
52
|
-
*/
|
|
53
|
-
const debugError = (prefix, ...args) => {
|
|
54
|
-
if ((0, exports.isDev)()) {
|
|
55
|
-
console.error(prefix, ...args);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
exports.debugError = debugError;
|
|
59
|
-
/**
|
|
60
|
-
* Create a namespaced debug logger
|
|
61
|
-
* @param namespace - Logger namespace (e.g., 'ColdBoot', 'DeviceAuth')
|
|
62
|
-
* @returns Object with log, warn, error methods
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* const debug = createDebugLogger('ColdBoot');
|
|
67
|
-
* debug.log('Starting authentication');
|
|
68
|
-
* debug.warn('Token expires soon');
|
|
69
|
-
* debug.error('Authentication failed', error);
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
const createDebugLogger = (namespace) => {
|
|
73
|
-
const prefix = `[${namespace}]`;
|
|
74
|
-
return {
|
|
75
|
-
log: (...args) => (0, exports.debugLog)(prefix, ...args),
|
|
76
|
-
warn: (...args) => (0, exports.debugWarn)(prefix, ...args),
|
|
77
|
-
error: (...args) => (0, exports.debugError)(prefix, ...args),
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
exports.createDebugLogger = createDebugLogger;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Centralized logging utilities for consistent logging across the application
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logPerformance = exports.logError = exports.logPayment = exports.logDevice = exports.logUser = exports.logSession = exports.logApi = exports.logAuth = exports.logger = exports.LogLevel = void 0;
|
|
7
|
-
var LogLevel;
|
|
8
|
-
(function (LogLevel) {
|
|
9
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
10
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
11
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
12
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
13
|
-
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
14
|
-
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
15
|
-
class Logger {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.level = LogLevel.INFO;
|
|
18
|
-
this.isDevelopment = process.env.NODE_ENV === 'development';
|
|
19
|
-
}
|
|
20
|
-
setLevel(level) {
|
|
21
|
-
this.level = level;
|
|
22
|
-
}
|
|
23
|
-
shouldLog(level) {
|
|
24
|
-
return level >= this.level;
|
|
25
|
-
}
|
|
26
|
-
formatMessage(level, message, context) {
|
|
27
|
-
const timestamp = new Date().toISOString();
|
|
28
|
-
const contextStr = context ? ` [${Object.entries(context).map(([k, v]) => `${k}:${v}`).join(', ')}]` : '';
|
|
29
|
-
return `[${timestamp}] ${level}${contextStr}: ${message}`;
|
|
30
|
-
}
|
|
31
|
-
debug(message, context, ...args) {
|
|
32
|
-
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
33
|
-
const formattedMessage = this.formatMessage('DEBUG', message, context);
|
|
34
|
-
if (this.isDevelopment) {
|
|
35
|
-
console.log(formattedMessage, ...args);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
info(message, context, ...args) {
|
|
40
|
-
if (this.shouldLog(LogLevel.INFO)) {
|
|
41
|
-
const formattedMessage = this.formatMessage('INFO', message, context);
|
|
42
|
-
console.log(formattedMessage, ...args);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
warn(message, context, ...args) {
|
|
46
|
-
if (this.shouldLog(LogLevel.WARN)) {
|
|
47
|
-
const formattedMessage = this.formatMessage('WARN', message, context);
|
|
48
|
-
console.warn(formattedMessage, ...args);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
error(message, error, context, ...args) {
|
|
52
|
-
if (this.shouldLog(LogLevel.ERROR)) {
|
|
53
|
-
const formattedMessage = this.formatMessage('ERROR', message, context);
|
|
54
|
-
if (error) {
|
|
55
|
-
console.error(formattedMessage, error, ...args);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
console.error(formattedMessage, ...args);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Specialized logging methods for common patterns
|
|
63
|
-
auth(message, context, ...args) {
|
|
64
|
-
this.info(`🔐 ${message}`, { ...context, category: 'auth' }, ...args);
|
|
65
|
-
}
|
|
66
|
-
api(message, context, ...args) {
|
|
67
|
-
this.info(`🌐 ${message}`, { ...context, category: 'api' }, ...args);
|
|
68
|
-
}
|
|
69
|
-
session(message, context, ...args) {
|
|
70
|
-
this.info(`📱 ${message}`, { ...context, category: 'session' }, ...args);
|
|
71
|
-
}
|
|
72
|
-
user(message, context, ...args) {
|
|
73
|
-
this.info(`👤 ${message}`, { ...context, category: 'user' }, ...args);
|
|
74
|
-
}
|
|
75
|
-
device(message, context, ...args) {
|
|
76
|
-
this.info(`📱 ${message}`, { ...context, category: 'device' }, ...args);
|
|
77
|
-
}
|
|
78
|
-
payment(message, context, ...args) {
|
|
79
|
-
this.info(`💳 ${message}`, { ...context, category: 'payment' }, ...args);
|
|
80
|
-
}
|
|
81
|
-
// Performance logging
|
|
82
|
-
performance(operation, duration, context) {
|
|
83
|
-
const level = duration > 1000 ? LogLevel.WARN : LogLevel.INFO;
|
|
84
|
-
const message = `⏱️ ${operation} completed in ${duration}ms`;
|
|
85
|
-
if (level === LogLevel.WARN) {
|
|
86
|
-
this.warn(message, { ...context, category: 'performance', duration });
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
this.info(message, { ...context, category: 'performance', duration });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// Error logging with stack trace
|
|
93
|
-
errorWithStack(message, error, context) {
|
|
94
|
-
this.error(message, error, { ...context, stack: error.stack });
|
|
95
|
-
}
|
|
96
|
-
// Group related log messages
|
|
97
|
-
group(label, fn) {
|
|
98
|
-
if (this.isDevelopment && this.shouldLog(LogLevel.DEBUG)) {
|
|
99
|
-
console.group(label);
|
|
100
|
-
fn();
|
|
101
|
-
console.groupEnd();
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
fn();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// Create singleton instance
|
|
109
|
-
exports.logger = new Logger();
|
|
110
|
-
// Convenience functions for common logging patterns
|
|
111
|
-
const logAuth = (message, context, ...args) => exports.logger.auth(message, context, ...args);
|
|
112
|
-
exports.logAuth = logAuth;
|
|
113
|
-
const logApi = (message, context, ...args) => exports.logger.api(message, context, ...args);
|
|
114
|
-
exports.logApi = logApi;
|
|
115
|
-
const logSession = (message, context, ...args) => exports.logger.session(message, context, ...args);
|
|
116
|
-
exports.logSession = logSession;
|
|
117
|
-
const logUser = (message, context, ...args) => exports.logger.user(message, context, ...args);
|
|
118
|
-
exports.logUser = logUser;
|
|
119
|
-
const logDevice = (message, context, ...args) => exports.logger.device(message, context, ...args);
|
|
120
|
-
exports.logDevice = logDevice;
|
|
121
|
-
const logPayment = (message, context, ...args) => exports.logger.payment(message, context, ...args);
|
|
122
|
-
exports.logPayment = logPayment;
|
|
123
|
-
const logError = (message, error, context, ...args) => exports.logger.error(message, error, context, ...args);
|
|
124
|
-
exports.logError = logError;
|
|
125
|
-
const logPerformance = (operation, duration, context) => exports.logger.performance(operation, duration, context);
|
|
126
|
-
exports.logPerformance = logPerformance;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debug Utilities
|
|
3
|
-
*
|
|
4
|
-
* Provides safe logging functions that only output in development mode.
|
|
5
|
-
* All logs are stripped in production builds.
|
|
6
|
-
*
|
|
7
|
-
* @module shared/utils/debugUtils
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Check if running in development mode
|
|
11
|
-
*/
|
|
12
|
-
export const isDev = () => {
|
|
13
|
-
if (typeof __DEV__ !== 'undefined')
|
|
14
|
-
return __DEV__;
|
|
15
|
-
try {
|
|
16
|
-
return typeof process !== 'undefined' && process.env?.NODE_ENV === 'development';
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Log a debug message (only in development)
|
|
24
|
-
* @param prefix - Log prefix (e.g., '[ColdBoot]')
|
|
25
|
-
* @param args - Arguments to log
|
|
26
|
-
*/
|
|
27
|
-
export const debugLog = (prefix, ...args) => {
|
|
28
|
-
if (isDev()) {
|
|
29
|
-
console.log(prefix, ...args);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Log a debug warning (only in development)
|
|
34
|
-
* @param prefix - Log prefix
|
|
35
|
-
* @param args - Arguments to log
|
|
36
|
-
*/
|
|
37
|
-
export const debugWarn = (prefix, ...args) => {
|
|
38
|
-
if (isDev()) {
|
|
39
|
-
console.warn(prefix, ...args);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Log a debug error (only in development)
|
|
44
|
-
* @param prefix - Log prefix
|
|
45
|
-
* @param args - Arguments to log
|
|
46
|
-
*/
|
|
47
|
-
export const debugError = (prefix, ...args) => {
|
|
48
|
-
if (isDev()) {
|
|
49
|
-
console.error(prefix, ...args);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Create a namespaced debug logger
|
|
54
|
-
* @param namespace - Logger namespace (e.g., 'ColdBoot', 'DeviceAuth')
|
|
55
|
-
* @returns Object with log, warn, error methods
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* const debug = createDebugLogger('ColdBoot');
|
|
60
|
-
* debug.log('Starting authentication');
|
|
61
|
-
* debug.warn('Token expires soon');
|
|
62
|
-
* debug.error('Authentication failed', error);
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export const createDebugLogger = (namespace) => {
|
|
66
|
-
const prefix = `[${namespace}]`;
|
|
67
|
-
return {
|
|
68
|
-
log: (...args) => debugLog(prefix, ...args),
|
|
69
|
-
warn: (...args) => debugWarn(prefix, ...args),
|
|
70
|
-
error: (...args) => debugError(prefix, ...args),
|
|
71
|
-
};
|
|
72
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized logging utilities for consistent logging across the application
|
|
3
|
-
*/
|
|
4
|
-
export var LogLevel;
|
|
5
|
-
(function (LogLevel) {
|
|
6
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
7
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
8
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
9
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
10
|
-
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
11
|
-
})(LogLevel || (LogLevel = {}));
|
|
12
|
-
class Logger {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.level = LogLevel.INFO;
|
|
15
|
-
this.isDevelopment = process.env.NODE_ENV === 'development';
|
|
16
|
-
}
|
|
17
|
-
setLevel(level) {
|
|
18
|
-
this.level = level;
|
|
19
|
-
}
|
|
20
|
-
shouldLog(level) {
|
|
21
|
-
return level >= this.level;
|
|
22
|
-
}
|
|
23
|
-
formatMessage(level, message, context) {
|
|
24
|
-
const timestamp = new Date().toISOString();
|
|
25
|
-
const contextStr = context ? ` [${Object.entries(context).map(([k, v]) => `${k}:${v}`).join(', ')}]` : '';
|
|
26
|
-
return `[${timestamp}] ${level}${contextStr}: ${message}`;
|
|
27
|
-
}
|
|
28
|
-
debug(message, context, ...args) {
|
|
29
|
-
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
30
|
-
const formattedMessage = this.formatMessage('DEBUG', message, context);
|
|
31
|
-
if (this.isDevelopment) {
|
|
32
|
-
console.log(formattedMessage, ...args);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
info(message, context, ...args) {
|
|
37
|
-
if (this.shouldLog(LogLevel.INFO)) {
|
|
38
|
-
const formattedMessage = this.formatMessage('INFO', message, context);
|
|
39
|
-
console.log(formattedMessage, ...args);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
warn(message, context, ...args) {
|
|
43
|
-
if (this.shouldLog(LogLevel.WARN)) {
|
|
44
|
-
const formattedMessage = this.formatMessage('WARN', message, context);
|
|
45
|
-
console.warn(formattedMessage, ...args);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
error(message, error, context, ...args) {
|
|
49
|
-
if (this.shouldLog(LogLevel.ERROR)) {
|
|
50
|
-
const formattedMessage = this.formatMessage('ERROR', message, context);
|
|
51
|
-
if (error) {
|
|
52
|
-
console.error(formattedMessage, error, ...args);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
console.error(formattedMessage, ...args);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// Specialized logging methods for common patterns
|
|
60
|
-
auth(message, context, ...args) {
|
|
61
|
-
this.info(`🔐 ${message}`, { ...context, category: 'auth' }, ...args);
|
|
62
|
-
}
|
|
63
|
-
api(message, context, ...args) {
|
|
64
|
-
this.info(`🌐 ${message}`, { ...context, category: 'api' }, ...args);
|
|
65
|
-
}
|
|
66
|
-
session(message, context, ...args) {
|
|
67
|
-
this.info(`📱 ${message}`, { ...context, category: 'session' }, ...args);
|
|
68
|
-
}
|
|
69
|
-
user(message, context, ...args) {
|
|
70
|
-
this.info(`👤 ${message}`, { ...context, category: 'user' }, ...args);
|
|
71
|
-
}
|
|
72
|
-
device(message, context, ...args) {
|
|
73
|
-
this.info(`📱 ${message}`, { ...context, category: 'device' }, ...args);
|
|
74
|
-
}
|
|
75
|
-
payment(message, context, ...args) {
|
|
76
|
-
this.info(`💳 ${message}`, { ...context, category: 'payment' }, ...args);
|
|
77
|
-
}
|
|
78
|
-
// Performance logging
|
|
79
|
-
performance(operation, duration, context) {
|
|
80
|
-
const level = duration > 1000 ? LogLevel.WARN : LogLevel.INFO;
|
|
81
|
-
const message = `⏱️ ${operation} completed in ${duration}ms`;
|
|
82
|
-
if (level === LogLevel.WARN) {
|
|
83
|
-
this.warn(message, { ...context, category: 'performance', duration });
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this.info(message, { ...context, category: 'performance', duration });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// Error logging with stack trace
|
|
90
|
-
errorWithStack(message, error, context) {
|
|
91
|
-
this.error(message, error, { ...context, stack: error.stack });
|
|
92
|
-
}
|
|
93
|
-
// Group related log messages
|
|
94
|
-
group(label, fn) {
|
|
95
|
-
if (this.isDevelopment && this.shouldLog(LogLevel.DEBUG)) {
|
|
96
|
-
console.group(label);
|
|
97
|
-
fn();
|
|
98
|
-
console.groupEnd();
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
fn();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// Create singleton instance
|
|
106
|
-
export const logger = new Logger();
|
|
107
|
-
// Convenience functions for common logging patterns
|
|
108
|
-
export const logAuth = (message, context, ...args) => logger.auth(message, context, ...args);
|
|
109
|
-
export const logApi = (message, context, ...args) => logger.api(message, context, ...args);
|
|
110
|
-
export const logSession = (message, context, ...args) => logger.session(message, context, ...args);
|
|
111
|
-
export const logUser = (message, context, ...args) => logger.user(message, context, ...args);
|
|
112
|
-
export const logDevice = (message, context, ...args) => logger.device(message, context, ...args);
|
|
113
|
-
export const logPayment = (message, context, ...args) => logger.payment(message, context, ...args);
|
|
114
|
-
export const logError = (message, error, context, ...args) => logger.error(message, error, context, ...args);
|
|
115
|
-
export const logPerformance = (operation, duration, context) => logger.performance(operation, duration, context);
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debug Utilities
|
|
3
|
-
*
|
|
4
|
-
* Provides safe logging functions that only output in development mode.
|
|
5
|
-
* All logs are stripped in production builds.
|
|
6
|
-
*
|
|
7
|
-
* @module shared/utils/debugUtils
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Check if running in development mode
|
|
11
|
-
*/
|
|
12
|
-
export declare const isDev: () => boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Log a debug message (only in development)
|
|
15
|
-
* @param prefix - Log prefix (e.g., '[ColdBoot]')
|
|
16
|
-
* @param args - Arguments to log
|
|
17
|
-
*/
|
|
18
|
-
export declare const debugLog: (prefix: string, ...args: unknown[]) => void;
|
|
19
|
-
/**
|
|
20
|
-
* Log a debug warning (only in development)
|
|
21
|
-
* @param prefix - Log prefix
|
|
22
|
-
* @param args - Arguments to log
|
|
23
|
-
*/
|
|
24
|
-
export declare const debugWarn: (prefix: string, ...args: unknown[]) => void;
|
|
25
|
-
/**
|
|
26
|
-
* Log a debug error (only in development)
|
|
27
|
-
* @param prefix - Log prefix
|
|
28
|
-
* @param args - Arguments to log
|
|
29
|
-
*/
|
|
30
|
-
export declare const debugError: (prefix: string, ...args: unknown[]) => void;
|
|
31
|
-
/**
|
|
32
|
-
* Create a namespaced debug logger
|
|
33
|
-
* @param namespace - Logger namespace (e.g., 'ColdBoot', 'DeviceAuth')
|
|
34
|
-
* @returns Object with log, warn, error methods
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const debug = createDebugLogger('ColdBoot');
|
|
39
|
-
* debug.log('Starting authentication');
|
|
40
|
-
* debug.warn('Token expires soon');
|
|
41
|
-
* debug.error('Authentication failed', error);
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare const createDebugLogger: (namespace: string) => {
|
|
45
|
-
log: (...args: unknown[]) => void;
|
|
46
|
-
warn: (...args: unknown[]) => void;
|
|
47
|
-
error: (...args: unknown[]) => void;
|
|
48
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized logging utilities for consistent logging across the application
|
|
3
|
-
*/
|
|
4
|
-
export declare enum LogLevel {
|
|
5
|
-
DEBUG = 0,
|
|
6
|
-
INFO = 1,
|
|
7
|
-
WARN = 2,
|
|
8
|
-
ERROR = 3,
|
|
9
|
-
NONE = 4
|
|
10
|
-
}
|
|
11
|
-
export interface LogContext {
|
|
12
|
-
component?: string;
|
|
13
|
-
method?: string;
|
|
14
|
-
userId?: string;
|
|
15
|
-
sessionId?: string;
|
|
16
|
-
requestId?: string;
|
|
17
|
-
[key: string]: unknown;
|
|
18
|
-
}
|
|
19
|
-
declare class Logger {
|
|
20
|
-
private level;
|
|
21
|
-
private isDevelopment;
|
|
22
|
-
setLevel(level: LogLevel): void;
|
|
23
|
-
private shouldLog;
|
|
24
|
-
private formatMessage;
|
|
25
|
-
debug(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
26
|
-
info(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
27
|
-
warn(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
28
|
-
error(message: string, error?: Error | unknown, context?: LogContext, ...args: unknown[]): void;
|
|
29
|
-
auth(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
30
|
-
api(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
31
|
-
session(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
32
|
-
user(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
33
|
-
device(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
34
|
-
payment(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
35
|
-
performance(operation: string, duration: number, context?: LogContext): void;
|
|
36
|
-
errorWithStack(message: string, error: Error, context?: LogContext): void;
|
|
37
|
-
group(label: string, fn: () => void): void;
|
|
38
|
-
}
|
|
39
|
-
export declare const logger: Logger;
|
|
40
|
-
export declare const logAuth: (message: string, context?: LogContext, ...args: unknown[]) => void;
|
|
41
|
-
export declare const logApi: (message: string, context?: LogContext, ...args: unknown[]) => void;
|
|
42
|
-
export declare const logSession: (message: string, context?: LogContext, ...args: unknown[]) => void;
|
|
43
|
-
export declare const logUser: (message: string, context?: LogContext, ...args: unknown[]) => void;
|
|
44
|
-
export declare const logDevice: (message: string, context?: LogContext, ...args: unknown[]) => void;
|
|
45
|
-
export declare const logPayment: (message: string, context?: LogContext, ...args: unknown[]) => void;
|
|
46
|
-
export declare const logError: (message: string, error?: Error | unknown, context?: LogContext, ...args: unknown[]) => void;
|
|
47
|
-
export declare const logPerformance: (operation: string, duration: number, context?: LogContext) => void;
|
|
48
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for isDev() utility.
|
|
3
|
-
*
|
|
4
|
-
* These tests manipulate the global __DEV__ and process.env.NODE_ENV
|
|
5
|
-
* to verify isDev() works across RN, Node, and browser-like environments.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
describe('isDev', () => {
|
|
9
|
-
const originalDev = (globalThis as any).__DEV__;
|
|
10
|
-
const originalNodeEnv = process.env.NODE_ENV;
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
// Restore globals
|
|
14
|
-
if (originalDev === undefined) {
|
|
15
|
-
delete (globalThis as any).__DEV__;
|
|
16
|
-
} else {
|
|
17
|
-
(globalThis as any).__DEV__ = originalDev;
|
|
18
|
-
}
|
|
19
|
-
process.env.NODE_ENV = originalNodeEnv;
|
|
20
|
-
|
|
21
|
-
// Clear module cache so isDev re-evaluates
|
|
22
|
-
jest.resetModules();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
async function loadIsDev() {
|
|
26
|
-
const mod = await import('../debugUtils');
|
|
27
|
-
return mod.isDev;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
it('returns true when __DEV__ is true (React Native)', async () => {
|
|
31
|
-
(globalThis as any).__DEV__ = true;
|
|
32
|
-
const isDev = await loadIsDev();
|
|
33
|
-
expect(isDev()).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('returns false when __DEV__ is false', async () => {
|
|
37
|
-
(globalThis as any).__DEV__ = false;
|
|
38
|
-
const isDev = await loadIsDev();
|
|
39
|
-
expect(isDev()).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('falls back to NODE_ENV when __DEV__ is undefined', async () => {
|
|
43
|
-
delete (globalThis as any).__DEV__;
|
|
44
|
-
process.env.NODE_ENV = 'development';
|
|
45
|
-
const isDev = await loadIsDev();
|
|
46
|
-
expect(isDev()).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('returns false when NODE_ENV is production and __DEV__ is undefined', async () => {
|
|
50
|
-
delete (globalThis as any).__DEV__;
|
|
51
|
-
process.env.NODE_ENV = 'production';
|
|
52
|
-
const isDev = await loadIsDev();
|
|
53
|
-
expect(isDev()).toBe(false);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debug Utilities
|
|
3
|
-
*
|
|
4
|
-
* Provides safe logging functions that only output in development mode.
|
|
5
|
-
* All logs are stripped in production builds.
|
|
6
|
-
*
|
|
7
|
-
* @module shared/utils/debugUtils
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/* global __DEV__ */
|
|
11
|
-
declare const __DEV__: boolean | undefined;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Check if running in development mode
|
|
15
|
-
*/
|
|
16
|
-
export const isDev = (): boolean => {
|
|
17
|
-
if (typeof __DEV__ !== 'undefined') return __DEV__;
|
|
18
|
-
try {
|
|
19
|
-
return typeof process !== 'undefined' && process.env?.NODE_ENV === 'development';
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Log a debug message (only in development)
|
|
27
|
-
* @param prefix - Log prefix (e.g., '[ColdBoot]')
|
|
28
|
-
* @param args - Arguments to log
|
|
29
|
-
*/
|
|
30
|
-
export const debugLog = (prefix: string, ...args: unknown[]): void => {
|
|
31
|
-
if (isDev()) {
|
|
32
|
-
console.log(prefix, ...args);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Log a debug warning (only in development)
|
|
38
|
-
* @param prefix - Log prefix
|
|
39
|
-
* @param args - Arguments to log
|
|
40
|
-
*/
|
|
41
|
-
export const debugWarn = (prefix: string, ...args: unknown[]): void => {
|
|
42
|
-
if (isDev()) {
|
|
43
|
-
console.warn(prefix, ...args);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Log a debug error (only in development)
|
|
49
|
-
* @param prefix - Log prefix
|
|
50
|
-
* @param args - Arguments to log
|
|
51
|
-
*/
|
|
52
|
-
export const debugError = (prefix: string, ...args: unknown[]): void => {
|
|
53
|
-
if (isDev()) {
|
|
54
|
-
console.error(prefix, ...args);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Create a namespaced debug logger
|
|
60
|
-
* @param namespace - Logger namespace (e.g., 'ColdBoot', 'DeviceAuth')
|
|
61
|
-
* @returns Object with log, warn, error methods
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```ts
|
|
65
|
-
* const debug = createDebugLogger('ColdBoot');
|
|
66
|
-
* debug.log('Starting authentication');
|
|
67
|
-
* debug.warn('Token expires soon');
|
|
68
|
-
* debug.error('Authentication failed', error);
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export const createDebugLogger = (namespace: string) => {
|
|
72
|
-
const prefix = `[${namespace}]`;
|
|
73
|
-
return {
|
|
74
|
-
log: (...args: unknown[]) => debugLog(prefix, ...args),
|
|
75
|
-
warn: (...args: unknown[]) => debugWarn(prefix, ...args),
|
|
76
|
-
error: (...args: unknown[]) => debugError(prefix, ...args),
|
|
77
|
-
};
|
|
78
|
-
};
|