@datadog/mobile-react-native-openfeature 3.9.0 → 3.10.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/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,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
|
+
});
|