Skip to content

Commit 53cc624

Browse files
authored
feat: Update to latest common, add polling interval parameter (#100)
* plumb polling interval through
1 parent 2700b04 commit 53cc624

10 files changed

+65
-16
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@eppo/js-client-sdk](./js-client-sdk.md) &gt; [EppoJSClient](./js-client-sdk.eppojsclient.md) &gt; [getExperimentContainerEntry](./js-client-sdk.eppojsclient.getexperimentcontainerentry.md)
4+
5+
## EppoJSClient.getExperimentContainerEntry() method
6+
7+
**Signature:**
8+
9+
```typescript
10+
getExperimentContainerEntry<T>(flagExperiment: IContainerExperiment<T>, subjectKey: string, subjectAttributes: Record<string, AttributeType>): T;
11+
```
12+
13+
## Parameters
14+
15+
| Parameter | Type | Description |
16+
| --- | --- | --- |
17+
| flagExperiment | IContainerExperiment&lt;T&gt; | |
18+
| subjectKey | string | |
19+
| subjectAttributes | Record&lt;string, AttributeType&gt; | |
20+
21+
**Returns:**
22+
23+
T
24+

docs/js-client-sdk.eppojsclient.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export declare class EppoJSClient extends EppoClient
2929
| [getBoolAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getboolassignment.md) | | |
3030
| [getBooleanAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getbooleanassignment.md) | | |
3131
| [getBooleanAssignmentDetails(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getbooleanassignmentdetails.md) | | |
32+
| [getExperimentContainerEntry(flagExperiment, subjectKey, subjectAttributes)](./js-client-sdk.eppojsclient.getexperimentcontainerentry.md) | | |
3233
| [getIntegerAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getintegerassignment.md) | | |
3334
| [getIntegerAssignmentDetails(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getintegerassignmentdetails.md) | | |
3435
| [getJSONAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getjsonassignment.md) | | |

docs/js-client-sdk.iclientconfig.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export interface IClientConfig
2525
| [numPollRequestRetries?](./js-client-sdk.iclientconfig.numpollrequestretries.md) | | number | _(Optional)_ Number of additional times polling for updated configurations will be attempted before giving up. Polling is done after a successful initial request. Subsequent attempts are done using an exponential backoff. (Default: 7) |
2626
| [persistentStore?](./js-client-sdk.iclientconfig.persistentstore.md) | | IAsyncStore&lt;Flag&gt; | _(Optional)_ A custom class to use for storing flag configurations. This is useful for cases where you want to use a different storage mechanism than the default storage provided by the SDK. |
2727
| [pollAfterFailedInitialization?](./js-client-sdk.iclientconfig.pollafterfailedinitialization.md) | | boolean | _(Optional)_ Poll for new configurations even if the initial configuration request failed. (default: false) |
28-
| [pollAfterSuccessfulInitialization?](./js-client-sdk.iclientconfig.pollaftersuccessfulinitialization.md) | | boolean | _(Optional)_ Poll for new configurations (every 30 seconds) after successfully requesting the initial configuration. (default: false) |
28+
| [pollAfterSuccessfulInitialization?](./js-client-sdk.iclientconfig.pollaftersuccessfulinitialization.md) | | boolean | _(Optional)_ Poll for new configurations (every <code>pollingIntervalMs</code>) after successfully requesting the initial configuration. (default: false) |
29+
| [pollingIntervalMs?](./js-client-sdk.iclientconfig.pollingintervalms.md) | | number | _(Optional)_ Amount of time to wait between API calls to refresh configuration data. Default of 30\_000 (30 seconds). |
2930
| [requestTimeoutMs?](./js-client-sdk.iclientconfig.requesttimeoutms.md) | | number | _(Optional)_ \* Timeout in milliseconds for the HTTPS request for the experiment configuration. (Default: 5000) |
3031
| [skipInitialRequest?](./js-client-sdk.iclientconfig.skipinitialrequest.md) | | boolean | _(Optional)_ Skip the request for new configurations during initialization. (default: false) |
3132
| [throwOnFailedInitialization?](./js-client-sdk.iclientconfig.throwonfailedinitialization.md) | | boolean | _(Optional)_ Throw an error if unable to fetch an initial configuration during initialization. (default: true) |

docs/js-client-sdk.iclientconfig.pollaftersuccessfulinitialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## IClientConfig.pollAfterSuccessfulInitialization property
66

7-
Poll for new configurations (every 30 seconds) after successfully requesting the initial configuration. (default: false)
7+
Poll for new configurations (every `pollingIntervalMs`<!-- -->) after successfully requesting the initial configuration. (default: false)
88

99
**Signature:**
1010

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@eppo/js-client-sdk](./js-client-sdk.md) &gt; [IClientConfig](./js-client-sdk.iclientconfig.md) &gt; [pollingIntervalMs](./js-client-sdk.iclientconfig.pollingintervalms.md)
4+
5+
## IClientConfig.pollingIntervalMs property
6+
7+
Amount of time to wait between API calls to refresh configuration data. Default of 30\_000 (30 seconds).
8+
9+
**Signature:**
10+
11+
```typescript
12+
pollingIntervalMs?: number;
13+
```

js-client-sdk.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { IAssignmentDetails } from '@eppo/js-client-sdk-common';
1616
import { IAssignmentEvent } from '@eppo/js-client-sdk-common';
1717
import { IAssignmentLogger } from '@eppo/js-client-sdk-common';
1818
import { IAsyncStore } from '@eppo/js-client-sdk-common';
19+
import { IContainerExperiment } from '@eppo/js-client-sdk-common';
1920
import { ObfuscatedFlag } from '@eppo/js-client-sdk-common';
2021

2122
// @public (undocumented)
@@ -50,6 +51,8 @@ export class EppoJSClient extends EppoClient {
5051
// (undocumented)
5152
getBooleanAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: boolean): IAssignmentDetails<boolean>;
5253
// (undocumented)
54+
getExperimentContainerEntry<T>(flagExperiment: IContainerExperiment<T>, subjectKey: string, subjectAttributes: Record<string, AttributeType>): T;
55+
// (undocumented)
5356
getIntegerAssignment(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: number): number;
5457
// (undocumented)
5558
getIntegerAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: number): IAssignmentDetails<number>;
@@ -99,6 +102,7 @@ export interface IClientConfig {
99102
persistentStore?: IAsyncStore<Flag>;
100103
pollAfterFailedInitialization?: boolean;
101104
pollAfterSuccessfulInitialization?: boolean;
105+
pollingIntervalMs?: number;
102106
requestTimeoutMs?: number;
103107
skipInitialRequest?: boolean;
104108
throwOnFailedInitialization?: boolean;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk",
3-
"version": "3.6.0",
3+
"version": "3.7.0",
44
"description": "Eppo SDK for client-side JavaScript applications",
55
"main": "dist/index.js",
66
"files": [
@@ -59,6 +59,6 @@
5959
"webpack-cli": "^4.10.0"
6060
},
6161
"dependencies": {
62-
"@eppo/js-client-sdk-common": "4.2.0"
62+
"@eppo/js-client-sdk-common": "4.3.0"
6363
}
6464
}

src/index.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '@eppo/js-client-sdk-common';
1616
import * as td from 'testdouble';
1717

18-
const { POLL_INTERVAL_MS, POLL_JITTER_PCT } = constants;
18+
const { DEFAULT_POLL_INTERVAL_MS, POLL_JITTER_PCT } = constants;
1919

2020
import {
2121
IAssignmentTestCase,
@@ -406,7 +406,7 @@ describe('initialization options', () => {
406406
let mockLogger: IAssignmentLogger;
407407
let returnUfc = readMockUfcResponse; // function so it can be overridden per-test
408408

409-
const maxRetryDelay = POLL_INTERVAL_MS * POLL_JITTER_PCT;
409+
const maxRetryDelay = DEFAULT_POLL_INTERVAL_MS * POLL_JITTER_PCT;
410410
const mockConfigResponse = {
411411
flags: {
412412
[obfuscatedFlagKey]: mockObfuscatedUfcFlagConfig,
@@ -492,7 +492,7 @@ describe('initialization options', () => {
492492
expect(client.getStringAssignment(flagKey, 'subject', {}, 'default-value')).toBe('control');
493493

494494
// By default, no more calls
495-
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS * 10);
495+
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS * 10);
496496
expect(callCount).toBe(2);
497497
});
498498

@@ -577,7 +577,7 @@ describe('initialization options', () => {
577577
await jest.advanceTimersByTimeAsync(maxRetryDelay);
578578

579579
// Should be polling
580-
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS * 10);
580+
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS * 10);
581581
expect(callCount).toBe(11);
582582
});
583583

@@ -609,7 +609,7 @@ describe('initialization options', () => {
609609
);
610610

611611
// Expect no further configuration requests
612-
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS);
612+
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS);
613613
expect(callCount).toBe(1);
614614
});
615615

@@ -649,7 +649,7 @@ describe('initialization options', () => {
649649
'default-value',
650650
);
651651

652-
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS);
652+
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS);
653653

654654
// Expect a new call from poller
655655
expect(callCount).toBe(3);
@@ -1025,7 +1025,7 @@ describe('initialization options', () => {
10251025
'default-value',
10261026
);
10271027
// Advance time so a poll happened and check again
1028-
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS);
1028+
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS);
10291029
expect(getInstance().getStringAssignment(flagKey, 'subject', {}, 'default-value')).toBe(
10301030
'control',
10311031
);

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ export interface IClientConfig {
7171
pollAfterFailedInitialization?: boolean;
7272

7373
/**
74-
* Poll for new configurations (every 30 seconds) after successfully requesting the initial configuration. (default: false)
74+
* Poll for new configurations (every `pollingIntervalMs`) after successfully requesting the initial configuration. (default: false)
7575
*/
7676
pollAfterSuccessfulInitialization?: boolean;
7777

78+
/**
79+
* Amount of time to wait between API calls to refresh configuration data. Default of 30_000 (30 seconds).
80+
*/
81+
pollingIntervalMs?: number;
82+
7883
/**
7984
* Number of additional times polling for updated configurations will be attempted before giving up.
8085
* Polling is done after a successful initial request. Subsequent attempts are done using an exponential
@@ -461,6 +466,7 @@ export async function init(config: IClientConfig): Promise<EppoClient> {
461466
numPollRequestRetries: config.numPollRequestRetries ?? undefined,
462467
pollAfterSuccessfulInitialization: config.pollAfterSuccessfulInitialization ?? false,
463468
pollAfterFailedInitialization: config.pollAfterFailedInitialization ?? false,
469+
pollingIntervalMs: config.pollingIntervalMs ?? undefined,
464470
throwOnFailedInitialization: true, // always use true here as underlying instance fetch is surrounded by try/catch
465471
skipInitialPoll: config.skipInitialRequest ?? false,
466472
};

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@
380380
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
381381
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==
382382

383-
"@eppo/js-client-sdk-common@4.2.0":
384-
version "4.2.0"
385-
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-4.2.0.tgz#713910bf7c5291300d48b408bced995ae00e2834"
386-
integrity sha512-DzT3q1jwpb8yEgKLtPzCxaW6X+rUmYuX5jnGqPzLM2WDlfZ0rkUdDqBt9lzw76DkSZu+C7dpzHcH9EnWuDms8w==
383+
"@eppo/js-client-sdk-common@4.3.0":
384+
version "4.3.0"
385+
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-4.3.0.tgz#66c0e5904091ac1a9c2bc3bf4017637b13404ce8"
386+
integrity sha512-ur270vCZjUuKuEohF1vH7yh1MBxtDbVcduCJzJmJ6m7kjoyvqNPzG/+lYPEol6Bpr9wV42ciIB+A1cYeNZ7gSA==
387387
dependencies:
388388
js-base64 "^3.7.7"
389389
md5 "^2.3.0"

0 commit comments

Comments
 (0)