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
Original file line number Diff line number Diff line change
Expand Up @@ -1153,3 +1153,35 @@ it('populates polling and streaming config in the factory context', async () =>

manager.close();
});

it('warns when a payload filter key is configured', () => {
const config = makeConfig({
serviceEndpoints: new ServiceEndpoints(
'https://stream',
'https://poll',
'https://events',
'/bulk',
'/diagnostic',
true,
'microservice-1',
),
});

const manager = createFDv2DataManagerBase(makeBaseConfig({ config }));

expect(config.logger.warn).toHaveBeenCalledWith(
expect.stringContaining('Payload filtering is not supported with the FDv2 data system'),
);

manager.close();
});

it('does not warn when no payload filter key is configured', () => {
const config = makeConfig();

const manager = createFDv2DataManagerBase(makeBaseConfig({ config }));

expect(config.logger.warn).not.toHaveBeenCalled();

manager.close();
});
3 changes: 3 additions & 0 deletions packages/shared/sdk-client/src/api/LDOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ export interface LDOptions {
* This payload filter key only applies to the default streaming and polling data sources. It will not affect
* TestData or FileData data sources, nor will it be applied to any data source provided through the featureStore
* config property.
*
* Payload filtering is not supported with the FDv2 data system, so this key has no effect on requests made by
* FDv2 data sources.
*/
payloadFilterKey?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ export function createFDv2DataManagerBase(
} = baseConfig;

const { logger } = config;

if (config.serviceEndpoints.payloadFilterKey !== undefined) {
logger?.warn(
`${logTag} Payload filtering is not supported with the FDv2 data system; the configured payload filter has no effect on FDv2 requests`,
);
}

const statusManager: DataSourceStatusManager = createDataSourceStatusManager(emitter);
const endpoints = fdv2Endpoints();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { LDLogger } from '@launchdarkly/js-sdk-common';

import { LDOptions } from '../src/api/options/LDOptions';
import LDClientImpl from '../src/LDClientImpl';
import { createBasicPlatform } from './createBasicPlatform';

describe('given a client using the FDv2 data system', () => {
const callbacks = {
onFailed: jest.fn(),
onError: jest.fn(),
onReady: jest.fn(),
onUpdate: jest.fn(),
hasEventListeners: jest.fn(),
};
let platform: any;
let logger: LDLogger;
let client: LDClientImpl;

function makeOptions(overrides: LDOptions = {}): LDOptions {
return {
sendEvents: false,
diagnosticOptOut: true,
logger,
dataSystem: {
dataSource: {
dataSourceOptionsType: 'custom',
initializers: [],
synchronizers: [],
},
},
...overrides,
};
}

beforeEach(() => {
platform = createBasicPlatform();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

afterEach(() => {
client?.close();
jest.resetAllMocks();
});

it('warns when a payload filter key is configured', () => {
client = new LDClientImpl(
'sdk-key',
platform,
makeOptions({ payloadFilterKey: 'microservice-1' }),
callbacks,
);

expect(logger.warn).toHaveBeenCalledWith(
expect.stringContaining('Payload filtering is not supported with the FDv2 data system'),
);
});

it('does not warn when no payload filter key is configured', () => {
client = new LDClientImpl('sdk-key', platform, makeOptions(), callbacks);

expect(logger.warn).not.toHaveBeenCalledWith(
expect.stringContaining('Payload filtering is not supported'),
);
});
});
7 changes: 7 additions & 0 deletions packages/shared/sdk-server/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ function constructFDv2(
}

const { logger } = config;

if (config.payloadFilterKey !== undefined) {
logger?.warn(
'Payload filtering is not supported with the FDv2 data system; the configured payload filter has no effect on FDv2 requests',
);
}

const baseHeaders = defaultHeaders(
sdkKey,
platform.info,
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/sdk-server/src/api/options/LDOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ export interface LDOptions {
* This payload filter key only applies to the default streaming and polling data sources. It will not affect
* TestData or FileData data sources, nor will it be applied to any data source provided through the featureStore
* config property.
*
* Payload filtering is not supported with the FDv2 data system, so this key has no effect on requests made by
* FDv2 data sources.
*/
payloadFilterKey?: string;

Expand Down
Loading