Skip to content

Commit cc85fa1

Browse files
feat: remove batch forwarding to kits
Remove the client-side sendBatchToForwarders path that pushed event batches into kit processBatch. Server-side mParticle integration now handles this data, making the client-side batch-stream forwarding redundant. - Drop the sendBatchToForwarders() call site in batchUploader.ts - Remove the sendBatchToForwarders method and its now-unused batch filtering helper imports from forwarders.js - Remove the associated test coverage in batchUploader.spec.ts and tests-forwarders.ts
1 parent 0ec95bb commit cc85fa1

4 files changed

Lines changed: 0 additions & 1181 deletions

File tree

src/batchUploader.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,6 @@ export class BatchUploader {
368368
mpInstance
369369
);
370370

371-
if (uploadBatchObject) {
372-
try {
373-
mpInstance._Forwarders.sendBatchToForwarders(
374-
uploadBatchObject
375-
);
376-
} catch (e) {
377-
mpInstance.Logger.error(
378-
`Error forwarding batch to kits. ${e}`
379-
);
380-
}
381-
}
382-
383371
const onCreateBatchCallback =
384372
mpInstance._Store.SDKConfig.onCreateBatch;
385373

src/forwarders.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import {
88
isBlockedByEventFilter,
99
filterEventAttributes,
1010
filterUserIdentities,
11-
isBatchEventAllowed,
12-
filterBatchEventAttributes,
13-
filterBatchIdentities,
1411
} from './forwarder-utils';
1512

1613
const { Modify, Identify, Login, Logout } = Constants.IdentityMethods;
@@ -266,61 +263,6 @@ export default function Forwarders(mpInstance, kitBlocker) {
266263
}
267264
};
268265

