Skip to content

feat: add batch stream wrapper function#86

Merged
khushi1033 merged 9 commits intodevelopmentfrom
feat/batch-stream-wrapper
Apr 9, 2026
Merged

feat: add batch stream wrapper function#86
khushi1033 merged 9 commits intodevelopmentfrom
feat/batch-stream-wrapper

Conversation

@khushi1033
Copy link
Copy Markdown
Contributor

@khushi1033 khushi1033 commented Apr 8, 2026

Summary

Implements the processBatch hook to support batch-level event forwarding. When called by the mParticle SDK after each batch upload, the kit forwards the full batch object (events, user attributes, identities, consent state, and non-event lifecycle data) to window.Rokt.batch_stream on the Rokt WSDK. Mirrors the existing event queue pattern with two new queues: batchQueue (drains when the kit initialises) and batchStreamQueue (drains when batch_stream becomes available).

Updated @mparticle/web-sdk to pull in the latest type definitions (Batch, SDKEvent, IMParticleUser, KitInterface). To fully conform to KitInterface, the following changes were made:

  • init and process parameter types widened to match the interface (Record<string, unknown> / SDKEvent), with internal casts to the kit's typed shapes
  • Identity callbacks (onUserIdentified, onLoginComplete, onLogoutComplete, onModifyComplete) updated to accept IMParticleUser with the correct second parameter where required
  • Public interface methods (init, process, processBatch, identity callbacks, attribute methods) now return descriptive strings on success and error to comply with KitInterface
  • id property added to satisfy the required KitInterface.id field
  • processEventQueue renamed to drainQueues to reflect that it now drains both the event and batch pre-init queues

Testing Plan

Added #processBatch tests in test/src/tests.spec.ts covering: happy path forwarding, non-event data passthrough, pre-init queuing and flush, batch_stream unavailable queuing and flush, window.Rokt undefined graceful fallback, and flush ordering. All tests existing from before continue to pass without modification.

@khushi1033 khushi1033 marked this pull request as ready for review April 8, 2026 18:37
Copy link
Copy Markdown
Contributor

@jamesnrokt jamesnrokt left a comment

Choose a reason for hiding this comment

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

Fairly hard to review given the changes to implement the interface at the same time as the batching updates. May be worth splitting?

src/Rokt-Kit.ts Outdated
getMPID(): string;
getAllUserAttributes(): Record<string, unknown>;
interface FilteredUser extends IMParticleUser {
getMPID?(): string;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are we removing getAllUserAttributes() but keeping the others?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We shouldn't need to extend IMParticleUser at all. if you look at the definition, it extends, User, which has all of these.

Yes it's technically a filtered user, but there's no difference bewteen an IMparticleUser and a FilteredUser from an interface perspective, so let's just use IMparticleUser.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Works for me!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@khushi1033 - just making sure yous ee this comment, since you pushed a change to fix alex's update, which made this comment, and my reply "outdated", and collapsed the comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rmi22186 Yeah sorry was still looking into it - I'm running into an issue though, since getMPID and getUserIdentities live on the User base type, which IMParticleUser extends, Typescript can't see them. Seeing in this comment it's intentionally not re-exported so thinking might have to stick to extending until that's updated?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@khushi1033 that's probably fine for now because eventually will be removed from . I'd add a comment saying that it needs to be cleaned up in the future so we don't forget. Something to add to our cool down week I'd say.

Co-authored-by: James Newman <james.newman@rokt.com>
@khushi1033 khushi1033 merged commit c361fa2 into development Apr 9, 2026
5 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 9, 2026
# [1.24.0](v1.23.0...v1.24.0) (2026-04-09)

### Features

* add batch stream wrapper function ([#86](#86)) ([c361fa2](c361fa2))
@mparticle-automation
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.24.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants