Skip to content

Commit

Permalink
feat: Update to latest common, add polling interval parameter (#100)
Browse files Browse the repository at this point in the history
* plumb polling interval through
  • Loading branch information
typotter authored Nov 7, 2024
1 parent 2700b04 commit 53cc624
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 16 deletions.
24 changes: 24 additions & 0 deletions docs/js-client-sdk.eppojsclient.getexperimentcontainerentry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[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)

## EppoJSClient.getExperimentContainerEntry() method

**Signature:**

```typescript
getExperimentContainerEntry<T>(flagExperiment: IContainerExperiment<T>, subjectKey: string, subjectAttributes: Record<string, AttributeType>): T;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| flagExperiment | IContainerExperiment&lt;T&gt; | |
| subjectKey | string | |
| subjectAttributes | Record&lt;string, AttributeType&gt; | |

**Returns:**

T

1 change: 1 addition & 0 deletions docs/js-client-sdk.eppojsclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export declare class EppoJSClient extends EppoClient
| [getBoolAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getboolassignment.md) | | |
| [getBooleanAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getbooleanassignment.md) | | |
| [getBooleanAssignmentDetails(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getbooleanassignmentdetails.md) | | |
| [getExperimentContainerEntry(flagExperiment, subjectKey, subjectAttributes)](./js-client-sdk.eppojsclient.getexperimentcontainerentry.md) | | |
| [getIntegerAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getintegerassignment.md) | | |
| [getIntegerAssignmentDetails(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getintegerassignmentdetails.md) | | |
| [getJSONAssignment(flagKey, subjectKey, subjectAttributes, defaultValue)](./js-client-sdk.eppojsclient.getjsonassignment.md) | | |
Expand Down
3 changes: 2 additions & 1 deletion docs/js-client-sdk.iclientconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export interface IClientConfig
| [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) |
| [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. |
| [pollAfterFailedInitialization?](./js-client-sdk.iclientconfig.pollafterfailedinitialization.md) | | boolean | _(Optional)_ Poll for new configurations even if the initial configuration request failed. (default: false) |
| [pollAfterSuccessfulInitialization?](./js-client-sdk.iclientconfig.pollaftersuccessfulinitialization.md) | | boolean | _(Optional)_ Poll for new configurations (every 30 seconds) after successfully requesting the initial configuration. (default: false) |
| [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) |
| [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). |
| [requestTimeoutMs?](./js-client-sdk.iclientconfig.requesttimeoutms.md) | | number | _(Optional)_ \* Timeout in milliseconds for the HTTPS request for the experiment configuration. (Default: 5000) |
| [skipInitialRequest?](./js-client-sdk.iclientconfig.skipinitialrequest.md) | | boolean | _(Optional)_ Skip the request for new configurations during initialization. (default: false) |
| [throwOnFailedInitialization?](./js-client-sdk.iclientconfig.throwonfailedinitialization.md) | | boolean | _(Optional)_ Throw an error if unable to fetch an initial configuration during initialization. (default: true) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## IClientConfig.pollAfterSuccessfulInitialization property

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

**Signature:**

Expand Down
13 changes: 13 additions & 0 deletions docs/js-client-sdk.iclientconfig.pollingintervalms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[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)

## IClientConfig.pollingIntervalMs property

Amount of time to wait between API calls to refresh configuration data. Default of 30\_000 (30 seconds).

**Signature:**

```typescript
pollingIntervalMs?: number;
```
4 changes: 4 additions & 0 deletions js-client-sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IAssignmentDetails } from '@eppo/js-client-sdk-common';
import { IAssignmentEvent } from '@eppo/js-client-sdk-common';
import { IAssignmentLogger } from '@eppo/js-client-sdk-common';
import { IAsyncStore } from '@eppo/js-client-sdk-common';
import { IContainerExperiment } from '@eppo/js-client-sdk-common';
import { ObfuscatedFlag } from '@eppo/js-client-sdk-common';

// @public (undocumented)
Expand Down Expand Up @@ -50,6 +51,8 @@ export class EppoJSClient extends EppoClient {
// (undocumented)
getBooleanAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: boolean): IAssignmentDetails<boolean>;
// (undocumented)
getExperimentContainerEntry<T>(flagExperiment: IContainerExperiment<T>, subjectKey: string, subjectAttributes: Record<string, AttributeType>): T;
// (undocumented)
getIntegerAssignment(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: number): number;
// (undocumented)
getIntegerAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: number): IAssignmentDetails<number>;
Expand Down Expand Up @@ -99,6 +102,7 @@ export interface IClientConfig {
persistentStore?: IAsyncStore<Flag>;
pollAfterFailedInitialization?: boolean;
pollAfterSuccessfulInitialization?: boolean;
pollingIntervalMs?: number;
requestTimeoutMs?: number;
skipInitialRequest?: boolean;
throwOnFailedInitialization?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/js-client-sdk",
"version": "3.6.0",
"version": "3.7.0",
"description": "Eppo SDK for client-side JavaScript applications",
"main": "dist/index.js",
"files": [
Expand Down Expand Up @@ -59,6 +59,6 @@
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@eppo/js-client-sdk-common": "4.2.0"
"@eppo/js-client-sdk-common": "4.3.0"
}
}
14 changes: 7 additions & 7 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@eppo/js-client-sdk-common';
import * as td from 'testdouble';

const { POLL_INTERVAL_MS, POLL_JITTER_PCT } = constants;
const { DEFAULT_POLL_INTERVAL_MS, POLL_JITTER_PCT } = constants;

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

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

// By default, no more calls
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS * 10);
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS * 10);
expect(callCount).toBe(2);
});

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

// Should be polling
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS * 10);
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS * 10);
expect(callCount).toBe(11);
});

Expand Down Expand Up @@ -609,7 +609,7 @@ describe('initialization options', () => {
);

// Expect no further configuration requests
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS);
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS);
expect(callCount).toBe(1);
});

Expand Down Expand Up @@ -649,7 +649,7 @@ describe('initialization options', () => {
'default-value',
);

await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS);
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS);

// Expect a new call from poller
expect(callCount).toBe(3);
Expand Down Expand Up @@ -1025,7 +1025,7 @@ describe('initialization options', () => {
'default-value',
);
// Advance time so a poll happened and check again
await jest.advanceTimersByTimeAsync(POLL_INTERVAL_MS);
await jest.advanceTimersByTimeAsync(DEFAULT_POLL_INTERVAL_MS);
expect(getInstance().getStringAssignment(flagKey, 'subject', {}, 'default-value')).toBe(
'control',
);
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ export interface IClientConfig {
pollAfterFailedInitialization?: boolean;

/**
* Poll for new configurations (every 30 seconds) after successfully requesting the initial configuration. (default: false)
* Poll for new configurations (every `pollingIntervalMs`) after successfully requesting the initial configuration. (default: false)
*/
pollAfterSuccessfulInitialization?: boolean;

/**
* Amount of time to wait between API calls to refresh configuration data. Default of 30_000 (30 seconds).
*/
pollingIntervalMs?: number;

/**
* 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
Expand Down Expand Up @@ -461,6 +466,7 @@ export async function init(config: IClientConfig): Promise<EppoClient> {
numPollRequestRetries: config.numPollRequestRetries ?? undefined,
pollAfterSuccessfulInitialization: config.pollAfterSuccessfulInitialization ?? false,
pollAfterFailedInitialization: config.pollAfterFailedInitialization ?? false,
pollingIntervalMs: config.pollingIntervalMs ?? undefined,
throwOnFailedInitialization: true, // always use true here as underlying instance fetch is surrounded by try/catch
skipInitialPoll: config.skipInitialRequest ?? false,
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

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

0 comments on commit 53cc624

Please sign in to comment.