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

fix((INT-360): enhancement: shopify ecom fix and enhancement #2493

Closed
wants to merge 37 commits into from

Conversation

anantjain45823
Copy link
Contributor

@anantjain45823 anantjain45823 commented Aug 18, 2023

Description of the change

We are changing the code base for shopify as there are many layers through which a payload goes to be enhanced
This PR includes the changes regarding the same.
We have used layering concept where we have identifier events Layer, Track event Layer, Identify Events layer and enhancement Layer.
Todo :- Incorporate mapping for each ecommerce event.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Fix #1

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers mentioned in a comment
  • Changes have been reviewed by at least one other engineer
  • Issue from task tracker has a link to this pull request

@anantjain45823 anantjain45823 changed the title enhancement: shopify ecom fix and enhancement fix: enhancement: shopify ecom fix and enhancement Aug 18, 2023
@anantjain45823 anantjain45823 changed the title fix: enhancement: shopify ecom fix and enhancement fix((INT-153): enhancement: shopify ecom fix and enhancement Aug 18, 2023
@linear
Copy link

linear bot commented Aug 18, 2023

INT-153 Research: Shopify Ecomm spec review

Repo: https://github.com/rudderlabs/rudder-shopify-tracker

Analyze whether shopify events are adhering to Rudderstack Ecomm spec

Research Spec

Shopify Ecomm spec review

@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (8bca3e4) 87.24% compared to head (093825f) 87.10%.

❗ Current head 093825f differs from pull request most recent head cffefdf. Consider uploading reports for the commit cffefdf to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2493      +/-   ##
===========================================
- Coverage    87.24%   87.10%   -0.14%     
===========================================
  Files          641      613      -28     
  Lines        28519    28540      +21     
  Branches      6780     6776       -4     
===========================================
- Hits         24880    24861      -19     
- Misses        3310     3347      +37     
- Partials       329      332       +3     
Files Coverage Δ
src/v0/sources/shopify_v2/commonUtils.js 100.00% <100.00%> (ø)
src/v0/sources/shopify_v2/config.js 100.00% <100.00%> (ø)
src/v0/sources/shopify_v2/enrichmentLayer.js 100.00% <100.00%> (ø)
src/v0/sources/shopify_v2/identifierEventsLayer.js 100.00% <100.00%> (ø)
src/v0/sources/shopify_v2/identifyEventsLayer.js 100.00% <100.00%> (ø)
...c/v0/sources/shopify_v2/identityResolutionLayer.js 100.00% <100.00%> (ø)
src/v0/sources/shopify_v2/trackEventsLayer.js 100.00% <100.00%> (ø)
src/v0/sources/shopify_v2/transform.js 100.00% <100.00%> (ø)
src/v0/util/index.js 87.85% <100.00%> (+0.02%) ⬆️

... and 136 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/v0/sources/shopify V2/commonUtils.js Outdated Show resolved Hide resolved
src/v0/sources/shopify V2/commonUtils.js Outdated Show resolved Hide resolved
src/v0/sources/shopify V2/commonUtils.js Outdated Show resolved Hide resolved
src/v0/sources/shopify V2/config.js Outdated Show resolved Hide resolved
src/v0/sources/shopify V2/commonUtils.js Outdated Show resolved Hide resolved
src/v0/sources/shopify V2/config.js Outdated Show resolved Hide resolved
src/v0/sources/shopify V2/trackEventsLayer.js Outdated Show resolved Hide resolved
src/v0/sources/shopify V2/config.js Outdated Show resolved Hide resolved
@anantjain45823 anantjain45823 changed the title fix((INT-153): enhancement: shopify ecom fix and enhancement fix((INT-360): enhancement: shopify ecom fix and enhancement Aug 22, 2023
@linear
Copy link

linear bot commented Aug 22, 2023

@anantjain45823 anantjain45823 requested a review from a team as a code owner August 24, 2023 08:34
@Gauravudia Gauravudia self-assigned this Aug 24, 2023
@@ -3,7 +3,7 @@ const path = require('path');
const version = 'v0';
const { RedisDB } = require('./redisConnector');
jest.mock('ioredis', () => require('../../../test/__mocks__/redis'));
const sourcesList = ['shopify'];
const sourcesList = ['shopify', 'shopify_v2'];
Copy link
Member

Choose a reason for hiding this comment

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

lets not keep shopify_v2. Lets create a new Shopify dir under v1 dir on the same level as v0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refer this please

const { RedisDB } = require('../../../util/redis/redisConnector');
const logger = require('../../../logger');

const identifierEventLayer = {
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
const identifierEventLayer = {
const IdentifierEventLayer = {

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

statusCode: 200,
};

const identifierEvents = ['rudderIdentifier', 'rudderSessionIdentifier'];
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
const identifierEvents = ['rudderIdentifier', 'rudderSessionIdentifier'];
const IDENTIFIER_EVENTS = ['rudderIdentifier', 'rudderSessionIdentifier'];

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

async processIdentifierEvent(event, metricMetadata) {
let value;
let field;
if (event.event === 'rudderIdentifier') {
Copy link
Member

Choose a reason for hiding this comment

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

Change the argument name to something which provides more clarity event.event doesn't provide much clarity.

Comment on lines +71 to +80
lineItems[element.id] = {
quantity: element?.quantity,
variant_id: element?.variant_id,
key: element?.key,
price: element?.price,
product_id: element?.product_id,
sku: element?.sku,
title: element?.title,
vendor: element?.vendor,
};
Copy link
Member

Choose a reason for hiding this comment

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

Optional chaining is not needed here

// eslint-disable-next-line no-param-reassign
event.userId = String(event.userId);
}
if (!get(event, 'traits.email')) {
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
if (!get(event, 'traits.email')) {
if (!get(event, 'context.traits.email')) {

event.setProperty(`integrations.${INTEGRATION}`, true);
event.setProperty('context.library', {
name: 'RudderStack Shopify Cloud',
version: '1.0.0',
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
version: '1.0.0',
version: '1.1.0',

Copy link
Member

Choose a reason for hiding this comment

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

Should be a constant this version number based on the implementations appropriate constant should be used

extractCustomFields,
} = require('../../util');

const trackLayer = {
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
const trackLayer = {
const TrackLayer = {

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

}
},

async processTrackEvent(event, eventName, dbData, metricMetadata) {
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
async processTrackEvent(event, eventName, dbData, metricMetadata) {
async processTrackEvent(shopifyEvent, shopifyEventName, dbData, metricMetadata) {

return updatedCartProperties;
},

async generateProductAddedAndRemovedEvents(event, dbData, metricMetadata) {
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
async generateProductAddedAndRemovedEvents(event, dbData, metricMetadata) {
async generateProductAddedAndRemovedEvents(shopifyEvent, dbData, metricMetadata) {

// if no prev cart is found we trigger product added event for every line_item present
if (!prevLineItems) {
event?.line_items.forEach((product) => {
const updatedProduct = this.getUpdatedProductProperties(product, event?.id || event?.token);
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
const updatedProduct = this.getUpdatedProductProperties(product, event?.id || event?.token);
const updatedProduct = this.getUpdatedProductProperties(product, event.id || event.token);

Comment on lines +174 to +180
const updatedCartProperties = product;
if (updatedQuantity) {
updatedCartProperties.quantity = updatedQuantity;
}
updatedCartProperties.cart_id = cart_token;
return updatedCartProperties;
},
Copy link
Member

Choose a reason for hiding this comment

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

why are we calling updatedCartProperties for this variable we are updating products?

Comment on lines +70 to +71
let properties = this.createPropertiesForEcomEvent(event, shopifyTopic);
properties = removeUndefinedAndNullValues(properties);
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
let properties = this.createPropertiesForEcomEvent(event, shopifyTopic);
properties = removeUndefinedAndNullValues(properties);
const properties = removeUndefinedAndNullValues(this.createPropertiesForEcomEvent(event, shopifyTopic));

);
if (productAddedOrRemovedEvents.length === 0) return [NO_OPERATION_SUCCESS];
productAddedOrRemovedEvents = productAddedOrRemovedEvents.map((productEvent) =>
this.mapCustomerDetails(productEvent, event, dbData, eventName),
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
this.mapCustomerDetails(productEvent, event, dbData, eventName),
this.mapCustomerDetails(productEvent, shopifyEvent, dbData, eventName),

if (!get(payload, 'traits.email')) {
const email = extractEmailFromPayload(event);
if (email) {
updatedPayload.setProperty('traits.email', email);
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
updatedPayload.setProperty('traits.email', email);
updatedPayload.setProperty('context.traits.email', email);

Comment on lines +48 to +49
const cartToken = getCartToken(message, shopifyTopic);
if (!isDefinedAndNotNull(cartToken)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we validate using dbData since we already have that? Why are we validating with cartToken here?

);
if (isDefinedAndNotNull(anonymousId)) {
updatedMessage.setProperty('anonymousId', anonymousId);
} else if (!message.userId) {
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
} else if (!message.userId) {
} else if (!isDefineNotNullandBlank(message.userId)) {

} else if (!message.userId) {
updatedMessage.setProperty('userId', 'shopify-admin');
}
if (isDefinedAndNotNull(sessionId)) {
Copy link
Member

Choose a reason for hiding this comment

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

Use not blank as well for empty string

Comment on lines +278 to +306
if (SHOPIFY_TO_RUDDER_ECOM_EVENTS_MAP.CART_UPDATED === eventName) {
let productAddedOrRemovedEvents = await this.generateProductAddedAndRemovedEvents(
event,
dbData,
metricMetadata,
);
if (productAddedOrRemovedEvents.length === 0) return [NO_OPERATION_SUCCESS];
productAddedOrRemovedEvents = productAddedOrRemovedEvents.map((productEvent) =>
this.mapCustomerDetails(productEvent, event, dbData, eventName),
);
return productAddedOrRemovedEvents;
}
// if event is checkout updated we get the updated event name
if (SHOPIFY_TO_RUDDER_ECOM_EVENTS_MAP.CHECKOUTS_UPDATE === eventName) {
updatedEventName = this.getUpdatedEventNameForCheckoutUpateEvent(event);
}
if (Object.keys(RUDDER_ECOM_MAP).includes(updatedEventName)) {
payload = this.ecomPayloadBuilder(event, updatedEventName);
} else if (Object.keys(SHOPIFY_NON_ECOM_TRACK_MAP).includes(updatedEventName)) {
payload = this.nonEcomPayloadBuilder(event, updatedEventName);
} else {
stats.increment('invalid_shopify_event', {
event: eventName,
...metricMetadata,
});
return [NO_OPERATION_SUCCESS];
}
return [this.mapCustomerDetails(payload, event, dbData, eventName)];
},
Copy link
Member

Choose a reason for hiding this comment

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

can we try using switch case here?

// return msgpack.encode(lineItems);
};

const getUnhashedLineItems = (lineItems) => {
Copy link
Member

Choose a reason for hiding this comment

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

Change fxn name

Comment on lines +199 to +201
if (prevQuantity) {
delete prevLineItems[key];
}
Copy link
Member

Choose a reason for hiding this comment

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

Elaborate what are we doing here?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

35.2% 35.2% Coverage
6.2% 6.2% Duplication

@devops-github-rudderstack
Copy link
Contributor

This PR is considered to be stale. It has been open for 20 days with no further activity thus it is going to be closed in 7 days. To avoid such a case please consider removing the stale label manually or add a comment to the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants