Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: evaluation logic in typescript for nodejs sdk #1258

Draft
wants to merge 61 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0a704e7
feat: finish all logic
duyhungtnn Sep 18, 2024
704869f
fix: invalid logic when convert evaluation
duyhungtnn Sep 18, 2024
fb4fea5
chore: move to evaluation folder
duyhungtnn Sep 18, 2024
2e67318
Create README.md
duyhungtnn Sep 18, 2024
3b13ee9
fix: build fail
duyhungtnn Sep 18, 2024
f9f4aa5
fix: build fail
duyhungtnn Sep 18, 2024
4040097
fix: test can't run
duyhungtnn Sep 19, 2024
f50c74d
test: start add rule evaluation test
duyhungtnn Sep 19, 2024
879dc33
tests: finish clause_evaluator_test.ts
duyhungtnn Sep 20, 2024
089a7e8
fix: generate bucket fail
duyhungtnn Sep 23, 2024
5628978
fix: invalid test has been run
duyhungtnn Sep 24, 2024
4054ee1
tests: add getPrerequisiteDownwards
duyhungtnn Sep 24, 2024
75a2e89
fix: testcase get_prerequisite_downwards
duyhungtnn Sep 27, 2024
a3ea38c
chore: disable unrelated CI flow
duyhungtnn Sep 27, 2024
e85b5bd
chore: add get_eval_features_test.ts
duyhungtnn Sep 27, 2024
7182388
chore: add assign_user_off_variationt_test.ts
duyhungtnn Sep 27, 2024
29fb295
chore: add assign_user_target_test.ts
duyhungtnn Sep 27, 2024
8890c97
Create assign_user_rule_test.ts
duyhungtnn Sep 27, 2024
601bc0f
chore: revert changes on ui/web
duyhungtnn Sep 27, 2024
130c9da
chore: restore go mod
duyhungtnn Sep 27, 2024
cbefa07
chore: restore go code
duyhungtnn Sep 27, 2024
3c41dad
.gitignore is now working
duyhungtnn Sep 27, 2024
9e6dd0e
test: added full tests as the golang package
duyhungtnn Sep 29, 2024
9aae0b2
Merge branch 'main' into feat/node-evaluation-package
duyhungtnn Sep 29, 2024
ac941db
chore: update proto
duyhungtnn Sep 29, 2024
3362f7d
chore: format code
duyhungtnn Sep 29, 2024
14bb1bf
Create pr-evaluation-ts.yaml
duyhungtnn Sep 29, 2024
8d5ad19
Update pr-evaluation-ts.yaml
duyhungtnn Sep 29, 2024
9ae8f7f
Update pr-evaluation-ts.yaml
duyhungtnn Sep 29, 2024
5ab4820
Revert "Update pr-evaluation-ts.yaml"
duyhungtnn Sep 29, 2024
37d607b
Update assign_user_default_strategy_test.ts
duyhungtnn Sep 29, 2024
1b2d5b8
.gitignore is now working
duyhungtnn Sep 30, 2024
959872a
Merge branch 'feat/node-evaluation-package' of https://github.com/buc…
duyhungtnn Sep 30, 2024
7ff3397
chore: remote proto folder - use shared folder instead
duyhungtnn Sep 30, 2024
d596fc0
Update index.ts
duyhungtnn Sep 30, 2024
5f49771
Update pr-evaluation-ts.yaml
duyhungtnn Sep 30, 2024
9872577
fix: build fail
duyhungtnn Sep 30, 2024
f2efffb
fix: build fail
duyhungtnn Sep 30, 2024
b2bf1f6
Update pr-evaluation-ts.yaml
duyhungtnn Sep 30, 2024
45f970f
Update dependencyEvaluator.ts
duyhungtnn Sep 30, 2024
d77f696
chore: remove incorrect comments
duyhungtnn Sep 30, 2024
75f9dd7
Merge branch 'feat/node-evaluation-package' of https://github.com/buc…
duyhungtnn Sep 30, 2024
b9ab6b3
deps: remove unused deps
duyhungtnn Oct 3, 2024
e65a375
chore: add back google-protobuf
duyhungtnn Oct 3, 2024
ccfdb78
chore: add proto generate script
duyhungtnn Oct 4, 2024
92ede5a
Update pr-evaluation-ts.yaml
duyhungtnn Oct 4, 2024
93fb577
ci: missing protoc
duyhungtnn Oct 4, 2024
ed63627
Update pr-evaluation-ts.yaml
duyhungtnn Oct 4, 2024
2e425f7
Update pr-evaluation-ts.yaml
duyhungtnn Oct 4, 2024
48ac51d
fix: correct lib destination folder
duyhungtnn Oct 21, 2024
f5633e4
chore: export the func evaluator.listSegmentIDs()
duyhungtnn Oct 26, 2024
b94b9f2
fix: build fail when using the evaluation package
duyhungtnn Oct 27, 2024
3967af0
chore: correct typo
duyhungtnn Oct 30, 2024
7fa1051
fix: missing export Evaluation, UserEvaluations
duyhungtnn Nov 7, 2024
d25968b
fix: export Strategy
duyhungtnn Nov 8, 2024
740c09a
fix: create feature with offVariation
duyhungtnn Nov 8, 2024
06404b1
fix: export Clause
duyhungtnn Nov 8, 2024
e34825f
fix: export Reason
duyhungtnn Nov 8, 2024
2184c96
Update package.json
duyhungtnn Nov 9, 2024
b5bdba6
chore: restore .gitignore
duyhungtnn Nov 19, 2024
71a4932
chore: change user evaluations id to use feature updated at
duyhungtnn Dec 6, 2024
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
133 changes: 133 additions & 0 deletions .github/workflows/pr-evaluation-ts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: pr-evaluation-ts

on:
pull_request:
branches:
- main
paths:
- "evaluation/typescript/**"
- "!**/**.md"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
NODE_VERSION: 20
NPM_TOKEN: ${{ secrets.NPM_TOKEN || '' }}
EVALUATION_DIRECTORY: "evaluation/typescript"

jobs:
install-dependencies:
name: Install dependencies
defaults:
run:
working-directory: ${{ env.EVALUATION_DIRECTORY }}
runs-on: ubuntu-latest
outputs:
YARN_CACHE_DIR: ${{ steps.yarn-cache-dir-path.outputs.dir }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Set yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Init
run: make init

lint:
name: Lint
defaults:
run:
working-directory: ${{ env.EVALUATION_DIRECTORY }}
needs: install-dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/cache@v4
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ needs.install-dependencies.outputs.YARN_CACHE_DIR }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Format
run: make fmt
- name: Lint
run: make lint

unit-test:
name: Unit test
defaults:
run:
working-directory: ${{ env.EVALUATION_DIRECTORY }}
needs: install-dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/cache@v4
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ needs.install-dependencies.outputs.YARN_CACHE_DIR }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Protoc
uses: arduino/setup-protoc@v3
- name: Generated proto code
run: make gen_proto
- name: Unit test
run: make test

build:
name: Build
defaults:
run:
working-directory: ${{ env.EVALUATION_DIRECTORY }}
needs: install-dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/cache@v4
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ needs.install-dependencies.outputs.YARN_CACHE_DIR }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Protoc
uses: arduino/setup-protoc@v3
- name: Generated proto code
run: make gen_proto
- name: Package Build
run: make build
1 change: 1 addition & 0 deletions .github/workflows/pr-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
paths-ignore:
- "ui/**"
- "**/**.md"
- "evaluation/typescript/**"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
14 changes: 14 additions & 0 deletions evaluation/typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.DS_Store

