Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @splitio/sdk
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: test
on:
pull_request:
branches:
- '*'

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

jobs:
build:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'npm'

- name: npm ci
run: npm ci

- name: npm check
run: npm run check

- name: npm test
run: npm run test
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +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",
"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",
"publish:stable": "npm run check && npm run build && npm publish"
Expand Down
3 changes: 3 additions & 0 deletions scripts/build_esm_replace_imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
replace './lib/js-split-provider' './lib/js-split-provider.js' ./es/index.js -r

if [ $? -eq 0 ]
then
exit 0
Expand Down
28 changes: 0 additions & 28 deletions scripts/ts-tests.sh

This file was deleted.

10 changes: 6 additions & 4 deletions src/__tests__/nodeSuites/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/js-split-provider.js';
export * from './lib/js-split-provider';
44 changes: 15 additions & 29 deletions src/lib/js-split-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(
Expand All @@ -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;
}

Expand Down Expand Up @@ -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<string> = {
value: value,
variant: value,
flagMetadata: flagMetadata,
reason: StandardResolutionReasons.TARGETING_MATCH,
};
return details;
Expand Down