import { NativeModule, registerWebModule, SharedObject } from 'expo'; import type { Session } from './Session'; import type { ExpoAppMetricsModuleType, LogAttributeValue, LogEventOptions, LogRecord, Metric, MetricAttributes, NetworkRequestObserverEvents, MetricInput, SessionType, } from './types'; export * from './types'; class NetworkRequestObserverWeb extends SharedObject { // Web has no native interceptor, so this never emits. Kept as a no-op so cross-platform code // can construct it without guarding on Platform.OS. } class WebSession extends globalThis.expo.SharedObject { readonly id = 'web-session'; readonly startDate = new Date().toISOString(); constructor(readonly type: SessionType = 'main') { super(); } async isActive(): Promise { return true; } async getEndDate(): Promise { return null; } async getMetrics(): Promise { return []; } async getLogs(): Promise { return []; } async addMetric(_metric: MetricInput): Promise {} } class ExpoAppMetricsModule extends NativeModule implements ExpoAppMetricsModuleType { NetworkRequestObserver = NetworkRequestObserverWeb as unknown as ExpoAppMetricsModuleType['NetworkRequestObserver']; Session = WebSession as unknown as typeof Session; private mainSession: WebSession | null = null; async markFirstRender() {} async markInteractive(attributes?: MetricAttributes) {} logEvent(name: string, options?: LogEventOptions) {} setGlobalAttributes(attributes?: Record | null) {} async clearStoredEntries() {} async getInactiveSessions() { return []; } reportError() {} getMainSession(): Session { this.mainSession ??= new WebSession('main'); return this.mainSession as unknown as Session; } async getForegroundSession() { return null; } } export default registerWebModule(ExpoAppMetricsModule, 'ExpoAppMetrics');