-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathevent-factory.ts
25 lines (23 loc) · 1.04 KB
/
event-factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { assertUserIdentity, CoreEventFactory } from '@segment/analytics-core'
import { createMessageId } from '../lib/get-message-id'
import { SegmentEvent } from './types'
// use declaration merging to downcast CoreSegmentEvent without adding any runtime code.
// if/when we decide to add an actual implementation to NodeEventFactory that actually changes the event shape, we can remove this.
export interface NodeEventFactory {
alias(...args: Parameters<CoreEventFactory['alias']>): SegmentEvent
group(...args: Parameters<CoreEventFactory['group']>): SegmentEvent
identify(...args: Parameters<CoreEventFactory['identify']>): SegmentEvent
track(...args: Parameters<CoreEventFactory['track']>): SegmentEvent
page(...args: Parameters<CoreEventFactory['page']>): SegmentEvent
screen(...args: Parameters<CoreEventFactory['screen']>): SegmentEvent
}
export class NodeEventFactory extends CoreEventFactory {
constructor() {
super({
createMessageId,
onFinishedEvent: (event) => {
assertUserIdentity(event)
},
})
}
}