import { AvoInspectorEnvValueType } from "./AvoInspectorEnv"; import { AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler"; import { AvoDeduplicator } from "./AvoDeduplicator"; /** * One observed event, the single argument of `trackSchemaFromEvent`. The gateway fields * are for a gateway-scoped Inspector API key; blank values are treated as absent. */ export interface InspectorEvent { /** The event name. A missing, empty or whitespace-only name is sent as "Missing Event Name". */ eventName: string; /** The event's properties. Absent or null: an event with no properties. */ eventProperties?: { [propName: string]: any; } | null; /** Optional stream id to correlate events. */ streamId?: string; /** Reference of the gateway output this observation was bound for. Absent = gateway checkpoint. */ outputReference?: string; /** Low-cardinality label of the source the event came from (e.g. "web"). Never a user id. */ originHint?: string; /** App version of the source that produced this event; overrides the instance version. */ originAppVersion?: string; } /** * The gateway fields of a Codegen call (`_avoFunctionTrackSchemaFromEvent`), with the same * meaning as on InspectorEvent. Not re-exported from the package root, but not marked internal: * stripInternal would drop it from the declarations while that public method still uses it. */ export interface CodegenGatewayFields { outputReference?: string; originHint?: string; originAppVersion?: string; } type SchemaEntry = { propertyName: string; propertyType: string; children?: any; }; export declare class AvoInspector { environment: AvoInspectorEnvValueType; avoNetworkCallsHandler: AvoNetworkCallsHandler; avoDeduplicator: AvoDeduplicator; apiKey: string; version: string; private publicEncryptionKey?; private eventSpecFetcher; private eventSpecCache; private eventValidator; private generatedAnonymousId; private batchSize; private batchQueue; private destroyed; private destroyWaiters; private pending; private validations; private drainScheduled; private drainThisTurn; private untilDestroyed; private untilGivenUp; /** The exit drain ran out of time for validations: their events are sent unvalidated. */ private giveUpValidations; private get pendingCount(); private trackPending; private static instancesWithWork; private static exitDrainArmed; private static exitReportArmed; private static exitDeadline; private static waitingValidations; private releaseWaiting; private validationOutcomes; private giveUpWaiters; private static lastTrackAt; private static validationGraceUsedFor; private static explicitFlushDeadlines; private static drainOnExit; private static reportOnExit; private static armExitDrain; private static disarmExitDrain; private updateExitDrain; private static _shouldLog; /** Whether the SDK writes its diagnostic log lines (shared by every instance). */ static get shouldLog(): boolean; static set shouldLog(enable: boolean); /** * Creates an Inspector instance. A missing or unsupported `env` falls back to dev. * * @throws if `apiKey` or `version` is blank, or `apiKey` contains a character that * cannot be sent in an HTTP header. */ constructor(options: { apiKey: string; env: AvoInspectorEnvValueType; version: string; appName?: string; publicEncryptionKey?: string; /** Flush when this many events are buffered. Default 30; always 1 in dev. */ batchSize?: number; /** Flush once the oldest buffered event is this many seconds old. Default 30. */ batchFlushSeconds?: number; /** Maximum buffered events; the oldest are dropped first. Default 1000. */ maxQueueSize?: number; /** Start no background flush timer (recommended for serverless). Default false. */ disableBatchTimer?: boolean; }); private static resolveBatchOptions; /** * Resolves the gateway options for one event. outputReference / originHint are * omitted when blank; appVersion is the per-event override, null for a * source-scoped event without one, else the instance version. */ private resolveGatewayFields; private static warnUnknownEventKeys; /** * Extracts the event schema and queues it for the Inspector API. * * Resolves with the schema once the event is queued. In dev (batch size 1) the send * happens within the call and a non-200 response resolves `[]`; with batching the * batch's HTTP outcome is not observable here. Buffered events are only delivered * by a later size or time trigger, or by `flush()` — call `flush()` before exit. * * Anything but an object (such as a 1.x call `trackSchemaFromEvent(name, properties)`) * sends nothing, prints an always-on error naming the fix, and resolves `[]`. */ trackSchemaFromEvent(event: InspectorEvent): Promise>; /** * Codegen entry point: like `trackSchemaFromEvent`, and additionally records the * Avo function's `eventId` / `eventHash` so the event is sent with `avoFunction: true`. */ _avoFunctionTrackSchemaFromEvent(eventName: string, eventProperties: { [propName: string]: any; }, eventId: string, eventHash: string, streamId?: string, options?: CodegenGatewayFields): Promise>; private track; /** * Codegen/manual deduplication applies only to plain calls. A call carrying gateway * options is a distinct observation per gateway output and is always sent. */ private shouldRegisterEvent; /** * Samples the event, then queues it. When event spec validation is active the spec * is fetched (or read from cache) first, so the event joins the queue once its * validation results are merged in; flush() awaits that fetch before draining. */ private sampleAndEnqueue; private enqueue; private sendBatch; private isValidationActive; /** * Sends every buffered event, then waits until all in-flight sends (and spec fetches * that will enqueue) have completed or `timeoutMs` (default 10000) has elapsed. * Resolves `true` if, when it resolves, this instance has nothing buffered, waiting or in * flight (always after destroy()), and `false` if the timeout won. Never rejects. Call it * before process exit or before a serverless handler returns. */ flush(timeoutMs?: number): Promise; private hasDrained; private flushWithin; /** Turns the SDK's diagnostic logging on or off for every instance. */ enableLogging(enable: boolean): void; /** Returns the schema of `eventProperties` without tracking or sending anything. */ extractSchema(eventProperties: { [propName: string]: any; }, shouldLogIfEnabled?: boolean): Array<{ propertyName: string; propertyType: string; children?: any; }>; /** * Fetch event spec and validate. Returns validation results + metadata if * validation succeeds, or null if unavailable (prod, no spec, fetch error). */ private fetchAndValidate; /** * Cancels and cleans up: discards the pending batch unsent, abandons in-flight * requests and stops the flush timer. Does not flush. After destroy() the instance * is terminated and trackSchemaFromEvent resolves [] without sending; a call still * waiting on a spec fetch or on its immediate send also resolves []. */ destroy(): void; } export {};