Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional request timeout #41

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .husky/pre-commit
100644 → 100755
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to be executable so it can run as a commit hook

Empty file.
8 changes: 4 additions & 4 deletions docs/js-client-sdk.eppojsclient.getassignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EppoJSClient.getAssignment() method

<b>Signature:</b>
**Signature:**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest auto-generated docs use ** for bolding and _ for italic. (which I prefer in GitHub markdown anyways 📈 )


```typescript
getAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): string | null;
Expand All @@ -16,10 +16,10 @@ getAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<st
| --- | --- | --- |
| subjectKey | string | |
| flagKey | string | |
| subjectAttributes | Record&lt;string, any&gt; | <i>(Optional)</i> |
| assignmentHooks | IAssignmentHooks | <i>(Optional)</i> |
| subjectAttributes | Record&lt;string, any&gt; | _(Optional)_ |
| assignmentHooks | IAssignmentHooks | _(Optional)_ |

<b>Returns:</b>
**Returns:**

string \| null

8 changes: 4 additions & 4 deletions docs/js-client-sdk.eppojsclient.getboolassignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EppoJSClient.getBoolAssignment() method

<b>Signature:</b>
**Signature:**

```typescript
getBoolAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): boolean | null;
Expand All @@ -16,10 +16,10 @@ getBoolAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Recor
| --- | --- | --- |
| subjectKey | string | |
| flagKey | string | |
| subjectAttributes | Record&lt;string, any&gt; | <i>(Optional)</i> |
| assignmentHooks | IAssignmentHooks | <i>(Optional)</i> |
| subjectAttributes | Record&lt;string, any&gt; | _(Optional)_ |
| assignmentHooks | IAssignmentHooks | _(Optional)_ |

<b>Returns:</b>
**Returns:**

boolean \| null

8 changes: 4 additions & 4 deletions docs/js-client-sdk.eppojsclient.getjsonstringassignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EppoJSClient.getJSONStringAssignment() method

<b>Signature:</b>
**Signature:**

```typescript
getJSONStringAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): string | null;
Expand All @@ -16,10 +16,10 @@ getJSONStringAssignment(subjectKey: string, flagKey: string, subjectAttributes?:
| --- | --- | --- |
| subjectKey | string | |
| flagKey | string | |
| subjectAttributes | Record&lt;string, any&gt; | <i>(Optional)</i> |
| assignmentHooks | IAssignmentHooks | <i>(Optional)</i> |
| subjectAttributes | Record&lt;string, any&gt; | _(Optional)_ |
| assignmentHooks | IAssignmentHooks | _(Optional)_ |

<b>Returns:</b>
**Returns:**

string \| null

8 changes: 4 additions & 4 deletions docs/js-client-sdk.eppojsclient.getnumericassignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EppoJSClient.getNumericAssignment() method

<b>Signature:</b>
**Signature:**

```typescript
getNumericAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): number | null;
Expand All @@ -16,10 +16,10 @@ getNumericAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Re
| --- | --- | --- |
| subjectKey | string | |
| flagKey | string | |
| subjectAttributes | Record&lt;string, any&gt; | <i>(Optional)</i> |
| assignmentHooks | IAssignmentHooks | <i>(Optional)</i> |
| subjectAttributes | Record&lt;string, any&gt; | _(Optional)_ |
| assignmentHooks | IAssignmentHooks | _(Optional)_ |

<b>Returns:</b>
**Returns:**

number \| null

8 changes: 4 additions & 4 deletions docs/js-client-sdk.eppojsclient.getparsedjsonassignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EppoJSClient.getParsedJSONAssignment() method

<b>Signature:</b>
**Signature:**

