@datadog/mobile-react-native-openfeature 3.7.0 → 3.8.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 +187 -15
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/provider.js +1 -1
- package/lib/commonjs/provider.js.map +1 -1
- package/lib/commonjs/rumContext.js +44 -0
- package/lib/commonjs/rumContext.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/provider.js +1 -1
- package/lib/module/provider.js.map +1 -1
- package/lib/module/rumContext.js +37 -0
- package/lib/module/rumContext.js.map +1 -0
- package/lib/typescript/core/src/flags/internal.d.ts.map +1 -1
- package/lib/typescript/core/src/flags/rumIntegration.d.ts +14 -0
- package/lib/typescript/core/src/flags/rumIntegration.d.ts.map +1 -0
- package/lib/typescript/core/src/index.d.ts +2 -1
- package/lib/typescript/core/src/index.d.ts.map +1 -1
- package/lib/typescript/core/src/version.d.ts +1 -1
- package/lib/typescript/react-native-openfeature/src/index.d.ts +4 -2
- package/lib/typescript/react-native-openfeature/src/index.d.ts.map +1 -1
- package/lib/typescript/react-native-openfeature/src/provider.d.ts.map +1 -1
- package/lib/typescript/react-native-openfeature/src/rumContext.d.ts +23 -0
- package/lib/typescript/react-native-openfeature/src/rumContext.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/__utils__/rumContext.types.ts +55 -0
- package/src/__tests__/__utils__/tsconfig.json +8 -0
- package/src/__tests__/provider.test.ts +30 -0
- package/src/__tests__/rumContext.compatibility.test.ts +122 -0
- package/src/__tests__/rumContext.integration.test.ts +414 -0
- package/src/__tests__/rumContext.test.ts +100 -0
- package/src/__tests__/rumContext.types.test.ts +27 -0
- package/src/index.ts +4 -1
- package/src/provider.ts +5 -3
- package/src/rumContext.ts +54 -0
package/src/index.ts
CHANGED
|
@@ -9,10 +9,13 @@ import { configurationFromString } from '@datadog/mobile-react-native';
|
|
|
9
9
|
import { DatadogOfflineOpenFeatureProvider } from './offlineProvider';
|
|
10
10
|
import { DatadogOpenFeatureProvider } from './provider';
|
|
11
11
|
import type { DatadogOpenFeatureProviderOptions } from './provider';
|
|
12
|
+
import { enrichWithRumUser } from './rumContext';
|
|
13
|
+
import type { EnrichableEvaluationContext } from './rumContext';
|
|
12
14
|
|
|
13
15
|
export {
|
|
14
16
|
DatadogOpenFeatureProvider,
|
|
15
17
|
DatadogOfflineOpenFeatureProvider,
|
|
18
|
+
enrichWithRumUser,
|
|
16
19
|
configurationFromString
|
|
17
20
|
};
|
|
18
|
-
export type { DatadogOpenFeatureProviderOptions };
|
|
21
|
+
export type { DatadogOpenFeatureProviderOptions, EnrichableEvaluationContext };
|
package/src/provider.ts
CHANGED
|
@@ -41,9 +41,11 @@ export class DatadogOpenFeatureProvider extends DatadogCoreOpenFeatureProvider {
|
|
|
41
41
|
const newDdContext = toDdContext(newContext);
|
|
42
42
|
|
|
43
43
|
// Promise chain in case `onContextChange` is called multiple times.
|
|
44
|
-
this.contextChangePromise = this.contextChangePromise
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
this.contextChangePromise = this.contextChangePromise
|
|
45
|
+
.catch(() => undefined)
|
|
46
|
+
.then(() => {
|
|
47
|
+
return this.flagsClient.setEvaluationContext(newDdContext);
|
|
48
|
+
});
|
|
47
49
|
|
|
48
50
|
// Wait for the current context change to complete.
|
|
49
51
|
await this.contextChangePromise;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 * as DatadogSdk from '@datadog/mobile-react-native';
|
|
8
|
+
import type {
|
|
9
|
+
EvaluationContext,
|
|
10
|
+
EvaluationContextValue
|
|
11
|
+
} from '@openfeature/web-sdk';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An application context that permits top-level undefined values to remove RUM defaults.
|
|
15
|
+
* Unlike OpenFeature's EvaluationContext, this input can contain these explicit tombstones.
|
|
16
|
+
* If enrichment cannot run, the context is returned unchanged, including undefined values.
|
|
17
|
+
*/
|
|
18
|
+
export type EnrichableEvaluationContext = {
|
|
19
|
+
targetingKey?: string | undefined;
|
|
20
|
+
} & Record<string, EvaluationContextValue | undefined>;
|
|
21
|
+
|
|
22
|
+
type RumContextEnricher = typeof DatadogSdk.__ddEnrichEvaluationContextWithRumUser;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Explicitly add the current RUM user to an OpenFeature evaluation context.
|
|
26
|
+
*
|
|
27
|
+
* The helper reads the RUM user each time it is called and returns a new context; it does not keep
|
|
28
|
+
* the OpenFeature context synchronized when the RUM user changes. The RUM user ID supplies the
|
|
29
|
+
* targeting key, while flat primitive user properties supply attributes. Application fields take
|
|
30
|
+
* precedence, and an explicitly undefined application field removes the corresponding RUM value
|
|
31
|
+
* from the returned context when enrichment succeeds.
|
|
32
|
+
*
|
|
33
|
+
* If the core SDK's enrichment helper is unavailable, logs a warning and returns the application
|
|
34
|
+
* context unchanged so OpenFeature initialization and evaluation can continue without RUM values.
|
|
35
|
+
*/
|
|
36
|
+
export const enrichWithRumUser = (
|
|
37
|
+
context: EnrichableEvaluationContext
|
|
38
|
+
): EvaluationContext => {
|
|
39
|
+
const enricher = (DatadogSdk as {
|
|
40
|
+
__ddEnrichEvaluationContextWithRumUser?: RumContextEnricher;
|
|
41
|
+
}).__ddEnrichEvaluationContextWithRumUser;
|
|
42
|
+
|
|
43
|
+
if (typeof enricher !== 'function') {
|
|
44
|
+
// InternalLog may also be absent from the core module, or have verbosity disabled.
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.warn(
|
|
47
|
+
'DATADOG: `enrichWithRumUser` could not access the core RUM enrichment helper. Returning the application context unchanged. Check SDK compatibility.'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return context as EvaluationContext;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return enricher(context) as EvaluationContext;
|
|
54
|
+
};
|