mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-01 11:10:00 +00:00
- Create authEventBus.ts with typed event hooks - Create authTracking.ts to subscribe telemetry to auth events - Remove direct telemetry imports from firebaseAuthStore - Remove useCurrentUser import from MixpanelTelemetryProvider - Breaks ~600 circular dependency cycles Amp-Thread-ID: https://ampcode.com/threads/T-019bfe73-6a29-7638-8160-8de515af8707 Co-authored-by: Amp <amp@ampcode.com>
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
/**
|
|
* Telemetry Provider - OSS Build Safety
|
|
*
|
|
* CRITICAL: OSS Build Safety
|
|
* This module is conditionally compiled based on distribution. When building
|
|
* the open source version (DISTRIBUTION unset), this entire module and its dependencies
|
|
* are excluded through via tree-shaking.
|
|
*
|
|
* To verify OSS builds exclude this code:
|
|
* 1. `DISTRIBUTION= pnpm build` (OSS build)
|
|
* 2. `grep -RinE --include='*.js' 'trackWorkflow|trackEvent|mixpanel' dist/` (should find nothing)
|
|
* 3. Check dist/assets/*.js files contain no tracking code
|
|
*
|
|
* This approach maintains complete separation between cloud and OSS builds
|
|
* while ensuring the open source version contains no telemetry dependencies.
|
|
*/
|
|
import { isCloud } from '@/platform/distribution/types'
|
|
|
|
import { initAuthTracking } from './authTracking'
|
|
import { MixpanelTelemetryProvider } from './providers/cloud/MixpanelTelemetryProvider'
|
|
import type { TelemetryProvider } from './types'
|
|
|
|
// Singleton instance
|
|
let _telemetryProvider: TelemetryProvider | null = null
|
|
let _authTrackingInitialized = false
|
|
|
|
/**
|
|
* Telemetry factory - conditionally creates provider based on distribution
|
|
* Returns singleton instance.
|
|
*
|
|
* CRITICAL: This returns undefined in OSS builds. There is no telemetry provider
|
|
* for OSS builds and all tracking calls are no-ops.
|
|
*/
|
|
export function useTelemetry(): TelemetryProvider | null {
|
|
if (_telemetryProvider === null) {
|
|
// Use distribution check for tree-shaking
|
|
if (isCloud) {
|
|
_telemetryProvider = new MixpanelTelemetryProvider()
|
|
|
|
if (!_authTrackingInitialized) {
|
|
initAuthTracking(() => _telemetryProvider)
|
|
_authTrackingInitialized = true
|
|
}
|
|
}
|
|
// For OSS builds, _telemetryProvider stays null
|
|
}
|
|
|
|
return _telemetryProvider
|
|
}
|