-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
## EppoJSClient.getAssignment() method | ||
|
||
<b>Signature:</b> | ||
**Signature:** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The latest auto-generated docs use |
||
|
||
```typescript | ||
getAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): string | null; | ||
|
@@ -16,10 +16,10 @@ getAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<st | |
| --- | --- | --- | | ||
| subjectKey | string | | | ||
| flagKey | string | | | ||
| subjectAttributes | Record<string, any> | <i>(Optional)</i> | | ||
| assignmentHooks | IAssignmentHooks | <i>(Optional)</i> | | ||
| subjectAttributes | Record<string, any> | _(Optional)_ | | ||
| assignmentHooks | IAssignmentHooks | _(Optional)_ | | ||
|
||
<b>Returns:</b> | ||
**Returns:** | ||
|
||
string \| null | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
Eppo API key | ||
|
||
<b>Signature:</b> | ||
**Signature:** | ||
|
||
```typescript | ||
apiKey: string; | ||
|
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) > [@eppo/js-client-sdk](./js-client-sdk.md) > [IClientConfig](./js-client-sdk.iclientconfig.md) > [requestTimeoutMs](./js-client-sdk.iclientconfig.requesttimeoutms.md) | ||
|
||
## IClientConfig.requestTimeoutMs property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
``` |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did a |
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": [ | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"ts-loader": "^9.3.1", | ||
"typescript": "^4.7.4", | ||
"webpack": "^5.73.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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