ld-react-components
Advanced tools
Comparing version 1.0.50 to 1.0.51
@@ -0,1 +1,13 @@ | ||
# v1.0.51 (Thu Oct 24 2019) | ||
#### 🐛 Bug Fix | ||
- Refactor for TypeScript: LaunchDarklyClient [#54](https://github.com/intuit/LD-React-Components/pull/54) ([@Kausam](https://github.com/Kausam)) | ||
#### Authors: 1 | ||
- [@Kausam](https://github.com/Kausam) | ||
--- | ||
# v1.0.50 (Fri Oct 18 2019) | ||
@@ -2,0 +14,0 @@ |
import hash from 'hash.js'; | ||
import * as LDClient from 'ldclient-js'; | ||
interface IUser extends LDClient.LDUser { | ||
authId: string | ||
} | ||
interface IOptions extends LDClient.LDOptions { | ||
baseTimeout: number | ||
} | ||
interface IClientParams { | ||
user: IUser | ||
envClientKey: string | ||
options: IOptions | ||
} | ||
interface IInitParams { | ||
clientParams: IClientParams | ||
timeout: number | ||
logUpdates?: boolean | ||
} | ||
class LDApi { | ||
@@ -9,9 +27,9 @@ | ||
constructor(env) { | ||
constructor(env: string) { | ||
this.env = env; | ||
} | ||
init(user, envClientKey, options, timeout, logUpdates = false) { | ||
init({clientParams:{user, envClientKey, options}, timeout, logUpdates=false}: IInitParams) { | ||
// makes the flags available to the client | ||
this.ldClient = this.createClient(user, envClientKey, options); | ||
this.ldClient = this.createClient({user, envClientKey, options}); | ||
if (!options) { | ||
@@ -31,7 +49,7 @@ // eslint-disable-next-line no-console | ||
*/ | ||
initWithPromise(user, envClientKey, options, timeout, logUpdates = false) { | ||
this.ldClient = this.createClient(user, envClientKey, options); | ||
initWithPromise({clientParams:{user, envClientKey, options}, timeout, logUpdates=false}: IInitParams): Promise<unknown> { | ||
this.ldClient = this.createClient({user, envClientKey, options}); | ||
return new Promise((resolve, reject) => { | ||
return this.handleEvents(timeout, this.ldClient, logUpdates, resolve, reject); | ||
return this.handleEvents(timeout, this.ldClient, logUpdates, resolve, reject); | ||
}); | ||
@@ -45,5 +63,5 @@ } | ||
* @param envClientKey SDK key for the env | ||
* @returns {*} | ||
* @returns {LDClient.LDClient} fresh instance of launch darkly client | ||
*/ | ||
createClient(user, envClientKey, options) { | ||
createClient({user, envClientKey, options}: IClientParams): LDClient.LDClient { | ||
if (typeof user.authId === 'undefined') { | ||
@@ -103,3 +121,3 @@ throw new Error('AuthId was not passed to launchDarkly client'); | ||
// eslint-disable-next-line no-unused-vars | ||
handleEvents(timeout, ldClient, logUpdates = false, resolve?, reject?) { | ||
handleEvents(timeout:number, ldClient:LDClient.LDClient, logUpdates = false, resolve?, reject?) { | ||
if (ldClient === undefined) { | ||
@@ -146,5 +164,5 @@ const error = new Error('ERROR: ldClient is undefined'); | ||
* @param defaultValue boolean value that is the default (this is used we can get the feature flag from LD) | ||
* @returns {object} Value of feature flag. Flags can be boolean or enums, depending on their configuration | ||
* @returns {any} Value of feature flag. Flags can be boolean or enums, depending on their configuration | ||
*/ | ||
getFeatureFlag(featureId, defaultValue) { | ||
getFeatureFlag(featureId: string, defaultValue: boolean) { | ||
if (defaultValue === undefined) { | ||
@@ -170,6 +188,6 @@ throw new Error('Default value must be passed to getPromiseFeatureFlag'); | ||
* @param defaultValue boolean value (this is used we can get the feature flag from LD) | ||
* @returns {object} Value of feature flag as a promise. | ||
* @returns {Promise<unknown>} Value of feature flag as a promise. | ||
* Flags can be boolean or enums, depending on their configuration | ||
*/ | ||
getPromiseFeatureFlag(featureFlag, defaultValue) { | ||
getPromiseFeatureFlag(featureFlag: string, defaultValue: boolean): Promise<unknown> { | ||
return new Promise(resolve => { | ||
@@ -184,6 +202,6 @@ resolve(this.getFeatureFlag(featureFlag, defaultValue)); | ||
* | ||
* @returns {object} Value of feature flags. Flags can be boolean or enums, depending on their configuration | ||
* @returns {LDClient.LDFlagSet} Value of feature flags. Flags can be boolean or enums, depending on their configuration | ||
*/ | ||
getAllFlags() { | ||
getAllFlags(): LDClient.LDFlagSet { | ||
if (!this.ldClient) { | ||
@@ -190,0 +208,0 @@ return {}; |
{ | ||
"name": "ld-react-components", | ||
"version": "1.0.50", | ||
"version": "1.0.51", | ||
"description": "Semantic component helpers to support LaunchDarkly in your react app.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -287,2 +287,5 @@ <div align="center"> | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="https://github.com/Kausam"><img src="https://avatars2.githubusercontent.com/u/19550684?v=4" width="100px;" alt="Kausam"/><br /><sub><b>Kausam</b></sub></a><br /><a href="https://github.com/intuit/LD-React-Components/commits?author=Kausam" title="Code">💻</a></td> | ||
</tr> | ||
</table> | ||
@@ -289,0 +292,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6040385
51841
313