Skip to content

Commit

Permalink
initial commit (1.0.17)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkw-statsig committed Mar 19, 2021
0 parents commit d9a2b28
Show file tree
Hide file tree
Showing 36 changed files with 18,772 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
12 changes: 12 additions & 0 deletions .gitattributes
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
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
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
25 changes: 25 additions & 0 deletions .gitignore
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/
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github/

*.md
7 changes: 7 additions & 0 deletions .prettierrc.js
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,
};
4 changes: 4 additions & 0 deletions CODEOWNERS
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
14 changes: 14 additions & 0 deletions LICENSE
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.
10 changes: 10 additions & 0 deletions README.md
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)
193 changes: 193 additions & 0 deletions docs/README.md
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.&lt;boolean&gt;</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.&lt;boolean&gt;</code>
* [.isReady()](#statsig.isReady) ⇒ <code>boolean</code>
* [.shutdown()](#statsig.shutdown)

<a name="statsig.initialize"></a>

### statsig.initialize(sdkKey, [user], [options]) ⇒ <code>Promise.&lt;boolean&gt;</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.&lt;boolean&gt;</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.&lt;boolean&gt;</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.&lt;boolean&gt;</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.&lt;string, \*&gt;</code>
* [.StatsigOptions](#StatsigOptions) : <code>Object</code>
* [.DynamicConfig](#DynamicConfig) : <code>Object</code>

<a name="StatsigUser"></a>

### StatsigUser : <code>Object.&lt;string, \*&gt;</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>&quot;&#x27;&#x27;&quot;</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)
Loading

0 comments on commit d9a2b28

Please sign in to comment.