Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jco breaking change #8

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
EdgeeComponentsDataCollection,
EdgeeRequest,
Dict,
Event,
PageData,
TrackData,
UserData,
Context
} from "../types/interfaces/edgee-components-data-collection";
import type {
dataCollection as EdgeeDataCollection,
} from "../types/wit";

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

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

type JSONArray = JSONValue[];

const convertDict = (dict: Dict): Map<string, string> => {
const convertDict = (dict: EdgeeDataCollection.Dict): Map<string, string> => {
const data = new Map<string, string>();

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

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

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

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

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

export const dataCollection: typeof EdgeeComponentsDataCollection = {
export const dataCollection: typeof EdgeeDataCollection = {

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

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

user(e: Event, settings: Dict) {
user(e: EdgeeDataCollection.Event, settings: EdgeeDataCollection.Dict) {
if (e.data.tag != 'user') {
throw new Error("Missing user data");
}
9 changes: 4 additions & 5 deletions types/interfaces/edgee-components-data-collection.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export namespace EdgeeComponentsDataCollection {
export function page(e: Event, settings: Dict): EdgeeRequest;
export function track(e: Event, settings: Dict): EdgeeRequest;
export function user(e: Event, settings: Dict): EdgeeRequest;
}
/** @module Interface edgee:components/data-collection **/
export function page(e: Event, settings: Dict): EdgeeRequest;
export function track(e: Event, settings: Dict): EdgeeRequest;
export function user(e: Event, settings: Dict): EdgeeRequest;
export type Dict = Array<[string, string]>;
/**
* # Variants
4 changes: 2 additions & 2 deletions types/wit.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { EdgeeComponentsDataCollection } from './interfaces/edgee-components-data-collection.js';
export const dataCollection: typeof EdgeeComponentsDataCollection;
// world edgee:native/data-collection
export * as dataCollection from './interfaces/edgee-components-data-collection.js'; // export edgee:components/data-collection