Skip to content

refactor: update forwarder module to TS#1260

Open
jaissica12 wants to merge 3 commits into
developmentfrom
refactor/SDKE-1109-update-forwarders-to-TS
Open

refactor: update forwarder module to TS#1260
jaissica12 wants to merge 3 commits into
developmentfrom
refactor/SDKE-1109-update-forwarders-to-TS

Conversation

@jaissica12
Copy link
Copy Markdown
Contributor

@jaissica12 jaissica12 commented May 12, 2026

Background

  • Continuing the effort to migrate remaining JavaScript modules to TypeScript for improved type safety and developer experience across the SDK codebase.

What Has Changed

  • Converted src/forwarders.js to src/forwarders.ts with full type annotations on all methods, parameters, and return types
  • Updated src/forwarders.interfaces.ts with corrected and expanded interface definitions to support the conversion
  • Updated src/sdkRuntimeModels.ts with type adjustments needed for forwarder-related models
  • Updated src/store.ts with type refinements required by the forwarder module

Screenshots/Video

Screenshot 2026-05-20 at 11 30 43 PM Screenshot 2026-05-20 at 11 33 06 PM Screenshot 2026-05-20 at 11 33 59 PM Screenshot 2026-05-20 at 11 34 39 PM

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

Reference Issue (For employees only. Ignore if you are an outside contributor)

@jaissica12 jaissica12 marked this pull request as ready for review May 21, 2026 02:45
@jaissica12 jaissica12 requested a review from a team as a code owner May 21, 2026 02:45
@cursor
Copy link
Copy Markdown

cursor Bot commented May 21, 2026

PR Summary

Medium Risk
Moderate risk because it touches the core kit/forwarder dispatch path (event/batch forwarding, kit init, identity/user attribute propagation) and adds several type-driven casts that could mask runtime mismatches.

Overview
Migrates the forwarder subsystem to TypeScript by converting forwarders to forwarders.ts and adding an IForwarders contract, with explicit types across init, event forwarding, batch forwarding, pixel config handling, and forwarding-stats upload.

Expands forwarder/kit interfaces to include processBatch support and additional config types (e.g., IConfigResponse, user-attribute filtering types, forwarding-stats queue types), and updates public/runtime types so _getActiveForwarders and store activeForwarders are typed as MPForwarder[] instead of ConfiguredKit[].

Reviewed by Cursor Bugbot for commit 15106a8. Bugbot is set up for automated code reviews on this repo. Configure here.

@sonarqubecloud
Copy link
Copy Markdown

Comment thread src/forwarders.ts
import { Batch } from '@mparticle/event-models';
import { IMParticleUser, ISDKUserIdentity } from './identity-user-interfaces';
import KitBlocker from './kitBlocking';
import { Dictionary } from './utils';
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.

Clean up these imports

Comment thread src/forwarders.ts
}
if (
!self.isEnabledForUserAttributes(
!(this.isEnabledForUserAttributes as Function)(
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 do we need as Function?

Comment thread src/forwarders.ts

// Check user attribute filtering rules
clonedEvent.UserAttributes = KitFilterHelper.filterUserAttributes(
clonedEvent.UserAttributes = (KitFilterHelper.filterUserAttributes as Function)(
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.

Same here. This feels like we're trying to bypass type safety.

Comment thread src/forwarders.ts
}

for (const forwarder of mpInstance._Store.activeForwarders) {
for (
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.

Is there a reason we needed to change this to a standard for loop?

Comment thread src/forwarders.ts

if (result) {
mpInstance.Logger.verbose(result);
mpInstance.Logger.verbose(result as 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.

Isn't this already a string?

Comment thread src/forwarders.ts
// sideloaded kits, this will need to be refactored.
this.processSideloadedKits = function(mpConfig) {
this.processSideloadedKits = function(
mpConfig: IConfigResponse & { sideloadedKits?: { kitInstance: { register: Function; name: string }; filterDictionary: IKitFilterSettings }[] }
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.

If we don't have a type for this, let's make one.

Comment thread src/sdkRuntimeModels.ts
endSession(): void;
init(apiKey: string, config: SDKInitConfig, instanceName?: string): void;
_getActiveForwarders(): ConfiguredKit[];
_getActiveForwarders(): MPForwarder[];
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.

Let's be careful with this because MPForwarder and ConfiguredKit might have specific "contracts".

Comment thread src/sdkRuntimeModels.ts
name: string
): Dictionary<string> | null;
filterUserIdentities?(
userIdentitiesObject: Record<string, 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.

I think we may have this type defined for this.

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