Skip to content

Commit 0922be2

Browse files
Merge pull request #10 from splitio/fme-9594
[FME-9594] fix build, add github workflow, add evaluationWithDetails
2 parents 4bd7af2 + 920ca3c commit 0922be2

File tree

9 files changed

+67
-65
lines changed

9 files changed

+67
-65
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @splitio/sdk

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: test
2+
on:
3+
pull_request:
4+
branches:
5+
- '*'
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
build:
13+
name: Run tests
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v5
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 'lts/*'
23+
cache: 'npm'
24+
25+
- name: npm ci
26+
run: npm ci
27+
28+
- name: npm check
29+
run: npm run check
30+
31+
- name: npm test
32+
run: npm run test

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-json
7+
- id: check-yaml
8+
- id: end-of-file-fixer
9+
- id: trailing-whitespace

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@
6060
"build": "rimraf lib es && npm run build-cjs && npm run build-esm",
6161
"check": "npm run check:version",
6262
"check:version": "cross-env NODE_ENV=test tape -r ./ts-node.register src/settings/__tests__/defaults.spec.js",
63-
"pretest-ts-decls": "npm run build-esm && npm run build-cjs && npm link",
64-
"test-ts-decls": "./scripts/ts-tests.sh",
65-
"posttest-ts-decls": "npm unlink && npm install",
6663
"test": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/node.spec.js | tap-min",
6764
"publish:rc": "npm run check && npm run build && npm publish --tag canary",
6865
"publish:stable": "npm run check && npm run build && npm publish"

scripts/build_esm_replace_imports.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# replace splitio-commons imports to use ES modules
44
replace '@splitsoftware/splitio-commons/src' '@splitsoftware/splitio-commons/esm' ./es -r
55

6+
# Fix import extension in es/index.js
7+
replace './lib/js-split-provider' './lib/js-split-provider.js' ./es/index.js -r
8+
69
if [ $? -eq 0 ]
710
then
811
exit 0

scripts/ts-tests.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/__tests__/nodeSuites/client.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ export default async function(assert) {
4747
};
4848

4949
const getBooleanSplitWithKeyTest = async (client) => {
50-
let result = await client.getBooleanValue('my_feature', false);
51-
assert.equals(result, true);
50+
let result = await client.getBooleanDetails('my_feature', false);
51+
assert.equals(result.value, true);
52+
assert.looseEquals(result.flagMetadata, { desc: 'this applies only to ON treatment' });
5253

53-
result = await client.getBooleanValue('my_feature', true, { targetingKey: 'randomKey' });
54-
assert.equals(result, false);
54+
result = await client.getBooleanDetails('my_feature', true, { targetingKey: 'randomKey' });
55+
assert.equals(result.value, false);
56+
assert.looseEquals(result.flagMetadata, {});
5557
};
5658

5759
const getStringSplitTest = async (client) => {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './lib/js-split-provider.js';
1+
export * from './lib/js-split-provider';

src/lib/js-split-provider.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Consumer = {
2020
};
2121

2222
const CONTROL_VALUE_ERROR_MESSAGE = "Received the 'control' value from Split.";
23+
const CONTROL_TREATMENT = "control";
2324

2425
export class OpenFeatureSplitProvider implements Provider {
2526
metadata = {
@@ -53,32 +54,15 @@ export class OpenFeatureSplitProvider implements Provider {
5354
this.transformContext(context)
5455
);
5556

56-
let value: boolean;
57-
switch (details.value as unknown) {
58-
case "on":
59-
value = true;
60-
break;
61-
case "off":
62-
value = false;
63-
break;
64-
case "true":
65-
value = true;
66-
break;
67-
case "false":
68-
value = false;
69-
break;
70-
case true:
71-
value = true;
72-
break;
73-
case false:
74-
value = false;
75-
break;
76-
case "control":
77-
throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE);
78-
default:
79-
throw new ParseError(`Invalid boolean value for ${details.value}`);
57+
if ( details.value === "on" || details.value === "true" ) {
58+
return { ...details, value: true };
59+
}
60+
61+
if ( details.value === "off" || details.value === "false" ) {
62+
return { ...details, value: false };
8063
}
81-
return { ...details, value };
64+
65+
throw new ParseError(`Invalid boolean value for ${details.value}`);
8266
}
8367

8468
async resolveStringEvaluation(
@@ -90,9 +74,6 @@ export class OpenFeatureSplitProvider implements Provider {
9074
flagKey,
9175
this.transformContext(context)
9276
);
93-
if (details.value === "control") {
94-
throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE);
95-
}
9677
return details;
9778
}
9879

@@ -130,14 +111,19 @@ export class OpenFeatureSplitProvider implements Provider {
130111
);
131112
} else {
132113
await this.initialized;
133-
const value = this.client.getTreatment(
114+
const {treatment: value, config}: SplitIO.TreatmentWithConfig = this.client.getTreatmentWithConfig(
134115
consumer.key,
135116
flagKey,
136117
consumer.attributes
137118
);
119+
if (value === CONTROL_TREATMENT) {
120+
throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE);
121+
}
122+
const flagMetadata = config ? JSON.parse(config) : undefined;
138123
const details: ResolutionDetails<string> = {
139124
value: value,
140125
variant: value,
126+
flagMetadata: flagMetadata,
141127
reason: StandardResolutionReasons.TARGETING_MATCH,
142128
};
143129
return details;

0 commit comments

Comments
 (0)