Skip to content

Commit 7893edf

Browse files
Merge pull request #8 from edgee-cloud/jco-breaking-change
Jco breaking change
2 parents 517edac + af8b294 commit 7893edf

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

src/index.ts

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
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";
114

125
const API_ENDPOINT = "https://your-endpoint.com/path";
136

@@ -25,7 +18,7 @@ interface JSONObject {
2518

2619
type JSONArray = JSONValue[];
2720

28-
const convertDict = (dict: Dict): Map<string, string> => {
21+
const convertDict = (dict: EdgeeDataCollection.Dict): Map<string, string> => {
2922
const data = new Map<string, string>();
3023

3124
for (const [key, value] of dict) {
@@ -35,7 +28,7 @@ const convertDict = (dict: Dict): Map<string, string> => {
3528
return data;
3629
};
3730

38-
const buildEdgeeRequest = (payload: JSONObject, apiKey: string): EdgeeRequest => ({
31+
const buildEdgeeRequest = (payload: JSONObject, apiKey: string): EdgeeDataCollection.EdgeeRequest => ({
3932
method: 'POST',
4033
url: API_ENDPOINT,
4134
headers: [
@@ -46,7 +39,7 @@ const buildEdgeeRequest = (payload: JSONObject, apiKey: string): EdgeeRequest =>
4639
forwardClientHeaders: true,
4740
});
4841

49-
const buildPagePayload = (data: PageData, context: Context): JSONObject => {
42+
const buildPagePayload = (data: EdgeeDataCollection.PageData, context: EdgeeDataCollection.Context): JSONObject => {
5043
const sessionId = parseInt(context.session.sessionId);
5144
const pageTitle = data.title;
5245
// TODO extract data/context fields and build payload object
@@ -56,7 +49,7 @@ const buildPagePayload = (data: PageData, context: Context): JSONObject => {
5649
};
5750
};
5851

59-
const buildTrackPayload = (data: TrackData, context: Context): JSONObject => {
52+
const buildTrackPayload = (data: EdgeeDataCollection.TrackData, context: EdgeeDataCollection.Context): JSONObject => {
6053
const sessionId = parseInt(context.session.sessionId);
6154
const eventName = data.name;
6255
const eventProperties = convertDict(data.properties);
@@ -68,7 +61,7 @@ const buildTrackPayload = (data: TrackData, context: Context): JSONObject => {
6861
};
6962
};
7063

71-
const buildUserPayload = (data: UserData, context: Context): JSONObject => {
64+
const buildUserPayload = (data: EdgeeDataCollection.UserData, context: EdgeeDataCollection.Context): JSONObject => {
7265
const sessionId = parseInt(context.session.sessionId);
7366
const userId = data.userId;
7467
// TODO extract data/context fields and build payload object
@@ -78,9 +71,9 @@ const buildUserPayload = (data: UserData, context: Context): JSONObject => {
7871
};
7972
};
8073

81-
export const dataCollection: typeof EdgeeComponentsDataCollection = {
74+
export const dataCollection: typeof EdgeeDataCollection = {
8275

83-
page(e: Event, settings: Dict) {
76+
page(e: EdgeeDataCollection.Event, settings: EdgeeDataCollection.Dict) {
8477
if (e.data.tag != 'page') {
8578
throw new Error("Missing page data");
8679
}
@@ -97,7 +90,7 @@ export const dataCollection: typeof EdgeeComponentsDataCollection = {
9790
return buildEdgeeRequest(payload, apiKey);
9891
},
9992

100-
track(e: Event, settings: Dict) {
93+
track(e: EdgeeDataCollection.Event, settings: EdgeeDataCollection.Dict) {
10194
if (e.data.tag != 'track') {
10295
throw new Error("Missing track data");
10396
}
@@ -115,7 +108,7 @@ export const dataCollection: typeof EdgeeComponentsDataCollection = {
115108
return buildEdgeeRequest(payload, apiKey);
116109
},
117110

118-
user(e: Event, settings: Dict) {
111+
user(e: EdgeeDataCollection.Event, settings: EdgeeDataCollection.Dict) {
119112
if (e.data.tag != 'user') {
120113
throw new Error("Missing user data");
121114
}

types/interfaces/edgee-components-data-collection.d.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
export namespace EdgeeComponentsDataCollection {
2-
export function page(e: Event, settings: Dict): EdgeeRequest;
3-
export function track(e: Event, settings: Dict): EdgeeRequest;
4-
export function user(e: Event, settings: Dict): EdgeeRequest;
5-
}
1+
/** @module Interface edgee:components/data-collection **/
2+
export function page(e: Event, settings: Dict): EdgeeRequest;
3+
export function track(e: Event, settings: Dict): EdgeeRequest;
4+
export function user(e: Event, settings: Dict): EdgeeRequest;
65
export type Dict = Array<[string, string]>;
76
/**
87
* # Variants

types/wit.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { EdgeeComponentsDataCollection } from './interfaces/edgee-components-data-collection.js';
2-
export const dataCollection: typeof EdgeeComponentsDataCollection;
1+
// world edgee:native/data-collection
2+
export * as dataCollection from './interfaces/edgee-components-data-collection.js'; // export edgee:components/data-collection

0 commit comments

Comments
 (0)