@datadog/mobile-react-native-openfeature 3.9.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -10
- package/lib/commonjs/datadogCoreProvider.js +129 -0
- package/lib/commonjs/datadogCoreProvider.js.map +1 -0
- package/lib/commonjs/offlineEvaluation.js +198 -0
- package/lib/commonjs/offlineEvaluation.js.map +1 -0
- package/lib/commonjs/offlineProvider.js +44 -8
- package/lib/commonjs/offlineProvider.js.map +1 -1
- package/lib/commonjs/rules-based.js +62 -0
- package/lib/commonjs/rules-based.js.map +1 -0
- package/lib/module/datadogCoreProvider.js +122 -0
- package/lib/module/datadogCoreProvider.js.map +1 -0
- package/lib/module/offlineEvaluation.js +192 -0
- package/lib/module/offlineEvaluation.js.map +1 -0
- package/lib/module/offlineProvider.js +45 -9
- package/lib/module/offlineProvider.js.map +1 -1
- package/lib/module/rules-based.js +50 -0
- package/lib/module/rules-based.js.map +1 -0
- package/lib/typescript/core/src/config/FileBasedConfiguration.d.ts.map +1 -1
- package/lib/typescript/core/src/config/FileBasedConfiguration.type.d.ts +2 -0
- package/lib/typescript/core/src/config/FileBasedConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/core/src/config/async/AutoInstrumentationConfiguration.d.ts +4 -0
- package/lib/typescript/core/src/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
- package/lib/typescript/core/src/config/async/PartialInitializationConfiguration.d.ts +2 -0
- package/lib/typescript/core/src/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
- package/lib/typescript/core/src/config/features/RumConfiguration.d.ts +4 -0
- package/lib/typescript/core/src/config/features/RumConfiguration.d.ts.map +1 -1
- package/lib/typescript/core/src/config/features/RumConfiguration.type.d.ts +21 -0
- package/lib/typescript/core/src/config/features/RumConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/core/src/config/features/RumConfigurationNative.d.ts +2 -0
- package/lib/typescript/core/src/config/features/RumConfigurationNative.d.ts.map +1 -1
- package/lib/typescript/core/src/flags/FlagsClient.d.ts +38 -1
- package/lib/typescript/core/src/flags/FlagsClient.d.ts.map +1 -1
- package/lib/typescript/core/src/flags/internal.d.ts +1 -0
- package/lib/typescript/core/src/flags/internal.d.ts.map +1 -1
- package/lib/typescript/core/src/flags/types.d.ts +1 -1
- package/lib/typescript/core/src/flags/types.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/DdRum.d.ts +1 -0
- package/lib/typescript/core/src/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/types.d.ts +6 -0
- package/lib/typescript/core/src/rum/types.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/AccountInfoSingleton/AccountInfoSingleton.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
- package/lib/typescript/core/src/specs/NativeDdRum.d.ts +6 -0
- package/lib/typescript/core/src/specs/NativeDdRum.d.ts.map +1 -1
- package/lib/typescript/core/src/version.d.ts +1 -1
- package/lib/typescript/core/src/version.d.ts.map +1 -1
- package/lib/typescript/react-native-openfeature/src/datadogCoreProvider.d.ts +31 -0
- package/lib/typescript/react-native-openfeature/src/datadogCoreProvider.d.ts.map +1 -0
- package/lib/typescript/react-native-openfeature/src/index.d.ts +1 -0
- package/lib/typescript/react-native-openfeature/src/index.d.ts.map +1 -1
- package/lib/typescript/react-native-openfeature/src/offlineEvaluation.d.ts +33 -0
- package/lib/typescript/react-native-openfeature/src/offlineEvaluation.d.ts.map +1 -0
- package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts +14 -8
- package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts.map +1 -1
- package/lib/typescript/react-native-openfeature/src/rules-based.d.ts +17 -0
- package/lib/typescript/react-native-openfeature/src/rules-based.d.ts.map +1 -0
- package/package.json +8 -4
- package/rules-based/package.json +7 -0
- package/src/__tests__/__utils__/coreConfiguration.ts +84 -0
- package/src/__tests__/datadogCoreProvider.integration.test.ts +230 -0
- package/src/__tests__/datadogCoreProvider.test.ts +587 -0
- package/src/__tests__/entrypoints.test.ts +35 -0
- package/src/__tests__/offlineProvider.delegation.test.ts +795 -0
- package/src/__tests__/offlineProvider.test.ts +74 -10
- package/src/datadogCoreProvider.ts +223 -0
- package/src/index.ts +1 -0
- package/src/offlineEvaluation.ts +295 -0
- package/src/offlineProvider.ts +64 -13
- package/src/rules-based.ts +58 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FlagsConfiguration } from '@datadog/flagging-core';
|
|
2
|
+
import { DatadogCoreEvaluationProvider } from './datadogCoreProvider';
|
|
3
|
+
export { configurationFromString as coreConfigurationFromString } from '@datadog/flagging-core/rules-based';
|
|
4
|
+
export type { FlagsConfiguration } from '@datadog/flagging-core';
|
|
5
|
+
/**
|
|
6
|
+
* Evaluates manually supplied precomputed or rules-based configurations in JavaScript using
|
|
7
|
+
* @datadog/flagging-core. Ported from openfeature-js-client's browser DatadogCoreProvider.
|
|
8
|
+
*
|
|
9
|
+
* Unlike the native-backed providers, this provider does not use DdFlags, fetch configuration,
|
|
10
|
+
* or send exposure/RUM events. Load a configuration before registering it with OpenFeature.
|
|
11
|
+
* Precomputed configurations require a matching OpenFeature context, including when it is empty.
|
|
12
|
+
*/
|
|
13
|
+
export declare class DatadogCoreProvider extends DatadogCoreEvaluationProvider {
|
|
14
|
+
private fallbackConfigurationSequence;
|
|
15
|
+
protected computeConfigurationId(configuration: FlagsConfiguration): string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=rules-based.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules-based.d.ts","sourceRoot":"","sources":["../../../../src/rules-based.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAGtE,OAAO,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAC5G,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,6BAA6B;IAClE,OAAO,CAAC,6BAA6B,CAAK;IAE1C,SAAS,CAAC,sBAAsB,CAC5B,aAAa,EAAE,kBAAkB,GAClC,MAAM;CA4BZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native-openfeature",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "A client-side React Native module to provide OpenFeature integration with Datadog Feature Flags",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"main": "lib/commonjs/index",
|
|
24
24
|
"files": [
|
|
25
25
|
"src/**",
|
|
26
|
-
"lib/**"
|
|
26
|
+
"lib/**",
|
|
27
|
+
"rules-based/package.json"
|
|
27
28
|
],
|
|
28
29
|
"types": "lib/typescript/react-native-openfeature/src/index.d.ts",
|
|
29
30
|
"react-native": "src/index",
|
|
@@ -37,8 +38,11 @@
|
|
|
37
38
|
"lint": "eslint .",
|
|
38
39
|
"prepare": "rm -rf lib && yarn bob build"
|
|
39
40
|
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@datadog/flagging-core": "3.1.1"
|
|
43
|
+
},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"@datadog/mobile-react-native": "^3.
|
|
45
|
+
"@datadog/mobile-react-native": "^3.11.0",
|
|
42
46
|
"@openfeature/core": "^1.9.2",
|
|
43
47
|
"@openfeature/web-sdk": "^1.8.0",
|
|
44
48
|
"@testing-library/react-native": "7.0.2",
|
|
@@ -83,5 +87,5 @@
|
|
|
83
87
|
]
|
|
84
88
|
]
|
|
85
89
|
},
|
|
86
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "740f7bb57bf494788159bc5b6f7d9fd2673c3879"
|
|
87
91
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { configurationFromString } from '@datadog/flagging-core/rules-based';
|
|
8
|
+
import type {
|
|
9
|
+
PrecomputedConfiguration,
|
|
10
|
+
RulesConfiguration
|
|
11
|
+
} from '@datadog/flagging-core';
|
|
12
|
+
|
|
13
|
+
// Adapted from openfeature-js-client/packages/browser/test/data/rules-v1-wire.json.
|
|
14
|
+
// Targets country=US with a logged true/on allocation; the unlogged fallback returns false/off.
|
|
15
|
+
export const rulesWire = JSON.stringify({
|
|
16
|
+
version: 1,
|
|
17
|
+
rules: {
|
|
18
|
+
etag: 'rules-etag',
|
|
19
|
+
response:
|
|
20
|
+
'CgASBHByb2QabQoJdGVzdC1mbGFnEmAQBBoCKAEaBAgBKAAiKgoKYWxsb2NhdGlvbhAAGgwSCgoEc2FsdBABGGQiCgoECAAQZBgHIAEoASImCghmYWxsYmFjaxoMEgoKBHNhbHQQARhkIgwKBAgAEGQQARgHIAIiBhIECgIIAyICCgAqAm9uKgNvZmYqAlVTKgdjb3VudHJ5MgReVVMkOgkKATEKATIKATNKBSoDEgEC'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const rulesConfiguration = (): { rules: RulesConfiguration } => {
|
|
25
|
+
const configuration = configurationFromString(rulesWire);
|
|
26
|
+
if (!configuration.rules) {
|
|
27
|
+
throw new Error('Invalid rules fixture');
|
|
28
|
+
}
|
|
29
|
+
return { rules: configuration.rules };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const matchingContext = { targetingKey: 'user-1', country: 'US' };
|
|
33
|
+
|
|
34
|
+
export const precomputedConfiguration = (): {
|
|
35
|
+
precomputed: PrecomputedConfiguration;
|
|
36
|
+
} => ({
|
|
37
|
+
precomputed: {
|
|
38
|
+
context: matchingContext,
|
|
39
|
+
response: {
|
|
40
|
+
data: {
|
|
41
|
+
attributes: {
|
|
42
|
+
createdAt: '2026-07-06T23:01:56.822Z',
|
|
43
|
+
flags: {
|
|
44
|
+
'boolean-flag': {
|
|
45
|
+
allocationKey: 'allocation',
|
|
46
|
+
variationKey: 'on',
|
|
47
|
+
variationType: 'boolean',
|
|
48
|
+
variationValue: true,
|
|
49
|
+
reason: 'TARGETING_MATCH',
|
|
50
|
+
doLog: true
|
|
51
|
+
},
|
|
52
|
+
'string-flag': {
|
|
53
|
+
allocationKey: 'allocation',
|
|
54
|
+
variationKey: 'greeting',
|
|
55
|
+
variationType: 'string',
|
|
56
|
+
variationValue: 'hello',
|
|
57
|
+
reason: 'STATIC',
|
|
58
|
+
doLog: false
|
|
59
|
+
},
|
|
60
|
+
'number-flag': {
|
|
61
|
+
allocationKey: 'allocation',
|
|
62
|
+
variationKey: 'amount',
|
|
63
|
+
variationType: 'number',
|
|
64
|
+
variationValue: 3.14,
|
|
65
|
+
reason: 'STATIC',
|
|
66
|
+
doLog: false
|
|
67
|
+
},
|
|
68
|
+
'object-flag': {
|
|
69
|
+
allocationKey: 'allocation',
|
|
70
|
+
variationKey: 'settings',
|
|
71
|
+
variationType: 'object',
|
|
72
|
+
variationValue: {
|
|
73
|
+
nested: { enabled: true },
|
|
74
|
+
list: [1, 2]
|
|
75
|
+
},
|
|
76
|
+
reason: 'STATIC',
|
|
77
|
+
doLog: false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { configurationToString } from '@datadog/flagging-core/rules-based';
|
|
8
|
+
import type { EvaluationContext } from '@openfeature/web-sdk';
|
|
9
|
+
import {
|
|
10
|
+
ErrorCode,
|
|
11
|
+
OpenFeature,
|
|
12
|
+
ProviderEvents,
|
|
13
|
+
ProviderStatus
|
|
14
|
+
} from '@openfeature/web-sdk';
|
|
15
|
+
|
|
16
|
+
// Exercise the public exports, the real pinned evaluator, and the real OpenFeature lifecycle.
|
|
17
|
+
import {
|
|
18
|
+
coreConfigurationFromString,
|
|
19
|
+
DatadogCoreProvider
|
|
20
|
+
} from '../rules-based';
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
matchingContext,
|
|
24
|
+
precomputedConfiguration,
|
|
25
|
+
rulesWire
|
|
26
|
+
} from './__utils__/coreConfiguration';
|
|
27
|
+
|
|
28
|
+
const DOMAIN = 'datadog-core-test';
|
|
29
|
+
|
|
30
|
+
const precomputedProvider = (): DatadogCoreProvider => {
|
|
31
|
+
const provider = new DatadogCoreProvider();
|
|
32
|
+
provider.setConfiguration(
|
|
33
|
+
coreConfigurationFromString(
|
|
34
|
+
configurationToString(precomputedConfiguration())
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
return provider;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe('DatadogCoreProvider with OpenFeature', () => {
|
|
41
|
+
afterEach(async () => {
|
|
42
|
+
await OpenFeature.clearProviders();
|
|
43
|
+
await OpenFeature.clearContext(DOMAIN);
|
|
44
|
+
await OpenFeature.clearContext();
|
|
45
|
+
OpenFeature.clearHandlers();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('registers precomputed configuration and resolves every flag type without enabling DdFlags', async () => {
|
|
49
|
+
await OpenFeature.setProviderAndWait(
|
|
50
|
+
DOMAIN,
|
|
51
|
+
precomputedProvider(),
|
|
52
|
+
matchingContext
|
|
53
|
+
);
|
|
54
|
+
const client = OpenFeature.getClient(DOMAIN);
|
|
55
|
+
expect(client.providerStatus).toBe(ProviderStatus.READY);
|
|
56
|
+
expect(client.getBooleanValue('boolean-flag', false)).toBe(true);
|
|
57
|
+
expect(client.getStringValue('string-flag', 'default')).toBe('hello');
|
|
58
|
+
expect(client.getNumberValue('number-flag', 0)).toBe(3.14);
|
|
59
|
+
expect(client.getObjectValue('object-flag', {})).toEqual({
|
|
60
|
+
nested: { enabled: true },
|
|
61
|
+
list: [1, 2]
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('parses rules via the public helper and reevaluates when the OpenFeature context changes', async () => {
|
|
66
|
+
const provider = new DatadogCoreProvider();
|
|
67
|
+
provider.setConfiguration(coreConfigurationFromString(rulesWire));
|
|
68
|
+
await OpenFeature.setProviderAndWait(DOMAIN, provider, {
|
|
69
|
+
targetingKey: 'user-1',
|
|
70
|
+
country: 'CA'
|
|
71
|
+
});
|
|
72
|
+
const client = OpenFeature.getClient(DOMAIN);
|
|
73
|
+
expect(client.getBooleanDetails('test-flag', false)).toMatchObject({
|
|
74
|
+
value: false,
|
|
75
|
+
variant: 'off',
|
|
76
|
+
reason: 'SPLIT'
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
await OpenFeature.setContext(DOMAIN, matchingContext);
|
|
80
|
+
expect(client.providerStatus).toBe(ProviderStatus.READY);
|
|
81
|
+
expect(client.getBooleanDetails('test-flag', false)).toMatchObject({
|
|
82
|
+
value: true,
|
|
83
|
+
reason: 'TARGETING_MATCH'
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it.each([
|
|
88
|
+
{},
|
|
89
|
+
{ country: 'CA' },
|
|
90
|
+
{ targetingKey: undefined, country: 'CA' },
|
|
91
|
+
{ targetingKey: null, country: 'CA' }
|
|
92
|
+
])(
|
|
93
|
+
'keeps missing/null subjects distinct from explicit empty keys for rules: %j',
|
|
94
|
+
async context => {
|
|
95
|
+
const provider = new DatadogCoreProvider();
|
|
96
|
+
provider.setConfiguration(coreConfigurationFromString(rulesWire));
|
|
97
|
+
await OpenFeature.setProviderAndWait(
|
|
98
|
+
DOMAIN,
|
|
99
|
+
provider,
|
|
100
|
+
(context as unknown) as EvaluationContext
|
|
101
|
+
);
|
|
102
|
+
const client = OpenFeature.getClient(DOMAIN);
|
|
103
|
+
expect(client.getBooleanDetails('test-flag', true)).toMatchObject({
|
|
104
|
+
value: true,
|
|
105
|
+
reason: 'ERROR',
|
|
106
|
+
errorCode: ErrorCode.TARGETING_KEY_MISSING
|
|
107
|
+
});
|
|
108
|
+
await OpenFeature.setContext(DOMAIN, {
|
|
109
|
+
targetingKey: '',
|
|
110
|
+
country: 'CA'
|
|
111
|
+
});
|
|
112
|
+
expect(client.getBooleanDetails('test-flag', true)).toMatchObject({
|
|
113
|
+
value: false,
|
|
114
|
+
reason: 'SPLIT'
|
|
115
|
+
});
|
|
116
|
+
await OpenFeature.setContext(DOMAIN, {});
|
|
117
|
+
expect(client.getBooleanDetails('test-flag', true).errorCode).toBe(
|
|
118
|
+
ErrorCode.TARGETING_KEY_MISSING
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
it('enters ERROR on mismatching or cleared contexts and recovers on a matching context', async () => {
|
|
124
|
+
await OpenFeature.setProviderAndWait(
|
|
125
|
+
DOMAIN,
|
|
126
|
+
precomputedProvider(),
|
|
127
|
+
matchingContext
|
|
128
|
+
);
|
|
129
|
+
const client = OpenFeature.getClient(DOMAIN);
|
|
130
|
+
await OpenFeature.setContext(DOMAIN, { targetingKey: 'other' });
|
|
131
|
+
expect(client.providerStatus).toBe(ProviderStatus.ERROR);
|
|
132
|
+
expect(client.getBooleanDetails('boolean-flag', false)).toMatchObject({
|
|
133
|
+
value: false,
|
|
134
|
+
errorCode: ErrorCode.INVALID_CONTEXT
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
await OpenFeature.setContext(DOMAIN, matchingContext);
|
|
138
|
+
expect(client.providerStatus).toBe(ProviderStatus.READY);
|
|
139
|
+
expect(client.getBooleanValue('boolean-flag', false)).toBe(true);
|
|
140
|
+
|
|
141
|
+
await OpenFeature.clearContext(DOMAIN);
|
|
142
|
+
expect(client.providerStatus).toBe(ProviderStatus.ERROR);
|
|
143
|
+
expect(client.getBooleanDetails('boolean-flag', false)).toMatchObject({
|
|
144
|
+
value: false,
|
|
145
|
+
errorCode: ErrorCode.INVALID_CONTEXT
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('recovers from missing configuration via setConfiguration after initialization settles', async () => {
|
|
150
|
+
const provider = new DatadogCoreProvider();
|
|
151
|
+
await expect(
|
|
152
|
+
OpenFeature.setProviderAndWait(DOMAIN, provider, matchingContext)
|
|
153
|
+
).rejects.toMatchObject({ code: ErrorCode.PROVIDER_NOT_READY });
|
|
154
|
+
const client = OpenFeature.getClient(DOMAIN);
|
|
155
|
+
expect(client.providerStatus).toBe(ProviderStatus.ERROR);
|
|
156
|
+
|
|
157
|
+
provider.setConfiguration(precomputedConfiguration());
|
|
158
|
+
expect(client.providerStatus).toBe(ProviderStatus.READY);
|
|
159
|
+
expect(client.getBooleanValue('boolean-flag', false)).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('propagates parse errors from configuration replacement, then recovers and serves new values', async () => {
|
|
163
|
+
const provider = precomputedProvider();
|
|
164
|
+
await OpenFeature.setProviderAndWait(DOMAIN, provider, matchingContext);
|
|
165
|
+
const client = OpenFeature.getClient(DOMAIN);
|
|
166
|
+
const changed = jest.fn();
|
|
167
|
+
client.addHandler(ProviderEvents.ConfigurationChanged, changed);
|
|
168
|
+
provider.setConfiguration(coreConfigurationFromString('not json'));
|
|
169
|
+
expect(client.providerStatus).toBe(ProviderStatus.ERROR);
|
|
170
|
+
expect(client.getBooleanDetails('boolean-flag', false)).toMatchObject({
|
|
171
|
+
value: false,
|
|
172
|
+
errorCode: ErrorCode.PARSE_ERROR
|
|
173
|
+
});
|
|
174
|
+
expect(changed).not.toHaveBeenCalled();
|
|
175
|
+
|
|
176
|
+
const replacement = precomputedConfiguration();
|
|
177
|
+
replacement.precomputed.response.data.attributes.flags[
|
|
178
|
+
'string-flag'
|
|
179
|
+
].variationValue = 'updated';
|
|
180
|
+
provider.setConfiguration(replacement);
|
|
181
|
+
expect(client.providerStatus).toBe(ProviderStatus.READY);
|
|
182
|
+
expect(client.getStringValue('string-flag', 'default')).toBe('updated');
|
|
183
|
+
expect(changed).toHaveBeenCalledTimes(1);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('recovers with a replacement matching the current context after a context error', async () => {
|
|
187
|
+
const provider = precomputedProvider();
|
|
188
|
+
await OpenFeature.setProviderAndWait(DOMAIN, provider, matchingContext);
|
|
189
|
+
await OpenFeature.setContext(DOMAIN, { targetingKey: 'other' });
|
|
190
|
+
const replacement = precomputedConfiguration();
|
|
191
|
+
replacement.precomputed.context = { targetingKey: 'other' };
|
|
192
|
+
provider.setConfiguration(replacement);
|
|
193
|
+
const client = OpenFeature.getClient(DOMAIN);
|
|
194
|
+
expect(client.providerStatus).toBe(ProviderStatus.READY);
|
|
195
|
+
expect(client.getBooleanValue('boolean-flag', false)).toBe(true);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('keeps providers in different domains independent', async () => {
|
|
199
|
+
const otherDomain = 'datadog-core-other';
|
|
200
|
+
const provider = precomputedProvider();
|
|
201
|
+
const otherProvider = precomputedProvider();
|
|
202
|
+
try {
|
|
203
|
+
await OpenFeature.setProviderAndWait(
|
|
204
|
+
DOMAIN,
|
|
205
|
+
provider,
|
|
206
|
+
matchingContext
|
|
207
|
+
);
|
|
208
|
+
await OpenFeature.setProviderAndWait(
|
|
209
|
+
otherDomain,
|
|
210
|
+
otherProvider,
|
|
211
|
+
matchingContext
|
|
212
|
+
);
|
|
213
|
+
provider.setConfiguration({});
|
|
214
|
+
expect(OpenFeature.getClient(DOMAIN).providerStatus).toBe(
|
|
215
|
+
ProviderStatus.ERROR
|
|
216
|
+
);
|
|
217
|
+
expect(OpenFeature.getClient(otherDomain).providerStatus).toBe(
|
|
218
|
+
ProviderStatus.READY
|
|
219
|
+
);
|
|
220
|
+
expect(
|
|
221
|
+
OpenFeature.getClient(otherDomain).getBooleanValue(
|
|
222
|
+
'boolean-flag',
|
|
223
|
+
false
|
|
224
|
+
)
|
|
225
|
+
).toBe(true);
|
|
226
|
+
} finally {
|
|
227
|
+
await OpenFeature.clearContext(otherDomain);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|