avo-inspector 2.2.0 → 2.2.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +130 -0
  3. package/bin/avo-inspector.js +97 -0
  4. package/dist/AvoBatcher.d.ts +4 -11
  5. package/dist/AvoEncryption.d.ts +33 -0
  6. package/dist/AvoInspector.d.ts +35 -6
  7. package/dist/AvoNetworkCallsHandler.d.ts +42 -12
  8. package/dist/AvoSchemaParser.d.ts +12 -5
  9. package/dist/browser.js.LICENSE.txt +5 -0
  10. package/dist/eventSpec/AvoEventSpecCache.d.ts +73 -0
  11. package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +141 -0
  12. package/dist/eventSpec/AvoEventSpecFetcher.d.ts +54 -0
  13. package/dist/eventSpec/EventValidator.d.ts +34 -0
  14. package/dist/eventSpec/cache.d.ts +73 -0
  15. package/dist/eventSpec/index.d.ts +4 -0
  16. package/dist/eventSpec/types.d.ts +74 -0
  17. package/dist/index.js +2 -1
  18. package/dist/index.js.LICENSE.txt +5 -0
  19. package/dist-browser/AvoAnonymousId.d.ts +26 -0
  20. package/dist-browser/AvoBatcher.d.ts +26 -0
  21. package/dist-browser/AvoDeduplicator.d.ts +20 -0
  22. package/dist-browser/AvoEncryption.d.ts +33 -0
  23. package/dist-browser/AvoGuid.d.ts +3 -0
  24. package/dist-browser/AvoInspector.d.ts +78 -0
  25. package/dist-browser/AvoInspectorEnv.d.ts +7 -0
  26. package/dist-browser/AvoNetworkCallsHandler.d.ts +74 -0
  27. package/dist-browser/AvoSchemaParser.d.ts +20 -0
  28. package/dist-browser/AvoStorage.d.ts +22 -0
  29. package/dist-browser/__mocks__/xhr.d.ts +12 -0
  30. package/dist-browser/__mocks__/xhrError.d.ts +12 -0
  31. package/dist-browser/__tests__/AnonymousId_test.d.ts +1 -0
  32. package/dist-browser/__tests__/AvoEncryption_test.d.ts +1 -0
  33. package/dist-browser/__tests__/AvoInspectorEventSpec_test.d.ts +1 -0
  34. package/dist-browser/__tests__/AvoInspector_test.d.ts +1 -0
  35. package/dist-browser/__tests__/BatcherPublic_test.d.ts +1 -0
  36. package/dist-browser/__tests__/Batcher_test.d.ts +1 -0
  37. package/dist-browser/__tests__/Deduplicator_test.d.ts +1 -0
  38. package/dist-browser/__tests__/EncryptedPropertyTracking_test.d.ts +1 -0
  39. package/dist-browser/__tests__/EventSpecCache_test.d.ts +1 -0
  40. package/dist-browser/__tests__/EventSpecFetcher_test.d.ts +1 -0
  41. package/dist-browser/__tests__/EventValidator_test.d.ts +1 -0
  42. package/dist-browser/__tests__/NetworkCallsHandler_test.d.ts +1 -0
  43. package/dist-browser/__tests__/Parsing_test.d.ts +1 -0
  44. package/dist-browser/__tests__/Storage_test.d.ts +1 -0
  45. package/dist-browser/__tests__/ValidationIntegration_test.d.ts +1 -0
  46. package/dist-browser/__tests__/constants.d.ts +36 -0
  47. package/dist-browser/__tests__/helpers/encryptionHelpers.d.ts +13 -0
  48. package/dist-browser/__tests__/helpers/mockFactories.d.ts +49 -0
  49. package/dist-browser/eventSpec/AvoEventSpecCache.d.ts +73 -0
  50. package/dist-browser/eventSpec/AvoEventSpecFetchTypes.d.ts +109 -0
  51. package/dist-browser/eventSpec/AvoEventSpecFetcher.d.ts +55 -0
  52. package/dist-browser/eventSpec/EventValidator.d.ts +90 -0
  53. package/dist-browser/eventSpec/index.d.ts +4 -0
  54. package/dist-browser/index.d.ts +2 -0
  55. package/dist-browser/utils.d.ts +3 -0
  56. package/dist-native/AvoBatcher.d.ts +24 -0
  57. package/dist-native/AvoBatcher.js +82 -0
  58. package/dist-native/AvoDeduplicator.d.ts +36 -0
  59. package/dist-native/AvoDeduplicator.js +142 -0
  60. package/dist-native/AvoGuid.d.ts +3 -0
  61. package/dist-native/AvoGuid.js +14 -0
  62. package/dist-native/AvoInspector.d.ts +52 -0
  63. package/dist-native/AvoInspector.js +220 -0
  64. package/dist-native/AvoInspectorEnv.d.ts +7 -0
  65. package/dist-native/AvoInspectorEnv.js +8 -0
  66. package/dist-native/AvoInstallationId.d.ts +5 -0
  67. package/dist-native/AvoInstallationId.js +36 -0
  68. package/dist-native/AvoNetworkCallsHandler.d.ts +48 -0
  69. package/dist-native/AvoNetworkCallsHandler.js +142 -0
  70. package/dist-native/AvoSchemaParser.d.ts +11 -0
  71. package/dist-native/AvoSchemaParser.js +95 -0
  72. package/dist-native/AvoSessionTracker.d.ts +15 -0
  73. package/dist-native/AvoSessionTracker.js +104 -0
  74. package/dist-native/AvoStorage.d.ts +22 -0
  75. package/dist-native/AvoStorage.js +336 -0
  76. package/dist-native/__mocks__/xhr.d.ts +12 -0
  77. package/dist-native/__mocks__/xhr.js +14 -0
  78. package/dist-native/__mocks__/xhrError.d.ts +12 -0
  79. package/dist-native/__mocks__/xhrError.js +14 -0
  80. package/dist-native/__tests__/AvoInspector.d.ts +1 -0
  81. package/dist-native/__tests__/AvoInspector.js +207 -0
  82. package/dist-native/__tests__/Batcher.d.ts +1 -0
  83. package/dist-native/__tests__/Batcher.js +280 -0
  84. package/dist-native/__tests__/BatcherPublic.d.ts +1 -0
  85. package/dist-native/__tests__/BatcherPublic.js +82 -0
  86. package/dist-native/__tests__/Deduplicator.d.ts +1 -0
  87. package/dist-native/__tests__/Deduplicator.js +111 -0
  88. package/dist-native/__tests__/InstallationId.d.ts +1 -0
  89. package/dist-native/__tests__/InstallationId.js +40 -0
  90. package/dist-native/__tests__/NetworkCallsHandler.d.ts +1 -0
  91. package/dist-native/__tests__/NetworkCallsHandler.js +132 -0
  92. package/dist-native/__tests__/Parsing.d.ts +1 -0
  93. package/dist-native/__tests__/Parsing.js +115 -0
  94. package/dist-native/__tests__/Sessions.d.ts +1 -0
  95. package/dist-native/__tests__/Sessions.js +179 -0
  96. package/dist-native/__tests__/Storage.d.ts +1 -0
  97. package/dist-native/__tests__/Storage.js +173 -0
  98. package/dist-native/__tests__/constants.d.ts +36 -0
  99. package/dist-native/__tests__/constants.js +47 -0
  100. package/dist-native/index.d.ts +2 -0
  101. package/dist-native/index.js +7 -0
  102. package/dist-native/utils.d.ts +3 -0
  103. package/dist-native/utils.js +42 -0
  104. package/jest.config.js +6 -0
  105. package/package.json +8 -2
  106. package/webpack.browserConfig.js +1 -1
  107. package/webpack.config.js +1 -1
  108. package/.claude/settings.local.json +0 -9
