Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.202.5/containers/typescript-node/.devcontainer/base.Dockerfile

# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
ARG VARIANT="$VARIANT"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}


RUN if [ ! -d /workspaces \]; then mkdir /workspaces; fi && chown -R $USER_UID:$USER_GID /workspaces

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

# [Optional] Uncomment if you want to install more global node packages
# RUN su node -c "npm install -g <your-package-list -here>"

# Install kubectl
RUN curl -sSL -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \
&& chmod +x /usr/local/bin/kubectl

# Install Helm
RUN curl -s https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash -
57 changes: 57 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.202.5/containers/typescript-node
{
"name": "Feature tog-node",
//runArgs is used to set container name to USERNAME.programname
//the reason it shows ${localEnv:USERNAME} is so that it covers both Windwos and *nix systems as frontend VSCode
"runArgs": ["--init", "--network=host", "--name=tog-node"],
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"args": {
"VARIANT": "16-bullseye"
}
},

"portsAttributes": {
"9080": {
"label": "api port",
"onAutoForward": "notify"
}
},
// Set *default* container specific settings.json values on container create.
"settings": {},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"ms-azuretools.vscode-docker",
"mindaro-dev.file-downloader",
"github.vscode-pull-request-github",
"redhat.vscode-yaml"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"features": {
"docker-from-docker": {
"version": "latest",
"moby": true
},
"kubectl-helm-minikube": "latest",
"git": "latest",
"github-cli": "latest"
},

// install all dependent packages after container is built and files copied into
"postCreateCommand": "npm install -g npm@^7.24.2 && npm install husky --save-dev && npm set-script prepare \"husky install\" && npm run prepare",
"postStartCommand": "npm update -g"
}
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/lib/index.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/lib/**/*.js"
]
},
{
"name": "Test via NPM test",
"type": "node",
"request": "launch",
"runtimeArgs": ["run-script", "test"],
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"sourceMaps": true,
"envFile": "${workspaceFolder}/.env",
"cwd": "${workspaceRoot}",
"console": "integratedTerminal"
},
]
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { SessionClient } = require('tog-node')
const sessions = new SessionClient('redis://127.0.0.1:6379')

// wherever you whish to retrieve a session
const session = await sessions.session('my_app', 'session-123-xyz')
const session = await sessions.session('my_app', 'session-123-xyz', ["session traits 1","session traits 2"])

const buttonColor = session.flags['blue-button'] ? 'blue' : 'red'
```
Expand All @@ -43,7 +43,9 @@ await flags.saveFlag({
name: 'blue-button',
description: 'Makes the call-to-action button blue',
rollout: [
{ value: false}
{ percentage: 30, value: true } // will be `true` for 30% of users
{ traits:["beta","power_user"], percentage: 60, value true} // for sessions that match both traits "beta" and "power_user", 60% of the chances will be true
]
})

Expand Down
52 changes: 36 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 27 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test:watch": "jest --watch --runInBand",
"docs": "typedoc",
"build": "tsc",
"release": "./scripts/release.sh"
"release": "./scripts/release.sh",
"prepare": "husky install"
},
"files": [
"/lib"
Expand All @@ -18,7 +19,8 @@
"license": "ISC",
"dependencies": {
"ioredis": "^4.17.3",
"murmurhash-js": "^1.0.0"
"murmurhash-js": "^1.0.0",
"typescript": "^4.5.5"
},
"devDependencies": {
"@babel/core": "^7.10.2",
Expand All @@ -28,10 +30,10 @@
"@types/jest": "^27.4.0",
"@types/murmurhash-js": "^1.0.3",
"babel-jest": "^25.5.1",
"husky": "^8.0.1",
"jest": "^27.5.1",
"standard-version": "^9.0.0",
"typedoc": "^0.22.11",
"typescript": "^3.9.5",
"wait-for-expect": "^3.0.2"
},
"babel": {
Expand All @@ -46,5 +48,27 @@
],
"@babel/preset-typescript"
]
},
"jest": {
"verbose": true,
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": ".",
"testRegex": "\\.(spec|test)\\.ts$",
"collectCoverage": true,
"collectCoverageFrom": [
"<rootDir>/src/**/*.(t|j)s"
],
"coveragePathIgnorePatterns": [
"<rootDir>/node_modules",
"<rootDir>/migrations",
"<rootDir>/dist",
"<rootDir>/test"
],
"coverageDirectory": "<rootDir>/test/coverage",
"testEnvironment": "node"
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './types'
export * from './flagClient'
export * from './sessionClient'
export {resolveState} from './sessions'
4 changes: 2 additions & 2 deletions src/sessionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class SessionClient {
* @param id Unique session ID
* @param options Options used when creating the flag, which are ignored if it already exists
*/
async session(namespace: string, id: string, options?: SessionOptions): Promise<Session> {
async session(namespace: string, id: string, traits?: string[], options?: SessionOptions): Promise<Session> {
try {
const flagOverrides = options && options.flags || {}
const availableFlags = await withTimeout(
Expand All @@ -59,7 +59,7 @@ export class SessionClient {
const flags = availableFlags
.reduce((all, flag) => ({
...all,
[flag.name]: resolveState(flag.rollout, flag.timestamp || 0, id)
[flag.name]: resolveState(flag.rollout, flag.timestamp || 0, id, traits ?? [])
}), {})
const session: Session = {
namespace,
Expand Down
Loading