Skip to content

refactor: update ecommerce module to TS#1259

Open
jaissica12 wants to merge 4 commits into
developmentfrom
refactor/SDKE-1108-update-ecommerce-module-to-TS
Open

refactor: update ecommerce module to TS#1259
jaissica12 wants to merge 4 commits into
developmentfrom
refactor/SDKE-1108-update-ecommerce-module-to-TS

Conversation

@jaissica12
Copy link
Copy Markdown
Contributor

@jaissica12 jaissica12 commented May 12, 2026

Background

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

What Has Changed

  • Converted src/ecommerce.js to src/ecommerce.ts with full type annotations on all methods and parameters
  • Converted test/src/tests-eCommerce.js to test/src/tests-eCommerce.ts with necessary type casts for intentional type-mismatch tests that validate error handling

Screenshots/Video

  • Add to Cart
Screenshot 2026-05-25 at 6 48 45 PM Screenshot 2026-05-25 at 6 48 57 PM
  • Purchase
Screenshot 2026-05-25 at 6 50 25 PM Screenshot 2026-05-25 at 6 50 37 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

  • var declarations replaced with const/let (SonarCloud compliance)
  • ShoppingCart initialization corrected from [] to {} to align with SDKShoppingCart interface type
  • No functional/behavioral changes

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

@jaissica12 jaissica12 force-pushed the refactor/SDKE-1108-update-ecommerce-module-to-TS branch from 5887ac3 to 8ff79fb Compare May 25, 2026 22:41
@jaissica12 jaissica12 changed the base branch from master to development May 25, 2026 22:42
@jaissica12 jaissica12 marked this pull request as ready for review May 26, 2026 11:33
@jaissica12 jaissica12 requested a review from a team as a code owner May 26, 2026 11:33
@cursor
Copy link
Copy Markdown

cursor Bot commented May 26, 2026

PR Summary

Medium Risk
Commerce event creation and expansion are customer-facing; the ShoppingCart shape change from [] to {} is the main runtime surface worth validating in integration tests even though the PR targets parity.

Overview
Migrates the eCommerce implementation and its test suite from JavaScript to TypeScript, wiring the constructor and methods to IECommerce, @mparticle/event-models, and sdkRuntimeModels types instead of untyped parameters.

The module now uses typed const/let, arrow/forEach callbacks with explicit product/promotion types, and a _self indirection so internal helpers stay callable from expansion paths where this would otherwise break. createCommerceEventObject initializes ShoppingCart as an empty object (SDKShoppingCart) rather than an array. Tests move to .ts with Function casts where they deliberately pass invalid inputs, and they reference ProductActionType / PromotionActionType from test constants instead of mParticle.* aliases.

Reviewed by Cursor Bugbot for commit 1830ed4. 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 1 potential issue.

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 8ff79fb. Configure here.

Comment thread src/ecommerce.ts
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
10.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.

2 participants