From 2b21d2f7e6b6e84e68d19a4f4279f6424500b5a2 Mon Sep 17 00:00:00 2001 From: sushaan-k Date: Sun, 17 May 2026 23:07:52 -0400 Subject: [PATCH] fix(ts-sdk): honor options.priority and options.scope in EventClient.bulkPush `EventClient.bulkPush(type, inputs, options)` silently dropped `options.priority` and `options.scope` because the per-event mapping only read those fields from each `EventWithMetadata` input and never fell back to the shared `options` argument. `additionalMetadata` already falls back to `options.additionalMetadata`, and `EventClient.push` honors all three fields from `options`, so the previous behaviour was inconsistent. Mirror the `additionalMetadata` fallback for `priority` and `scope` so the shared options argument applies to every event in the batch that does not set its own override. Closes #3931 --- .../src/clients/event/event-client.test.ts | 32 +++++++++++++++++++ .../src/clients/event/event-client.ts | 4 +-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/sdks/typescript/src/clients/event/event-client.test.ts b/sdks/typescript/src/clients/event/event-client.test.ts index b987dcadb8..9fa8827a6e 100644 --- a/sdks/typescript/src/clients/event/event-client.test.ts +++ b/sdks/typescript/src/clients/event/event-client.test.ts @@ -129,6 +129,38 @@ describe('EventClient', () => { }); }); + it('should apply options.priority and options.scope as defaults in bulkPush', async () => { + const clientSpy = jest.spyOn(client.client, 'bulkPush').mockResolvedValue({ + events: [], + }); + + const events = [ + { payload: { foo: 'bar1' } }, + { payload: { foo: 'bar2' }, priority: 7, scope: 'per-event-scope' }, + ]; + + await client.bulkPush('type', events, { priority: 3, scope: 'shared-scope' }); + + expect(clientSpy).toHaveBeenCalledWith({ + events: [ + { + key: 'type', + payload: '{"foo":"bar1"}', + eventTimestamp: expect.any(Date), + priority: 3, + scope: 'shared-scope', + }, + { + key: 'type', + payload: '{"foo":"bar2"}', + eventTimestamp: expect.any(Date), + priority: 7, + scope: 'per-event-scope', + }, + ], + }); + }); + it('should throw an error when bulkPush fails', async () => { // Mock the bulkPush method to throw an error const clientSpy = jest.spyOn(client.client, 'bulkPush'); diff --git a/sdks/typescript/src/clients/event/event-client.ts b/sdks/typescript/src/clients/event/event-client.ts index 75f6da8f52..d6d4ab8e49 100644 --- a/sdks/typescript/src/clients/event/event-client.ts +++ b/sdks/typescript/src/clients/event/event-client.ts @@ -113,8 +113,8 @@ export class EventClient { payload: JSON.stringify(input.payload), eventTimestamp: new Date(), additionalMetadata: Object.keys(enhanced).length > 0 ? JSON.stringify(enhanced) : undefined, - priority: input.priority, - scope: input.scope, + priority: input.priority ?? options.priority, + scope: input.scope ?? options.scope, }; });