UNPKG

avo-inspector

Version:

[![npm version](https://badge.fury.io/js/avo-inspector.svg)](https://badge.fury.io/js/avo-inspector)

85 lines (84 loc) 3.38 kB
import type { EventSpecMetadata } from "./eventSpec/AvoEventSpecFetchTypes"; /** * Recursive type for schema children. * - For object properties: array of EventProperty objects * - For list properties: array of strings (primitive types) or nested structures */ export type SchemaChild = string | EventProperty | SchemaChild[]; /** * Property schema with optional validation results. */ export interface EventProperty { propertyName: string; propertyType: string; encryptedPropertyValue?: string; children?: SchemaChild[]; /** Event/variant IDs that FAILED validation (present if smaller or equal to passed) */ failedEventIds?: string[]; /** Event/variant IDs that PASSED validation (present if smaller than failed) */ passedEventIds?: string[]; } export interface BaseBody { apiKey: string; appName: string; appVersion: string; libVersion: string; env: string; libPlatform: "web"; messageId: string; trackingId: string; createdAt: string; sessionId: string; streamId: string; samplingRate: number; /** Event spec metadata from EventSpecResponse (moved from EventSchemaBody) */ eventSpecMetadata?: EventSpecMetadata; /** RSA public encryption key - allows Inspector to validate encrypted values against tracking plan */ publicEncryptionKey?: string; } export interface SessionStartedBody extends BaseBody { type: "sessionStarted"; } export interface EventSchemaBody extends BaseBody { type: "event"; /** ID of the base event from spec (null if no spec available) */ eventId: string | null; /** Name seen in code */ eventName?: string; eventProperties: EventProperty[]; avoFunction: boolean; eventHash: string | null; /** Branch ID from getEventSpec response when value validation was performed */ validatedBranchId?: string; } export declare class AvoNetworkCallsHandler { private readonly apiKey; private readonly envName; private readonly appName; private readonly appVersion; private readonly libVersion; private readonly publicEncryptionKey?; private samplingRate; private sending; private static readonly trackingEndpoint; constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string, publicEncryptionKey?: string); callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: Error | null) => any): void; private fixStreamIds; bodyForSessionStartedCall(): SessionStartedBody; bodyForEventSchemaCall(eventName: string, eventProperties: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata, validatedBranchId?: string): EventSchemaBody; private createBaseCallBody; /** * Calls Inspector API immediately with a single event (bypasses batching). * Used when event spec validation is available. * Note: Does not drop due to sampling - validated events are always sent. */ callInspectorImmediately(eventBody: EventSchemaBody, onCompleted: (error: Error | null) => any): void; /** * Check if event should be dropped based on sampling rate. */ private shouldDropBySampling; /** * Core Inspector API call logic shared by batch and immediate calls. */ private callInspectorApi; }