1
- import {
2
- EdgeeComponentsDataCollection ,
3
- EdgeeRequest ,
4
- Dict ,
5
- Event ,
6
- PageData ,
7
- TrackData ,
8
- UserData ,
9
- Context
10
- } from "../types/interfaces/edgee-components-data-collection" ;
1
+ import type {
2
+ dataCollection as EdgeeDataCollection ,
3
+ } from "../types/wit" ;
11
4
12
5
const API_ENDPOINT = "https://your-endpoint.com/path" ;
13
6
@@ -25,7 +18,7 @@ interface JSONObject {
25
18
26
19
type JSONArray = JSONValue [ ] ;
27
20
28
- const convertDict = ( dict : Dict ) : Map < string , string > => {
21
+ const convertDict = ( dict : EdgeeDataCollection . Dict ) : Map < string , string > => {
29
22
const data = new Map < string , string > ( ) ;
30
23
31
24
for ( const [ key , value ] of dict ) {
@@ -35,7 +28,7 @@ const convertDict = (dict: Dict): Map<string, string> => {
35
28
return data ;
36
29
} ;
37
30
38
- const buildEdgeeRequest = ( payload : JSONObject , apiKey : string ) : EdgeeRequest => ( {
31
+ const buildEdgeeRequest = ( payload : JSONObject , apiKey : string ) : EdgeeDataCollection . EdgeeRequest => ( {
39
32
method : 'POST' ,
40
33
url : API_ENDPOINT ,
41
34
headers : [
@@ -46,7 +39,7 @@ const buildEdgeeRequest = (payload: JSONObject, apiKey: string): EdgeeRequest =>
46
39
forwardClientHeaders : true ,
47
40
} ) ;
48
41
49
- const buildPagePayload = ( data : PageData , context : Context ) : JSONObject => {
42
+ const buildPagePayload = ( data : EdgeeDataCollection . PageData , context : EdgeeDataCollection . Context ) : JSONObject => {
50
43
const sessionId = parseInt ( context . session . sessionId ) ;
51
44
const pageTitle = data . title ;
52
45
// TODO extract data/context fields and build payload object
@@ -56,7 +49,7 @@ const buildPagePayload = (data: PageData, context: Context): JSONObject => {
56
49
} ;
57
50
} ;
58
51
59
- const buildTrackPayload = ( data : TrackData , context : Context ) : JSONObject => {
52
+ const buildTrackPayload = ( data : EdgeeDataCollection . TrackData , context : EdgeeDataCollection . Context ) : JSONObject => {
60
53
const sessionId = parseInt ( context . session . sessionId ) ;
61
54
const eventName = data . name ;
62
55
const eventProperties = convertDict ( data . properties ) ;
@@ -68,7 +61,7 @@ const buildTrackPayload = (data: TrackData, context: Context): JSONObject => {
68
61
} ;
69
62
} ;
70
63
71
- const buildUserPayload = ( data : UserData , context : Context ) : JSONObject => {
64
+ const buildUserPayload = ( data : EdgeeDataCollection . UserData , context : EdgeeDataCollection . Context ) : JSONObject => {
72
65
const sessionId = parseInt ( context . session . sessionId ) ;
73
66
const userId = data . userId ;
74
67
// TODO extract data/context fields and build payload object
@@ -78,9 +71,9 @@ const buildUserPayload = (data: UserData, context: Context): JSONObject => {
78
71
} ;
79
72
} ;
80
73
81
- export const dataCollection : typeof EdgeeComponentsDataCollection = {
74
+ export const dataCollection : typeof EdgeeDataCollection = {
82
75
83
- page ( e : Event , settings : Dict ) {
76
+ page ( e : EdgeeDataCollection . Event , settings : EdgeeDataCollection . Dict ) {
84
77
if ( e . data . tag != 'page' ) {
85
78
throw new Error ( "Missing page data" ) ;
86
79
}
@@ -97,7 +90,7 @@ export const dataCollection: typeof EdgeeComponentsDataCollection = {
97
90
return buildEdgeeRequest ( payload , apiKey ) ;
98
91
} ,
99
92
100
- track ( e : Event , settings : Dict ) {
93
+ track ( e : EdgeeDataCollection . Event , settings : EdgeeDataCollection . Dict ) {
101
94
if ( e . data . tag != 'track' ) {
102
95
throw new Error ( "Missing track data" ) ;
103
96
}
@@ -115,7 +108,7 @@ export const dataCollection: typeof EdgeeComponentsDataCollection = {
115
108
return buildEdgeeRequest ( payload , apiKey ) ;
116
109
} ,
117
110
118
- user ( e : Event , settings : Dict ) {
111
+ user ( e : EdgeeDataCollection . Event , settings : EdgeeDataCollection . Dict ) {
119
112
if ( e . data . tag != 'user' ) {
120
113
throw new Error ( "Missing user data" ) ;
121
114
}
0 commit comments