Skip to content

Commit b83ae41

Browse files
Generate latest bundle
1 parent bee0026 commit b83ae41

File tree

10 files changed

+36637
-0
lines changed

10 files changed

+36637
-0
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
import { BaseEvent, Batch } from '@mparticle/event-models';
2+
import { DataPlanDocument, DataPlanMatch, DataPlanPoint, DataPlanPointSchema, ValidationResultEvent } from '@mparticle/data-planning-models';
3+
/**
4+
* This is an instance of the DataPlanEventValidator
5+
*
6+
* This class can be either instantiated to validate a set of events
7+
* and user attributes or used statically to provide simple comparisons
8+
* of [[DataPlanMatchType]] and
9+
* [[DataPlanMatch]] attributes.
10+
*
11+
* ## Usage
12+
*
13+
* ### Creating an instance
14+
*
15+
* An instance of a [[DataPlanEventValidator]] is initialized with a
16+
* [[DataPlanDocument]] that will be used to validate all subsequent
17+
* events. This docuemnt is also used to generate an internal list of
18+
* [[DataPlanPoint]]s representing **planned** events;
19+
*
20+
* ```typescript
21+
* const dataPlanDocument = {
22+
* data_points: [
23+
* {
24+
* "description": "big screen desc",
25+
* "match": {
26+
* "type": "screen_view",
27+
* "criteria": {
28+
* "screen_name": "screenA"
29+
* }
30+
* },
31+
* "validator": {
32+
* "type": "json_schema",
33+
* "definition": {
34+
* "properties": {
35+
* "data": {
36+
* "additionalProperties": false,
37+
* "properties": {
38+
* "screen_name": {
39+
* "const": "screenA"
40+
* },
41+
* "activity_type": {
42+
* "type": "string"
43+
* }
44+
* },
45+
* "required": [
46+
* "screen_name",
47+
* "activity_type"
48+
* ]
49+
* }
50+
* }
51+
* }
52+
* }
53+
* },
54+
* ],
55+
* }
56+
* ```
57+
*
58+
* Once initialized, the [[validateEventBatch]] method is used to perform
59+
* the bulk of the validation. This will return an array of
60+
* [[ValidationResultEvent]] objects.
61+
*
62+
* ```ts
63+
* const validator = new DataPlanEventValidator(dataPlanDocument);
64+
* const validationResults = validator.validateEventBatch(eventBatch);
65+
* ```
66+
*
67+
* An example [[ValidationResultEvent]]:
68+
* ```json
69+
* [
70+
* {
71+
* "event_type": "validation_results",
72+
* "data": {
73+
* "match": {
74+
* "type": "screen_view",
75+
* "criteria": {
76+
* "screen_name": "screenA"
77+
* }
78+
* },
79+
* "validation_errors": [
80+
* {
81+
* "validation_error_type": "unplanned"
82+
* }
83+
* ]
84+
* }
85+
* }
86+
* ]
87+
*
88+
* ```
89+
*
90+
* ### As a static class
91+
*
92+
* The [[DataPlanEventValidator]] also exposes static methods that can be
93+
* used independently of the instance for looking up and comparing
94+
* [[DataPlanMatchType]]
95+
*/
96+
export declare class DataPlanEventValidator {
97+
dataPlanDocument: DataPlanDocument;
98+
eventBatchForLogging: Batch | null;
99+
dataPlanMatchLookups: {
100+
[key: string]: DataPlanPointSchema;
101+
};
102+
constructor(dataPlanDocument: DataPlanDocument, eventBatchForLogging?: Batch | null);
103+
/**
104+
* Adds a [[DataPlanPoint]] to an internal hashmap of events and their
105+
* respective matchers and schemas for validation
106+
*
107+
* Usage:
108+
* ```typescript
109+
* const point: DataPlanPoint = {
110+
* match: {
111+
* type: 'custom_event',
112+
* criteria: {
113+
* event_name: 'This is a test event',
114+
* custom_event_type: 'location'
115+
* }
116+
* },
117+
* validator: {
118+
* type: 'json_schema',
119+
* definition: {
120+
* properties: {
121+
* data: {
122+
* additionalProperties: false,
123+
* properties: {
124+
* event_name: {
125+
* const: 'This is a test event'
126+
* },
127+
* custom_event_type: {
128+
* const: 'location'
129+
* }
130+
* },
131+
* required: ['custom_event_type', 'event_name']
132+
* }
133+
* }
134+
* }
135+
* }
136+
* };
137+
*
138+
* const batch: Batch = {
139+
* events: [
140+
* {
141+
* event_type: 'custom_event',
142+
* },
143+
* ],
144+
* environment: 'development',
145+
* mpid: '123456789',
146+
* };
147+
*
148+
* validator.addToMatchLookups(point, batch);
149+
* ```
150+
*
151+
* @param point A single [[DataPlanPoint]]
152+
* @param eventBatchForLogging A [[Batch]] object used for logging
153+
* @category Core
154+
*/
155+
addToMatchLookups(point: DataPlanPoint, eventBatchForLogging?: Batch | null): void;
156+
/**
157+
* Combines Validation Error Results with User Attribute Validation as a
158+
* single Array of [[ValidationResultEvent]] objects
159+
* @param eventErrors An array of [[ValidationResultEvent]] objects
160+
* @param userAttributeErrors User Attribute Errors as a
161+
* [[ValidationResultEvent]]
162+
* @returns A concatenated array of [[ValidationResultEvent]] objects
163+
*/
164+
private combineErrors;
165+
/**
166+
* Validates Events and User Attributes, returning both in an array of
167+
* [[ValidationResultEvent]] objects
168+
* @category Core
169+
* @param eventBatch A single [[Batch]]
170+
*/
171+
validateEventBatch(eventBatch: Batch): ValidationResultEvent[];
172+
/**
173+
* Validates a single [[BaseEvent]] and returns the result as a
174+
* [[ValidationResultEvent]]
175+
* @param event A Base EVent
176+
* @returns a single Validation Result
177+
*/
178+
validateEvent(event: BaseEvent): ValidationResultEvent;
179+
/**
180+
* Validates a single [[Batch]] and returns the results as a
181+
* [[ValidationResultEvent]]
182+
* @param eventBatch A single [[Batch]]
183+
* @returns Validation Results
184+
*/
185+
validateEvents(eventBatch: Batch): ValidationResultEvent[];
186+
validateUserAttributes(eventBatch: Batch): ValidationResultEvent;
187+
/**
188+
* Returns a matchKey string from a DataPlanMatch Object
189+
* @param match A [[DataPlanMatch]] object
190+
*/
191+
static generateMatchKey(match: DataPlanMatch): string;
192+
/**
193+
* Returns a matchKey for a [[BaseEvent]]
194+
* @param eventToMatch A [[BaseEvent]]
195+
* @returns A `matchKey` as a string
196+
*/
197+
static getMatchKey(eventToMatch: BaseEvent): string | null;
198+
/**
199+
* Generates a [[DataPlanMatch]] based on the `matchType` of a `BaseEvent`
200+
* @param eventToMatch A [[BaseEvent]]
201+
* @returns A [[DataPlanMatch]] for the event
202+
*/
203+
static synthesizeMatch(eventToMatch: BaseEvent): DataPlanMatch;
204+
private getEventKey;
205+
}

dist/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './data_planning/data_plan_event_validator';
2+
export * from './services/data_plan_service';
3+
export * from './validation/JSONSchemaValidator';
4+
export * from './utils/config';

0 commit comments

Comments
 (0)