Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
265
resources/js/modules/api-manager/index.js
Normal file
265
resources/js/modules/api-manager/index.js
Normal file
@@ -0,0 +1,265 @@
|
||||
// modules/api-manager/index.js
|
||||
import { Logger } from '../../core/logger.js';
|
||||
import { ObserverManager } from './ObserverManager.js';
|
||||
import { MediaManager } from './MediaManager.js';
|
||||
import { StorageManager } from './StorageManager.js';
|
||||
import { DeviceManager } from './DeviceManager.js';
|
||||
import { AnimationManager } from './AnimationManager.js';
|
||||
import { WorkerManager } from './WorkerManager.js';
|
||||
import { PerformanceManager } from './PerformanceManager.js';
|
||||
import { PermissionManager } from './PermissionManager.js';
|
||||
import { BiometricAuthManager } from './BiometricAuthManager.js';
|
||||
|
||||
/**
|
||||
* Centralized API Manager for all Web APIs
|
||||
* Provides unified, simplified access to modern browser APIs
|
||||
*/
|
||||
const APIManagerModule = {
|
||||
name: 'api-manager',
|
||||
|
||||
// Module-level init (called by module system)
|
||||
init(config = {}, state = null) {
|
||||
Logger.info('[APIManager] Module initialized - All Web APIs available');
|
||||
this.initializeAPIManagers(config);
|
||||
this.exposeGlobalAPI();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize all API managers
|
||||
*/
|
||||
initializeAPIManagers(config) {
|
||||
this.observers = new ObserverManager(config.observers || {});
|
||||
this.media = new MediaManager(config.media || {});
|
||||
this.storage = new StorageManager(config.storage || {});
|
||||
this.device = new DeviceManager(config.device || {});
|
||||
this.animation = new AnimationManager(config.animation || {});
|
||||
this.worker = new WorkerManager(config.worker || {});
|
||||
this.performance = new PerformanceManager(config.performance || {});
|
||||
this.permissions = new PermissionManager(config.permissions || {});
|
||||
this.biometric = new BiometricAuthManager(config.biometric || {});
|
||||
|
||||
Logger.info('[APIManager] All API managers initialized');
|
||||
},
|
||||
|
||||
/**
|
||||
* Expose global API for easy access
|
||||
*/
|
||||
exposeGlobalAPI() {
|
||||
// Make API managers globally available
|
||||
if (typeof window !== 'undefined') {
|
||||
window.API = {
|
||||
observers: this.observers,
|
||||
media: this.media,
|
||||
storage: this.storage,
|
||||
device: this.device,
|
||||
animation: this.animation,
|
||||
worker: this.worker,
|
||||
performance: this.performance,
|
||||
permissions: this.permissions,
|
||||
biometric: this.biometric
|
||||
};
|
||||
|
||||
Logger.info('[APIManager] Global API exposed at window.API');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get specific API manager
|
||||
*/
|
||||
getAPI(name) {
|
||||
return this[name] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if specific Web API is supported
|
||||
*/
|
||||
isSupported(apiName) {
|
||||
const supportMap = {
|
||||
// Observer APIs
|
||||
'IntersectionObserver': 'IntersectionObserver' in window,
|
||||
'ResizeObserver': 'ResizeObserver' in window,
|
||||
'MutationObserver': 'MutationObserver' in window,
|
||||
'PerformanceObserver': 'PerformanceObserver' in window,
|
||||
|
||||
// Media APIs
|
||||
'MediaDevices': navigator.mediaDevices !== undefined,
|
||||
'WebRTC': 'RTCPeerConnection' in window,
|
||||
'WebAudio': 'AudioContext' in window || 'webkitAudioContext' in window,
|
||||
'MediaRecorder': 'MediaRecorder' in window,
|
||||
|
||||
// Storage APIs
|
||||
'IndexedDB': 'indexedDB' in window,
|
||||
'CacheAPI': 'caches' in window,
|
||||
'WebLocks': 'locks' in navigator,
|
||||
'BroadcastChannel': 'BroadcastChannel' in window,
|
||||
|
||||
// Device APIs
|
||||
'Geolocation': 'geolocation' in navigator,
|
||||
'DeviceMotion': 'DeviceMotionEvent' in window,
|
||||
'DeviceOrientation': 'DeviceOrientationEvent' in window,
|
||||
'Vibration': 'vibrate' in navigator,
|
||||
'Battery': 'getBattery' in navigator,
|
||||
'NetworkInfo': 'connection' in navigator,
|
||||
|
||||
// Animation APIs
|
||||
'WebAnimations': 'animate' in Element.prototype,
|
||||
'VisualViewport': 'visualViewport' in window,
|
||||
|
||||
// Worker APIs
|
||||
'WebWorkers': 'Worker' in window,
|
||||
'ServiceWorker': 'serviceWorker' in navigator,
|
||||
'SharedWorker': 'SharedWorker' in window,
|
||||
|
||||
// Performance APIs
|
||||
'PerformanceAPI': 'performance' in window,
|
||||
'NavigationTiming': 'getEntriesByType' in performance,
|
||||
|
||||
// Permission APIs
|
||||
'Permissions': 'permissions' in navigator,
|
||||
'WebAuthn': 'credentials' in navigator && 'create' in navigator.credentials
|
||||
};
|
||||
|
||||
return supportMap[apiName] || false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get browser capabilities report
|
||||
*/
|
||||
getCapabilities() {
|
||||
const capabilities = {};
|
||||
|
||||
// Check all API support
|
||||
Object.keys(this.getSupportMap()).forEach(api => {
|
||||
capabilities[api] = this.isSupported(api);
|
||||
});
|
||||
|
||||
return {
|
||||
capabilities,
|
||||
modernBrowser: this.isModernBrowser(),
|
||||
recommendedAPIs: this.getRecommendedAPIs(),
|
||||
summary: this.getCapabilitySummary(capabilities)
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if browser is considered modern
|
||||
*/
|
||||
isModernBrowser() {
|
||||
const requiredAPIs = [
|
||||
'IntersectionObserver',
|
||||
'ResizeObserver',
|
||||
'WebAnimations',
|
||||
'IndexedDB'
|
||||
];
|
||||
|
||||
return requiredAPIs.every(api => this.isSupported(api));
|
||||
},
|
||||
|
||||
/**
|
||||
* Get recommended APIs for current browser
|
||||
*/
|
||||
getRecommendedAPIs() {
|
||||
const recommendations = [];
|
||||
|
||||
if (this.isSupported('IntersectionObserver')) {
|
||||
recommendations.push({
|
||||
api: 'IntersectionObserver',
|
||||
use: 'Lazy loading, scroll triggers, viewport detection',
|
||||
example: 'API.observers.intersection(elements, callback)'
|
||||
});
|
||||
}
|
||||
|
||||
if (this.isSupported('WebAnimations')) {
|
||||
recommendations.push({
|
||||
api: 'Web Animations',
|
||||
use: 'High-performance animations with timeline control',
|
||||
example: 'API.animation.animate(element, keyframes, options)'
|
||||
});
|
||||
}
|
||||
|
||||
if (this.isSupported('IndexedDB')) {
|
||||
recommendations.push({
|
||||
api: 'IndexedDB',
|
||||
use: 'Client-side database for complex data',
|
||||
example: 'API.storage.db.set(key, value)'
|
||||
});
|
||||
}
|
||||
|
||||
if (this.isSupported('MediaDevices')) {
|
||||
recommendations.push({
|
||||
api: 'Media Devices',
|
||||
use: 'Camera, microphone, screen sharing',
|
||||
example: 'API.media.getUserCamera()'
|
||||
});
|
||||
}
|
||||
|
||||
return recommendations;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get capability summary
|
||||
*/
|
||||
getCapabilitySummary(capabilities) {
|
||||
const total = Object.keys(capabilities).length;
|
||||
const supported = Object.values(capabilities).filter(Boolean).length;
|
||||
const percentage = Math.round((supported / total) * 100);
|
||||
|
||||
return {
|
||||
total,
|
||||
supported,
|
||||
percentage,
|
||||
grade: this.getGrade(percentage)
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Get grade based on API support percentage
|
||||
*/
|
||||
getGrade(percentage) {
|
||||
if (percentage >= 90) return 'A+';
|
||||
if (percentage >= 80) return 'A';
|
||||
if (percentage >= 70) return 'B';
|
||||
if (percentage >= 60) return 'C';
|
||||
return 'D';
|
||||
},
|
||||
|
||||
/**
|
||||
* Get support map for reference
|
||||
*/
|
||||
getSupportMap() {
|
||||
return {
|
||||
'IntersectionObserver': 'Viewport intersection detection',
|
||||
'ResizeObserver': 'Element resize detection',
|
||||
'MutationObserver': 'DOM change detection',
|
||||
'PerformanceObserver': 'Performance metrics monitoring',
|
||||
'MediaDevices': 'Camera and microphone access',
|
||||
'WebRTC': 'Real-time communication',
|
||||
'WebAudio': 'Audio processing and synthesis',
|
||||
'MediaRecorder': 'Audio/video recording',
|
||||
'IndexedDB': 'Client-side database',
|
||||
'CacheAPI': 'HTTP cache management',
|
||||
'WebLocks': 'Resource locking',
|
||||
'BroadcastChannel': 'Cross-tab communication',
|
||||
'Geolocation': 'GPS and location services',
|
||||
'DeviceMotion': 'Accelerometer and gyroscope',
|
||||
'DeviceOrientation': 'Device orientation',
|
||||
'Vibration': 'Haptic feedback',
|
||||
'Battery': 'Battery status',
|
||||
'NetworkInfo': 'Network connection info',
|
||||
'WebAnimations': 'High-performance animations',
|
||||
'VisualViewport': 'Viewport information',
|
||||
'WebWorkers': 'Background processing',
|
||||
'ServiceWorker': 'Background sync and caching',
|
||||
'SharedWorker': 'Shared background processing',
|
||||
'PerformanceAPI': 'Performance measurement',
|
||||
'NavigationTiming': 'Navigation timing metrics',
|
||||
'Permissions': 'Browser permission management',
|
||||
'WebAuthn': 'Biometric authentication'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Export für module system
|
||||
export const init = APIManagerModule.init.bind(APIManagerModule);
|
||||
export default APIManagerModule;
|
||||
Reference in New Issue
Block a user