Skip to content

Commit 48e088b

Browse files
prepare 3.1.1 release (#6)
1 parent 7131d96 commit 48e088b

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

package-lock.json

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EventSender.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as errors from './errors';
22
import * as utils from './utils';
3+
import uuidv1 from 'uuid/v1';
34

45
const MAX_URL_LENGTH = 2000;
56

@@ -23,12 +24,14 @@ export default function EventSender(platform, eventsUrl, environmentId, options)
2324

2425
function sendChunk(events, usePost) {
2526
const jsonBody = JSON.stringify(events);
27+
const payloadId = uuidv1();
2628

2729
function doPostRequest(canRetry) {
2830
const headers = utils.extend(
2931
{
3032
'Content-Type': 'application/json',
3133
'X-LaunchDarkly-Event-Schema': '3',
34+
'X-LaunchDarkly-Payload-ID': payloadId,
3235
},
3336
utils.getLDHeaders(platform, options)
3437
);

src/__tests__/EventSender-test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ describe('EventSender', () => {
118118
expect(r.headers['x-launchdarkly-wrapper']).toBeUndefined();
119119
});
120120

121+
it('should send unique payload IDs', async () => {
122+
const options = { sendLDHeaders: true };
123+
const server = platform.testing.http.newServer();
124+
server.byDefault(respond(202));
125+
const sender = EventSender(platform, server.url, envId, options);
126+
const event = { kind: 'identify', key: 'userKey' };
127+
await sender.sendEvents([event], false);
128+
await sender.sendEvents([event], false);
129+
130+
const r0 = await server.nextRequest();
131+
const r1 = await server.nextRequest();
132+
const id0 = r0.headers['x-launchdarkly-payload-id'];
133+
const id1 = r1.headers['x-launchdarkly-payload-id'];
134+
expect(id0).toBeTruthy();
135+
expect(id1).toBeTruthy();
136+
expect(id0).not.toEqual(id1);
137+
});
138+
121139
it('should send wrapper info if present', async () => {
122140
const options = { sendLDHeaders: true, wrapperName: 'FakeSDK' };
123141
const server = platform.testing.http.newServer();
@@ -146,9 +164,13 @@ describe('EventSender', () => {
146164
await sender.sendEvents([event], false);
147165

148166
expect(server.requests.length()).toEqual(2);
149-
await server.nextRequest();
167+
const r0 = await server.nextRequest();
150168
const r1 = await server.nextRequest();
169+
expect(JSON.parse(r0.body)).toEqual([event]);
151170
expect(JSON.parse(r1.body)).toEqual([event]);
171+
const id0 = r0.headers['x-launchdarkly-payload-id'];
172+
expect(id0).toBeTruthy();
173+
expect(r1.headers['x-launchdarkly-payload-id']).toEqual(id0);
152174
});
153175
}
154176

0 commit comments

Comments
 (0)