Skip to content

Commit fb54768

Browse files
maya-the-mangoaarsilvtypotter
authored
Selki/node sdk relay features/bandits handling (#104)
* nest app boilerplate for node sdk relay * nest app boilerplate for node sdk relay * nest app boilerplate for node sdk relay improvements * assignment handling WIP * get assignment handling proxy * get assignment handling proxy * get assignment handling proxy * get bandits handling proxy * Include test case for special characters (#103) * test case for special characters * update obfuscated config * update names in description * include unevaluated allocation * update cyrillic language example * fix reason * build and run + workflows for node-server relay * review changes * review changes * feat: React Native Application using Eppo SDK (#106) * inital app from create-expo-app * add Eppo SDK; traditional and precomputed client * Eppo Client provider and basic flag/bandit display * fix: workflow typo (#109) * fixed type injection for node-server-sdk relay app * updated README.md * build and run update * nest app boilerplate for node sdk relay * nest app boilerplate for node sdk relay * nest app boilerplate for node sdk relay improvements * assignment handling WIP * get assignment handling proxy * get assignment handling proxy * get assignment handling proxy * get bandits handling proxy * build and run + workflows for node-server relay * review changes * review changes * fixed type injection for node-server-sdk relay app * updated README.md * build and run update --------- Co-authored-by: Aaron Silverman <[email protected]> Co-authored-by: Tyler Potter <[email protected]>
1 parent d46b866 commit fb54768

22 files changed

+5596
-0
lines changed

.github/workflows/test-sdk-packages.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ jobs:
3131
sdkName: 'eppo/python-sdk'
3232
sdkRelayDir: 'python-sdk-relay'
3333
secrets: inherit
34+
35+
test-node-sdk:
36+
strategy:
37+
fail-fast: false
38+
matrix: ['linux']
39+
uses: ./.github/workflows/test-server-sdk.yml
40+
with:
41+
platform: ${{ matrix.platform }}
42+
sdkName: 'eppo/node-server-sdk'
43+
sdkRelayDir: 'node-sdk-relay'
44+
secrets: inherit
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
/build
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# dotenv environment variable files
39+
.env
40+
.env.development.local
41+
.env.test.local
42+
.env.production.local
43+
.env.local
44+
45+
# temp directory
46+
.temp
47+
.tmp
48+
49+
# Runtime data
50+
pids
51+
*.pid
52+
*.seed
53+
*.pid.lock
54+
55+
# Diagnostic reports (https://nodejs.org/api/report.html)
56+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 120,
6+
"tabWidth": 2
7+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<p align="center">
2+
3+
## Description
4+
5+
This is a relay app that is part of SDK Package Test Runner project. It's responsible for relaying SDK test runner's requests to Eppo's node-server-sdk.
6+
More details about SDK package test runner [here](https://github.com/Eppo-exp/sdk-test-data/tree/main/package-testing/sdk-test-runner).
7+
8+
9+
## Project setup
10+
11+
```bash
12+
$ yarn install
13+
```
14+
15+
## Compile and run the project
16+
17+
```bash
18+
# development
19+
$ yarn run start
20+
21+
# watch mode
22+
$ yarn run start:dev
23+
24+
# production mode
25+
$ yarn run start:prod
26+
```
27+
28+
## Run tests
29+
30+
```bash
31+
# unit tests
32+
$ yarn run test
33+
```
34+
35+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
# Set default values for vars
4+
: "${SDK_REF:=main}"
5+
: "${SDK_RELAY_HOST:=localhost}"
6+
: "${SDK_RELAY_PORT:=4000}"
7+
SDK="https://github.com/Eppo-exp/node-server-sdk.git"
8+
9+
# Run the poller
10+
yarn install
11+
echo "Listening on port ${SDK_RELAY_PORT}"
12+
yarn start:prod
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copy & rename this file into typescript project roots and install the following dev deps
2+
// yarn add prettier eslint typescript-eslint eslint-plugin-prettier eslint-config-prettier --dev
3+
4+
import globals from 'globals';
5+
import pluginJs from '@eslint/js';
6+
import tseslint from 'typescript-eslint';
7+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
8+
9+
export default [
10+
{ files: ['**/*.{js,mjs,cjs,ts}'] },
11+
{ languageOptions: { globals: globals.browser } },
12+
pluginJs.configs.recommended,
13+
...tseslint.configs.recommended,
14+
eslintPluginPrettierRecommended,
15+
{ ignores: ['dist/**'] }, // Ignore built artifacts
16+
];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"deleteOutDir": true
7+
}
8+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "eppo-node-sdk-relay",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "",
6+
"private": true,
7+
"license": "MIT",
8+
"type": "commonjs",
9+
"scripts": {
10+
"build": "nest build",
11+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
12+
"start": "nest start",
13+
"start:dev": "nest start --watch",
14+
"start:debug": "nest start --debug --watch",
15+
"start:prod": "node dist/main",
16+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
17+
"test": "jest",
18+
"test:watch": "jest --watch",
19+
"test:cov": "jest --coverage",
20+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
21+
"test:e2e": "jest --config ./test/jest-e2e.json"
22+
},
23+
"dependencies": {
24+
"@eppo/node-server-sdk": "^3.7.2",
25+
"@eslint/js": "^9.16.0",
26+
"@nestjs/common": "^10.0.0",
27+
"@nestjs/core": "^10.0.0",
28+
"@nestjs/platform-express": "^10.0.0",
29+
"globals": "^15.13.0",
30+
"reflect-metadata": "^0.2.0",
31+
"rxjs": "^7.8.1",
32+
"typescript-eslint": "^8.18.0"
33+
},
34+
"devDependencies": {
35+
"@nestjs/cli": "^10.0.0",
36+
"@nestjs/schematics": "^10.0.0",
37+
"@nestjs/testing": "^10.0.0",
38+
"@types/express": "^5.0.0",
39+
"@types/jest": "^29.5.2",
40+
"@types/node": "^20.3.1",
41+
"@types/supertest": "^6.0.0",
42+
"@typescript-eslint/eslint-plugin": "^8.0.0",
43+
"@typescript-eslint/parser": "^8.0.0",
44+
"eslint": "^8.0.0",
45+
"eslint-config-prettier": "^9.0.0",
46+
"eslint-plugin-prettier": "^5.0.0",
47+
"jest": "^29.5.0",
48+
"prettier": "^3.0.0",
49+
"source-map-support": "^0.5.21",
50+
"supertest": "^7.0.0",
51+
"ts-jest": "^29.1.0",
52+
"ts-loader": "^9.4.3",
53+
"ts-node": "^10.9.1",
54+
"tsconfig-paths": "^4.2.0",
55+
"typescript": "^5.1.3"
56+
},
57+
"jest": {
58+
"moduleFileExtensions": [
59+
"js",
60+
"json",
61+
"ts"
62+
],
63+
"rootDir": "src",
64+
"testRegex": ".*\\.spec\\.ts$",
65+
"transform": {
66+
"^.+\\.(t|j)s$": "ts-jest"
67+
},
68+
"collectCoverageFrom": [
69+
"**/*.(t|j)s"
70+
],
71+
"coverageDirectory": "../coverage",
72+
"testEnvironment": "node"
73+
}
74+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
5+
describe('AppController', () => {
6+
let appController: AppController;
7+
8+
beforeEach(async () => {
9+
const app: TestingModule = await Test.createTestingModule({
10+
controllers: [AppController],
11+
providers: [AppService],
12+
}).compile();
13+
14+
appController = app.get<AppController>(AppController);
15+
});
16+
17+
describe('root', () => {
18+
it('should return "Hello World!"', () => {
19+
expect(appController.getHello()).toBe('Hello World!');
20+
});
21+
});
22+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Body, Controller, Get, HttpCode, Post } from '@nestjs/common';
2+
import { AppService } from './app.service';
3+
import { AssignmentDto, BanditDto, BanditTestRunnerInput } from './types';
4+
import { EppoClientProxy } from './eppoClientProxy';
5+
import { BanditActions, getInstance, init } from '@eppo/node-server-sdk';
6+
import getLogger from './main';
7+
8+
@Controller()
9+
export class AppController {
10+
eppoClientProxy = new EppoClientProxy();
11+
constructor(private readonly appService: AppService) {}
12+
13+
@Get()
14+
getHello(): string {
15+
return this.appService.getHello();
16+
}
17+
18+
@Post('flags/v1/assignment')
19+
getAssignment(@Body() requestedAssignmentBody: AssignmentDto) {
20+
return this.eppoClientProxy.getAssignment(getInstance(), requestedAssignmentBody);
21+
}
22+
23+
@Post('/bandits/v1/action')
24+
getBanditAction(@Body() requestedBanditBody: BanditTestRunnerInput) {
25+
const parsedActions: BanditActions = {};
26+
const parsedInput: BanditDto = JSON.parse(JSON.stringify(requestedBanditBody));
27+
28+
if (requestedBanditBody.actions instanceof Array) {
29+
for (const action of requestedBanditBody.actions) {
30+
parsedActions[action.actionKey] = action;
31+
delete action.actionKey;
32+
}
33+
34+
parsedInput.actions = parsedActions;
35+
}
36+
37+
return this.eppoClientProxy.getBanditAction(getInstance(), parsedInput);
38+
}
39+
40+
@HttpCode(200)
41+
@Post('/sdk/reset')
42+
async resetSdk() {
43+
const currentInstance = getInstance();
44+
currentInstance.stopPolling();
45+
await init({
46+
apiKey: 'test',
47+
assignmentLogger: getLogger(),
48+
pollAfterFailedInitialization: true,
49+
banditLogger: getLogger(),
50+
baseUrl: process.env.EPPO_BASE_URL || 'http://localhost:5000/api',
51+
});
52+
53+
return {};
54+
}
55+
}

0 commit comments

Comments
 (0)