@@ -0,0 +1,78 @@
1
+ import { type AvoInspectorEnvValueType } from "./AvoInspectorEnv";
2
+ import { AvoBatcher } from "./AvoBatcher";
3
+ import { AvoStorage } from "./AvoStorage";
4
+ import { AvoDeduplicator } from "./AvoDeduplicator";
5
+ export declare class AvoInspector {
6
+ environment: AvoInspectorEnvValueType;
7
+ avoBatcher: AvoBatcher;
8
+ avoDeduplicator: AvoDeduplicator;
9
+ apiKey: string;
10
+ version: string;
11
+ private avoNetworkCallsHandler;
12
+ private publicEncryptionKey?;
13
+ private streamId?;
14
+ private eventSpecCache?;
15
+ private eventSpecFetcher?;
16
+ static avoStorage: AvoStorage;
17
+ private static _batchSize;
18
+ static get batchSize(): number;
19
+ static set batchSize(newSize: number);
20
+ private static _batchFlushSeconds;
21
+ static get batchFlushSeconds(): number;
22
+ private static _shouldLog;
23
+ static get shouldLog(): boolean;
24
+ static set shouldLog(enable: boolean);
25
+ private static _networkTimeout;
26
+ static get networkTimeout(): number;
27
+ static set networkTimeout(timeout: number);
28
+ constructor(options: {
29
+ apiKey: string;
30
+ env: AvoInspectorEnvValueType;
31
+ version: string;
32
+ appName?: string;
33
+ suffix?: string;
34
+ publicEncryptionKey?: string;
35
+ });
36
+ trackSchemaFromEvent(eventName: string, eventProperties: Record<string, any>): Promise<Array<{
37
+ propertyName: string;
38
+ propertyType: string;
39
+ encryptedPropertyValue?: string;
40
+ children?: any;
41
+ }>>;
42
+ private _avoFunctionTrackSchemaFromEvent;
43
+ trackSchema(eventName: string, eventSchema: Array<{
44
+ propertyName: string;
45
+ propertyType: string;
46
+ encryptedPropertyValue?: string;
47
+ children?: any;
48
+ }>): Promise<void>;
49
+ private trackSchemaInternal;
50
+ enableLogging(enable: boolean): void;
51
+ extractSchema(eventProperties: Record<string, any>, shouldLogIfEnabled?: boolean): Array<{
52
+ propertyName: string;
53
+ propertyType: string;
54
+ encryptedPropertyValue?: string;
55
+ children?: any;
56
+ }>;
57
+ setBatchSize(newBatchSize: number): void;
58
+ setBatchFlushSeconds(newBatchFlushSeconds: number): void;
59
+ /**
60
+ * Fetches the event spec if spec fetching is enabled.
61
+ * Used by trackSchema when we don't have raw properties to validate.
62
+ *
63
+ * Note: EventSpec fetching only happens in dev/staging environments.
64
+ */
65
+ private fetchEventSpecIfNeeded;
66
+ /**
67
+ * Fetches event spec and validates the event against it.
68
+ * Returns ValidationResult if spec is available, null otherwise.
69
+ *
70
+ * Note: EventSpec fetching and validation only happens in dev/staging environments.
71
+ */
72
+ private fetchAndValidateEvent;
73
+ /**
74
+ * Sends an event immediately with validation data (bypasses batching).
75
+ * Logs validation errors if shouldLog is true.
76
+ */
77
+ private sendEventWithValidation;
78
+ }
@@ -0,0 +1,7 @@
1
+ export declare const AvoInspectorEnv: {
2
+ readonly Prod: "prod";
3
+ readonly Dev: "dev";
4
+ readonly Staging: "staging";
5
+ };
6
+ export type AvoInspectorEnvType = typeof AvoInspectorEnv;
7
+ export type AvoInspectorEnvValueType = AvoInspectorEnvType[keyof AvoInspectorEnvType];
@@ -0,0 +1,74 @@
1
+ import type { EventSpecMetadata } from "./eventSpec/AvoEventSpecFetchTypes";
2
+ import type { ValidationIssue } from "./eventSpec/EventValidator";
3
+ export interface BaseBody {
4
+ apiKey: string;
5
+ appName: string;
6
+ appVersion: string;
7
+ libVersion: string;
8
+ env: string;
9
+ libPlatform: "web";
10
+ messageId: string;
11
+ trackingId: string;
12
+ createdAt: string;
13
+ sessionId: string;
14
+ anonymousId: string;
15
+ samplingRate: number;
16
+ }
17
+ export interface SessionStartedBody extends BaseBody {
18
+ type: "sessionStarted";
19
+ }
20
+ export interface EventSchemaBody extends BaseBody {
21
+ type: "event";
22
+ /** ID of the matched base event */
23
+ eventId: string | null;
24
+ /** ID of the matched variant (if any) */
25
+ variantId?: string | null;
26
+ /** Name seen in code */
27
+ eventName?: string;
28
+ /** Event spec metadata from EventSpecResponse */
29
+ eventSpecMetadata?: EventSpecMetadata;
30
+ /** Array of validation issues found during validation */
31
+ validationErrors?: ValidationIssue[];
32
+ eventProperties: Array<{
33
+ propertyName: string;
34
+ propertyType: string;
35
+ encryptedPropertyValue?: string;
36
+ children?: any;
37
+ }>;
38
+ avoFunction: boolean;
39
+ eventHash: string | null;
40
+ }
41
+ export declare class AvoNetworkCallsHandler {
42
+ private readonly apiKey;
43
+ private readonly envName;
44
+ private readonly appName;
45
+ private readonly appVersion;
46
+ private readonly libVersion;
47
+ private samplingRate;
48
+ private sending;
49
+ private static readonly trackingEndpoint;
50
+ constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string);
51
+ callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: Error | null) => any): void;
52
+ private fixAnonymousIds;
53
+ bodyForSessionStartedCall(): SessionStartedBody;
54
+ bodyForEventSchemaCall(eventName: string, eventProperties: Array<{
55
+ propertyName: string;
56
+ propertyType: string;
57
+ children?: any;
58
+ }>, eventId: string | null, eventHash: string | null, variantId?: string | null, eventSpecMetadata?: EventSpecMetadata, validationErrors?: ValidationIssue[]): EventSchemaBody;
59
+ private createBaseCallBody;
60
+ /**
61
+ * Calls Inspector API immediately with a single event (bypasses batching).
62
+ * Used when event spec validation is available.
63
+ * Note: Does not drop due to sampling - validated events are always sent.
64
+ */
65
+ callInspectorImmediately(eventBody: EventSchemaBody, onCompleted: (error: Error | null) => any): void;
66
+ /**
67
+ * Check if event should be dropped based on sampling rate.
68
+ */
69
+ private shouldDropBySampling;
70
+ /**
71
+ * Core Inspector API call logic shared by batch and immediate calls.
72
+ */
73
+ private callInspectorApi;
74
+ }
@@ -0,0 +1,20 @@
1
+ export declare class AvoSchemaParser {
2
+ /**
3
+ * Returns true only if we have a valid encryption key and can send encrypted values.
4
+ * If no key is present, returns false and no property values will be sent.
5
+ */
6
+ private static canSendEncryptedValues;
7
+ /**
8
+ * Returns the encrypted property value if encryption is enabled, otherwise undefined.
9
+ * Never returns unencrypted values - only encrypted or nothing.
10
+ */
11
+ private static getEncryptedPropertyValueIfEnabled;
12
+ static extractSchema(eventProperties: Record<string, any>, publicEncryptionKey?: string, env?: string): Array<{
13
+ propertyName: string;
14
+ propertyType: string;
15
+ encryptedPropertyValue?: string;
16
+ children?: any;
17
+ }>;
18
+ private static removeDuplicates;
19
+ private static getPropValueType;
20
+ }
@@ -0,0 +1,22 @@
1
+ declare abstract class PlatformAvoStorage {
2
+ abstract init(shouldLog: boolean, suffix: string): void;
3
+ abstract getItemAsync<T>(key: string): Promise<T | null>;
4
+ abstract getItem<T>(key: string): T | null;
5
+ abstract setItem<T>(key: string, value: T): void;
6
+ abstract removeItem(key: string): void;
7
+ abstract runAfterInit(func: () => void): void;
8
+ abstract isInitialized(): boolean;
9
+ parseJson<T>(maybeItem: string | null | undefined): T | null;
10
+ }
11
+ export declare class AvoStorage {
12
+ Platform: string | null;
13
+ storageImpl: PlatformAvoStorage;
14
+ constructor(shouldLog: boolean, suffix?: string);
15
+ isInitialized(): boolean;
16
+ getItemAsync<T>(key: string): Promise<T | null>;
17
+ getItem<T>(key: string): T | null;
18
+ setItem<T>(key: string, value: T): void;
19
+ removeItem(key: string): void;
20
+ runAfterInit(func: () => void): void;
21
+ }
22
+ export {};
@@ -0,0 +1,12 @@
1
+ /// <reference types="jest" />
2
+ declare const xhrMock: {
3
+ open: jest.Mock<any, any, any>;
4
+ send: jest.Mock<any, any, any>;
5
+ setRequestHeader: jest.Mock<any, any, any>;
6
+ onload: jest.Mock<any, any, any>;
7
+ onerror: jest.Mock<any, any, any>;
8
+ ontimeout: jest.Mock<any, any, any>;
9
+ status: number;
10
+ response: string;
11
+ };
12
+ export default xhrMock;
@@ -0,0 +1,12 @@
1
+ /// <reference types="jest" />
2
+ declare const xhrErrorMock: {
3
+ open: jest.Mock<any, any, any>;
4
+ send: jest.Mock<any, any, any>;
5
+ setRequestHeader: jest.Mock<any, any, any>;
6
+ onload: jest.Mock<any, any, any>;
7
+ onerror: jest.Mock<any, any, any>;
8
+ ontimeout: jest.Mock<any, any, any>;
9
+ status: number;
10
+ statusText: string;
11
+ };
12
+ export default xhrErrorMock;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ declare const defaultOptions: {
2
+ apiKey: string;
3
+ env: "prod";
4
+ version: string;
5
+ shouldLog: boolean;
6
+ };
7
+ declare const error: {
8
+ API_KEY: string;
9
+ VERSION: string;
10
+ };
11
+ declare const mockedReturns: {
12
+ INSTALLATION_ID: string;
13
+ GUID: string;
14
+ SESSION_ID: string;
15
+ };
16
+ declare const networkCallType: {
17
+ EVENT: string;
18
+ SESSION_STARTED: string;
19
+ };
20
+ declare const requestMsg: {
21
+ ERROR: string;
22
+ TIMEOUT: string;
23
+ };
24
+ declare const trackingEndpoint = "https://api.avo.app/inspector/v1/track";
25
+ declare const sessionTimeMs: number;
26
+ declare const type: {
27
+ STRING: string;
28
+ INT: string;
29
+ OBJECT: string;
30
+ FLOAT: string;
31
+ LIST: string;
32
+ BOOL: string;
33
+ NULL: string;
34
+ UNKNOWN: string;
35
+ };
36
+ export { defaultOptions, error, mockedReturns, networkCallType, requestMsg, sessionTimeMs, type, trackingEndpoint };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Test helper: Generates a new ECC key pair for testing encryption.
3
+ * This is also available in the CLI tool (bin/avo-inspector.js) for production use.
4
+ */
5
+ export declare function generateKeyPair(): {
6
+ publicKey: string;
7
+ privateKey: string;
8
+ };
9
+ /**
10
+ * Test helper: Decrypts a value that was encrypted using encryptValue.
11
+ * Used for testing purposes only.
12
+ */
13
+ export declare function decryptValue(encryptedValue: string, privateKey: string): any;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Shared mock factories for testing event spec related functionality.
3
+ * These helpers reduce duplication across test files.
4
+ */
5
+ import type { PropertySpec, PropertyTypeSpec, VariantSpec, EventSpec, EventSpecResponse, EventSpecMetadata } from "../../eventSpec/AvoEventSpecFetchTypes";
6
+ /**
7
+ * Creates a PropertyTypeSpec with defaults.
8
+ */
9
+ export declare function createPropertyTypeSpec(overrides?: Partial<PropertyTypeSpec>): PropertyTypeSpec;
10
+ /**
11
+ * Creates a PropertySpec with sensible defaults.
12
+ */
13
+ export declare function createPropertySpec(overrides?: Partial<PropertySpec>): PropertySpec;
14
+ /**
15
+ * Creates a required string property.
16
+ */
17
+ export declare function createRequiredStringProperty(id: string, extraOverrides?: Partial<PropertySpec>): PropertySpec;
18
+ /**
19
+ * Creates an optional number property.
20
+ */
21
+ export declare function createNumberProperty(id: string, extraOverrides?: Partial<PropertySpec>): PropertySpec;
22
+ /**
23
+ * Creates an enum property with allowed values.
24
+ */
25
+ export declare function createEnumProperty(id: string, allowedValues: string[], extraOverrides?: Partial<PropertySpec>): PropertySpec;
26
+ /**
27
+ * Creates a VariantSpec with defaults.
28
+ */
29
+ export declare function createVariantSpec(overrides?: Partial<VariantSpec>): VariantSpec;
30
+ /**
31
+ * Creates an EventSpec with defaults.
32
+ */
33
+ export declare function createEventSpec(overrides?: Partial<EventSpec>): EventSpec;
34
+ /**
35
+ * Creates an EventSpec with common properties for testing.
36
+ */
37
+ export declare function createUserLoginEventSpec(): EventSpec;
38
+ /**
39
+ * Creates EventSpecMetadata with defaults.
40
+ */
41
+ export declare function createEventSpecMetadata(overrides?: Partial<EventSpecMetadata>): EventSpecMetadata;
42
+ /**
43
+ * Creates an EventSpecResponse with defaults.
44
+ */
45
+ export declare function createEventSpecResponse(events?: EventSpec[], metadataOverrides?: Partial<EventSpecMetadata>): EventSpecResponse;
46
+ /**
47
+ * Creates a simple EventSpecResponse with one event for basic testing.
48
+ */
49
+ export declare function createSimpleEventSpecResponse(eventName?: string): EventSpecResponse;
@@ -0,0 +1,73 @@
1
+ import type { EventSpecResponse } from "./AvoEventSpecFetchTypes";
2
+ /**
3
+ * EventSpecCache implements a dual-condition cache with LRU eviction.
4
+ *
5
+ * Cache Policy:
6
+ * - Entries expire after 5 minutes OR 50 cache hits, whichever comes first
7
+ * - When 50 cache hits occur globally, the oldest cached entry is evicted
8
+ * - Each cache entry tracks: spec, timestamp, and hit count
9
+ *
10
+ * Cache Key Format: ${apiKey}:${streamId}:${eventName}
11
+ *
12
+ * Note: Event count only increments on cache hits, not on every tracked event.
13
+ * This ensures the cache evicts based on actual usage, not overall tracking volume.
14
+ */
15
+ export declare class EventSpecCache {
16
+ /** Cache storage: key -> CacheEntry */
17
+ private cache;
18
+ /** Time-to-live in milliseconds (5 minutes) */
19
+ private readonly TTL_MS;
20
+ /** Maximum cache hit count before rotating cache (50 hits) */
21
+ private readonly MAX_EVENT_COUNT;
22
+ /** Global cache hit counter to track when to rotate cache */
23
+ private globalEventCount;
24
+ /** Whether to log debug information */
25
+ private readonly shouldLog;
26
+ constructor(shouldLog?: boolean);
27
+ /**
28
+ * Generates a cache key from the provided parameters.
29
+ */
30
+ private generateKey;
31
+ /**
32
+ * Retrieves an event spec response from the cache if it exists and is valid.
33
+ * Returns null if the entry is missing, expired, or has exceeded event count.
34
+ *
35
+ * On cache hit, increments the hit count for this entry and the global counter.
36
+ */
37
+ get(apiKey: string, streamId: string, eventName: string): EventSpecResponse | null;
38
+ /**
39
+ * Stores an event spec response in the cache.
40
+ */
41
+ set(apiKey: string, streamId: string, eventName: string, spec: EventSpecResponse): void;
42
+ /**
43
+ * Determines if a cache entry should be evicted based on:
44
+ * - Age (older than 5 minutes)
45
+ * - Hit count (50 or more cache hits)
46
+ */
47
+ private shouldEvict;
48
+ /**
49
+ * Evicts the oldest cache entry based on timestamp.
50
+ * This implements the LRU (Least Recently Used) eviction policy.
51
+ */
52
+ private evictOldest;
53
+ /**
54
+ * Clears all cached entries. Useful for testing.
55
+ */
56
+ clear(): void;
57
+ /**
58
+ * Returns the current size of the cache.
59
+ */
60
+ size(): number;
61
+ /**
62
+ * Returns cache statistics for debugging.
63
+ */
64
+ getStats(): {
65
+ size: number;
66
+ globalEventCount: number;
67
+ entries: Array<{
68
+ key: string;
69
+ age: number;
70
+ eventCount: number;
71
+ }>;
72
+ };
73
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * This file is generated. Internal development changes should be made in the generator
3
+ * and the file should be re-generated. External contributions are welcome to submit
4
+ * changes directly to this file, and we'll apply them to the generator internally.
5
+ */
6
+ /**
7
+ * Represents the type specification for a property.
8
+ * Can be a primitive type or a nested object structure.
9
+ */
10
+ export interface PropertyTypeSpec {
11
+ /** The type category: "primitive" for simple types, "object" for nested structures */
12
+ type: "primitive" | "object";
13
+ /** For primitive: the type name (e.g., "string", "int"). For object: nested property specs */
14
+ value: string | Record<string, PropertySpec>;
15
+ }
16
+ /**
17
+ * Represents the specification for a single property in an event.
18
+ * Supports recursive nesting for object types.
19
+ */
20
+ export interface PropertySpec {
21
+ /** Unique identifier for this property */
22
+ id: string;
23
+ /** Type specification - contains type category and value */
24
+ t: PropertyTypeSpec;
25
+ /** Required flag */
26
+ r: boolean;
27
+ /** Is list (array) flag */
28
+ l?: boolean;
29
+ /** Minimum value (for numeric types) */
30
+ min?: number;
31
+ /** Maximum value (for numeric types) */
32
+ max?: number;
33
+ /** Enum values (allowed values for the property) */
34
+ v?: string[];
35
+ /** Regex pattern for string validation */
36
+ rx?: string;
37
+ }
38
+ /**
39
+ * Represents a variant of an event with additional or modified properties.
40
+ */
41
+ export interface VariantSpec {
42
+ /** Unique identifier for this variant */
43
+ variantId: string;
44
+ /** Event ID for this variant (base event id) */
45
+ eventId: string;
46
+ /** Suffix to append to the base event name */
47
+ nameSuffix: string;
48
+ /** Name of the variant in this source (if different from canonical name) */
49
+ mappedName?: string;
50
+ /** Properties specific to this variant */
51
+ props: Record<string, PropertySpec>;
52
+ }
53
+ /**
54
+ * Represents the complete specification for an event, including base event
55
+ * and optional variants.
56
+ */
57
+ export interface EventSpec {
58
+ /** Unique identifier for this event */
59
+ id: string;
60
+ /** Canonical Avo name for this event */
61
+ name: string;
62
+ /** Name of the event in this source (if different from canonical name) */
63
+ mappedName?: string;
64
+ /** Properties for this event */
65
+ props: Record<string, PropertySpec>;
66
+ /** Variants of this event with additional/modified properties */
67
+ variants: VariantSpec[];
68
+ }
69
+ /**
70
+ * Metadata returned with the event spec response.
71
+ */
72
+ export interface EventSpecMetadata {
73
+ /** Schema identifier */
74
+ schemaId: string;
75
+ /** Branch identifier */
76
+ branchId: string;
77
+ /** Latest action identifier (replaces versionId/createdAt) */
78
+ latestActionId: string;
79
+ /** Optional source identifier */
80
+ sourceId?: string;
81
+ }
82
+ /**
83
+ * Response structure from the getEventSpec endpoint.
84
+ * Contains an array of potential event matches (due to name mapping).
85
+ */
86
+ export interface EventSpecResponse {
87
+ /** Array of potential event matches */
88
+ events: EventSpec[];
89
+ /** Metadata about the schema and source */
90
+ metadata: EventSpecMetadata;
91
+ }
92
+ /** Cache entry for storing event specs with metadata. */
93
+ export interface EventSpecCacheEntry {
94
+ /** The cached event specification response */
95
+ spec: EventSpecResponse;
96
+ /** Timestamp when this entry was cached */
97
+ timestamp: number;
98
+ /** Number of events processed since this entry was cached */
99
+ eventCount: number;
100
+ }
101
+ /** Parameters for fetching event specifications from the API. */
102
+ export interface FetchEventSpecParams {
103
+ /** The API key */
104
+ apiKey: string;
105
+ /** The stream ID */
106
+ streamId: string;
107
+ /** The name of the event */
108
+ eventName: string;
109
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * This file is generated. Internal development changes should be made in the generator
3
+ * and the file should be re-generated. External contributions are welcome to submit
4
+ * changes directly to this file, and we'll apply them to the generator internally.
5
+ */
6
+ import type { EventSpecResponse, FetchEventSpecParams } from "./AvoEventSpecFetchTypes";
7
+ /**
8
+ * EventSpecFetcher handles fetching event specifications from the Avo API.
9
+ *
10
+ * Endpoint: GET /streamInspectorEventShapes
11
+ * Base URL: http://localhost:5001/avo-web-app/us-central1 (local dev)
12
+ * https://us-central1-avo-web-app.cloudfunctions.net (production)
13
+ */
14
+ export declare class AvoEventSpecFetcher {
15
+ /** Base URL for the event spec API */
16
+ private readonly baseUrl;
17
+ /** Network timeout in milliseconds */
18
+ private readonly timeout;
19
+ /** In-flight requests to prevent duplicate fetches */
20
+ private inFlightRequests;
21
+ /** Whether to log debug information */
22
+ private readonly shouldLog;
23
+ /** Environment name */
24
+ private readonly env;
25
+ constructor(timeout: number | undefined, shouldLog: boolean | undefined, env: string, baseUrl?: string);
26
+ /** Generates a unique key for tracking in-flight requests. */
27
+ private generateRequestKey;
28
+ /**
29
+ * Fetches an event specification from the API.
30
+ *
31
+ * Returns null if:
32
+ * - The network request fails
33
+ * - The response has an invalid status code (non-200)
34
+ * - The response is invalid or malformed
35
+ * - The request times out
36
+ *
37
+ * This method gracefully degrades - failures do not throw errors.
38
+ * When null is returned, validation should be skipped for that event.
39
+ */
40
+ fetch(params: FetchEventSpecParams): Promise<EventSpecResponse | null>;
41
+ /** Internal fetch implementation. */
42
+ private fetchInternal;
43
+ /** Builds the complete URL with query parameters. */
44
+ private buildUrl;
45
+ /**
46
+ * Makes an HTTP GET request using XMLHttpRequest.
47
+ * Returns the parsed JSON response or null on failure.
48
+ */
49
+ private makeRequest;
50
+ /**
51
+ * Basic shape check - ensures response has the minimum expected structure.
52
+ * Does not perform deep validation of all fields.
53
+ */
54
+ private hasExpectedShape;
55
+ }