import { getUUID } from './uuid' ; import { GroupEventType , GroupTraits , IdentifyEventType , JsonMap , ScreenEventType , TrackEventType , UserTraits , AliasEventType , EventType , SegmentEvent , } from './types' ; import type { UserInfoState } from './store/userInfo' ; export const createTrackEvent = ( { event , properties = { } , } ) : TrackEventType => ( { type : EventType . TrackEvent , event , properties , } ) ; export const createScreenEvent = ( { name , properties = { } , } ) : ScreenEventType => ( { type : EventType . ScreenEvent , name , properties , } ) ; export const createIdentifyEvent = ( { userTraits = { } , } ) : IdentifyEventType => { return { type : EventType . IdentifyEvent , traits : userTraits , } ; } ; export const createGroupEvent = ( { groupId , groupTraits = { } , } ) : GroupEventType => ( { type : EventType . GroupEvent , groupId , traits : groupTraits , } ) ; export const createAliasEvent = ( { anonymousId , userId , newUserId , } ) : AliasEventType => ( { type : EventType . AliasEvent , userId : newUserId , previousId : userId || anonymousId , } ) ; const isAliasEvent = ( event ) : event is AliasEventType => event . type === EventType . AliasEvent ; export const applyRawEventData = ( event , userInfo ) => { return { ... event , anonymousId : userInfo . anonymousId , messageId : getUUID ( ) , timestamp : new Date ( ) . toISOString ( ) , integrations : event . integrations ?? { } , userId : isAliasEvent ( event ) ? event . userId : userInfo . userId , } ; } ;