Skip to content
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

refactor: Create Interfaces for eCommerce #964

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

  • Defines TypeScript interfaces for eCommerce

Testing Plan

  • Was this tested locally? If not, explain why.
  • N/A - these are type definitions

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

@alexs-mparticle alexs-mparticle added the refactor Changes to the structure of the code label Jan 15, 2025
Copy link
Member

@rmi22186 rmi22186 left a comment

Choose a reason for hiding this comment

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

looks great!

src/ecommerce.interfaces.ts Outdated Show resolved Hide resolved
src/ecommerce.interfaces.ts Outdated Show resolved Hide resolved
src/ecommerce.interfaces.ts Outdated Show resolved Hide resolved
src/ecommerce.interfaces.ts Show resolved Hide resolved
src/ecommerce.interfaces.ts Show resolved Hide resolved
src/ecommerce.interfaces.ts Outdated Show resolved Hide resolved
src/ecommerce.interfaces.ts Show resolved Hide resolved
src/ecommerce.interfaces.ts Outdated Show resolved Hide resolved
test/src/tests-identities-attributes.ts Outdated Show resolved Hide resolved
test/src/tests-identity.ts Outdated Show resolved Hide resolved
Comment on lines 100 to 113

/*
* @deprecated
*/
logPurchase(
transactionAttributes: TransactionAttributes,
product: SDKProduct | SDKProduct[],
clearCart?: boolean,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags
): void;
/*
* @deprecated
*/
Copy link
Member

Choose a reason for hiding this comment

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

for consistency with spacing, either add a line before the deprecation on line 111 or remove the new line at 100

"Category"?: string;
"Name"?: string;
"Id"?: string;
"Item Price"?: string;
Copy link
Member

Choose a reason for hiding this comment

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

a customer is allowed to add this as a string or number, but then we parse it into a number

https://github.com/mParticle/mparticle-web-sdk/blob/master/src/ecommerce.js#L267-L273

"Name"?: string;
"Id"?: string;
"Item Price"?: string;
"Quantity"?: string;
Copy link
Member

Choose a reason for hiding this comment

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

a customer is allowed to add it as a string or number, but then we parse it into a number https://github.com/mParticle/mparticle-web-sdk/blob/master/src/ecommerce.js#L282-L287

"Quantity"?: string;
"Position"?: number;
"Variant"?: string;
"Total Product Amount": string;
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/mParticle/mparticle-web-sdk/blob/master/src/ecommerce.js#L299 makes this a number

Suggested change
"Total Product Amount": string;
"Total Product Amount": number;

"Coupon Code"?: string;
"Total Amount"?: number;
"Shipping Amount"?: string;
"Tax Amount"?: string;
Copy link
Member

Choose a reason for hiding this comment

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

this gets sanitized and is a number - https://github.com/mParticle/mparticle-web-sdk/blob/master/src/ecommerce.js#L33-L37

Suggested change
"Tax Amount"?: string;
"Tax Amount"?: number;

"Affiliation"?: string;
"Coupon Code"?: string;
"Total Amount"?: number;
"Shipping Amount"?: string;
Copy link
Member

Choose a reason for hiding this comment

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

src/ecommerce.js Show resolved Hide resolved
src/ecommerce.interfaces.ts Show resolved Hide resolved
test/src/tests-identity.ts Outdated Show resolved Hide resolved
@@ -150,7 +156,7 @@ export interface SDKProduct {
Position?: number;
CouponCode?: string;
TotalAmount?: number;
Attributes?: { [key: string]: string };
Attributes?: Record<string, unknown> | undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

creatProduct technically assigns this to null if there are no attributes. Probably should be a future refactor to have it be undefined.

Suggested change
Attributes?: Record<string, unknown> | undefined;
Attributes?: Record<string, unknown> | null;

@@ -36,7 +36,7 @@ interface IECommerceShared {
brand?: string,
position?: number,
couponCode?: string,
attributes?: SDKEventAttrs,
attributes?: SDKEventAttrs
Copy link
Member

Choose a reason for hiding this comment

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

,

@@ -339,7 +339,7 @@ export function convertProducts(
price: sdkProduct.Price,
quantity: sdkProduct.Quantity,
coupon_code: sdkProduct.CouponCode,
custom_attributes: sdkProduct.Attributes,
custom_attributes: sdkProduct.Attributes as Record<string, string>,
Copy link
Member

Choose a reason for hiding this comment

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

see if this should be string, unknown

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Record<string, string> doesn't work because EventsApi.Product requires custom_attributes to be [key: string]: string

@alexs-mparticle alexs-mparticle merged commit 61ce006 into refactor/ts-migration-blackout-2024 Jan 17, 2025
24 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Changes to the structure of the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants