From 139b82baf2b8c425ce5121d62cb85445ed690cef Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 15:05:12 -0300 Subject: [PATCH 01/10] [FME-9594] fix build, add github workflow, add evaluationWithDetails --- .github/workflows/ci-cd.yml | 49 +++++++++++++++++++++++++ scripts/build_esm_replace_imports.sh | 3 ++ src/__tests__/nodeSuites/client.spec.js | 10 +++-- src/index.ts | 2 +- src/lib/js-split-provider.ts | 44 ++++++++-------------- 5 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..d8aab3a --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,49 @@ +name: ci-cd +on: + pull_request: + branches: + - master + - development + push: + branches: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: read + id-token: write + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 'lts/*' + cache: 'npm' + + - name: npm ci + run: npm ci + + - name: npm ts tests + run: npm run test-ts-decls + + - name: npm check + run: npm run check + + - name: npm test-browser + run: npm run test-browser + + - name: npm test-node + run: npm run test-node + + - name: npm build + run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build diff --git a/scripts/build_esm_replace_imports.sh b/scripts/build_esm_replace_imports.sh index 81cfb81..f08f970 100755 --- a/scripts/build_esm_replace_imports.sh +++ b/scripts/build_esm_replace_imports.sh @@ -3,6 +3,9 @@ # replace splitio-commons imports to use ES modules replace '@splitsoftware/splitio-commons/src' '@splitsoftware/splitio-commons/esm' ./es -r +# Fix import extension in es/index.js +sed -i '' -e "s|from './lib/js-split-provider'|from './lib/js-split-provider.js'|" es/index.js + if [ $? -eq 0 ] then exit 0 diff --git a/src/__tests__/nodeSuites/client.spec.js b/src/__tests__/nodeSuites/client.spec.js index e134e64..2cdc813 100644 --- a/src/__tests__/nodeSuites/client.spec.js +++ b/src/__tests__/nodeSuites/client.spec.js @@ -47,11 +47,13 @@ export default async function(assert) { }; const getBooleanSplitWithKeyTest = async (client) => { - let result = await client.getBooleanValue('my_feature', false); - assert.equals(result, true); + let result = await client.getBooleanDetails('my_feature', false); + assert.equals(result.value, true); + assert.looseEquals(result.flagMetadata, { desc: 'this applies only to ON treatment' }); - result = await client.getBooleanValue('my_feature', true, { targetingKey: 'randomKey' }); - assert.equals(result, false); + result = await client.getBooleanDetails('my_feature', true, { targetingKey: 'randomKey' }); + assert.equals(result.value, false); + assert.looseEquals(result.flagMetadata, {}); }; const getStringSplitTest = async (client) => { diff --git a/src/index.ts b/src/index.ts index 039d5a4..6750e9f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export * from './lib/js-split-provider.js'; +export * from './lib/js-split-provider'; diff --git a/src/lib/js-split-provider.ts b/src/lib/js-split-provider.ts index 6fdaf55..6bcfc1b 100644 --- a/src/lib/js-split-provider.ts +++ b/src/lib/js-split-provider.ts @@ -20,6 +20,7 @@ type Consumer = { }; const CONTROL_VALUE_ERROR_MESSAGE = "Received the 'control' value from Split."; +const CONTROL_TREATMENT = "control"; export class OpenFeatureSplitProvider implements Provider { metadata = { @@ -53,32 +54,15 @@ export class OpenFeatureSplitProvider implements Provider { this.transformContext(context) ); - let value: boolean; - switch (details.value as unknown) { - case "on": - value = true; - break; - case "off": - value = false; - break; - case "true": - value = true; - break; - case "false": - value = false; - break; - case true: - value = true; - break; - case false: - value = false; - break; - case "control": - throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE); - default: - throw new ParseError(`Invalid boolean value for ${details.value}`); + if ( details.value === "on" || details.value === "true" ) { + return { ...details, value: true }; + } + + if ( details.value === "off" || details.value === "false" ) { + return { ...details, value: false }; } - return { ...details, value }; + + throw new ParseError(`Invalid boolean value for ${details.value}`); } async resolveStringEvaluation( @@ -90,9 +74,6 @@ export class OpenFeatureSplitProvider implements Provider { flagKey, this.transformContext(context) ); - if (details.value === "control") { - throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE); - } return details; } @@ -130,14 +111,19 @@ export class OpenFeatureSplitProvider implements Provider { ); } else { await this.initialized; - const value = this.client.getTreatment( + const {treatment: value, config}: SplitIO.TreatmentWithConfig = this.client.getTreatmentWithConfig( consumer.key, flagKey, consumer.attributes ); + if (value === CONTROL_TREATMENT) { + throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE); + } + const flagMetadata = config ? JSON.parse(config) : undefined; const details: ResolutionDetails = { value: value, variant: value, + flagMetadata: flagMetadata, reason: StandardResolutionReasons.TARGETING_MATCH, }; return details; From 531259bb71ad0d8df3ac2a961073f3cd155e6a28 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 15:06:14 -0300 Subject: [PATCH 02/10] Fix main branch name --- .github/workflows/ci-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index d8aab3a..edc4289 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,7 +2,7 @@ name: ci-cd on: pull_request: branches: - - master + - main - development push: branches: From 159dd9028921f12b3c373b59a9d6b03e33ebea74 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 15:16:06 -0300 Subject: [PATCH 03/10] Fix ci --- scripts/build_esm_replace_imports.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_esm_replace_imports.sh b/scripts/build_esm_replace_imports.sh index f08f970..efa9e81 100755 --- a/scripts/build_esm_replace_imports.sh +++ b/scripts/build_esm_replace_imports.sh @@ -4,7 +4,7 @@ replace '@splitsoftware/splitio-commons/src' '@splitsoftware/splitio-commons/esm' ./es -r # Fix import extension in es/index.js -sed -i '' -e "s|from './lib/js-split-provider'|from './lib/js-split-provider.js'|" es/index.js +replace './lib/js-split-provider' './lib/js-split-provider.js' ./es/index.js -r if [ $? -eq 0 ] then From 3655dccbf92eb23287cd8121c2a12f38957add9d Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 15:21:57 -0300 Subject: [PATCH 04/10] Remove ts-tests temporally --- package.json | 1 - scripts/ts-tests.sh | 28 ---------------------------- 2 files changed, 29 deletions(-) delete mode 100755 scripts/ts-tests.sh diff --git a/package.json b/package.json index 527e3dc..cf67a7f 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "check": "npm run check:version", "check:version": "cross-env NODE_ENV=test tape -r ./ts-node.register src/settings/__tests__/defaults.spec.js", "pretest-ts-decls": "npm run build-esm && npm run build-cjs && npm link", - "test-ts-decls": "./scripts/ts-tests.sh", "posttest-ts-decls": "npm unlink && npm install", "test": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/node.spec.js | tap-min", "publish:rc": "npm run check && npm run build && npm publish --tag canary", diff --git a/scripts/ts-tests.sh b/scripts/ts-tests.sh deleted file mode 100755 index 2263e92..0000000 --- a/scripts/ts-tests.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -cd ts-tests ## Go to typescript tests folder -echo "Installing dependencies for TypeScript declarations testing..." -npm install ## Install dependencies -npm install @types/node@6.0.31 ## Install type definitions for Node.js v6.x (the oldest supported version) -echo "Dependencies installed, linking the package." -npm link @splitsoftware/splitio ## Link to the cloned code -echo "Running tsc compiler." -./node_modules/.bin/tsc ## Run typescript compiler. No need for flags as we have a tsconfig.json file - -echo "Testing again with the latest @types/node version..." -npm install @types/node@14 ## Install latest type definitions for Node.js -echo "Dependencies installed, linking the package." -npm link @splitsoftware/splitio ## Link to the cloned code -echo "Running tsc compiler." -./node_modules/.bin/tsc ## Run typescript compiler. No need for flags as we have a tsconfig.json file - -if [ $? -eq 0 ] -then - echo "✅ Successfully compiled TS tests." - npm unlink @splitsoftware/splitio - exit 0 -else - echo "☠️ Error compiling TS tests." - npm unlink @splitsoftware/splitio - exit 1 -fi From 2414bbac70076ad985c9bb7739e0febfdda0b6e9 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 15:23:34 -0300 Subject: [PATCH 05/10] Remove ts-tests temporally --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index cf67a7f..54ffd02 100644 --- a/package.json +++ b/package.json @@ -60,8 +60,6 @@ "build": "rimraf lib es && npm run build-cjs && npm run build-esm", "check": "npm run check:version", "check:version": "cross-env NODE_ENV=test tape -r ./ts-node.register src/settings/__tests__/defaults.spec.js", - "pretest-ts-decls": "npm run build-esm && npm run build-cjs && npm link", - "posttest-ts-decls": "npm unlink && npm install", "test": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/node.spec.js | tap-min", "publish:rc": "npm run check && npm run build && npm publish --tag canary", "publish:stable": "npm run check && npm run build && npm publish" From 3d32f1072ae457ef39e61c25fdbb6d13a5a03d7a Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 15:25:19 -0300 Subject: [PATCH 06/10] fix ci --- .github/workflows/ci-cd.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index edc4289..5948cbc 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,10 +1,6 @@ name: ci-cd on: pull_request: - branches: - - main - - development - push: branches: - '*' @@ -33,9 +29,6 @@ jobs: - name: npm ci run: npm ci - - name: npm ts tests - run: npm run test-ts-decls - - name: npm check run: npm run check From cf57334f78a9a50e41b1d7826a71254b8c77c7cf Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 15:26:49 -0300 Subject: [PATCH 07/10] fix ci --- .github/workflows/ci-cd.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 5948cbc..106a429 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -32,11 +32,5 @@ jobs: - name: npm check run: npm run check - - name: npm test-browser - run: npm run test-browser - - - name: npm test-node - run: npm run test-node - - - name: npm build - run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build + - name: npm test + run: npm run test From a1e2730bc5b27bdad34e5e5844b1ef18fa42b24e Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 16:04:01 -0300 Subject: [PATCH 08/10] Add precomitconfig and codeowners files and update filename to test --- .github/CODEOWNERS | 1 + .github/workflows/{ci-cd.yml => test.yml} | 10 +++------- .pre-commit-config.yaml | 9 +++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .github/CODEOWNERS rename .github/workflows/{ci-cd.yml => test.yml} (67%) create mode 100644 .pre-commit-config.yaml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..9e31981 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @splitio/sdk diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/test.yml similarity index 67% rename from .github/workflows/ci-cd.yml rename to .github/workflows/test.yml index 106a429..2546ded 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/test.yml @@ -1,24 +1,20 @@ -name: ci-cd +name: test on: pull_request: branches: - '*' concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true -permissions: - contents: read - id-token: write - jobs: build: name: Build runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Setup Node.js uses: actions/setup-node@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6ffb54a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-added-large-files + - id: check-json + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace \ No newline at end of file From 64e5daec7a2ed4262b0cd08eabe7536ca97c3b72 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 16:05:16 -0300 Subject: [PATCH 09/10] fix typo --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ffb54a..49239fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,4 +6,4 @@ repos: - id: check-json - id: check-yaml - id: end-of-file-fixer - - id: trailing-whitespace \ No newline at end of file + - id: trailing-whitespace From 920ca3cfc020d6d81fb7c0b0ff675bb8e563531f Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 25 Aug 2025 16:09:23 -0300 Subject: [PATCH 10/10] Rename job --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2546ded..81a9a8e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ concurrency: jobs: build: - name: Build + name: Run tests runs-on: ubuntu-latest steps: - name: Checkout code