```typescript
getParsedJSONAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): object | null;
Expand All @@ -16,10 +16,10 @@ getParsedJSONAssignment(subjectKey: string, flagKey: string, subjectAttributes?:
| --- | --- | --- |
| subjectKey | string | |
| flagKey | string | |
| subjectAttributes | Record&lt;string, any&gt; | <i>(Optional)</i> |
| assignmentHooks | IAssignmentHooks | <i>(Optional)</i> |
| subjectAttributes | Record&lt;string, any&gt; | _(Optional)_ |
| assignmentHooks | IAssignmentHooks | _(Optional)_ |

<b>Returns:</b>
**Returns:**

object \| null

8 changes: 4 additions & 4 deletions docs/js-client-sdk.eppojsclient.getstringassignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EppoJSClient.getStringAssignment() method

<b>Signature:</b>
**Signature:**

```typescript
getStringAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): string | null;
Expand All @@ -16,10 +16,10 @@ getStringAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Rec
| --- | --- | --- |
| subjectKey | string | |
| flagKey | string | |
| subjectAttributes | Record&lt;string, any&gt; | <i>(Optional)</i> |
| assignmentHooks | IAssignmentHooks | <i>(Optional)</i> |
| subjectAttributes | Record&lt;string, any&gt; | _(Optional)_ |
| assignmentHooks | IAssignmentHooks | _(Optional)_ |

<b>Returns:</b>
**Returns:**

string \| null

2 changes: 1 addition & 1 deletion docs/js-client-sdk.eppojsclient.instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EppoJSClient.instance property

<b>Signature:</b>
**Signature:**

```typescript
static instance: EppoJSClient;
Expand Down
4 changes: 2 additions & 2 deletions docs/js-client-sdk.eppojsclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

Client for assigning experiment variations.

<b>Signature:</b>
**Signature:**

```typescript
export declare class EppoJSClient extends EppoClient
```
<b>Extends:</b> EppoClient
**Extends:** EppoClient

## Properties

Expand Down
4 changes: 2 additions & 2 deletions docs/js-client-sdk.getinstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

Used to access a singleton SDK client instance. Use the method after calling init() to initialize the client.

<b>Signature:</b>
**Signature:**

```typescript
export declare function getInstance(): IEppoClient;
```
<b>Returns:</b>
**Returns:**

IEppoClient

Expand Down
2 changes: 1 addition & 1 deletion docs/js-client-sdk.iclientconfig.apikey.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Eppo API key

<b>Signature:</b>
**Signature:**

```typescript
apiKey: string;
Expand Down
2 changes: 1 addition & 1 deletion docs/js-client-sdk.iclientconfig.assignmentlogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Pass a logging implementation to send variation assignments to your data warehouse.

<b>Signature:</b>
**Signature:**

```typescript
assignmentLogger: IAssignmentLogger;
Expand Down
2 changes: 1 addition & 1 deletion docs/js-client-sdk.iclientconfig.baseurl.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Base URL of the Eppo API. Clients should use the default setting in most cases.

<b>Signature:</b>
**Signature:**

```typescript
baseUrl?: string;
Expand Down
13 changes: 7 additions & 6 deletions docs/js-client-sdk.iclientconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

Configuration used for initializing the Eppo client

<b>Signature:</b>
**Signature:**

```typescript
export interface IClientConfig
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [apiKey](./js-client-sdk.iclientconfig.apikey.md) | string | Eppo API key |
| [assignmentLogger](./js-client-sdk.iclientconfig.assignmentlogger.md) | IAssignmentLogger | Pass a logging implementation to send variation assignments to your data warehouse. |
| [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. |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [apiKey](./js-client-sdk.iclientconfig.apikey.md) | | string | Eppo API key |
| [assignmentLogger](./js-client-sdk.iclientconfig.assignmentlogger.md) | | IAssignmentLogger | Pass a logging implementation to send variation assignments to your data warehouse. |
| [baseUrl?](./js-client-sdk.iclientconfig.baseurl.md) | | string | _(Optional)_ Base URL of the Eppo API. Clients should use the default setting in most cases. |
| [requestTimeoutMs?](./js-client-sdk.iclientconfig.requesttimeoutms.md) | | number | _(Optional)_ \* Timeout in milliseconds for the HTTPS request for the experiment configuration. (Default: 5000) |

13 changes: 13 additions & 0 deletions docs/js-client-sdk.iclientconfig.requesttimeoutms.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; [requestTimeoutMs](./js-client-sdk.iclientconfig.requesttimeoutms.md)

## IClientConfig.requestTimeoutMs property
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated docs for newly added client configuration


\* Timeout in milliseconds for the HTTPS request for the experiment configuration. (Default: 5000)

**Signature:**

```typescript
requestTimeoutMs?: number;
```
4 changes: 2 additions & 2 deletions docs/js-client-sdk.init.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Initializes the Eppo client with configuration parameters. This method should be called once on application startup.

<b>Signature:</b>
**Signature:**

```typescript
export declare function init(config: IClientConfig): Promise<IEppoClient>;
Expand All @@ -18,7 +18,7 @@ export declare function init(config: IClientConfig): Promise<IEppoClient>;
| --- | --- | --- |
| config | [IClientConfig](./js-client-sdk.iclientconfig.md) | client configuration |

