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

fix: plugin-server normalizeEvent types #22892

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
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
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
Loading