Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@flowkey/tracking-pipeline
Advanced tools
This is a library which helps implementing tracking events and user property changes of an app to multiple tracking services in a declarative and fully typed manner.
It does so by providing a trackEvent
function which consumes the app events and can be called from anywhere in the app. Then the different tracking integrations need to implement an eventTransformer
which converts the app events into a format that is usable for the tracking services.
The event transformer should be a pure function which has no side effects and does not access any global state or objects (e.g. window, etc.). For each app event it can return one event or multiple events as an array.
To actually transfer the service native events to the service the tracking integration also needs to implement a sendEvent
event function which is able to process one tracking service event.
In addition to that a global getCommonEventInfos
can be defined to gather global parameters which might be needed for every event (e.g. the userId, ip address, etc.)
Here is an example:
type AppEvent =
| {
eventName: "SOMETHING_HAPPENED";
foo: string;
test: number;
}
| {
eventName: "I_NEED_TO_GENERATE_TWO_EVENTS";
};
type MyFancyTrackingServiceEvent = {
name: string;
data?: {
foo: string;
nested: {
test: number;
};
};
};
// We want to send the userId with every event so let's grab it from our app service
const getCommonEventInfos = async () => ({
userId: await AuthService.getUserId()
});
// This automatically derives a type from the async function definition above
type CommonEventInfo = Parameters<
Parameters<ReturnType<typeof getCommonEventInfos>["then"]>[0]
>[0];
const myFancyServiceIntegration: EventTrackingIntegration<
AppEvent,
MyFancyTrackingServiceEvent,
CommonEventInfo
> = {
init: async () => {
// If needed we can initialize the service e.g. with a token
await myFancyService.init("MYTOKEN");
},
name: "test",
sendEvent: async (event, commonInfos) => {
// Here we take the common infos we want and the event and send itthem to our service
await myFancyService.sendEvent({
user: commonInfos.userId,
event: {
name: event.name,
data: event.data || {}
}
});
},
transformEvent: event => {
switch (event.eventName) {
case "SOMETHING_HAPPENED":
return {
// Our service uses different event names, so we map this here
name: "it happened",
data: {
foo: event.foo,
nested: {
test: event.test
}
}
};
case "I_NEED_TO_GENERATE_TWO_EVENTS":
return [
{
name: "it happened once"
},
{
name: "it happened twice"
}
];
default:
return [];
}
}
};
// Add as many integrations as you need
const integrations = [myFancyServiceIntegration];
const sendEvent = createSendEventFunction<AppEvent, any, CommonEventInfo>({
integrations,
// This turns on event logging
options: { debug: true }
});
const trackEvent = createTrackEventFunction({
sendEvent,
getCommonEventInfos
});
const initializeIntegrations = createInitializeIntegrationsFunction({
integrations
});
// Run the init calls of all integrations
await initializeIntegrations();
await trackEvent({
eventName: "SOMETHING_HAPPENED",
foo: "bar",
test: 123
});
await trackEvent({
eventName: "I_NEED_TO_GENERATE_TWO_EVENTS"
});
Tracking user property changes works similarly.
type UserProperties = {
name?: string;
email?: string;
lastLogin?: Date;
};
// This service is only interested in updating the last login as a unix timestamp
type FancyServiceUserProperties = {
lastLoginTimestamp?: string;
};
const myFancyServiceIntegration: UserPropertiesTrackingIntegration<
UserProperties,
FancyServiceUserProperties
> = {
transformUserProperties: userProperties =>
Object.fromEntries(
Object.entries(userProperties)
.map(([key, value]) => {
switch (key) {
case "lastLogin":
return ["lastLoginTimestamp", value.getTime()];
default:
return [];
}
})
.filter(entry => entry.length)
),
async updateUserProperties(
userId: string,
userProperties: FancyServiceUserProperties
) {
await myFancyService.updateUserProperties(userId, userProperties);
}
};
const integrations = [myFancyServiceIntegration];
const updateUserProperties = createUpdateUserPropertiesFunction<
UserProperties,
FancyServiceUserProperties
>({
integrations
});
const trackUserProperties = createTrackUserPropertiesFunction({
updateUserProperties,
getUserId: () => AuthService.getUserId()
});
await trackUserProperties({
name: "Foo Bar"
});
await trackUserProperties({
lastLogin: new Date()
});
FAQs
Declarative pipeline for tracking events
The npm package @flowkey/tracking-pipeline receives a total of 101 weekly downloads. As such, @flowkey/tracking-pipeline popularity was classified as not popular.
We found that @flowkey/tracking-pipeline demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.