Skip to content

Commit

Permalink
fix: Fix logical mistakes in integration event processing (#470)
Browse files Browse the repository at this point in the history
We had multiple logical mistakes, such as not matching on lower-cased
content type headers or skipping the entire event handler when a single
integration did not define an event processor. This PR fixes these
logical issues.
  • Loading branch information
BYK authored Aug 1, 2024
1 parent 3b4d3fe commit 0f10d81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-chefs-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/overlay': patch
---

Fix event processing pipeline for integrations
29 changes: 15 additions & 14 deletions packages/overlay/src/sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ export function connectToSidecar(
const listener = (event: MessageEvent): void => {
log(`Received new ${contentType} event`);
for (const integration of integrations) {
if (!integration.processEvent) {
return;
const integrationData = integration.processEvent
? integration.processEvent({
contentType,
data: event.data,
})
: { event };

if (!integrationData) {
continue;
}
const processedEvent = integration.processEvent({
contentType,
data: event.data,
setIntegrationData(prev => {
const integrationName = integration.name;
return {
...prev,
[integrationName]: [...(prev[integrationName] || []), integrationData],
};
});
if (processedEvent) {
setIntegrationData(prev => {
const integrationName = integration.name;
return {
...prev,
[integrationName]: [...(prev[integrationName] || []), processedEvent],
};
});
}
}
};

Expand Down

0 comments on commit 0f10d81

Please sign in to comment.