UNPKG

ssr-web-avo-inspector

Version:

Avo Inspector for web with SSR and web workers support

93 lines (92 loc) 3.49 kB
import { AvoInspectorEnvValueType } from "./AvoInspectorEnv"; import { AvoBatcher } from "./AvoBatcher"; import { AvoStorage } from "./AvoStorage"; import { AvoDeduplicator } from "./AvoDeduplicator"; import type { ValidationResult } from "./eventSpec/AvoEventSpecFetchTypes"; export declare class AvoInspector { environment: AvoInspectorEnvValueType; avoBatcher: AvoBatcher; avoDeduplicator: AvoDeduplicator; apiKey: string; version: string; private avoNetworkCallsHandler; static avoStorage: AvoStorage; private eventSpecFetcher; private eventSpecCache; /** Last seen branchId from event spec responses, used for cache flush on branch change */ private lastSeenBranchId; private static _batchSize; static get batchSize(): number; static set batchSize(newSize: number); private static _batchFlushSeconds; static get batchFlushSeconds(): number; private static _shouldLog; static get shouldLog(): boolean; static set shouldLog(enable: boolean); constructor(options: { apiKey: string; env: AvoInspectorEnvValueType; version: string; appName?: string; suffix?: string; publicEncryptionKey?: string; }); trackSchemaFromEvent(eventName: string, eventProperties: { [propName: string]: any; }): Promise<Array<{ propertyName: string; propertyType: string; children?: any; }>>; private _avoFunctionTrackSchemaFromEvent; /** * Shared implementation for trackSchemaFromEvent and _avoFunctionTrackSchemaFromEvent. */ private trackSchemaFromEventInternal; trackSchema(eventName: string, eventSchema: Array<{ propertyName: string; propertyType: string; children?: any; }>): void; private trackSchemaInternal; enableLogging(enable: boolean): void; extractSchema(eventProperties: { [propName: string]: any; }, shouldLogIfEnabled?: boolean): Array<{ propertyName: string; propertyType: string; children?: any; }>; setBatchSize(newBatchSize: number): void; setBatchFlushSeconds(newBatchFlushSeconds: number): void; /** * Validates event properties against the Avo tracking plan spec. * * Active only in dev/staging environments. In prod, returns null immediately. * Null spec responses are cached to avoid re-fetching. * Cache is flushed when branchId changes between responses. * * @param eventName - The name of the event to validate * @param eventProperties - The properties to validate * @returns ValidationResult with property validation results, or null if spec unavailable */ validateEvent(eventName: string, eventProperties: { [propName: string]: any; }): Promise<ValidationResult | null>; /** * Merges validation results into the event schema. * Adds failedEventIds or passedEventIds to each property based on validation. * Recursively merges validation results for nested children. */ private mergeValidationResults; /** * Merges validation result into a single property, recursively handling children. */ private mergePropertyValidation; /** * Sends an event immediately with validation data (bypasses batching). * Encrypts property values if publicEncryptionKey is configured. * Logs validation info if shouldLog is true. */ private sendEventWithValidation; }