node_modules
yarn-error.log
lib
__dist
__lib
__test
__e2e
dist
.vscode/launch.json
src/google/
src/protoc-gen-openapiv2/
src/proto/
30 changes: 30 additions & 0 deletions evaluation/typescript/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.DS_Store
.vscode
__dist
__lib
__test
__e2e
e2e
example
src
tools
.eslintignore
.eslintrc.js
.gitignore
.nvmrc
.npmignore
.prettierignore
.prettierrc.js
ava-e2e.config.mjs
ava-test.config.mjs
babel-e2e.config.js
babel-test.config.js
babel.config.js
renovate.json
Makefile
tsconfig.json
tsconfig.test.json
tslint.json
yarn-error.log
bootstrap.js
index.ts
1 change: 1 addition & 0 deletions evaluation/typescript/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
1 change: 1 addition & 0 deletions evaluation/typescript/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.13.0
4 changes: 4 additions & 0 deletions evaluation/typescript/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.d.ts
src/google/
src/protoc-gen-openapiv2/
src/proto/
6 changes: 6 additions & 0 deletions evaluation/typescript/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
printWidth: 100,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'always',
};
3 changes: 3 additions & 0 deletions evaluation/typescript/.release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.1"
}
125 changes: 125 additions & 0 deletions evaluation/typescript/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
NPM_BIN_DIR := $(CURDIR)/node_modules/.bin
GENFILES_DIR := $(CURDIR)/__lib

GIT_REVISION := $(shell git rev-parse --verify HEAD)

export PACKAGE_NAME := $(shell node -p "require('./package.json').name")
export CURRENT_VERSION := $(shell npm view $(PACKAGE_NAME) version 2>/dev/null || echo 0.0.0)
export LOCAL_VERSION := $(shell node -p "require('./package.json').version")

.PHONY: init
init:
yarn

.PHONY: clean
clean:
rm -rf $(CURDIR)/__test $(CURDIR)/__lib

.PHONY: build
build: clean-build tsc copy-proto-external-api-files-to-lib rename-js

.PHONY: clean-build
clean-build:
rm -rf $(GENFILES_DIR)

.PHONY: tsc
tsc: clean
$(NPM_BIN_DIR)/tsc --project tsconfig.json
cp -r $(SRC_DIR)/proto __lib/

.PHONY: build_test
build_test: clean
$(NPM_BIN_DIR)/tsc --project tsconfig.test.json
cp -r $(SRC_DIR)/proto __test/

.PHONY: rename-js
rename-js:
$(NPM_BIN_DIR)/rename '$(GENFILES_DIR)/**/*.js' '{{f}}.mjs'

.PHONY: test
test: build_test
$(NPM_BIN_DIR)/ava --config ava.config.mjs

.PHONY: fmt
fmt: tsfmt

.PHONY: tsfmt
tsfmt:
$(NPM_BIN_DIR)/prettier --write '$(CURDIR)/src/**/*.ts'

.PHONY: lint
lint:
$(NPM_BIN_DIR)/eslint

.PHONY: fixLintErrors
fixLintErrors:
$(NPM_BIN_DIR)/eslint . --fix

.PHONY: copy-proto-external-api-files-to-lib
copy-proto-external-api-files-to-lib:
$(NPM_BIN_DIR)/cpx '$(SRC_DIR)/protoc-gen-openapiv2/**/*.{js,d.ts}' $(GENFILES_DIR)/protoc-gen-openapiv2
$(NPM_BIN_DIR)/cpx '$(SRC_DIR)/google/**/*.{js,d.ts}' $(GENFILES_DIR)/google

.PHONY: copy-genfiles
copy-genfiles:
@rm -rf $(CURDIR)/lib
$(NPM_BIN_DIR)/cpx '$(GENFILES_DIR)/**/*.{mjs,d.ts}' $(CURDIR)/lib
$(NPM_BIN_DIR)/cpx '$(GENFILES_DIR)/bucketeer.*' $(CURDIR)/lib
@find $(CURDIR)/lib -type f -exec chmod 644 {} +
$(NPM_BIN_DIR)/rename '$(CURDIR)/lib/**/*.js' '{{f}}.mjs'
$(NPM_BIN_DIR)/babel lib --extensions '.mjs' --config-file "$(CURDIR)/babel.config.js" --out-dir "lib"

.PHONY: publish-dry
publish-dry: copy-genfiles
npm publish --dry-run

.PHONY: publish
publish: copy-genfiles
ifeq ($(shell $(NPM_BIN_DIR)/semver -r ">$(CURRENT_VERSION)" $(LOCAL_VERSION) ),$(LOCAL_VERSION))
npm publish --access public
else
@echo "$(LOCAL_VERSION) exists. skip publish."
endif

