Skip to content

Commit 30ca269

Browse files
authored
Sticky sessions; handle getAssignment called before initialization (#4)
* Sticky sessions; handle getAssignment called before initialization * log assignment when returning session override * pass logger to getInstance method * remove usage with react section * compare to true string * pass logger to init * logger event queue * update docs * null check * use allowList when enabled is false * simplify * fix test * compare to true string
1 parent 57622df commit 30ca269

17 files changed

+411
-226
lines changed

README.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,3 @@ This SDK is for client-side JS applications that run in a web browser. For serve
88
## Getting Started
99

1010
Refer to our [SDK documentation](https://docs.geteppo.com/feature-flagging/randomization-sdk) for how to install and use the SDK.
11-
12-
## Usage with React
13-
14-
For usage in React applications, we recommend creating a [Context](https://reactjs.org/docs/context.html) provider to intialize the SDK and store the initialization status.
15-
16-
```tsx
17-
import { useEffect, useState, createContext } from 'react';
18-
import * as EppoSdk from '@eppo/js-client-sdk';
19-
20-
const EppoContext = createContext({ isInitialized: false });
21-
22-
function EppoProvider({ children }): JSX.Element {
23-
const [isInitialized, setIsInitialized] = useState(false);
24-
25-
useEffect(() => {
26-
EppoSdk.init({ apiKey: '<API-KEY>' })
27-
.then(() => setIsInitialized(true));
28-
}, []);
29-
30-
return (
31-
<EppoContext.Provider value={{ isInitialized }}>
32-
{children}
33-
</EppoContext.Provider>
34-
);
35-
}
36-
```
37-
38-
Use the context provider at the root of your component tree to wrap the rest of your application:
39-
40-
```tsx
41-
<EppoProvider>
42-
<MyApp />
43-
</EppoProvider>
44-
```
45-
46-
React components in your application should consume the context to check that the SDK has been initialized before assigning a variation. (Alternatively, you could have the `EppoProvider` wait to render its children until the SDK is initialized.)
47-
48-
```tsx
49-
import { useContext } from 'react';
50-
import * as EppoSdk from '@eppo/js-client-sdk';
51-
52-
const { isInitialized } = useContext(EppoContext);
53-
if (isInitialized) {
54-
const assignedVariation = EppoSdk.getInstance().getAssignment(subjectKey, experimentKey);
55-
...
56-
}
57-
```
58-
59-

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Pass a logging implementation to send variation assignments to your data warehou
99
<b>Signature:</b>
1010

1111
```typescript
12-
assignmentLogger?: IAssignmentLogger;
12+
assignmentLogger: IAssignmentLogger;
1313
```

docs/js-client-sdk.iclientconfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export interface IClientConfig
1717
| Property | Type | Description |
1818
| --- | --- | --- |
1919
| [apiKey](./js-client-sdk.iclientconfig.apikey.md) | string | Eppo API key |
20-
| [assignmentLogger?](./js-client-sdk.iclientconfig.assignmentlogger.md) | [IAssignmentLogger](./js-client-sdk.iassignmentlogger.md) | <i>(Optional)</i> Pass a logging implementation to send variation assignments to your data warehouse. |
20+
| [assignmentLogger](./js-client-sdk.iclientconfig.assignmentlogger.md) | [IAssignmentLogger](./js-client-sdk.iassignmentlogger.md) | Pass a logging implementation to send variation assignments to your data warehouse. |
2121
| [baseUrl?](./js-client-sdk.iclientconfig.baseurl.md) | string | <i>(Optional)</i> Base URL of the Eppo API. Clients should use the default setting in most cases. |
2222

docs/js-client-sdk.init.md

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

55
## init() function
66

7-
Initializes the Eppo client with configuration parameters. This method should be called once on application startup. After invocation of this method, the SDK will poll Eppo's API at regular intervals to retrieve assignment configurations.
7+
Initializes the Eppo client with configuration parameters. This method should be called once on application startup.
88

99
<b>Signature:</b>
1010

docs/js-client-sdk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Function | Description |
1010
| --- | --- |
1111
| [getInstance()](./js-client-sdk.getinstance.md) | Used to access a singleton SDK client instance. Use the method after calling init() to initialize the client. |
12-
| [init(config)](./js-client-sdk.init.md) | Initializes the Eppo client with configuration parameters. This method should be called once on application startup. After invocation of this method, the SDK will poll Eppo's API at regular intervals to retrieve assignment configurations. |
12+
| [init(config)](./js-client-sdk.init.md) | Initializes the Eppo client with configuration parameters. This method should be called once on application startup. |
1313

1414
## Interfaces
1515

js-client-sdk.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface IAssignmentLogger {
2525
// @public
2626
export interface IClientConfig {
2727
apiKey: string;
28-
assignmentLogger?: IAssignmentLogger;
28+
assignmentLogger: IAssignmentLogger;
2929
baseUrl?: string;
3030
}
3131

src/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
export const REQUEST_TIMEOUT_MILLIS = 5000;
22
export const BASE_URL = 'https://eppo.cloud/api';
3+
export const SESSION_ASSIGNMENT_CONFIG_LOADED = 'eppo-session-assignment-config-loaded';
4+
export const NULL_SENTINEL = 'EPPO_NULL';
5+
// number of logging events that may be queued while waiting for initialization
6+
export const MAX_EVENT_QUEUE_SIZE = 100;

0 commit comments

Comments
 (0)