269-
this.sendBatchToForwarders = function(batch) {
270-
if (
271-
mpInstance._Store.webviewBridgeEnabled ||
272-
!mpInstance._Store.activeForwarders
273-
) {
274-
return;
275-
}
276-
277-
for (const forwarder of mpInstance._Store.activeForwarders) {
278-
if (!forwarder.processBatch) {
279-
continue;
280-
}
281-
282-
try {
283-
const batchCopy = extend(true, {}, batch);
284-
285-
if (batchCopy.events) {
286-
batchCopy.events = batchCopy.events.filter(function(
287-
batchEvent
288-
) {
289-
return isBatchEventAllowed(batchEvent, forwarder);
290-
});
291-
292-
batchCopy.events.forEach(function(batchEvent) {
293-
filterBatchEventAttributes(batchEvent, forwarder);
294-
});
295-
}
296-
297-
batchCopy.user_identities = filterBatchIdentities(
298-
batchCopy.user_identities,
299-
forwarder.userIdentityFilters
300-
);
301-
302-
if (batchCopy.user_attributes) {
303-
batchCopy.user_attributes = KitFilterHelper.filterUserAttributes(
304-
batchCopy.user_attributes,
305-
forwarder.userAttributeFilters
306-
);
307-
}
308-
309-
if (!batchCopy.events || batchCopy.events.length === 0) {
310-
continue;
311-
}
312-
313-
const result = forwarder.processBatch(batchCopy);
314-
315-
if (result) {
316-
mpInstance.Logger.verbose(result);
317-
}
318-
} catch (e) {
319-
mpInstance.Logger.verbose(e);
320-
}
321-
}
322-
};
323-
324266
this.handleForwarderUserAttributes = function(functionNameKey, key, value) {
325267
if (
326268
(kitBlocker && kitBlocker.isAttributeKeyBlocked(key)) ||

test/jest/batchUploader.spec.ts

Lines changed: 0 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ describe('BatchUploader', () => {
55
let batchUploader: BatchUploader;
66
let mockMPInstance: IMParticleWebSDKInstance;
77
let originalFetch: typeof global.fetch;
8-
let mockSendBatchToForwarders: jest.Mock;
98

109
beforeEach(() => {
1110
const now = Date.now();
@@ -17,7 +16,6 @@ describe('BatchUploader', () => {
1716
global.fetch = jest.fn().mockResolvedValue({ ok: true, status: 200 });
1817

1918
// Create a mock mParticle instance with mocked methods for instantiating a BatchUploader
20-
mockSendBatchToForwarders = jest.fn();
2119
mockMPInstance = {
2220
_Store: {
2321
SDKConfig: {
@@ -30,9 +28,6 @@ describe('BatchUploader', () => {
3028
createServiceUrl: jest.fn().mockReturnValue('https://mock-url.com'),
3129
generateUniqueId: jest.fn().mockReturnValue('mock-uuid'),
3230
},
33-
_Forwarders: {
34-
sendBatchToForwarders: mockSendBatchToForwarders,
35-
},
3631
Identity: {
3732
getCurrentUser: jest.fn().mockReturnValue({
3833
getMPID: () => 'test-mpid',
@@ -58,227 +53,6 @@ describe('BatchUploader', () => {
5853
global.fetch = originalFetch;
5954
});
6055

61-
describe('batch forwarding to kits', () => {
62-
it('should call sendBatchToForwarders for each new batch in createNewBatches', () => {
63-
const mockEvents = [
64-
{
65-
EventName: 'Test Event',
66-
EventDataType: 4,
67-
MPID: 'test-mpid',
68-
SessionId: 'session-1',
69-
EventCategory: 1,
70-
Timestamp: Date.now(),
71-
},
72-
];
73-
74-
const mockUser = {
75-
getMPID: () => 'test-mpid',
76-
getConsentState: () => null,
77-
getUserIdentities: () => ({ userIdentities: {} }),
78-
getAllUserAttributes: () => ({}),
79-
};
80-
81-
BatchUploader['createNewBatches'](
82-
mockEvents as any,
83-
mockUser as any,
84-
mockMPInstance
85-
);
86-
87-
expect(mockSendBatchToForwarders).toHaveBeenCalledTimes(1);
88-
expect(mockSendBatchToForwarders).toHaveBeenCalledWith(
89-
expect.objectContaining({
90-
mpid: 'test-mpid',
91-
})
92-
);
93-
});
94-
95-
it('should call sendBatchToForwarders before onCreateBatch', () => {
96-
const callOrder: string[] = [];
97-
98-
mockSendBatchToForwarders.mockImplementation(() => {
99-
callOrder.push('sendBatchToForwarders');
100-
});
101-
102-
mockMPInstance._Store.SDKConfig.onCreateBatch = (batch) => {
103-
callOrder.push('onCreateBatch');
104-
return batch;
105-
};
106-
107-
const mockEvents = [
108-
{
109-
EventName: 'Test Event',
110-
EventDataType: 4,
111-
MPID: 'test-mpid',
112-
SessionId: 'session-1',
113-
EventCategory: 1,
114-
Timestamp: Date.now(),
115-
},
116-
];
117-
118-
const mockUser = {
119-
getMPID: () => 'test-mpid',
120-
getConsentState: () => null,
121-
getUserIdentities: () => ({ userIdentities: {} }),
122-
getAllUserAttributes: () => ({}),
123-
};
124-
125-
BatchUploader['createNewBatches'](
126-
mockEvents as any,
127-
mockUser as any,
128-
mockMPInstance
129-
);
130-
131-
expect(callOrder).toEqual([
132-
'sendBatchToForwarders',
133-
'onCreateBatch',
134-
]);
135-
});
136-
137-
it('should forward batch before onCreateBatch can modify it', () => {
138-
let forwardedEventCount = 0;
139-
140-
mockSendBatchToForwarders.mockImplementation((batch) => {
141-
forwardedEventCount = batch.events.length;
142-
});
143-
144-
mockMPInstance._Store.SDKConfig.onCreateBatch = (batch) => {
145-
batch.modified = true;
146-
batch.events = [];
147-
return batch;
148-
};
149-
150-
const mockEvents = [
151-
{
152-
EventName: 'Test Event',
153-
EventDataType: 4,
154-
MPID: 'test-mpid',
155-
SessionId: 'session-1',
156-
EventCategory: 1,
157-
Timestamp: Date.now(),
158-
},
159-
];
160-
161-
const mockUser = {
162-
getMPID: () => 'test-mpid',
163-
getConsentState: () => null,
164-
getUserIdentities: () => ({ userIdentities: {} }),
165-
getAllUserAttributes: () => ({}),
166-
};
167-
168-
BatchUploader['createNewBatches'](
169-
mockEvents as any,
170-
mockUser as any,
171-
mockMPInstance
172-
);
173-
174-
expect(forwardedEventCount).toBe(1);
175-
});
176-
177-
it('should forward batch even when onCreateBatch drops it', () => {
178-
mockMPInstance._Store.SDKConfig.onCreateBatch = () => {
179-
return null;
180-
};
181-
182-
(mockMPInstance.Logger as any).warning = jest.fn();
183-
184-
const mockEvents = [
185-
{
186-
EventName: 'Test Event',
187-
EventDataType: 4,
188-
MPID: 'test-mpid',
189-
SessionId: 'session-1',
190-
EventCategory: 1,
191-
Timestamp: Date.now(),
192-
},
193-
];
194-
195-
const mockUser = {
196-
getMPID: () => 'test-mpid',
197-
getConsentState: () => null,
198-
getUserIdentities: () => ({ userIdentities: {} }),
199-
getAllUserAttributes: () => ({}),
200-
};
201-
202-
BatchUploader['createNewBatches'](
203-
mockEvents as any,
204-
mockUser as any,
205-
mockMPInstance
206-
);
207-
208-
expect(mockSendBatchToForwarders).toHaveBeenCalledTimes(1);
209-
});
210-
211-
it('should not throw if sendBatchToForwarders errors', () => {
212-
mockSendBatchToForwarders.mockImplementation(() => {
213-
throw new Error('Kit failure');
214-
});
215-
216-
const mockEvents = [
217-
{
218-
EventName: 'Test Event',
219-
EventDataType: 4,
220-
MPID: 'test-mpid',
221-
SessionId: 'session-1',
222-
EventCategory: 1,
223-
Timestamp: Date.now(),
224-
},
225-
];
226-
227-
const mockUser = {
228-
getMPID: () => 'test-mpid',
229-
getConsentState: () => null,
230-
getUserIdentities: () => ({ userIdentities: {} }),
231-
getAllUserAttributes: () => ({}),
232-
};
233-
234-
expect(() => {
235-
BatchUploader['createNewBatches'](
236-
mockEvents as any,
237-
mockUser as any,
238-
mockMPInstance
239-
);
240-
}).not.toThrow();
241-
242-
expect(mockMPInstance.Logger.error).toHaveBeenCalled();
243-
});
244-
245-
it('should create separate batches per MPID and forward each', () => {
246-
const mockEvents = [
247-
{
248-
EventName: 'Event User A',
249-
EventDataType: 4,
250-
MPID: 'mpid-a',
251-
SessionId: 'session-1',
252-
EventCategory: 1,
253-
Timestamp: Date.now(),
254-
},
255-
{
256-
EventName: 'Event User B',
257-
EventDataType: 4,
258-
MPID: 'mpid-b',
259-
SessionId: 'session-1',
260-
EventCategory: 1,
261-
Timestamp: Date.now(),
262-
},
263-
];
264-
265-
const mockUser = {
266-
getMPID: () => 'mpid-a',
267-
getConsentState: () => null,
268-
getUserIdentities: () => ({ userIdentities: {} }),
269-
getAllUserAttributes: () => ({}),
270-
};
271-
272-
BatchUploader['createNewBatches'](
273-
mockEvents as any,
274-
mockUser as any,
275-
mockMPInstance
276-
);
277-
278-
expect(mockSendBatchToForwarders).toHaveBeenCalledTimes(2);
279-
});
280-
});
281-
28256
describe('shouldDebounceAST', () => {
28357
it('should return false for first call', () => {
28458
// First call should not be debounced

0 commit comments

Comments
 (0)