Skip to content

refactor: Migrate Forwarder module to TypeScript #988

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

Draft
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

alexs-mparticle
Copy link
Collaborator

Instructions

  1. PR target branch should be against development
  2. PR title name should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-title-check.yml
  3. PR branch prefix should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-branch-check-name.yml

Summary

  • {provide a thorough description of the changes}

Testing Plan

  • Was this tested locally? If not, explain why.
  • {explain how this has been tested, and what, if any, additional testing should be done}

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

@alexs-mparticle alexs-mparticle force-pushed the refactor/SQDSDKS-4475-forwarder-typescript branch from 5afc5b6 to 948c6a6 Compare February 28, 2025 14:10
@alexs-mparticle alexs-mparticle changed the base branch from test/SQDSDKS-5767-forwarder-tests-ts to development February 28, 2025 14:10
@alexs-mparticle alexs-mparticle force-pushed the refactor/SQDSDKS-4475-forwarder-typescript branch from 948c6a6 to 9acfdc4 Compare February 28, 2025 14:21
// constructor?: new () => IMPForwarder;
constructor: () => any;
name: string;
getId: () => number, // Should this be optional?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A side loaded kit may not implement getId so at a minimum, this should be optional.

export type Kit = Dictionary;
export interface Kit {
// constructor?: new () => IMPForwarder;
constructor: () => any;
Copy link
Member

@rmi22186 rmi22186 Feb 28, 2025

Choose a reason for hiding this comment

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

revisit the constructor value?

name: string;
getId(): number;
filters: IKitFilterSettings;
Copy link
Member

Choose a reason for hiding this comment

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

is this only for sideloaded kits?

screenAttributeFilters: number[];


// Side loaded kit functioanlity in Forwarder methods
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Side loaded kit functioanlity in Forwarder methods
// Side loaded kit functionality in Forwarder methods



// Side loaded kit functioanlity in Forwarder methods
kitInstance: UnregisteredKit;
Copy link
Member

Choose a reason for hiding this comment

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

i see this as existing on the unregistered Kit, rather than IMPForwarder

Comment on lines 118 to 121
id: number;
settings: ForwarderSettings;
forwarderStatsUploader: AsyncUploader;
isInitialized: boolean;
filteringConsentRuleValues: IFilteringConsentRuleValues;
filteringUserAttributeValue: IFilteringUserAttributeValue;
filteringEventAttributeValue: IFilteringEventAttributeValue;
excludeAnonymousUser: boolean;
userIdentityFilters: UserIdentityFilters;
userAttributeFilters: UserAttributeFilters;
Copy link
Member

Choose a reason for hiding this comment

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

i think a lot of these settings are actually supposed to be on an IKitConfig or IForwarder, and not the IMPForwarder Class. the naming is confusing, so taht's probably why they all got combined into here. maybe this class should be named IMPForwarderClass for now even though I know that's bad practice, but at least so we don't confuse IMPForwarder for the class, which has the class methods on it, vs having properties for an actual forwarder or kit, some of which are found here

this applies to most of the items from line 118-149, but double check

Comment on lines +147 to +143
isSandbox?: boolean;
hasSandbox?: boolean;
isVisible?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

these are on the kitconfig and not the IMPForwarder class also

// constructor?: new () => IMPForwarder;
constructor: () => any;
name: string;
getId: () => number, // Should this be optional?
Copy link
Member

Choose a reason for hiding this comment

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

yes

Comment on lines 10 to 12
// constructor: class {
// constructor() {}
// } as new () => IMPForwarder
Copy link
Member

Choose a reason for hiding this comment

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

flagging to make sure you address this commented code and we don't forget

Comment on lines 43 to 45
// @ts-ignore
constructor: this.constructor,
// constructor: this.constructor as { new(): IMPForwarder },
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -74,6 +76,7 @@ export class MockForwarder {
})
}

// TODO: Can we finally get rid of this?
Copy link
Member

Choose a reason for hiding this comment

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

i don't have the historical context here. is this something you did or i did?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's something you introduced but I can't recall why it wasn't ever flagged during code review: #568

@@ -3201,6 +3204,8 @@ describe('forwarders', function() {
// The received event gets replaced by the last event sent to the forwarder
// SideloadedKit11 has received the session start event, but not the Test Event
// SideloadedKit22 will receive the Test Event

console.log('EventName', window.SideloadedKit11.instance.receivedEvent.EventName);
Copy link
Member

Choose a reason for hiding this comment

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

remove?

src/apiClient.ts Outdated
@@ -23,7 +23,7 @@ export interface IAPIClient {
) => void;
initializeForwarderStatsUploader: () => AsyncUploader;
prepareForwardingStats: (
forwarder: MPForwarder,
forwarder: IMPForwarder,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note to self: This might need to be a RegisteredKit

src/apiClient.ts Outdated
@@ -192,7 +192,7 @@ export default function APIClient(
};

this.prepareForwardingStats = function(
forwarder: MPForwarder,
forwarder: IMPForwarder,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This may need to become a RegisteredKit

@alexs-mparticle alexs-mparticle force-pushed the refactor/SQDSDKS-4475-forwarder-typescript branch from 5239dcd to 6cb7247 Compare March 18, 2025 18:35
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