Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"packageManager": "[email protected]",
"//": "Pin jsonc-parser because v3.3.0 breaks rollup-plugin-esbuild",
"resolutions": {
"jsonc-parser": "3.2.0"
"jsonc-parser": "3.2.0",
"parse5": "7.2.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('When using a proxy', () => {
it('can use proxy in polling mode', async () => {
const proxy = await TestHttpServer.startProxy();
const server = await TestHttpServer.start();
server.forMethodAndPath('get', '/sdk/latest-all', TestHttpHandlers.respondJson(allData));
server.forMethodAndPath('get', '/sdk/poll', TestHttpHandlers.respondJson(allData));

const client = new LDClientNode(sdkKey, {
baseUri: server.url,
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('When using a proxy', () => {
const server = await TestHttpServer.start();
const events = new AsyncQueue<SSEItem>();
events.add({ type: 'put', data: JSON.stringify({ data: allData }) });
server.forMethodAndPath('get', '/all', TestHttpHandlers.sseStream(events));
server.forMethodAndPath('get', '/sdk/stream', TestHttpHandlers.sseStream(events));

const client = new LDClientNode(sdkKey, {
streamUri: server.url,
Expand All @@ -94,7 +94,7 @@ describe('When using a proxy', () => {
const proxy = await TestHttpServer.startProxy();
const pollingServer = await TestHttpServer.start();
const eventsServer = await TestHttpServer.start();
pollingServer.forMethodAndPath('get', '/sdk/latest-all', TestHttpHandlers.respondJson(allData));
pollingServer.forMethodAndPath('get', '/sdk/poll', TestHttpHandlers.respondJson(allData));
eventsServer.forMethodAndPath('post', '/diagnostic', TestHttpHandlers.respond(200));

const client = new LDClientNode(sdkKey, {
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/server-node/__tests__/LDClientNode.tls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('When using a TLS connection', () => {

it('can connect via HTTPS to a server with a self-signed certificate, if CA is specified', async () => {
server = await TestHttpServer.startSecure();
server.forMethodAndPath('get', '/sdk/latest-all', TestHttpHandlers.respondJson({}));
server.forMethodAndPath('get', '/sdk/poll', TestHttpHandlers.respondJson({}));

client = new LDClientNode('sdk-key', {
baseUri: server.url,
Expand All @@ -41,7 +41,7 @@ describe('When using a TLS connection', () => {

it('cannot connect via HTTPS to a server with a self-signed certificate, using default config', async () => {
server = await TestHttpServer.startSecure();
server.forMethodAndPath('get', '/sdk/latest-all', TestHttpHandlers.respondJson({}));
server.forMethodAndPath('get', '/sdk/poll', TestHttpHandlers.respondJson({}));

client = new LDClientNode('sdk-key', {
baseUri: server.url,
Expand All @@ -64,7 +64,7 @@ describe('When using a TLS connection', () => {
const events = new AsyncQueue<SSEItem>();
events.add({ type: 'put', data: JSON.stringify(eventData) });
server = await TestHttpServer.startSecure();
server.forMethodAndPath('get', '/stream/all', TestHttpHandlers.sseStream(events));
server.forMethodAndPath('get', '/stream/sdk/stream', TestHttpHandlers.sseStream(events));

client = new LDClientNode('sdk-key', {
baseUri: server.url,
Expand All @@ -83,7 +83,7 @@ describe('When using a TLS connection', () => {
it('can use custom TLS options for posting events', async () => {
server = await TestHttpServer.startSecure();
server.forMethodAndPath('post', '/events/bulk', TestHttpHandlers.respond(200));
server.forMethodAndPath('get', '/sdk/latest-all', TestHttpHandlers.respondJson({}));
server.forMethodAndPath('get', '/sdk/poll', TestHttpHandlers.respondJson({}));

client = new LDClientNode('sdk-key', {
baseUri: server.url,
Expand All @@ -99,7 +99,7 @@ describe('When using a TLS connection', () => {
await client.flush();

const flagsRequest = await server.nextRequest();
expect(flagsRequest.path).toEqual('/sdk/latest-all');
expect(flagsRequest.path).toEqual('/sdk/poll');

const eventsRequest = await server.nextRequest();
expect(eventsRequest.path).toEqual('/events/bulk');
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/server-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"dependencies": {
"@launchdarkly/js-server-sdk-common": "2.10.0",
"https-proxy-agent": "^5.0.1",
"launchdarkly-eventsource": "2.0.3"
"launchdarkly-eventsource": "2.2.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers: This adds support for getting header from event source.

},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EventListener, EventName, LDLogger } from '../../../src/api';
import { Payload } from '../../../src/internal/fdv2/payloadProcessor';
import { EventStream, PayloadStreamReader } from '../../../src/internal/fdv2/payloadStreamReader';


class MockEventStream implements EventStream {
private _listeners: Record<EventName, EventListener> = {};

Expand All @@ -26,7 +25,7 @@ it('it sets basis to true when intent code is xfer-full', () => {
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"}]}',
});
mockStream.simulateEvent('payload-transferred', {
data: '{"state": "mockState", "version": 1}',
Expand All @@ -48,7 +47,7 @@ it('it sets basis to false when intent code is xfer-changes', () => {
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-changes", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-changes", "id": "mockId"}]}',
});
mockStream.simulateEvent('payload-transferred', {
data: '{"state": "mockState", "version": 1}',
Expand All @@ -70,7 +69,7 @@ it('it sets basis to false and emits empty payload when intent code is none', ()
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "none", "id": "mockId", "target": 42}]}',
data: '{"payloads": [{"intentCode": "none", "id": "mockId", "target": 42}]}',
});
expect(receivedPayloads.length).toEqual(1);
expect(receivedPayloads[0].id).toEqual('mockId');
Expand All @@ -89,7 +88,7 @@ it('it handles xfer-full then xfer-changes', () => {
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagA", "version": 123, "object": {"objectFieldA": "objectValueA"}}',
Expand Down Expand Up @@ -131,7 +130,7 @@ it('it includes multiple types of updates in payload', () => {
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagA", "version": 123, "object": {"objectFieldA": "objectValueA"}}',
Expand Down Expand Up @@ -172,7 +171,7 @@ it('it does not include messages thats are not between server-intent and payload
data: '{"kind": "mockKind", "key": "flagShouldIgnore", "version": 123, "object": {"objectFieldShouldIgnore": "objectValueShouldIgnore"}}',
});
mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagA", "version": 123, "object": {"objectFieldA": "objectValueA"}}',
Expand Down Expand Up @@ -238,7 +237,7 @@ it('logs prescribed message when error event is encountered', () => {
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagA", "version": 123, "object": {"objectFieldA": "objectValueA"}}',
Expand Down Expand Up @@ -280,7 +279,7 @@ it('discards partially transferred data when an error is encountered', () => {
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagA", "version": 123, "object": {"objectFieldA": "objectValueA"}}',
Expand All @@ -295,7 +294,7 @@ it('discards partially transferred data when an error is encountered', () => {
data: '{"state": "mockState", "version": 1}',
});
mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId2"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId2"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagX", "version": 123, "object": {"objectFieldX": "objectValueX"}}',
Expand Down Expand Up @@ -339,7 +338,7 @@ it('silently ignores unrecognized kinds', () => {
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagA", "version": 123, "object": {"objectFieldA": "objectValueA"}}',
Expand Down Expand Up @@ -369,7 +368,7 @@ it('ignores additional payloads beyond the first payload in the server-intent me
});

mockStream.simulateEvent('server-intent', {
data: '{"payloads": [{"code": "xfer-full", "id": "mockId"},{"code": "IShouldBeIgnored", "id": "IShouldBeIgnored"}]}',
data: '{"payloads": [{"intentCode": "xfer-full", "id": "mockId"},{"intentCode": "IShouldBeIgnored", "id": "IShouldBeIgnored"}]}',
});
mockStream.simulateEvent('put-object', {
data: '{"kind": "mockKind", "key": "flagA", "version": 123, "object": {"objectFieldA": "objectValueA"}}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ it('applies payload filter to polling and streaming endpoints', () => {
'filterKey',
);

expect(getStreamingUri(endpoints, '/all', [])).toEqual(
'https://stream.launchdarkly.com/all?filter=filterKey',
expect(getStreamingUri(endpoints, '/sdk/stream', [])).toEqual(
'https://stream.launchdarkly.com/sdk/stream?filter=filterKey',
);
expect(getPollingUri(endpoints, '/sdk/latest-all', [])).toEqual(
'https://sdk.launchdarkly.com/sdk/latest-all?filter=filterKey',
expect(getPollingUri(endpoints, '/sdk/poll', [])).toEqual(
'https://sdk.launchdarkly.com/sdk/poll?filter=filterKey',
);
expect(
getPollingUri(endpoints, '/sdk/latest-all', [{ key: 'withReasons', value: 'true' }]),
).toEqual('https://sdk.launchdarkly.com/sdk/latest-all?withReasons=true&filter=filterKey');
getPollingUri(endpoints, '/sdk/poll', [{ key: 'withReasons', value: 'true' }]),
).toEqual('https://sdk.launchdarkly.com/sdk/poll?withReasons=true&filter=filterKey');
expect(getEventsUri(endpoints, '/bulk', [])).toEqual('https://events.launchdarkly.com/bulk');
});
Loading