Skip to content

Commit 18deecd

Browse files
authored
fix: Accept eventsUri option in Fastly SDK init() (#1791)
1 parent bd6a9c8 commit 18deecd

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

packages/sdk/fastly/__tests__/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ describe('init', () => {
3939
ldClient.close();
4040
});
4141

42+
it('does not throw when initialized with a custom eventsUri', () => {
43+
let client: LDClient | undefined;
44+
expect(() => {
45+
client = init(sdkKey, mockKVStore, {
46+
eventsUri: 'https://custom-events.example.com',
47+
eventsBackendName: 'custom-backend',
48+
});
49+
}).not.toThrow();
50+
// Close the client so its event processor's flush timer does not keep the
51+
// runtime (and the jest process) alive.
52+
client?.close();
53+
});
54+
4255
describe('flag tests', () => {
4356
it('evaluates a boolean flag with a variation call', async () => {
4457
const value = await ldClient.variation(flagKey1, context, false);

packages/sdk/fastly/__tests__/utils/validateOptions.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ describe('validateOptions', () => {
3232
).toBeTruthy();
3333
});
3434

35+
test('success with eventsUri and eventsBackendName', () => {
36+
expect(
37+
validateOptions('test-sdk-key', {
38+
featureStore: mockFeatureStore,
39+
logger: BasicLogger.get(),
40+
sendEvents: true,
41+
eventsUri: 'https://custom-events.example.com',
42+
eventsBackendName: 'custom-backend',
43+
}),
44+
).toBeTruthy();
45+
});
46+
3547
test('throws with invalid options', () => {
3648
expect(() => {
3749
validateOptions('test-sdk-key', {

packages/sdk/fastly/src/utils/validateOptions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const validators = {
2424
};
2525

2626
const validateOptions = (clientSideId: string, options: LDOptionsInternal) => {
27-
const { eventsBackendName, featureStore, logger, sendEvents, ...rest } = options;
27+
const { eventsBackendName, eventsUri, featureStore, logger, sendEvents, ...rest } = options;
2828
if (!clientSideId || !validators.clientSideId.is(clientSideId)) {
2929
throw new Error('You must configure the client with a client-side id');
3030
}
@@ -37,8 +37,9 @@ const validateOptions = (clientSideId: string, options: LDOptionsInternal) => {
3737
throw new Error('You must configure the client with a logger');
3838
}
3939

40-
if (JSON.stringify(rest) !== '{}') {
41-
throw new Error(`Invalid configuration: ${Object.keys(rest).toString()} not supported`);
40+
const unsupported = Object.keys(rest);
41+
if (unsupported.length !== 0) {
42+
throw new Error(`Invalid configuration: ${unsupported.toString()} not supported`);
4243
}
4344

4445
return true;

0 commit comments

Comments
 (0)