Skip to content

Commit 7a1473e

Browse files
committed
jitsu-js: prevent changes made by functions for one sync destination to affect event in another sync destination on the same stream
1 parent 7f4895a commit 7a1473e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

libs/jitsu-js/src/analytics-plugin.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,16 @@ export const emptyRuntime = (config: JitsuOptions): RuntimeFacade => ({
415415
},
416416
});
417417

418+
function deepCopy(o) {
419+
if (typeof o !== "object") {
420+
return o;
421+
}
422+
if (!o) {
423+
return o;
424+
}
425+
return JSON.parse(JSON.stringify(o));
426+
}
427+
418428
function deepMerge(target: any, source: any) {
419429
if (typeof source !== "object" || source === null) {
420430
return source;
@@ -574,15 +584,17 @@ async function processDestinations(
574584
const promises: Promise<any>[] = [];
575585

576586
for (const destination of destinations) {
577-
let newEvents = [originalEvent];
587+
let newEvents: AnalyticsClientEvent[] = [];
578588
if (destination.newEvents) {
579589
try {
580590
newEvents = destination.newEvents.map(e =>
581-
e === "same" ? originalEvent : isDiff(e) ? diff.patch(originalEvent, e.__diff) : e
591+
e === "same" ? deepCopy(originalEvent) : isDiff(e) ? diff.patch(deepCopy(originalEvent), e.__diff) : e
582592
);
583593
} catch (e) {
584594
console.error(`[JITSU] Error applying '${destination.id}' changes to event: ${e?.message}`, e);
585595
}
596+
} else {
597+
newEvents = [deepCopy(originalEvent)];
586598
}
587599
const credentials = { ...destination.credentials, ...destination.options };
588600

0 commit comments

Comments
 (0)