ssr-web-avo-inspector
Version:
Avo Inspector for web with SSR and web workers support
97 lines (96 loc) • 3.65 kB
TypeScript
import type { EventSpecMetadata } from "./eventSpec/AvoEventSpecFetchTypes";
export interface EventProperty {
propertyName: string;
propertyType: string;
encryptedPropertyValue?: string;
children?: any;
failedEventIds?: string[];
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;
publicEncryptionKey?: string;
}
export interface SessionStartedBody extends BaseBody {
type: "sessionStarted";
}
export interface EventSchemaBody extends BaseBody {
type: "event";
eventName: string;
eventProperties: EventProperty[];
avoFunction: boolean;
eventId: string | null;
eventHash: string | null;
eventSpecMetadata?: EventSpecMetadata;
validatedBranchId?: string;
}
export declare class AvoNetworkCallsHandler {
private apiKey;
private envName;
private appName;
private appVersion;
private libVersion;
private publicEncryptionKey?;
private samplingRate;
private sending;
private static trackingEndpoint;
constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string, publicEncryptionKey?: string);
/**
* Determines whether encryption should be applied.
* Truth table:
* dev + key = true
* staging + key = true
* prod + key = false
* dev + null = false
* dev + empty = false
*/
private shouldEncrypt;
/**
* Adds encrypted property values to event properties.
* For each property that has a corresponding value in eventValues:
* - Skip list-type properties (omitted entirely)
* - Encrypt the value and set encryptedPropertyValue
* - On failure: console.warn, omit property value, continue
*/
private addEncryptedValues;
callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: string | null) => any): void;
bodyForSessionStartedCall(): SessionStartedBody;
bodyForEventSchemaCall(eventName: string, eventProperties: Array<{
propertyName: string;
propertyType: string;
children?: any;
}>, eventId: string | null, eventHash: string | null): EventSchemaBody;
/**
* Async version of bodyForEventSchemaCall that also encrypts property values.
* Used when event validation has been performed and we have access to the
* original event property values for encryption.
*
* @param eventName - Event name
* @param eventProperties - Schema properties (type info)
* @param eventId - Event ID (null if not from Avo function)
* @param eventHash - Event hash (null if not from Avo function)
* @param eventValues - Original property values to encrypt
* @returns Promise resolving to EventSchemaBody with encrypted values
*/
bodyForValidatedEventSchemaCall(eventName: string, eventProperties: EventProperty[], eventId: string | null, eventHash: string | null, eventValues: {
[propName: string]: any;
}): Promise<EventSchemaBody>;
/**
* 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: string | null) => any): void;
private createBaseCallBody;
}