<b>Returns:</b>
**Returns:**

Promise&lt;IEppoClient&gt;

1 change: 1 addition & 0 deletions js-client-sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface IClientConfig {
apiKey: string;
assignmentLogger: IAssignmentLogger;
baseUrl?: string;
requestTimeoutMs?: number;
}

export { IEppoClient }
Expand Down
4 changes: 2 additions & 2 deletions package.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a yarn install using node 16.20, as that is the min version in our common client (source)

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/js-client-sdk",
"version": "1.4.0",
"version": "1.4.1",
"description": "Eppo SDK for client-side JavaScript applications",
"main": "dist/index.js",
"files": [
Expand Down Expand Up @@ -49,7 +49,7 @@
"prettier": "^2.7.1",
"terser-webpack-plugin": "^5.3.3",
"testdouble": "^3.16.6",
"ts-jest": "^28.0.5",
"ts-jest": "^29.1.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm was not happy installing an older version of ts-jest with a newer version of jest. Bumping appeased it.

"ts-loader": "^9.3.1",
"typescript": "^4.7.4",
"webpack": "^5.73.0",
Expand Down
46 changes: 29 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface IClientConfig {
* Pass a logging implementation to send variation assignments to your data warehouse.
*/
assignmentLogger: IAssignmentLogger;

/***
* Timeout in milliseconds for the HTTPS request for the experiment configuration. (Default: 5000)
*/
requestTimeoutMs?: number;
}

export { IAssignmentLogger, IAssignmentEvent, IEppoClient } from '@eppo/js-client-sdk-common';
Expand Down Expand Up @@ -133,23 +138,30 @@ export class EppoJSClient extends EppoClient {
*/
export async function init(config: IClientConfig): Promise<IEppoClient> {
validation.validateNotBlank(config.apiKey, 'API key required');
const axiosInstance = axios.create({
baseURL: config.baseUrl || constants.BASE_URL,
timeout: constants.REQUEST_TIMEOUT_MILLIS,
});
const httpClient = new HttpClient(axiosInstance, {
apiKey: config.apiKey,
sdkName,
sdkVersion,
});
EppoJSClient.instance.setLogger(config.assignmentLogger);

// default behavior is to use a non-expiring cache.
// this can be overridden after initialization.
EppoJSClient.instance.useNonExpiringAssignmentCache();

const configurationRequestor = new ExperimentConfigurationRequestor(localStorage, httpClient);
await configurationRequestor.fetchAndStoreConfigurations();
try {
const axiosInstance = axios.create({
baseURL: config.baseUrl || constants.BASE_URL,
timeout: config.requestTimeoutMs || constants.REQUEST_TIMEOUT_MILLIS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

});
const httpClient = new HttpClient(axiosInstance, {
apiKey: config.apiKey,
sdkName,
sdkVersion,
});
EppoJSClient.instance.setLogger(config.assignmentLogger);

// default behavior is to use a non-expiring cache.
// this can be overridden after initialization.
EppoJSClient.instance.useNonExpiringAssignmentCache();

const configurationRequestor = new ExperimentConfigurationRequestor(localStorage, httpClient);
await configurationRequestor.fetchAndStoreConfigurations();
} catch (error) {
console.warn(
'Error encountered initializing Eppo SDK, assignment calls will return null and not be logged',
);
throw error;
}
return EppoJSClient.instance;
}

Expand Down
Loading
Loading