Skip to content

Commit

Permalink
chore: refactor common server side logic for both app flows (#3760)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai authored Sep 26, 2024
1 parent 4b54592 commit e82d6c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 117 deletions.
88 changes: 0 additions & 88 deletions src/v1/sources/shopify/pixelWebhookEventTransform.js

This file was deleted.

32 changes: 10 additions & 22 deletions src/v1/sources/shopify/transform.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
/* eslint-disable @typescript-eslint/naming-convention */
const { isDefinedAndNotNull } = require('../../../v0/util');
const { processEventFromPixel } = require('./pixelTransform');
const { processPixelWebhookEvent } = require('./pixelWebhookEventTransform');
const { process: processLegacyEvents } = require('../../../v0/sources/shopify/transform');
const { process: processWebhookEvents } = require('../../../v0/sources/shopify/transform');

const process = async (inputEvent) => {
const { event, source } = inputEvent;
const metricMetadata = {
// eslint-disable-next-line unicorn/consistent-destructuring
writeKey: source?.WriteKey || event.query_parameters?.writeKey?.[0],
sourceId: source?.ID,
source: 'SHOPIFY',
};
const { event } = inputEvent;
// check on the source Config to identify the event is from the tracker-based (legacy)
// or the pixel-based (latest) implementation.
if (source && isDefinedAndNotNull(source.Config) && source?.Config?.version === 'pixel') {
const { pixelEventLabel: pixelClientEventLabel } = event;
if (pixelClientEventLabel) {
// this is a event fired from the web pixel loaded on the browser
// by the user interactions with the store.
const responseV2 = await processEventFromPixel(event);
return responseV2;
}
const webhookEventResponse = await processPixelWebhookEvent(event, metricMetadata, source);
return webhookEventResponse;
const { pixelEventLabel: pixelClientEventLabel } = event;
if (pixelClientEventLabel) {
// this is a event fired from the web pixel loaded on the browser
// by the user interactions with the store.
const responseV2 = await processEventFromPixel(event);
return responseV2;
}
// this is for default legacy tracker based server-side events processing
const response = await processLegacyEvents(event);
// this is for common logic for server-side events processing for both pixel and tracker apps.
const response = await processWebhookEvents(event);
return response;
};

Expand Down
12 changes: 5 additions & 7 deletions test/integrations/sources/shopify/v1ServerSideEventsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// the v1 transformation flow
import utils from '../../../../src/v0/util';
const defaultMockFns = () => {
jest.spyOn(utils, 'generateUUID').mockReturnValue('97fcd7b2-cc24-47d7-b776-057b7b199513');
jest.spyOn(utils, 'generateUUID').mockReturnValue('5d3e2cb6-4011-5c9c-b7ee-11bc1e905097');
};
import { dummySourceConfig } from './constants';

Expand Down Expand Up @@ -207,8 +207,7 @@ export const v1ServerSideEventsScenarios = [
context: {
library: {
name: 'RudderStack Shopify Cloud',
eventOrigin: 'server',
version: '2.0.0',
version: '1.0.0',
},
integration: {
name: 'SHOPIFY',
Expand Down Expand Up @@ -367,7 +366,7 @@ export const v1ServerSideEventsScenarios = [
},
},
timestamp: '2024-09-17T07:29:02.000Z',
anonymousId: '97fcd7b2-cc24-47d7-b776-057b7b199513',
anonymousId: '5d3e2cb6-4011-5c9c-b7ee-11bc1e905097',
},
],
},
Expand Down Expand Up @@ -491,8 +490,7 @@ export const v1ServerSideEventsScenarios = [
context: {
library: {
name: 'RudderStack Shopify Cloud',
eventOrigin: 'server',
version: '2.0.0',
version: '1.0.0',
},
integration: {
name: 'SHOPIFY',
Expand Down Expand Up @@ -583,7 +581,7 @@ export const v1ServerSideEventsScenarios = [
},
],
},
anonymousId: '97fcd7b2-cc24-47d7-b776-057b7b199513',
anonymousId: '5d3e2cb6-4011-5c9c-b7ee-11bc1e905097',
},
],
},
Expand Down

0 comments on commit e82d6c7

Please sign in to comment.