Skip to content

Commit

Permalink
fix: plugin-server normalizeEvent types (#22892)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiina303 authored Jun 12, 2024
1 parent ee5033a commit 23acd14
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions plugin-server/src/utils/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export function normalizeProcessPerson(event: PluginEvent, processPerson: boolea
return event
}

export function normalizeEvent(event: PluginEvent): PluginEvent {
export function normalizeEvent<T extends PipelineEvent | PluginEvent>(event: T): T {
event.distinct_id = sanitizeString(String(event.distinct_id))

let properties = event.properties ?? {}
Expand Down Expand Up @@ -245,7 +245,7 @@ export function normalizeEvent(event: PluginEvent): PluginEvent {
export function formPipelineEvent(message: Message): PipelineEvent {
// TODO: inefficient to do this twice?
const { data: dataStr, ...rawEvent } = JSON.parse(message.value!.toString())
const combinedEvent = { ...JSON.parse(dataStr), ...rawEvent }
const combinedEvent: PipelineEvent = { ...JSON.parse(dataStr), ...rawEvent }

// Track $set usage in events that aren't known to use it, before ingestion adds anything there
if (
Expand All @@ -261,13 +261,13 @@ export function formPipelineEvent(message: Message): PipelineEvent {
status.info('👀', 'Found $set usage in non-person event', {
event: combinedEvent.event,
team_id: combinedEvent.team_id,
token: combinedEvent.token,
})
}
}

const event: PipelineEvent = normalizeEvent({
...combinedEvent,
site_url: combinedEvent.site_url || null,
})
return event
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ describe('eachBatchX', () => {
ip: null,
now: null,
sent_at: null,
site_url: null,
site_url: '',
team_id: 1,
uuid: 'uuid1',
})
Expand Down

0 comments on commit 23acd14

Please sign in to comment.