refactor: convert events module to TS#1258
Conversation
|
PR SummaryMedium Risk Overview Expands commerce APIs to accept arrays in more places (e.g., Converts the event logging test suite to TypeScript by adding global type declarations and using casts/ Reviewed by Cursor Bugbot for commit 14dfc68. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ 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.
| this.logProductActionEvent = function( | ||
| productActionType, | ||
| product, | ||
| customAttrs, |
There was a problem hiding this comment.
Replacing self with this in regular functions risks broken context
Medium Severity
The original code used var self = this to lexically capture the Events instance, guaranteeing correct binding regardless of calling context. The refactored code replaces self with this inside regular (non-arrow) function expressions like logAST, logCheckoutEvent, logProductActionEvent, logPurchaseEvent, logRefundEvent, logPromotionEvent, and logImpressionEvent. Since these are not arrow functions, this is determined at call time. If any method is ever invoked without being called as a property of the Events object (e.g., stored in a variable, passed as a callback), this will be undefined in strict mode, causing a runtime crash. The project's tsconfig.json does not enable noImplicitThis, so the compiler won't catch this.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 14dfc68. Configure here.
| ProductImpressionList: imp.Name, | ||
| ProductList: Array.isArray(imp.Product) | ||
| ? imp.Product | ||
| : [imp.Product], |
There was a problem hiding this comment.
Unsafe cast silently mishandles SDKProductImpression input data
Medium Severity
The logImpressionEvent type signature now explicitly accepts SDKProductImpression | SDKProductImpression[], but the implementation unconditionally casts each item to SDKImpression via as SDKImpression and accesses .Name and .Product. SDKProductImpression has different properties (ProductImpressionList and ProductList), so passing one would silently produce impressions with undefined names and [undefined] product lists — silent data corruption with no error.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 14dfc68. Configure here.




Background
What Has Changed
src/events.jstosrc/events.tswith full type annotations on all method parameters, return types, and internal variablestest/src/tests-event-logging.jstotest/src/tests-event-logging.tswith proper global type declarations and type casts for intentionally invalid test inputssrc/events.interfaces.tsto expand thelogImpressionEventsignature to acceptSDKImpression | SDKImpression[] | SDKProductImpression | SDKProductImpression[]src/sdkRuntimeModels.ts,src/serverModel.ts, andsrc/store.tsScreenshots/Video
Checklist
Additional Notes
Reference Issue (For employees only. Ignore if you are an outside contributor)