Skip to content

Commit 498050d

Browse files
committed
preserve initial flags configuration API
1 parent 49caa72 commit 498050d

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

packages/browser/src/domain/configuration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export interface FlaggingInitConfiguration extends InitConfiguration {
1414
*/
1515
applicationId?: string
1616

17+
/**
18+
* Initial flags configuration (precomputed flags)
19+
*/
20+
initialFlagsConfiguration?: FlagsConfiguration
21+
1722
/**
1823
* RUM integration options
1924
* @deprecated Use enableExposureLogging instead. RUM-based exposure tracking will be removed in a future version.

packages/browser/src/openfeature/provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class DatadogProvider extends DatadogCoreProvider {
133133
this.flagsCache = new IndexedDBFlagsCache(options.clientToken)
134134
}
135135

136+
this.flagsConfiguration = options.initialFlagsConfiguration || {}
136137
this.status = ProviderStatus.NOT_READY
137138
}
138139

packages/browser/test/openfeature/provider-persistence.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ describe('DatadogProvider IndexedDB persistence', () => {
8888
})
8989

9090
describe('falls back to cached flags on network failure', () => {
91+
it('should preserve initialFlagsConfiguration as an in-memory fallback', async () => {
92+
const context = { targetingKey: 'initial-user' }
93+
const initialFlagsConfiguration: FlagsConfiguration = {
94+
precomputed: {
95+
response: precomputedResponse as any,
96+
context,
97+
fetchedAt: 1731939819456 as TimeStamp,
98+
},
99+
}
100+
global.fetch = failingFetchMock()
101+
const provider = new DatadogProvider({ ...options, initialFlagsConfiguration })
102+
103+
await provider.initialize(context)
104+
105+
expect(provider.status).toBe(ProviderStatus.STALE)
106+
const mockLogger = { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() }
107+
expect(provider.resolveStringEvaluation('string-flag', 'default', {}, mockLogger).value).toBe('red')
108+
})
109+
91110
it('should use IndexedDB cache and enter STALE state when network fails', async () => {
92111
// First: seed IndexedDB with a known config
93112
const context = { targetingKey: 'cached-user' }

0 commit comments

Comments
 (0)