-
Notifications
You must be signed in to change notification settings - Fork 0
Add events metadata #18
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
Changes from 2 commits
2edf70b
cc5142e
6c87923
cabacb1
fb507c3
08d85f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| 1.1.0 (February 12, 2026) | ||
| - Added ProviderEvents.Ready payload with Split SdkReadyMetadata | ||
| - Updated ConfigurationChanged to forward SdkUpdateMetadata in metadata | ||
| - Up to date with @openfeature/server-sdk 1.20.0 | ||
|
|
||
| 1.0.0 (October 1, 2025) | ||
| - First release. | ||
| - Up to date with @openfeature/web-sdk v1.6.1, and @splitsoftware/splitio-browserjs 1.4.0 | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@splitsoftware/openfeature-web-split-provider", | ||
| "version": "1.0.0", | ||
| "version": "1.1.0", | ||
| "description": "Split OpenFeature Web Provider", | ||
| "files": [ | ||
| "README.md", | ||
|
|
@@ -31,13 +31,13 @@ | |
| "npm": ">=3" | ||
| }, | ||
| "peerDependencies": { | ||
| "@openfeature/web-sdk": "^1.6.1", | ||
| "@splitsoftware/splitio-browserjs": "^1.4.0" | ||
| "@openfeature/web-sdk": "^1.7.2", | ||
ZamoraEmmanuel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "@splitsoftware/splitio-browserjs": "^1.7.0" | ||
|
||
| }, | ||
| "devDependencies": { | ||
| "@eslint/js": "^9.35.0", | ||
| "@openfeature/web-sdk": "^1.6.1", | ||
| "@splitsoftware/splitio-browserjs": "^1.4.0", | ||
| "@openfeature/web-sdk": "^1.7.2", | ||
| "@splitsoftware/splitio-browserjs": "^1.7.0", | ||
EmilianoSanchez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "copyfiles": "^2.4.1", | ||
| "cross-env": "^7.0.3", | ||
| "eslint": "^9.35.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { transformContext } from '../lib/context'; | ||
|
|
||
| describe('context', () => { | ||
| describe('transformContext', () => { | ||
| const defaultTrafficType = 'user'; | ||
|
|
||
| test('uses defaultTrafficType when context has no trafficType', () => { | ||
| const result = transformContext({ targetingKey: 'key-1' }, defaultTrafficType); | ||
| expect(result.trafficType).toBe('user'); | ||
| expect(result.targetingKey).toBe('key-1'); | ||
| expect(result.attributes).toEqual({}); | ||
| }); | ||
|
|
||
| test('uses context trafficType when present and non-empty', () => { | ||
| const result = transformContext( | ||
| { targetingKey: 'key-1', trafficType: 'account' }, | ||
| defaultTrafficType | ||
| ); | ||
| expect(result.trafficType).toBe('account'); | ||
| expect(result.targetingKey).toBe('key-1'); | ||
| expect(result.attributes).toEqual({}); | ||
| }); | ||
|
|
||
| test('falls back to default when trafficType is empty string', () => { | ||
| const result = transformContext( | ||
| { targetingKey: 'key-1', trafficType: '' }, | ||
| defaultTrafficType | ||
| ); | ||
| expect(result.trafficType).toBe('user'); | ||
| }); | ||
|
|
||
| test('falls back to default when trafficType is whitespace', () => { | ||
| const result = transformContext( | ||
| { targetingKey: 'key-1', trafficType: ' ' }, | ||
| defaultTrafficType | ||
| ); | ||
| expect(result.trafficType).toBe('user'); | ||
| }); | ||
|
|
||
| test('passes remaining context as attributes', () => { | ||
| const result = transformContext( | ||
| { | ||
| targetingKey: 'key-1', | ||
| trafficType: 'user', | ||
| region: 'eu', | ||
| plan: 'pro', | ||
| }, | ||
| defaultTrafficType | ||
| ); | ||
| expect(result.attributes).toEqual({ region: 'eu', plan: 'pro' }); | ||
| }); | ||
|
|
||
| test('deep-clones attributes (no reference)', () => { | ||
| const attrs = { nested: { value: 1 } }; | ||
| const result = transformContext( | ||
| { targetingKey: 'k', ...attrs }, | ||
| defaultTrafficType | ||
| ); | ||
| expect(result.attributes).toEqual({ nested: { value: 1 } }); | ||
| expect(result.attributes).not.toBe(attrs); | ||
| expect(result.attributes.nested).not.toBe(attrs.nested); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
| import { FlagNotFoundError, StandardResolutionReasons } from '@openfeature/web-sdk'; | ||
| import { evaluateTreatment } from '../lib/evaluation'; | ||
| import { CONTROL_TREATMENT } from '../lib/types'; | ||
|
|
||
| describe('evaluation', () => { | ||
| describe('evaluateTreatment', () => { | ||
| let mockClient; | ||
|
|
||
| beforeEach(() => { | ||
| mockClient = { | ||
| getTreatmentWithConfig: jest.fn((flagKey, attributes) => ({ | ||
| treatment: 'v1', | ||
| config: '{"x":1}', | ||
| })), | ||
| }; | ||
| }); | ||
|
|
||
| test('returns resolution details with value, variant, flagMetadata, reason', () => { | ||
| const consumer = { targetingKey: 'u1', trafficType: 'user', attributes: {} }; | ||
| const result = evaluateTreatment(mockClient, 'my-flag', consumer); | ||
|
|
||
| expect(result.value).toBe('v1'); | ||
| expect(result.variant).toBe('v1'); | ||
| expect(result.flagMetadata).toEqual({ config: '{"x":1}' }); | ||
| expect(result.reason).toBe(StandardResolutionReasons.TARGETING_MATCH); | ||
| expect(mockClient.getTreatmentWithConfig).toHaveBeenCalledWith('my-flag', {}); | ||
| }); | ||
|
|
||
| test('calls getTreatmentWithConfig with consumer attributes', () => { | ||
| const consumer = { | ||
| targetingKey: 'u1', | ||
| trafficType: 'account', | ||
| attributes: { region: 'eu', plan: 'pro' }, | ||
| }; | ||
| evaluateTreatment(mockClient, 'flag', consumer); | ||
| expect(mockClient.getTreatmentWithConfig).toHaveBeenCalledWith('flag', { | ||
| region: 'eu', | ||
| plan: 'pro', | ||
| }); | ||
| }); | ||
|
|
||
| test('uses empty string for config when config is falsy', () => { | ||
| mockClient.getTreatmentWithConfig.mockReturnValue({ treatment: 'on', config: null }); | ||
| const result = evaluateTreatment(mockClient, 'f', { | ||
| targetingKey: undefined, | ||
| trafficType: 'user', | ||
| attributes: {}, | ||
| }); | ||
| expect(result.flagMetadata.config).toBe(''); | ||
| }); | ||
|
|
||
| test('throws FlagNotFoundError when flagKey is null', () => { | ||
| const consumer = { targetingKey: 'u1', trafficType: 'user', attributes: {} }; | ||
| expect(() => evaluateTreatment(mockClient, null, consumer)).toThrow(FlagNotFoundError); | ||
| expect(() => evaluateTreatment(mockClient, null, consumer)).toThrow( | ||
| /flagKey must be a non-empty string/ | ||
| ); | ||
| }); | ||
|
|
||
| test('throws FlagNotFoundError when flagKey is empty string', () => { | ||
| const consumer = { targetingKey: 'u1', trafficType: 'user', attributes: {} }; | ||
| expect(() => evaluateTreatment(mockClient, '', consumer)).toThrow(FlagNotFoundError); | ||
| }); | ||
|
|
||
| test('throws FlagNotFoundError when treatment is control', () => { | ||
| mockClient.getTreatmentWithConfig.mockReturnValue({ | ||
| treatment: CONTROL_TREATMENT, | ||
| config: '', | ||
| }); | ||
| const consumer = { targetingKey: 'u1', trafficType: 'user', attributes: {} }; | ||
| expect(() => evaluateTreatment(mockClient, 'flag', consumer)).toThrow(FlagNotFoundError); | ||
| expect(() => evaluateTreatment(mockClient, 'flag', consumer)).toThrow(/control/); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.