####################################
# Generate proto definition files
####################################

ROOT_DIR := $(CURDIR)/../..
SRC_DIR := $(CURDIR)/src
PROTOBUF_INCLUDE_DIR := $(ROOT_DIR)/proto/external/protocolbuffers/protobuf/v23.4
GOOGLEAPIS := $(ROOT_DIR)/proto/external/googleapis/googleapis/83e756a66b80b072bd234abcfe89edf459090974
OPENAPI := $(ROOT_DIR)/proto/external/openapiv2
NPM_BIN_DIR := $(CURDIR)/node_modules/.bin

.PHONY: gen_proto
gen_proto: clean_proto gen_proto_external_api
protoc \
--plugin=protoc-gen-ts=$(NPM_BIN_DIR)/protoc-gen-ts \
--plugin=protoc-gen-js=$(NPM_BIN_DIR)/protoc-gen-js \
--js_out=import_style=commonjs,binary:$(SRC_DIR) \
--ts_out=service=grpc-web:$(SRC_DIR) \
-I $(ROOT_DIR) \
-I $(PROTOBUF_INCLUDE_DIR) \
-I $(GOOGLEAPIS) \
-I $(OPENAPI) \
$(shell find $(ROOT_DIR)/proto -type f -name "*.proto" -not -path "**/external/*.proto" -not -path "**/auth/*.proto" -not -path "**/experiment/*.proto" -not -path "**/test/*.proto" -not -path "**/push/*.proto" -not -path "**/notification/*.proto" -not -path "**/eventpersisterdwh/*.proto" -not -path "**/eventcounter/*.proto" -not -path "**/environment/*.proto" -not -path "**/batch/*.proto" -not -path "**/autoops/*.proto" -not -path "**/auditlog/*.proto" -not -path "**/account/*.proto" -not -path "**/openapi/web_default_settings.proto" -not -path "**/google/protobuf/*.proto" -not -path "**/google/api/*.proto" -not -path "**/protoc-gen-openapiv2/options/*.proto")


.PHONY: gen_proto_external_api
gen_proto_external_api:
protoc \
--plugin=protoc-gen-ts=$(NPM_BIN_DIR)/protoc-gen-ts \
--plugin=protoc-gen-js=$(NPM_BIN_DIR)/protoc-gen-js \
--js_out=import_style=commonjs,binary:$(SRC_DIR) \
--ts_out=service=grpc-web:$(SRC_DIR) \
-I $(PROTOBUF_INCLUDE_DIR) \
-I $(GOOGLEAPIS) \
-I $(OPENAPI) \
$(shell find $(GOOGLEAPIS) -type f -name "*.proto") $(shell find $(OPENAPI) -type f -name "*.proto")

.PHONY: clean_proto
clean_proto:
rm -rf $(SRC_DIR)/proto/
rm -rf $(SRC_DIR)/google/
rm -rf $(SRC_DIR)/protoc-gen-openapiv2/
9 changes: 9 additions & 0 deletions evaluation/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Evaluation module for Node.JS

## Setup
```export NPM_TOKEN="YOUR_NPM_TOKEN"```
```make init```
```make copy_proto_generated_code```

## Unit tests
```make test```
7 changes: 7 additions & 0 deletions evaluation/typescript/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (api) {
api.cache(true);

return {
presets: ['@babel/preset-env'],
};
};
27 changes: 27 additions & 0 deletions evaluation/typescript/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import tsEslint from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

export default [
{
files: ['src/**/*.ts', 'test/**/*.ts'],
ignores: ['**/*.d.ts', 'src/google/', 'src/protoc-gen-openapiv2/', 'src/proto/'],
languageOptions: {
parser: tsParser,
parserOptions: {
sourceType: 'module',
project: [`tsconfig.json`, `tsconfig.test.json`],
},
globals: {
node: true,
},
},
plugins: {
...tsEslint.configs.recommended,
eslintPluginPrettierRecommended,
},
rules: {
quotes: ['error', 'single', { avoidEscape: true }],
},
},
];
Loading
Loading