-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add node server package (#102)
* feat: add node server package * add docs * use supertest
Showing
39 changed files
with
1,623 additions
and
405 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
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
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
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"nextjs": "Next.js", | ||
"react": "React", | ||
"svelte": "Svelte", | ||
"angular": "Angular" | ||
} | ||
"svelte": "Svelte", | ||
"angular": "Angular", | ||
"node": "Node", | ||
"express": "Express", | ||
"koa": "Koa" | ||
} |
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,140 @@ | ||
import { Tab, Tabs, Callout } from "nextra-theme-docs"; | ||
|
||
# Express | ||
|
||
Our Express package allows you to use Abby within all server-side applications. | ||
If you're using Node < 18 you will need to also install any fetch polyfill. | ||
|
||
## Installation | ||
|
||
To get started make sure to install the packages using your favorite package manager. | ||
|
||
<Tabs items={["npm", "yarn", "pnpm"]}> | ||
<Tab> | ||
```bash | ||
npm i @tryabby/express | ||
``` | ||
</Tab> | ||
|
||
<Tab> | ||
```bash | ||
yarn add @tryabby/express | ||
``` | ||
</Tab> | ||
<Tab> | ||
```bash | ||
pnpm i @tryabby/express | ||
``` | ||
</Tab> | ||
</Tabs> | ||
|
||
## Usage | ||
|
||
### Create your config | ||
|
||
To use Abby you need to create your config first. You can do this by creating a file called `abby.config.ts` in your root folder. This file will be used to configure your project. | ||
|
||
```ts | ||
// abby.config.ts | ||
import { defineConfig } from "@tryabby/node"; | ||
|
||
export default defineConfig({ | ||
projectId: "<YOUR_PROJECT_ID>", | ||
currentEnvironment: environment.production ? "production" : "development", | ||
environments: ["production", "development"], | ||
tests: { | ||
test: { variants: ["A", "B"] }, | ||
footer: { variants: ["dark", "orange", "green"] }, | ||
// ... your tests | ||
}, | ||
flags: ["darkMode", "newFeature"], | ||
remoteConfig: { | ||
customButtonText: "String", | ||
maxSessionCount: "Number", | ||
}, | ||
}); | ||
``` | ||
|
||
### Create your Abby instance | ||
|
||
To use Abby in your code you need to call the `createAbby` function | ||
|
||
```ts | ||
import { createAbby } from "@tryabby/express"; | ||
import abbyConfig from "../abby.config"; | ||
|
||
const { abby, middleware } = createAbby(abbyConfig); | ||
``` | ||
|
||
### Using Abby in your code | ||
|
||
You can now use Abby in your code. Before you can use Abby inside of your route handlers you will need to add the middleware to your Express app. | ||
|
||
#### Middleware | ||
|
||
```ts | ||
import express from "express"; | ||
import { createAbby } from "@tryabby/express"; | ||
import abbyConfig from "../abby.config"; | ||
|
||
const { abby, middleware } = createAbby(abbyConfig); | ||
|
||
const app = express(); | ||
|
||
app.use(middleware); | ||
|
||
app.get("/", (req, res) => { | ||
const testVariant = abby.getTestVariant("test"); | ||
|
||
if (testVariant === "A") { | ||
// show variant A | ||
} else { | ||
// show variant B | ||
} | ||
}); | ||
|
||
app.listen(3000, () => { | ||
console.log("Server listening on port 3000"); | ||
}); | ||
``` | ||
|
||
#### Feature Flags | ||
|
||
You can call the `getFeatureFlag` function to get the value of a feature flag. | ||
Since you loaded all the information from our API this is a synchronous function. | ||
|
||
```ts | ||
if (abby.getFeatureFlag("newFeature")) { | ||
// use new algorithm | ||
} else { | ||
// use old algorithm | ||
} | ||
``` | ||
|
||
#### Remote Configs | ||
|
||
You can call the `getRemoteConfig` function to get the value of a remote config. | ||
|
||
```ts | ||
const maxSessionCount = abby.getRemoteConfig("maxSessionCount"); | ||
|
||
if (sessionCount < maxSessionCount) { | ||
// show session | ||
} else { | ||
// show error | ||
} | ||
``` | ||
|
||
#### A/B Tests | ||
|
||
You can call the `getTestVariant` function to get the variant of a test. | ||
|
||
```ts | ||
const testVariant = abby.getTestVariant("test"); | ||
|
||
if (testVariant === "A") { | ||
// show variant A | ||
} else { | ||
// show variant B | ||
} | ||
``` |
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,132 @@ | ||
import { Tab, Tabs, Callout } from "nextra-theme-docs"; | ||
|
||
# Koa | ||
|
||
Our Koa package allows you to use Abby within all server-side applications. | ||
If you're using Node < 18 you will need to also install any fetch polyfill. | ||
|
||
## Installation | ||
|
||
To get started make sure to install the packages using your favorite package manager. | ||
|
||
<Tabs items={["npm", "yarn", "pnpm"]}> | ||
<Tab> | ||
```bash | ||
npm i @tryabby/koa | ||
``` | ||
</Tab> | ||
|
||
<Tab> | ||
```bash | ||
yarn add @tryabby/koa | ||
``` | ||
</Tab> | ||
<Tab> | ||
```bash | ||
pnpm i @tryabby/koa | ||
``` | ||
</Tab> | ||
</Tabs> | ||
|
||
## Usage | ||
|
||
### Create your config | ||
|
||
To use Abby you need to create your config first. You can do this by creating a file called `abby.config.ts` in your root folder. This file will be used to configure your project. | ||
|
||
```ts | ||
// abby.config.ts | ||
import { defineConfig } from "@tryabby/node"; | ||
|
||
export default defineConfig({ | ||
projectId: "<YOUR_PROJECT_ID>", | ||
currentEnvironment: environment.production ? "production" : "development", | ||
environments: ["production", "development"], | ||
tests: { | ||
test: { variants: ["A", "B"] }, | ||
footer: { variants: ["dark", "orange", "green"] }, | ||
// ... your tests | ||
}, | ||
flags: ["darkMode", "newFeature"], | ||
remoteConfig: { | ||
customButtonText: "String", | ||
maxSessionCount: "Number", | ||
}, | ||
}); | ||
``` | ||
|
||
### Create your Abby instance | ||
|
||
To use Abby in your code you need to call the `createAbby` function | ||
|
||
```ts | ||
import { createAbby } from "@tryabby/koa"; | ||
import abbyConfig from "../abby.config"; | ||
|
||
const { abby, middleware } = createAbby(abbyConfig); | ||
``` | ||
|
||
### Using Abby in your code | ||
|
||
You can now use Abby in your code. Before you can use Abby inside of your route handlers you will need to add the middleware to your Koa app. | ||
|
||
#### Middleware | ||
|
||
```ts | ||
import Koa from "Koa"; | ||
import { createAbby } from "@tryabby/koa"; | ||
import abbyConfig from "../abby.config"; | ||
|
||
const { abby, middleware } = createAbby(abbyConfig); | ||
|
||
const app = new Koa(); | ||
|
||
app.use(middleware); | ||
|
||
// ... your routes | ||
|
||
app.listen(3000, () => { | ||
console.log("Server listening on port 3000"); | ||
}); | ||
``` | ||
|
||
#### Feature Flags | ||
|
||
You can call the `getFeatureFlag` function to get the value of a feature flag. | ||
Since you loaded all the information from our API this is a synchronous function. | ||
|
||
```ts | ||
if (abby.getFeatureFlag("newFeature")) { | ||
// use new algorithm | ||
} else { | ||
// use old algorithm | ||
} | ||
``` | ||
|
||
#### Remote Configs | ||
|
||
You can call the `getRemoteConfig` function to get the value of a remote config. | ||
|
||
```ts | ||
const maxSessionCount = abby.getRemoteConfig("maxSessionCount"); | ||
|
||
if (sessionCount < maxSessionCount) { | ||
// show session | ||
} else { | ||
// show error | ||
} | ||
``` | ||
|
||
#### A/B Tests | ||
|
||
You can call the `getTestVariant` function to get the variant of a test. | ||
|
||
```ts | ||
const testVariant = abby.getTestVariant("test"); | ||
|
||
if (testVariant === "A") { | ||
// show variant A | ||
} else { | ||
// show variant B | ||
} | ||
``` |
Oops, something went wrong.
631e914
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.
Successfully deployed to the following URLs:
abby-opensource – ./apps/web
abby-opensource-dynabase.vercel.app
preview.tryabby.com
abby-opensource-git-main-dynabase.vercel.app
abby-opensource.vercel.app
631e914
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.
Successfully deployed to the following URLs:
abby-docs – ./apps/docs
abby-docs-dynabase.vercel.app
abby-docs-git-main-dynabase.vercel.app
docs.tryabby.com
abby-docs.vercel.app
docs.tryabby.dev