-
Notifications
You must be signed in to change notification settings - Fork 0
feat: buildAndInit for isolated client instances #166
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
e20ef73
50e66aa
de9f653
fa5baab
953c4e4
159df11
a73bf0c
7e5abe1
92cdd1d
c4b2717
ddab6c0
d55d23d
3c18bc9
4b8077f
621cccb
ed3c4ce
5f96888
228e1e4
4d35d4f
cf3c2ba
132c0a5
6141581
82ec342
81ff3b1
fad43d3
febb3f8
212e26e
a943e90
ba219f2
5333574
aab1009
f93fa61
030aa33
e61ec6c
a000205
6f1a68e
654ffaa
74498b9
9176d21
a179e32
0734752
fb76db9
a384132
3ae0ec7
98bd24a
2d45fe5
5d3cabc
2712f6b
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 |
---|---|---|
|
@@ -60,7 +60,7 @@ | |
"webpack-cli": "^6.0.1" | ||
}, | ||
"dependencies": { | ||
"@eppo/js-client-sdk-common": "4.8.4" | ||
"@eppo/js-client-sdk-common": "4.9.0" | ||
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { | ||
IConfigurationStore, | ||
ObfuscatedFlag, | ||
Flag, | ||
EventDispatcher, | ||
} from '@eppo/js-client-sdk-common'; | ||
import * as td from 'testdouble'; | ||
|
||
import { clientOptionsToParameters } from './client-options-converter'; | ||
import { IClientOptions } from './i-client-config'; | ||
import { sdkName, sdkVersion } from './sdk-data'; | ||
|
||
describe('clientOptionsToParameters', () => { | ||
const mockStore = td.object<IConfigurationStore<Flag | ObfuscatedFlag>>(); | ||
|
||
it('converts basic client options', () => { | ||
const options: IClientOptions = { | ||
sdkKey: 'test-key', | ||
baseUrl: 'https://test.eppo.cloud', | ||
assignmentLogger: { logAssignment: jest.fn() }, | ||
}; | ||
|
||
const result = clientOptionsToParameters(options, mockStore); | ||
|
||
expect(result.isObfuscated).toBe(true); | ||
expect(result.flagConfigurationStore).toBeDefined(); | ||
expect(result.configurationRequestParameters).toEqual({ | ||
apiKey: 'test-key', | ||
baseUrl: 'https://test.eppo.cloud', | ||
sdkName, | ||
sdkVersion, | ||
numInitialRequestRetries: undefined, | ||
numPollRequestRetries: undefined, | ||
pollingIntervalMs: undefined, | ||
requestTimeoutMs: undefined, | ||
pollAfterFailedInitialization: undefined, | ||
pollAfterSuccessfulInitialization: undefined, | ||
throwOnFailedInitialization: undefined, | ||
skipInitialPoll: undefined, | ||
}); | ||
}); | ||
|
||
it('uses provided flag configuration store', () => { | ||
const options: IClientOptions = { | ||
sdkKey: 'test-key', | ||
assignmentLogger: { logAssignment: jest.fn() }, | ||
}; | ||
|
||
const result = clientOptionsToParameters(options, mockStore); | ||
|
||
expect(result.flagConfigurationStore).toBe(mockStore); | ||
}); | ||
|
||
it('converts client options with event ingestion config', () => { | ||
const options: IClientOptions = { | ||
sdkKey: 'test-key', | ||
assignmentLogger: { logAssignment: jest.fn() }, | ||
}; | ||
const mockDispatcher: EventDispatcher = td.object<EventDispatcher>(); | ||
|
||
const result = clientOptionsToParameters(options, mockStore, mockDispatcher); | ||
|
||
expect(result.eventDispatcher).toBeDefined(); | ||
}); | ||
|
||
it('converts client options with polling configuration', () => { | ||
const options: IClientOptions = { | ||
sdkKey: 'test-key', | ||
assignmentLogger: { logAssignment: jest.fn() }, | ||
pollingIntervalMs: 30000, | ||
pollAfterSuccessfulInitialization: true, | ||
pollAfterFailedInitialization: true, | ||
skipInitialRequest: true, | ||
}; | ||
|
||
const result = clientOptionsToParameters(options, mockStore); | ||
|
||
expect(result.configurationRequestParameters).toMatchObject({ | ||
pollingIntervalMs: 30000, | ||
pollAfterSuccessfulInitialization: true, | ||
pollAfterFailedInitialization: true, | ||
skipInitialPoll: true, | ||
}); | ||
}); | ||
|
||
it('converts client options with retry configuration', () => { | ||
const options: IClientOptions = { | ||
sdkKey: 'test-key', | ||
assignmentLogger: { logAssignment: jest.fn() }, | ||
requestTimeoutMs: 5000, | ||
numInitialRequestRetries: 3, | ||
numPollRequestRetries: 2, | ||
}; | ||
|
||
const result = clientOptionsToParameters(options, mockStore); | ||
|
||
expect(result.configurationRequestParameters).toMatchObject({ | ||
requestTimeoutMs: 5000, | ||
numInitialRequestRetries: 3, | ||
numPollRequestRetries: 2, | ||
}); | ||
}); | ||
|
||
it('handles undefined optional parameters', () => { | ||
const options: IClientOptions = { | ||
sdkKey: 'test-key', | ||
assignmentLogger: { logAssignment: jest.fn() }, | ||
}; | ||
|
||
const result = clientOptionsToParameters(options, mockStore); | ||
|
||
expect(result.configurationRequestParameters).toMatchObject({ | ||
baseUrl: undefined, | ||
pollingIntervalMs: undefined, | ||
requestTimeoutMs: undefined, | ||
numInitialRequestRetries: undefined, | ||
numPollRequestRetries: undefined, | ||
}); | ||
}); | ||
|
||
it('includes sdk metadata', () => { | ||
const options: IClientOptions = { | ||
sdkKey: 'test-key', | ||
assignmentLogger: { logAssignment: jest.fn() }, | ||
}; | ||
|
||
const result = clientOptionsToParameters(options, mockStore); | ||
|
||
expect(result.configurationRequestParameters).toMatchObject({ | ||
sdkName, | ||
sdkVersion, | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
BanditParameters, | ||
Check warning on line 2 in src/client-options-converter.ts
|
||
BanditVariation, EppoClientParameters, | ||
Check warning on line 3 in src/client-options-converter.ts
|
||
EventDispatcher, | ||
Flag, | ||
FlagConfigurationRequestParameters, | ||
Check warning on line 6 in src/client-options-converter.ts
|
||
IConfigurationStore, | ||
ObfuscatedFlag, | ||
Check warning on line 8 in src/client-options-converter.ts
|
||
} from '@eppo/js-client-sdk-common'; | ||
|
||
import { IClientOptions } from './i-client-config'; | ||
import { sdkName, sdkVersion } from './sdk-data'; | ||
|
||
/** | ||
* Converts IClientOptions to EppoClientParameters | ||
* @internal | ||
*/ | ||
export function clientOptionsToParameters( | ||
options: IClientOptions, | ||
flagConfigurationStore: IConfigurationStore<Flag>, | ||
eventDispatcher?: EventDispatcher, | ||
): EppoClientParameters { | ||
const parameters: EppoClientParameters = { | ||
flagConfigurationStore, | ||
isObfuscated: true, | ||
}; | ||
|
||
parameters.eventDispatcher = eventDispatcher; | ||
|
||
// Always include configuration request parameters | ||
parameters.configurationRequestParameters = { | ||
apiKey: options.sdkKey, | ||
sdkVersion, // dynamically picks up version. | ||
sdkName, // Hardcoded to `js-client-sdk` | ||
baseUrl: options.baseUrl, | ||
requestTimeoutMs: options.requestTimeoutMs, | ||
numInitialRequestRetries: options.numInitialRequestRetries, | ||
numPollRequestRetries: options.numPollRequestRetries, | ||
pollAfterSuccessfulInitialization: options.pollAfterSuccessfulInitialization, | ||
pollAfterFailedInitialization: options.pollAfterFailedInitialization, | ||
pollingIntervalMs: options.pollingIntervalMs, | ||
throwOnFailedInitialization: options.throwOnFailedInitialization, | ||
skipInitialPoll: options.skipInitialRequest, | ||
}; | ||
typotter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return parameters; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.