Skip to content

Commit e2af172

Browse files
authored
[FFL-648] allowed pollAfterSuccessfulInitialization to be configurable (#111)
* feat: make pollAfterSuccessfulInitialization configurable * test: add tests for pollAfterSuccessfulInitialization config * chore: bump minor version
1 parent e41476f commit e2af172

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/node-server-sdk",
3-
"version": "3.11.0",
3+
"version": "3.12.0",
44
"description": "Eppo node server SDK",
55
"main": "dist/index.js",
66
"files": [

src/i-client-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export interface IClientConfig {
4343
/** Poll for new configurations even if the initial configuration request failed. (default: false) */
4444
pollAfterFailedInitialization?: boolean;
4545

46+
/**
47+
* Poll for new configurations (every `pollingIntervalMs`) after successfully requesting the initial configuration. (default: true)
48+
* For server-side applications, this defaults to true to ensure configurations stay up-to-date for the life of the process.
49+
*/
50+
pollAfterSuccessfulInitialization?: boolean;
51+
4652
/** Amount of time in milliseconds to wait between API calls to refresh configuration data. Default of 30_000 (30s). */
4753
pollingIntervalMs?: number;
4854

src/index.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,4 +708,31 @@ describe('EppoClient E2E test', () => {
708708
});
709709
});
710710
});
711+
712+
describe('pollAfterSuccessfulInitialization', () => {
713+
it('should default to true when not specified', async () => {
714+
const client = await init({
715+
apiKey,
716+
baseUrl: `http://127.0.0.1:${TEST_SERVER_PORT}`,
717+
assignmentLogger: mockLogger,
718+
});
719+
720+
// Access the internal configurationRequestParameters to verify the default
721+
const configurationRequestParameters = client['configurationRequestParameters'];
722+
expect(configurationRequestParameters.pollAfterSuccessfulInitialization).toBe(true);
723+
});
724+
725+
it('should use the provided value when specified', async () => {
726+
const client = await init({
727+
apiKey,
728+
baseUrl: `http://127.0.0.1:${TEST_SERVER_PORT}`,
729+
assignmentLogger: mockLogger,
730+
pollAfterSuccessfulInitialization: false,
731+
});
732+
733+
// Access the internal configurationRequestParameters to verify the custom value
734+
const configurationRequestParameters = client['configurationRequestParameters'];
735+
expect(configurationRequestParameters.pollAfterSuccessfulInitialization).toBe(false);
736+
});
737+
});
711738
});

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export async function init(config: IClientConfig): Promise<EppoClient> {
7979
requestTimeoutMs,
8080
numInitialRequestRetries,
8181
numPollRequestRetries,
82-
// For server-side, we always want to keep polling for the life of the process
83-
pollAfterSuccessfulInitialization: true,
82+
// For server-side, we default to keep polling for the life of the process
83+
pollAfterSuccessfulInitialization: config.pollAfterSuccessfulInitialization ?? true,
8484
pollAfterFailedInitialization,
8585
pollingIntervalMs,
8686
throwOnFailedInitialization,

0 commit comments

Comments
 (0)