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

Support adding middleware to every device mode destination #1053

Merged
merged 1 commit into from
Apr 5, 2024
Merged

Conversation

silesky
Copy link
Contributor

@silesky silesky commented Mar 20, 2024

Add * glob support.

addDestinationMiddleware('*', ({ next, payload }) => {
  if (dropThisEventForSomeReason) {
     return null
  }
  next(payload)
})

[x] I've included a changeset

Copy link

changeset-bot bot commented Mar 20, 2024

🦋 Changeset detected

Latest commit: 286fb8a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-next Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -878,6 +878,90 @@ describe('addDestinationMiddleware', () => {
})
})

it('drops events if next is never called', async () => {
Copy link
Contributor Author

@silesky silesky Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scenarios were not affected, but there didn't seem to be any explicit test coverage -- and they are relevant to what we're trying to do with consent. Anyway, threw those addition tests in -- since the docs don't even mention that you can call next with "null" to drop events.

https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/middleware/#using-destination-middlewares

@silesky silesky marked this pull request as ready for review March 26, 2024 21:06
@silesky silesky requested a review from danieljackins April 5, 2024 17:02
@@ -226,7 +226,6 @@ export class LegacyDestination implements DestinationPlugin {
type: 'Dropped by plan',
})
)
return ctx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok to remove because our event queue doesn't do anything with the returned ctx?

Copy link
Contributor Author

@silesky silesky Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's dead code, since the ctx.cancel above throws an error (it's return type is never).

My editor kept auto-removing them for some reason, so I just kept it in.

image

if (
routing.length &&
routingMiddleware &&
plugin.type === 'destination'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool - so we were actually doing this check twice because addMiddleware also checks this

@silesky silesky merged commit fd09fbc into master Apr 5, 2024
5 checks passed
@silesky silesky deleted the add-glob branch April 5, 2024 20:11
@github-actions github-actions bot mentioned this pull request Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants