Skip to content

refactor: convert events module to TS#1258

Open
jaissica12 wants to merge 6 commits into
developmentfrom
refactor/SDKE-1106-migrate-event-modules-to-TS
Open

refactor: convert events module to TS#1258
jaissica12 wants to merge 6 commits into
developmentfrom
refactor/SDKE-1106-migrate-event-modules-to-TS

Conversation

@jaissica12
Copy link
Copy Markdown
Contributor

@jaissica12 jaissica12 commented May 12, 2026

Background

  • As part of the ongoing effort to migrate the mParticle Web SDK from JavaScript to TypeScript, this PR converts the events module and its corresponding test file to TypeScript for improved type safety and developer experience.

What Has Changed

  • Converted src/events.js to src/events.ts with full type annotations on all method parameters, return types, and internal variables
  • Converted test/src/tests-event-logging.js to test/src/tests-event-logging.ts with proper global type declarations and type casts for intentionally invalid test inputs
  • Updated src/events.interfaces.ts to expand the logImpressionEvent signature to accept SDKImpression | SDKImpression[] | SDKProductImpression | SDKProductImpression[]
  • Minor supporting type adjustments in src/sdkRuntimeModels.ts, src/serverModel.ts, and src/store.ts

Screenshots/Video

Screenshot 2026-05-13 at 7 34 08 AM Screenshot 2026-05-13 at 7 34 37 AM Screenshot 2026-05-13 at 7 35 03 AM Screenshot 2026-05-13 at 7 35 23 AM

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 changed the base branch from master to development May 12, 2026 21:07
@jaissica12 jaissica12 marked this pull request as ready for review May 13, 2026 11:51
@jaissica12 jaissica12 requested a review from a team as a code owner May 13, 2026 11:51
@cursor
Copy link
Copy Markdown

cursor Bot commented May 13, 2026

PR Summary

Medium Risk
Touches core event/commercial event logging code paths and broadens accepted input shapes for impressions/promotions, which could impact payload formatting if typings mask runtime differences. Most changes are refactors/type annotations, but they sit in a high-traffic area.

Overview
Converts the Events implementation and event-logging tests from JS to TypeScript, adding explicit types for event logging, location tracking, and DOM event handlers.

Expands commerce APIs to accept additional input shapes: logImpressionEvent now supports both SDKImpression and SDKProductImpression (single or array) with runtime branching to normalize payloads, and logPromotionEvent now accepts a single promotion or an array.

Includes supporting type tweaks (e.g., SDKPromotionAction.PromotionActionType union, SDKConfig.timeout optional) and minor runtime adjustments like safer error logging and globalThis.location usage, plus small casts in serverModel for DTO serialization.

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

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 14dfc68. Configure here.

Comment thread src/events.ts
Comment thread src/events.ts Outdated
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
4.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

1 participant