avo-inspector 2.2.2-alpha → 2.2.2-alpha.3
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.
- package/.claude/settings.local.json +18 -0
- package/README.md +38 -3
- package/bin/avo-inspector.js +78 -26
- package/dist/AvoBatcher.d.ts +3 -12
- package/dist/AvoInspector.d.ts +13 -7
- package/dist/AvoNetworkCallsHandler.d.ts +28 -21
- package/dist/AvoSchemaParser.d.ts +2 -6
- package/dist/AvoStreamId.d.ts +58 -0
- package/dist/eventSpec/AvoEventSpecCache.d.ts +2 -1
- package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +103 -65
- package/dist/eventSpec/AvoEventSpecFetcher.d.ts +11 -5
- package/dist/eventSpec/EventValidator.d.ts +16 -72
- package/dist/eventSpec/fetcher.d.ts +52 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/browser.js.LICENSE.txt +0 -5
- package/dist-browser/AvoAnonymousId.d.ts +0 -26
- package/dist-browser/AvoBatcher.d.ts +0 -26
- package/dist-browser/AvoDeduplicator.d.ts +0 -20
- package/dist-browser/AvoEncryption.d.ts +0 -33
- package/dist-browser/AvoGuid.d.ts +0 -3
- package/dist-browser/AvoInspector.d.ts +0 -78
- package/dist-browser/AvoInspectorEnv.d.ts +0 -7
- package/dist-browser/AvoNetworkCallsHandler.d.ts +0 -74
- package/dist-browser/AvoSchemaParser.d.ts +0 -20
- package/dist-browser/AvoStorage.d.ts +0 -22
- package/dist-browser/__mocks__/xhr.d.ts +0 -12
- package/dist-browser/__mocks__/xhrError.d.ts +0 -12
- package/dist-browser/__tests__/AnonymousId_test.d.ts +0 -1
- package/dist-browser/__tests__/AvoEncryption_test.d.ts +0 -1
- package/dist-browser/__tests__/AvoInspectorEventSpec_test.d.ts +0 -1
- package/dist-browser/__tests__/AvoInspector_test.d.ts +0 -1
- package/dist-browser/__tests__/BatcherPublic_test.d.ts +0 -1
- package/dist-browser/__tests__/Batcher_test.d.ts +0 -1
- package/dist-browser/__tests__/Deduplicator_test.d.ts +0 -1
- package/dist-browser/__tests__/EncryptedPropertyTracking_test.d.ts +0 -1
- package/dist-browser/__tests__/EventSpecCache_test.d.ts +0 -1
- package/dist-browser/__tests__/EventSpecFetcher_test.d.ts +0 -1
- package/dist-browser/__tests__/EventValidator_test.d.ts +0 -1
- package/dist-browser/__tests__/NetworkCallsHandler_test.d.ts +0 -1
- package/dist-browser/__tests__/Parsing_test.d.ts +0 -1
- package/dist-browser/__tests__/Storage_test.d.ts +0 -1
- package/dist-browser/__tests__/ValidationIntegration_test.d.ts +0 -1
- package/dist-browser/__tests__/constants.d.ts +0 -36
- package/dist-browser/__tests__/helpers/encryptionHelpers.d.ts +0 -13
- package/dist-browser/__tests__/helpers/mockFactories.d.ts +0 -49
- package/dist-browser/eventSpec/AvoEventSpecCache.d.ts +0 -73
- package/dist-browser/eventSpec/AvoEventSpecFetchTypes.d.ts +0 -109
- package/dist-browser/eventSpec/AvoEventSpecFetcher.d.ts +0 -55
- package/dist-browser/eventSpec/EventValidator.d.ts +0 -90
- package/dist-browser/eventSpec/index.d.ts +0 -4
- package/dist-browser/index.d.ts +0 -2
- package/dist-browser/utils.d.ts +0 -3
- package/dist-native/AvoBatcher.d.ts +0 -24
- package/dist-native/AvoBatcher.js +0 -82
- package/dist-native/AvoDeduplicator.d.ts +0 -36
- package/dist-native/AvoDeduplicator.js +0 -142
- package/dist-native/AvoGuid.d.ts +0 -3
- package/dist-native/AvoGuid.js +0 -14
- package/dist-native/AvoInspector.d.ts +0 -52
- package/dist-native/AvoInspector.js +0 -220
- package/dist-native/AvoInspectorEnv.d.ts +0 -7
- package/dist-native/AvoInspectorEnv.js +0 -8
- package/dist-native/AvoInstallationId.d.ts +0 -5
- package/dist-native/AvoInstallationId.js +0 -36
- package/dist-native/AvoNetworkCallsHandler.d.ts +0 -48
- package/dist-native/AvoNetworkCallsHandler.js +0 -142
- package/dist-native/AvoSchemaParser.d.ts +0 -11
- package/dist-native/AvoSchemaParser.js +0 -95
- package/dist-native/AvoSessionTracker.d.ts +0 -15
- package/dist-native/AvoSessionTracker.js +0 -104
- package/dist-native/AvoStorage.d.ts +0 -22
- package/dist-native/AvoStorage.js +0 -336
- package/dist-native/__mocks__/xhr.d.ts +0 -12
- package/dist-native/__mocks__/xhr.js +0 -14
- package/dist-native/__mocks__/xhrError.d.ts +0 -12
- package/dist-native/__mocks__/xhrError.js +0 -14
- package/dist-native/__tests__/AvoInspector.d.ts +0 -1
- package/dist-native/__tests__/AvoInspector.js +0 -207
- package/dist-native/__tests__/Batcher.d.ts +0 -1
- package/dist-native/__tests__/Batcher.js +0 -280
- package/dist-native/__tests__/BatcherPublic.d.ts +0 -1
- package/dist-native/__tests__/BatcherPublic.js +0 -82
- package/dist-native/__tests__/Deduplicator.d.ts +0 -1
- package/dist-native/__tests__/Deduplicator.js +0 -111
- package/dist-native/__tests__/InstallationId.d.ts +0 -1
- package/dist-native/__tests__/InstallationId.js +0 -40
- package/dist-native/__tests__/NetworkCallsHandler.d.ts +0 -1
- package/dist-native/__tests__/NetworkCallsHandler.js +0 -132
- package/dist-native/__tests__/Parsing.d.ts +0 -1
- package/dist-native/__tests__/Parsing.js +0 -115
- package/dist-native/__tests__/Sessions.d.ts +0 -1
- package/dist-native/__tests__/Sessions.js +0 -179
- package/dist-native/__tests__/Storage.d.ts +0 -1
- package/dist-native/__tests__/Storage.js +0 -173
- package/dist-native/__tests__/constants.d.ts +0 -36
- package/dist-native/__tests__/constants.js +0 -47
- package/dist-native/index.d.ts +0 -2
- package/dist-native/index.js +0 -7
- package/dist-native/utils.d.ts +0 -3
- package/dist-native/utils.js +0 -42
|
@@ -1,109 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EventValidator - Client-side validation of tracking events against the Avo Tracking Plan.
|
|
3
|
-
*
|
|
4
|
-
* This module handles:
|
|
5
|
-
* 1. Matching: Identifying the most likely Event and Variant from specs
|
|
6
|
-
* 2. Validation: Checking runtime properties against the matched spec rules
|
|
7
|
-
*/
|
|
8
|
-
import type { EventSpecResponse, EventSpec, EventSpecMetadata, VariantSpec } from "./AvoEventSpecFetchTypes";
|
|
9
|
-
/**
|
|
10
|
-
* Validation issue codes for client-side validation.
|
|
11
|
-
*/
|
|
12
|
-
export type ValidationIssueCode = "RequiredMissing" | "ValueBelowMin" | "ValueAboveMax" | "RegexMismatch" | "NotInAllowedValues" | "UnexpectedProperty" | "UnexpectedEvent" | "TypeMismatch";
|
|
13
|
-
/**
|
|
14
|
-
* Represents a validation issue found during event validation.
|
|
15
|
-
*
|
|
16
|
-
* Note: We do NOT include the received value to avoid sending user data to the backend.
|
|
17
|
-
* The backend can correlate issues with encrypted values via propertyName matching
|
|
18
|
-
* against eventProperties.encryptedPropertyValue in the payload.
|
|
19
|
-
*/
|
|
20
|
-
export interface ValidationIssue {
|
|
21
|
-
/** The type of validation issue */
|
|
22
|
-
code: ValidationIssueCode;
|
|
23
|
-
/** Property ID (preferred over name) */
|
|
24
|
-
propertyId?: string;
|
|
25
|
-
/** Property name - used to correlate with encryptedPropertyValue in eventProperties */
|
|
26
|
-
propertyName?: string;
|
|
27
|
-
/** Expected value for the validation rule (from spec, not user data) */
|
|
28
|
-
expected?: string | number | boolean;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Result of the validation process.
|
|
32
|
-
*/
|
|
33
|
-
export interface ValidationResult {
|
|
34
|
-
/** ID of the matched event, null if no match found */
|
|
35
|
-
eventId: string | null;
|
|
36
|
-
/** ID of the matched variant, null if base event or no match */
|
|
37
|
-
variantId: string | null;
|
|
38
|
-
/** Event spec metadata from the response */
|
|
39
|
-
eventSpecMetadata: EventSpecMetadata;
|
|
40
|
-
/** List of all validation issues found */
|
|
41
|
-
validationErrors: ValidationIssue[];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Runtime property value - can be any JSON-compatible type
|
|
45
|
-
*/
|
|
46
|
-
export type RuntimePropertyValue = string | number | boolean | null | undefined | object | Array<any>;
|
|
47
|
-
/**
|
|
48
|
-
* Runtime properties map
|
|
49
|
-
*/
|
|
50
|
-
export type RuntimeProperties = Record<string, RuntimePropertyValue>;
|
|
51
|
-
/**
|
|
52
|
-
* Internal match result for scoring
|
|
53
|
-
*/
|
|
54
|
-
interface MatchCandidate {
|
|
55
|
-
event: EventSpec;
|
|
56
|
-
variant: VariantSpec | null;
|
|
57
|
-
score: number;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Validates a runtime event against the EventSpecResponse.
|
|
61
|
-
*
|
|
62
|
-
* @param eventName - The event name observed at runtime
|
|
63
|
-
* @param properties - The properties observed at runtime
|
|
64
|
-
* @param specResponse - The EventSpecResponse from the backend
|
|
65
|
-
* @returns ValidationResult with match info and any validation errors
|
|
66
|
-
*/
|
|
67
|
-
export declare function validateEvent(eventName: string, properties: RuntimeProperties, specResponse: EventSpecResponse): ValidationResult;
|
|
68
|
-
/**
|
|
69
|
-
* Finds the closest matching Event and Variant for the runtime data.
|
|
70
|
-
*
|
|
71
|
-
* @param eventName - Runtime event name
|
|
72
|
-
* @param properties - Runtime properties
|
|
73
|
-
* @param events - Array of EventSpecs to match against
|
|
74
|
-
* @returns The best matching event and variant, or null if no match
|
|
75
|
-
*/
|
|
76
|
-
export declare function findClosestMatch(eventName: string, properties: RuntimeProperties, events: EventSpec[]): MatchCandidate | null;
|
|
77
|
-
/**
|
|
78
|
-
* Validates runtime properties against the matched event and variant specs.
|
|
79
|
-
*
|
|
80
|
-
* @param properties - Runtime properties
|
|
81
|
-
* @param event - Matched EventSpec
|
|
82
|
-
* @param variant - Matched VariantSpec (or null for base event)
|
|
83
|
-
* @returns Array of validation issues found
|
|
84
|
-
*/
|
|
85
|
-
export declare function validateProperties(properties: RuntimeProperties, event: EventSpec, variant: VariantSpec | null): ValidationIssue[];
|
|
86
|
-
/**
|
|
87
|
-
* Quick check if an event exists in the spec (without full validation).
|
|
88
|
-
*/
|
|
89
|
-
export declare function eventExistsInSpec(eventName: string, specResponse: EventSpecResponse): boolean;
|
|
90
|
-
export {};
|
package/dist-browser/index.d.ts
DELETED
package/dist-browser/utils.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler";
|
|
2
|
-
export interface AvoBatcherType {
|
|
3
|
-
handleSessionStarted(): void;
|
|
4
|
-
handleTrackSchema(eventName: string, schema: Array<{
|
|
5
|
-
propertyName: string;
|
|
6
|
-
propertyType: string;
|
|
7
|
-
children?: any;
|
|
8
|
-
}>, eventId: string | null, eventHash: string | null): void;
|
|
9
|
-
}
|
|
10
|
-
export declare class AvoBatcher implements AvoBatcherType {
|
|
11
|
-
private events;
|
|
12
|
-
private batchFlushAttemptTimestamp;
|
|
13
|
-
private networkCallsHandler;
|
|
14
|
-
constructor(networkCallsHandler: AvoNetworkCallsHandler);
|
|
15
|
-
handleSessionStarted(): void;
|
|
16
|
-
handleTrackSchema(eventName: string, schema: Array<{
|
|
17
|
-
propertyName: string;
|
|
18
|
-
propertyType: string;
|
|
19
|
-
children?: any;
|
|
20
|
-
}>, eventId: string | null, eventHash: string | null): void;
|
|
21
|
-
private checkIfBatchNeedsToBeSent;
|
|
22
|
-
private saveEvents;
|
|
23
|
-
static get cacheKey(): string;
|
|
24
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AvoBatcher = void 0;
|
|
4
|
-
var AvoInspector_1 = require("./AvoInspector");
|
|
5
|
-
var AvoBatcher = /** @class */ (function () {
|
|
6
|
-
function AvoBatcher(networkCallsHandler) {
|
|
7
|
-
var _this = this;
|
|
8
|
-
this.events = [];
|
|
9
|
-
this.networkCallsHandler = networkCallsHandler;
|
|
10
|
-
this.batchFlushAttemptTimestamp = Date.now();
|
|
11
|
-
AvoInspector_1.AvoInspector.avoStorage
|
|
12
|
-
.getItemAsync(AvoBatcher.cacheKey)
|
|
13
|
-
.then(function (savedEvents) {
|
|
14
|
-
if (savedEvents !== null) {
|
|
15
|
-
var nonNullSavedEvents = savedEvents.filter(function (event) { return event !== null; });
|
|
16
|
-
_this.events = _this.events.concat(nonNullSavedEvents);
|
|
17
|
-
_this.checkIfBatchNeedsToBeSent();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
AvoBatcher.prototype.handleSessionStarted = function () {
|
|
22
|
-
this.events.push(this.networkCallsHandler.bodyForSessionStartedCall());
|
|
23
|
-
this.saveEvents();
|
|
24
|
-
this.checkIfBatchNeedsToBeSent();
|
|
25
|
-
};
|
|
26
|
-
AvoBatcher.prototype.handleTrackSchema = function (eventName, schema, eventId, eventHash) {
|
|
27
|
-
this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(eventName, schema, eventId, eventHash));
|
|
28
|
-
this.saveEvents();
|
|
29
|
-
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
30
|
-
console.log("Avo Inspector: saved event " +
|
|
31
|
-
eventName +
|
|
32
|
-
" with schema " +
|
|
33
|
-
JSON.stringify(schema));
|
|
34
|
-
}
|
|
35
|
-
this.checkIfBatchNeedsToBeSent();
|
|
36
|
-
};
|
|
37
|
-
AvoBatcher.prototype.checkIfBatchNeedsToBeSent = function () {
|
|
38
|
-
var batchSize = this.events.length;
|
|
39
|
-
var now = Date.now();
|
|
40
|
-
var timeSinceLastFlushAttempt = now - this.batchFlushAttemptTimestamp;
|
|
41
|
-
var sendBySize = batchSize % AvoInspector_1.AvoInspector.batchSize == 0;
|
|
42
|
-
var sendByTime = timeSinceLastFlushAttempt >= AvoInspector_1.AvoInspector.batchFlushSeconds * 1000;
|
|
43
|
-
var avoBatcher = this;
|
|
44
|
-
if (sendBySize || sendByTime) {
|
|
45
|
-
this.batchFlushAttemptTimestamp = now;
|
|
46
|
-
var sendingEvents_1 = avoBatcher.events;
|
|
47
|
-
avoBatcher.events = [];
|
|
48
|
-
this.networkCallsHandler.callInspectorWithBatchBody(sendingEvents_1, function (error) {
|
|
49
|
-
if (error != null) {
|
|
50
|
-
avoBatcher.events = avoBatcher.events.concat(sendingEvents_1);
|
|
51
|
-
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
52
|
-
console.log("Avo Inspector: batch sending failed: " +
|
|
53
|
-
error +
|
|
54
|
-
". We will attempt to send your schemas with next batch");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
59
|
-
console.log("Avo Inspector: batch sent successfully.");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
avoBatcher.saveEvents();
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
AvoBatcher.prototype.saveEvents = function () {
|
|
67
|
-
if (this.events.length > 1000) {
|
|
68
|
-
var extraElements = this.events.length - 1000;
|
|
69
|
-
this.events.splice(0, extraElements);
|
|
70
|
-
}
|
|
71
|
-
AvoInspector_1.AvoInspector.avoStorage.setItem(AvoBatcher.cacheKey, this.events);
|
|
72
|
-
};
|
|
73
|
-
Object.defineProperty(AvoBatcher, "cacheKey", {
|
|
74
|
-
get: function () {
|
|
75
|
-
return "AvoInspectorEvents";
|
|
76
|
-
},
|
|
77
|
-
enumerable: false,
|
|
78
|
-
configurable: true
|
|
79
|
-
});
|
|
80
|
-
return AvoBatcher;
|
|
81
|
-
}());
|
|
82
|
-
exports.AvoBatcher = AvoBatcher;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export declare class AvoDeduplicator {
|
|
2
|
-
avoFunctionsEvents: {
|
|
3
|
-
[time: number]: string;
|
|
4
|
-
};
|
|
5
|
-
manualEvents: {
|
|
6
|
-
[time: number]: string;
|
|
7
|
-
};
|
|
8
|
-
avoFunctionsEventsParams: {
|
|
9
|
-
[eventName: string]: {
|
|
10
|
-
[propName: string]: any;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
manualEventsParams: {
|
|
14
|
-
[eventName: string]: {
|
|
15
|
-
[propName: string]: any;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
shouldRegisterEvent(eventName: string, params: {
|
|
19
|
-
[propName: string]: any;
|
|
20
|
-
}, fromAvoFunction: boolean): boolean;
|
|
21
|
-
private hasSameEventAs;
|
|
22
|
-
private lookForEventIn;
|
|
23
|
-
hasSeenEventParams(params: {
|
|
24
|
-
[propName: string]: any;
|
|
25
|
-
}, checkInAvoFunctions: boolean): boolean;
|
|
26
|
-
private lookForEventParamsIn;
|
|
27
|
-
shouldRegisterSchemaFromManually(eventName: string, eventSchema: Array<{
|
|
28
|
-
propertyName: string;
|
|
29
|
-
propertyType: string;
|
|
30
|
-
children?: any;
|
|
31
|
-
}>): boolean;
|
|
32
|
-
private hasSameShapeInAvoFunctionsAs;
|
|
33
|
-
private lookForEventSchemaIn;
|
|
34
|
-
private clearOldEvents;
|
|
35
|
-
private _clearEvents;
|
|
36
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AvoDeduplicator = void 0;
|
|
4
|
-
var AvoSchemaParser_1 = require("./AvoSchemaParser");
|
|
5
|
-
var utils_1 = require("./utils");
|
|
6
|
-
var AvoDeduplicator = /** @class */ (function () {
|
|
7
|
-
function AvoDeduplicator() {
|
|
8
|
-
this.avoFunctionsEvents = {};
|
|
9
|
-
this.manualEvents = {};
|
|
10
|
-
this.avoFunctionsEventsParams = {};
|
|
11
|
-
this.manualEventsParams = {};
|
|
12
|
-
}
|
|
13
|
-
AvoDeduplicator.prototype.shouldRegisterEvent = function (eventName, params, fromAvoFunction) {
|
|
14
|
-
this.clearOldEvents();
|
|
15
|
-
if (fromAvoFunction) {
|
|
16
|
-
this.avoFunctionsEvents[Date.now()] = eventName;
|
|
17
|
-
this.avoFunctionsEventsParams[eventName] = params;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
this.manualEvents[Date.now()] = eventName;
|
|
21
|
-
this.manualEventsParams[eventName] = params;
|
|
22
|
-
}
|
|
23
|
-
var checkInAvoFunctions = !fromAvoFunction;
|
|
24
|
-
return !this.hasSameEventAs(eventName, params, checkInAvoFunctions);
|
|
25
|
-
};
|
|
26
|
-
AvoDeduplicator.prototype.hasSameEventAs = function (eventName, params, checkInAvoFunctions) {
|
|
27
|
-
var result = false;
|
|
28
|
-
if (checkInAvoFunctions) {
|
|
29
|
-
if (this.lookForEventIn(eventName, params, this.avoFunctionsEventsParams)) {
|
|
30
|
-
result = true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
if (this.lookForEventIn(eventName, params, this.manualEventsParams)) {
|
|
35
|
-
result = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (result) {
|
|
39
|
-
delete this.avoFunctionsEventsParams[eventName];
|
|
40
|
-
delete this.manualEventsParams[eventName];
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
AvoDeduplicator.prototype.lookForEventIn = function (eventName, params, eventsStorage) {
|
|
45
|
-
for (var otherEventName in eventsStorage) {
|
|
46
|
-
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
47
|
-
if (otherEventName === eventName) {
|
|
48
|
-
var otherParams = eventsStorage[eventName];
|
|
49
|
-
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
};
|
|
57
|
-
AvoDeduplicator.prototype.hasSeenEventParams = function (params, checkInAvoFunctions) {
|
|
58
|
-
var result = false;
|
|
59
|
-
if (checkInAvoFunctions) {
|
|
60
|
-
if (this.lookForEventParamsIn(params, this.avoFunctionsEventsParams)) {
|
|
61
|
-
result = true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
if (this.lookForEventParamsIn(params, this.manualEventsParams)) {
|
|
66
|
-
result = true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
};
|
|
71
|
-
AvoDeduplicator.prototype.lookForEventParamsIn = function (params, eventsStorage) {
|
|
72
|
-
for (var otherEventName in eventsStorage) {
|
|
73
|
-
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
74
|
-
var otherParams = eventsStorage[otherEventName];
|
|
75
|
-
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return false;
|
|
81
|
-
};
|
|
82
|
-
AvoDeduplicator.prototype.shouldRegisterSchemaFromManually = function (eventName, eventSchema) {
|
|
83
|
-
this.clearOldEvents();
|
|
84
|
-
return !this.hasSameShapeInAvoFunctionsAs(eventName, eventSchema);
|
|
85
|
-
};
|
|
86
|
-
AvoDeduplicator.prototype.hasSameShapeInAvoFunctionsAs = function (eventName, eventSchema) {
|
|
87
|
-
var result = false;
|
|
88
|
-
if (this.lookForEventSchemaIn(eventName, eventSchema, this.avoFunctionsEventsParams)) {
|
|
89
|
-
result = true;
|
|
90
|
-
}
|
|
91
|
-
if (result) {
|
|
92
|
-
delete this.avoFunctionsEventsParams[eventName];
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
};
|
|
96
|
-
AvoDeduplicator.prototype.lookForEventSchemaIn = function (eventName, eventSchema, eventsStorage) {
|
|
97
|
-
for (var otherEventName in eventsStorage) {
|
|
98
|
-
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
99
|
-
if (otherEventName === eventName) {
|
|
100
|
-
var otherSchema = AvoSchemaParser_1.AvoSchemaParser.extractSchema(eventsStorage[eventName]);
|
|
101
|
-
if (otherSchema && (0, utils_1.deepEquals)(eventSchema, otherSchema)) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
};
|
|
109
|
-
AvoDeduplicator.prototype.clearOldEvents = function () {
|
|
110
|
-
var now = Date.now();
|
|
111
|
-
var msToConsiderOld = 300;
|
|
112
|
-
for (var time in this.avoFunctionsEvents) {
|
|
113
|
-
if (this.avoFunctionsEvents.hasOwnProperty(time)) {
|
|
114
|
-
var timestamp = Number(time) || 0;
|
|
115
|
-
if (now - timestamp > msToConsiderOld) {
|
|
116
|
-
var eventName = this.avoFunctionsEvents[time];
|
|
117
|
-
delete this.avoFunctionsEvents[time];
|
|
118
|
-
delete this.avoFunctionsEventsParams[eventName];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (var time in this.manualEvents) {
|
|
123
|
-
if (this.manualEvents.hasOwnProperty(time)) {
|
|
124
|
-
var timestamp = Number(time) || 0;
|
|
125
|
-
if (now - timestamp > msToConsiderOld) {
|
|
126
|
-
var eventName = this.manualEvents[time];
|
|
127
|
-
delete this.manualEvents[time];
|
|
128
|
-
delete this.manualEventsParams[eventName];
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
// used in tests
|
|
134
|
-
AvoDeduplicator.prototype._clearEvents = function () {
|
|
135
|
-
this.avoFunctionsEvents = {};
|
|
136
|
-
this.manualEvents = {};
|
|
137
|
-
this.avoFunctionsEventsParams = {};
|
|
138
|
-
this.manualEventsParams = {};
|
|
139
|
-
};
|
|
140
|
-
return AvoDeduplicator;
|
|
141
|
-
}());
|
|
142
|
-
exports.AvoDeduplicator = AvoDeduplicator;
|
package/dist-native/AvoGuid.d.ts
DELETED
package/dist-native/AvoGuid.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var AvoGuid = /** @class */ (function () {
|
|
4
|
-
function AvoGuid() {
|
|
5
|
-
}
|
|
6
|
-
AvoGuid.newGuid = function () {
|
|
7
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
8
|
-
var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
9
|
-
return v.toString(16);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
return AvoGuid;
|
|
13
|
-
}());
|
|
14
|
-
exports.default = AvoGuid;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { AvoInspectorEnvValueType } from "./AvoInspectorEnv";
|
|
2
|
-
import { AvoSessionTracker } from "./AvoSessionTracker";
|
|
3
|
-
import { AvoBatcher } from "./AvoBatcher";
|
|
4
|
-
import { AvoStorage } from "./AvoStorage";
|
|
5
|
-
import { AvoDeduplicator } from "./AvoDeduplicator";
|
|
6
|
-
export declare class AvoInspector {
|
|
7
|
-
environment: AvoInspectorEnvValueType;
|
|
8
|
-
avoBatcher: AvoBatcher;
|
|
9
|
-
avoDeduplicator: AvoDeduplicator;
|
|
10
|
-
sessionTracker: AvoSessionTracker;
|
|
11
|
-
apiKey: string;
|
|
12
|
-
version: string;
|
|
13
|
-
static avoStorage: AvoStorage;
|
|
14
|
-
private static _batchSize;
|
|
15
|
-
static get batchSize(): number;
|
|
16
|
-
static set batchSize(newSize: number);
|
|
17
|
-
private static _batchFlushSeconds;
|
|
18
|
-
static get batchFlushSeconds(): number;
|
|
19
|
-
private static _shouldLog;
|
|
20
|
-
static get shouldLog(): boolean;
|
|
21
|
-
static set shouldLog(enable: boolean);
|
|
22
|
-
constructor(options: {
|
|
23
|
-
apiKey: string;
|
|
24
|
-
env: AvoInspectorEnvValueType;
|
|
25
|
-
version: string;
|
|
26
|
-
appName?: string;
|
|
27
|
-
});
|
|
28
|
-
trackSchemaFromEvent(eventName: string, eventProperties: {
|
|
29
|
-
[propName: string]: any;
|
|
30
|
-
}): Array<{
|
|
31
|
-
propertyName: string;
|
|
32
|
-
propertyType: string;
|
|
33
|
-
children?: any;
|
|
34
|
-
}>;
|
|
35
|
-
private _avoFunctionTrackSchemaFromEvent;
|
|
36
|
-
trackSchema(eventName: string, eventSchema: Array<{
|
|
37
|
-
propertyName: string;
|
|
38
|
-
propertyType: string;
|
|
39
|
-
children?: any;
|
|
40
|
-
}>): void;
|
|
41
|
-
private trackSchemaInternal;
|
|
42
|
-
enableLogging(enable: boolean): void;
|
|
43
|
-
extractSchema(eventProperties: {
|
|
44
|
-
[propName: string]: any;
|
|
45
|
-
}, shouldLogIfEnabled?: boolean): Array<{
|
|
46
|
-
propertyName: string;
|
|
47
|
-
propertyType: string;
|
|
48
|
-
children?: any;
|
|
49
|
-
}>;
|
|
50
|
-
setBatchSize(newBatchSize: number): void;
|
|
51
|
-
setBatchFlushSeconds(newBatchFlushSeconds: number): void;
|
|
52
|
-
}
|