-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d9a2b28
Showing
36 changed files
with
18,772 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
* text=auto | ||
*.psd filter=lfs diff=lfs merge=lfs -text | ||
*.ai filter=lfs diff=lfs merge=lfs -text | ||
*.aep filter=lfs diff=lfs merge=lfs -text | ||
*.prproj filter=lfs diff=lfs merge=lfs -text | ||
*.png filter=lfs diff=lfs merge=lfs -text | ||
*.bmp filter=lfs diff=lfs merge=lfs -text | ||
*.gif filter=lfs diff=lfs merge=lfs -text | ||
*.jpg filter=lfs diff=lfs merge=lfs -text | ||
*.jpeg filter=lfs diff=lfs merge=lfs -text | ||
*.mov filter=lfs diff=lfs merge=lfs -text | ||
*.mp4 filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: tests | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
jest: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: cache .npm | ||
uses: actions/cache@v2 | ||
env: | ||
cache-name: npm | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | ||
- run: npm ci | ||
- run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
### VSCode | ||
|
||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
*.code-workspace | ||
|
||
# Local History for Visual Studio Code | ||
.history/ | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Builds | ||
dist/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
.DS_Store | ||
|
||
# JSDoc output | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.github/ | ||
|
||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
semi: true, | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
printWidth: 80, | ||
tabWidth: 2, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# These owners will be the default owners for everything in | ||
# the repo. Unless a later match takes precedence, | ||
# Global owners | ||
* @tore-statsig @marcos-statsig @roim-statsig @jkw-statsig @sroyal-statsig @tim-statsig @vijaye-statsig @alex-statsig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ISC License (ISC) | ||
Copyright (c) 2021, Statsig, Inc. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose | ||
with or without fee is hereby granted, provided that the above copyright notice | ||
and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Statsig | ||
|
||
## Statsig Javascript Client SDK | ||
|
||
The javascript SDK for client environments. If you're looking for a nodejs server SDK, try [https://github.com/statsig-io/node-js-server-sdk](https://github.com/statsig-io/node-js-server-sdk). | ||
|
||
Statsig helps you move faster with Feature Gates and Dynamic Configs. If you're new to Statsig, create an account at [statsig.com](https://www.statsig.com). | ||
|
||
## Getting Started | ||
Visit our [getting started guide](https://www.statsig.com/docs/js-client), or check out the [SDK Documentation](https://github.com/statsig-io/js-client-sdk/blob/main/docs/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
## Statsig | ||
The global statsig class for interacting with gates, configs, experiments configured in the statsig developer console. Also used for event logging to view in the statsig console, or for analyzing experiment impacts using pulse. | ||
|
||
**Kind**: global constant | ||
|
||
* [statsig](#statsig) | ||
* [.initialize(sdkKey, [user], [options])](#statsig.initialize) ⇒ <code>Promise.<boolean></code> | ||
* [.checkGate(gateName)](#statsig.checkGate) ⇒ <code>boolean</code> | ||
* [.getConfig(configName)](#statsig.getConfig) ⇒ [<code>DynamicConfig</code>](#DynamicConfig) | ||
* [.logEvent(eventName, [value], [metadata])](#statsig.logEvent) ⇒ <code>void</code> | ||
* [.switchUser(newUser)](#statsig.switchUser) ⇒ <code>Promise.<boolean></code> | ||
* [.isReady()](#statsig.isReady) ⇒ <code>boolean</code> | ||
* [.shutdown()](#statsig.shutdown) | ||
|
||
<a name="statsig.initialize"></a> | ||
|
||
### statsig.initialize(sdkKey, [user], [options]) ⇒ <code>Promise.<boolean></code> | ||
Initializes the statsig SDK. This must be called and complete before checking gates/configs or logging. | ||
|
||
**Kind**: static method of [<code>statsig</code>](#statsig) | ||
**Returns**: <code>Promise.<boolean></code> - - a promise which *always resolves*. The return value will specify success or failure of the initialization call. | ||
|
||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| sdkKey | <code>string</code> | | a SDK key, generated from the statsig developer console | | ||
| [user] | [<code>StatsigUser</code>](#typedefs.StatsigUser) | <code>{}</code> | an object containing user attributes. Pass a stable identifier as the key when possible, and any other attributes you have (ip, country, etc.) in order to use advanced gate conditions | | ||
| [options] | [<code>StatsigOptions</code>](#typedefs.StatsigOptions) | <code>{}</code> | manual sdk configuration for advanced setup | | ||
|
||
<a name="statsig.checkGate"></a> | ||
|
||
### statsig.checkGate(gateName) ⇒ <code>boolean</code> | ||
Checks the value of a gate for the current user | ||
|
||
**Kind**: static method of [<code>statsig</code>](#statsig) | ||
**Returns**: <code>boolean</code> - - value of a gate for the user. Gates are "off" (return false) by default | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| gateName | <code>string</code> | the name of the gate to check | | ||
|
||
<a name="statsig.getConfig"></a> | ||
|
||
### statsig.getConfig(configName) ⇒ [<code>DynamicConfig</code>](#DynamicConfig) | ||
Checks the value of a config for the current user | ||
|
||
**Kind**: static method of [<code>statsig</code>](#statsig) | ||
**Returns**: [<code>DynamicConfig</code>](#DynamicConfig) - - value of a config for the user | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| configName | <code>string</code> | the name of the config to get | | ||
|
||
<a name="statsig.logEvent"></a> | ||
|
||
### statsig.logEvent(eventName, [value], [metadata]) ⇒ <code>void</code> | ||
Log an event for data analysis and alerting or to measure the impact of an experiment | ||
|
||
**Kind**: static method of [<code>statsig</code>](#statsig) | ||
|
||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| eventName | <code>string</code> | | the name of the event (eventName = 'Purchase') | | ||
| [value] | <code>string</code> \| <code>number</code> | <code>null</code> | the value associated with the event (value = 10) | | ||
| [metadata] | <code>object</code> | <code></code> | other attributes associated with this event (metadata = {items: 2, currency: USD}) | | ||
|
||
### statsig.switchUser(newUser) ⇒ <code>Promise.<boolean></code> | ||
Switches the user associated with calls to fetch gates/configs from statsig. This client SDK is intended for single user environments, but its possible a user was unknown previously and then logged in, or logged out and switched to a different account. Use this function to update the gates/configs and associate event logs with the new user. | ||
|
||
**Kind**: static method of [<code>statsig</code>](#statsig) | ||
**Returns**: <code>Promise.<boolean></code> - - a promise which *always resolves* to a value which indicates success or failure | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| newUser | [<code>StatsigUser</code>](#typedefs.StatsigUser) | a set of user attributes identifying the new user | | ||
|
||
<a name="statsig.isReady"></a> | ||
|
||
### statsig.isReady() ⇒ <code>boolean</code> | ||
Checks to see if the SDK is in a ready state to check gates and configs | ||
If the SDK is initializing, or switching users, it is not in a ready state. | ||
|
||
**Kind**: static method of [<code>statsig</code>](#statsig) | ||
**Returns**: <code>boolean</code> - if the SDK is ready | ||
|
||
<a name="statsig.shutdown"></a> | ||
|
||
### statsig.shutdown() | ||
Informs the statsig SDK that the client is closing or shutting down | ||
so the SDK can clean up internal state | ||
|
||
**Kind**: static method of [<code>statsig</code>](#statsig) | ||
|
||
|
||
* [.StatsigUser](#StatsigUser) : <code>Object.<string, \*></code> | ||
* [.StatsigOptions](#StatsigOptions) : <code>Object</code> | ||
* [.DynamicConfig](#DynamicConfig) : <code>Object</code> | ||
|
||
<a name="StatsigUser"></a> | ||
|
||
### StatsigUser : <code>Object.<string, \*></code> | ||
An object of properties relating to the current user | ||
|
||
**Properties** | ||
|
||
| Name | Type | | ||
| --- | --- | | ||
| [userID] | <code>string</code> \| <code>number</code> | | ||
| [ip] | <code>string</code> | | ||
| [userAgent] | <code>string</code> | | ||
| [country] | <code>string</code> | | ||
| [email] | <code>string</code> | | ||
| [name] | <code>string</code> | | ||
| [custom] | <code>object</code> | | ||
|
||
<a name="StatsigOptions"></a> | ||
|
||
### StatsigOptions : <code>Object</code> | ||
An object of properties for initializing the sdk with advanced options | ||
|
||
**Properties** | ||
|
||
| Name | Type | | ||
| --- | --- | | ||
| [api] | <code>string</code> | | ||
|
||
<a name="DynamicConfig"></a> | ||
|
||
## DynamicConfig : <code>object</code> | ||
A class for fetching the json data configured for a DynamicConfig in the statsig console | ||
|
||
**Kind**: global namespace | ||
|
||
* [DynamicConfig](#DynamicConfig) : <code>object</code> | ||
* [.getBool(name, [defaultValue])](#DynamicConfig+getBool) ⇒ <code>boolean</code> | ||
* [.getString(name, [defaultValue])](#DynamicConfig+getString) ⇒ <code>string</code> | ||
* [.getNumber(name, [defaultValue])](#DynamicConfig+getNumber) ⇒ <code>number</code> | ||
* [.getObject(name, [defaultValue])](#DynamicConfig+getObject) ⇒ [<code>DynamicConfig</code>](#DynamicConfig) | ||
* [.getRawValue()](#DynamicConfig+getRawValue) ⇒ <code>any</code> | ||
|
||
<a name="DynamicConfig+getBool"></a> | ||
|
||
### dynamicConfig.getBool(name, [defaultValue]) ⇒ <code>boolean</code> | ||
Returns the boolean value of the given parameter, or the defaultValue if not found. | ||
|
||
**Kind**: instance method of [<code>DynamicConfig</code>](#DynamicConfig) | ||
|
||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| name | <code>string</code> | | The name of the parameter to check | | ||
| [defaultValue] | <code>boolean</code> | <code>false</code> | The default value of the parameter to return in cases where the parameter is not found or is not the correct type. | | ||
|
||
<a name="DynamicConfig+getString"></a> | ||
|
||
### dynamicConfig.getString(name, [defaultValue]) ⇒ <code>string</code> | ||
Returns the string value of the given parameter, or the defaultValue if not found. | ||
|
||
**Kind**: instance method of [<code>DynamicConfig</code>](#DynamicConfig) | ||
|
||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| name | <code>string</code> | | The name of the parameter to check | | ||
| [defaultValue] | <code>string</code> | <code>"''"</code> | The default value of the parameter to return in cases where the parameter is not found or is not the correct type. | | ||
|
||
<a name="DynamicConfig+getNumber"></a> | ||
|
||
### dynamicConfig.getNumber(name, [defaultValue]) ⇒ <code>number</code> | ||
Returns the number value of the given parameter, or the defaultValue if not found. | ||
|
||
**Kind**: instance method of [<code>DynamicConfig</code>](#DynamicConfig) | ||
|
||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| name | <code>string</code> | | The name of the parameter to check | | ||
| [defaultValue] | <code>number</code> | <code>0</code> | The default value of the parameter to return in cases where the parameter is not found or is not the correct type. | | ||
|
||
<a name="DynamicConfig+getObject"></a> | ||
|
||
### dynamicConfig.getObject(name, [defaultValue]) ⇒ [<code>DynamicConfig</code>](#DynamicConfig) | ||
Returns the object value of the given parameter as another DynamicConfig, or a DynamicConfig representing the defaultValue if not found. | ||
|
||
**Kind**: instance method of [<code>DynamicConfig</code>](#DynamicConfig) | ||
|
||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| name | <code>string</code> | | The name of the parameter to check | | ||
| [defaultValue] | <code>object</code> | <code>{}</code> | The default value of the parameter to return in cases where the parameter is not found or is not the correct type. | | ||
|
||
<a name="DynamicConfig+getRawValue"></a> | ||
|
||
### dynamicConfig.getRawValue() ⇒ <code>any</code> | ||
Returns the raw value of the DynamicConfig | ||
|
||
**Kind**: instance method of [<code>DynamicConfig</code>](#DynamicConfig) |
Oops, something went wrong.