avo-inspector 2.2.0-alpha.1 → 2.2.2-alpha
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/CHANGELOG.md +35 -2
- package/README.md +95 -0
- package/bin/avo-inspector.js +97 -0
- package/dist/AvoBatcher.d.ts +4 -2
- package/dist/AvoEncryption.d.ts +33 -0
- package/dist/AvoInspector.d.ts +31 -3
- package/dist/AvoNetworkCallsHandler.d.ts +28 -3
- package/dist/AvoSchemaParser.d.ts +12 -1
- package/dist/browser.js.LICENSE.txt +5 -0
- package/dist/eventSpec/AvoEventSpecCache.d.ts +73 -0
- package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +109 -0
- package/dist/eventSpec/AvoEventSpecFetcher.d.ts +54 -0
- package/dist/eventSpec/EventValidator.d.ts +90 -0
- package/dist/eventSpec/cache.d.ts +73 -0
- package/dist/eventSpec/index.d.ts +4 -0
- package/dist/eventSpec/types.d.ts +74 -0
- package/dist/index.js +2 -1
- package/dist/index.js.LICENSE.txt +5 -0
- package/dist-browser/AvoAnonymousId.d.ts +26 -0
- package/dist-browser/AvoBatcher.d.ts +26 -0
- package/dist-browser/AvoDeduplicator.d.ts +20 -0
- package/dist-browser/AvoEncryption.d.ts +33 -0
- package/dist-browser/AvoGuid.d.ts +3 -0
- package/dist-browser/AvoInspector.d.ts +78 -0
- package/dist-browser/AvoInspectorEnv.d.ts +7 -0
- package/dist-browser/AvoNetworkCallsHandler.d.ts +74 -0
- package/dist-browser/AvoSchemaParser.d.ts +20 -0
- package/dist-browser/AvoStorage.d.ts +22 -0
- package/dist-browser/__mocks__/xhr.d.ts +12 -0
- package/dist-browser/__mocks__/xhrError.d.ts +12 -0
- package/dist-browser/__tests__/AnonymousId_test.d.ts +1 -0
- package/dist-browser/__tests__/AvoEncryption_test.d.ts +1 -0
- package/dist-browser/__tests__/AvoInspectorEventSpec_test.d.ts +1 -0
- package/dist-browser/__tests__/AvoInspector_test.d.ts +1 -0
- package/dist-browser/__tests__/BatcherPublic_test.d.ts +1 -0
- package/dist-browser/__tests__/Batcher_test.d.ts +1 -0
- package/dist-browser/__tests__/Deduplicator_test.d.ts +1 -0
- package/dist-browser/__tests__/EncryptedPropertyTracking_test.d.ts +1 -0
- package/dist-browser/__tests__/EventSpecCache_test.d.ts +1 -0
- package/dist-browser/__tests__/EventSpecFetcher_test.d.ts +1 -0
- package/dist-browser/__tests__/EventValidator_test.d.ts +1 -0
- package/dist-browser/__tests__/NetworkCallsHandler_test.d.ts +1 -0
- package/dist-browser/__tests__/Parsing_test.d.ts +1 -0
- package/dist-browser/__tests__/Storage_test.d.ts +1 -0
- package/dist-browser/__tests__/ValidationIntegration_test.d.ts +1 -0
- package/dist-browser/__tests__/constants.d.ts +36 -0
- package/dist-browser/__tests__/helpers/encryptionHelpers.d.ts +13 -0
- package/dist-browser/__tests__/helpers/mockFactories.d.ts +49 -0
- package/dist-browser/eventSpec/AvoEventSpecCache.d.ts +73 -0
- package/dist-browser/eventSpec/AvoEventSpecFetchTypes.d.ts +109 -0
- package/dist-browser/eventSpec/AvoEventSpecFetcher.d.ts +55 -0
- package/dist-browser/eventSpec/EventValidator.d.ts +90 -0
- package/dist-browser/eventSpec/index.d.ts +4 -0
- package/dist-browser/index.d.ts +2 -0
- package/dist-browser/utils.d.ts +3 -0
- package/jest.config.js +6 -0
- package/package.json +8 -2
- package/webpack.browserConfig.js +1 -1
- package/webpack.config.js +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
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/jest.config.js
CHANGED
|
@@ -2,6 +2,7 @@ module.exports = {
|
|
|
2
2
|
preset: "ts-jest",
|
|
3
3
|
testEnvironment: "jsdom",
|
|
4
4
|
setupFiles: ["<rootDir>/src/__tests__/jest.setup.js"],
|
|
5
|
+
setupFilesAfterEnv: ["<rootDir>/src/__tests__/jest.setupAfterEnv.js"],
|
|
5
6
|
moduleNameMapper: {
|
|
6
7
|
"^react-native$": "<rootDir>/src/__tests__/jest.setup.js",
|
|
7
8
|
},
|
|
@@ -9,6 +10,7 @@ module.exports = {
|
|
|
9
10
|
"**/src/__tests__/**/*.ts",
|
|
10
11
|
"!**/src/__tests__/setup.ts",
|
|
11
12
|
"!**/src/__tests__/constants.ts",
|
|
13
|
+
"!**/src/__tests__/helpers/**",
|
|
12
14
|
],
|
|
13
15
|
testPathIgnorePatterns: [
|
|
14
16
|
"/node_modules/",
|
|
@@ -16,6 +18,10 @@ module.exports = {
|
|
|
16
18
|
"/examples/",
|
|
17
19
|
"/constants/",
|
|
18
20
|
],
|
|
21
|
+
modulePathIgnorePatterns: [
|
|
22
|
+
"<rootDir>/dist/",
|
|
23
|
+
"<rootDir>/dist-native/",
|
|
24
|
+
],
|
|
19
25
|
transform: {
|
|
20
26
|
"^.+\\.(ts|tsx)$": "ts-jest",
|
|
21
27
|
},
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
2
|
"name": "avo-inspector",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2-alpha",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"avo-inspector": "./bin/avo-inspector.js"
|
|
10
|
+
},
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "tsc --emitDeclarationOnly && webpack --config webpack.config.js",
|
|
10
13
|
"build-for-script-tag": "tsc --outDir dist-browser --emitDeclarationOnly && webpack --config webpack.browserConfig.js",
|
|
@@ -32,6 +35,9 @@
|
|
|
32
35
|
"url": "https://github.com/avohq/web-avo-inspector/issues"
|
|
33
36
|
},
|
|
34
37
|
"homepage": "https://github.com/avohq/web-avo-inspector#readme",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"eciesjs": "^0.4.11"
|
|
40
|
+
},
|
|
35
41
|
"devDependencies": {
|
|
36
42
|
"@babel/core": "^7.25.2",
|
|
37
43
|
"@babel/preset-env": "^7.25.3",
|
package/webpack.browserConfig.js
CHANGED