@datadog/mobile-react-native 3.5.3 → 3.6.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 +10 -0
- package/android/build.gradle +22 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +23 -4
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +3 -2
- package/android/src/main/kotlin/com/datadog/reactnative/HeatmapActionHandler.kt +121 -0
- package/android/src/main/kotlin/com/datadog/reactnative/HeatmapTouchResolver.kt +108 -0
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +19 -2
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +1 -1
- package/android/src/oldarch/kotlin/com/datadog/reactnative/HeatmapViewResolverFactory.kt +38 -0
- package/android/src/oldarch65/kotlin/com/datadog/reactnative/HeatmapViewResolverFactory.kt +20 -0
- package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdRum.kt +15 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +482 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +94 -49
- package/android/src/test/kotlin/com/datadog/reactnative/HeatmapTouchResolverTest.kt +529 -0
- package/datadog-configuration.schema.json +4 -0
- package/ios/Sources/DdSdk.mm +2 -0
- package/ios/Sources/DdSdkImplementation.swift +0 -1
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +3 -1
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/config/FileBasedConfiguration.js +1 -0
- package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +1 -0
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/commonjs/config/features/RumConfiguration.js +4 -0
- package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
- package/lib/commonjs/flags/FlagsClient.js +268 -3
- package/lib/commonjs/flags/FlagsClient.js.map +1 -1
- package/lib/commonjs/flags/configuration/context.js +70 -0
- package/lib/commonjs/flags/configuration/context.js.map +1 -0
- package/lib/commonjs/flags/configuration/index.js +39 -0
- package/lib/commonjs/flags/configuration/index.js.map +1 -0
- package/lib/commonjs/flags/configuration/precomputed.js +172 -0
- package/lib/commonjs/flags/configuration/precomputed.js.map +1 -0
- package/lib/commonjs/flags/configuration/types.js +33 -0
- package/lib/commonjs/flags/configuration/types.js.map +1 -0
- package/lib/commonjs/flags/configuration/wire.js +19 -0
- package/lib/commonjs/flags/configuration/wire.js.map +1 -0
- package/lib/commonjs/flags/internal.js +7 -3
- package/lib/commonjs/flags/internal.js.map +1 -1
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +27 -13
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +270 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +38 -72
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js +33 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +39 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.js +4 -4
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.js +0 -18
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js +109 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.js +0 -9
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +3 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/config/FileBasedConfiguration.js +1 -0
- package/lib/module/config/FileBasedConfiguration.js.map +1 -1
- package/lib/module/config/async/AutoInstrumentationConfiguration.js +1 -0
- package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/module/config/features/RumConfiguration.js +4 -0
- package/lib/module/config/features/RumConfiguration.js.map +1 -1
- package/lib/module/flags/FlagsClient.js +268 -3
- package/lib/module/flags/FlagsClient.js.map +1 -1
- package/lib/module/flags/configuration/context.js +62 -0
- package/lib/module/flags/configuration/context.js.map +1 -0
- package/lib/module/flags/configuration/index.js +18 -0
- package/lib/module/flags/configuration/index.js.map +1 -0
- package/lib/module/flags/configuration/precomputed.js +165 -0
- package/lib/module/flags/configuration/precomputed.js.map +1 -0
- package/lib/module/flags/configuration/types.js +27 -0
- package/lib/module/flags/configuration/types.js.map +1 -0
- package/lib/module/flags/configuration/wire.js +13 -0
- package/lib/module/flags/configuration/wire.js.map +1 -0
- package/lib/module/flags/internal.js +7 -3
- package/lib/module/flags/internal.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +27 -13
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +263 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +38 -72
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js +25 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +32 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.js +4 -4
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.js +0 -18
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js +101 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.js +0 -9
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts +1 -0
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +2 -0
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.d.ts +2 -0
- package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.type.d.ts +7 -0
- package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/flags/FlagsClient.d.ts +96 -0
- package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
- package/lib/typescript/flags/configuration/context.d.ts +20 -0
- package/lib/typescript/flags/configuration/context.d.ts.map +1 -0
- package/lib/typescript/flags/configuration/index.d.ts +5 -0
- package/lib/typescript/flags/configuration/index.d.ts.map +1 -0
- package/lib/typescript/flags/configuration/precomputed.d.ts +25 -0
- package/lib/typescript/flags/configuration/precomputed.d.ts.map +1 -0
- package/lib/typescript/flags/configuration/types.d.ts +24 -0
- package/lib/typescript/flags/configuration/types.d.ts.map +1 -0
- package/lib/typescript/flags/configuration/wire.d.ts +2 -0
- package/lib/typescript/flags/configuration/wire.d.ts.map +1 -0
- package/lib/typescript/flags/internal.d.ts.map +1 -1
- package/lib/typescript/flags/types.d.ts +1 -1
- package/lib/typescript/flags/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -2
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts +29 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.d.ts +8 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +20 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.d.ts +2 -2
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.d.ts +3 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.d.ts +18 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.d.ts +0 -6
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +12 -2
- package/src/DdSdkReactNative.tsx +5 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +5 -2
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
- package/src/config/FileBasedConfiguration.ts +2 -0
- package/src/config/FileBasedConfiguration.type.ts +1 -0
- package/src/config/__tests__/FileBasedConfiguration.test.ts +3 -0
- package/src/config/__tests__/__fixtures__/configuration-all-fields.json +1 -0
- package/src/config/async/AutoInstrumentationConfiguration.ts +5 -0
- package/src/config/features/RumConfiguration.ts +4 -0
- package/src/config/features/RumConfiguration.type.ts +8 -0
- package/src/flags/FlagsClient.ts +305 -3
- package/src/flags/__tests__/FlagsClient.test.ts +596 -0
- package/src/flags/__tests__/internal.test.ts +45 -0
- package/src/flags/configuration/__tests__/context.test.ts +120 -0
- package/src/flags/configuration/__tests__/precomputed.test.ts +301 -0
- package/src/flags/configuration/__tests__/wire.test.ts +127 -0
- package/src/flags/configuration/context.ts +76 -0
- package/src/flags/configuration/index.ts +27 -0
- package/src/flags/configuration/precomputed.ts +215 -0
- package/src/flags/configuration/types.ts +47 -0
- package/src/flags/configuration/wire.ts +15 -0
- package/src/flags/internal.ts +6 -3
- package/src/flags/types.ts +3 -1
- package/src/index.tsx +8 -0
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +38 -13
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +101 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +316 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +393 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +49 -115
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.ts +25 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +54 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.ts +5 -5
- package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.ts +1 -17
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.ts +106 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.ts +0 -18
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +1 -0
- package/src/version.ts +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +0 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.js.map +0 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +0 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.js.map +0 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.d.ts.map +0 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.d.ts +0 -7
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.d.ts.map +0 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.d.ts.map +0 -1
- /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdFlags.kt +0 -0
- /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdLogs.kt +0 -0
- /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdSdk.kt +0 -0
- /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdTrace.kt +0 -0
|
@@ -0,0 +1,120 @@
|
|
|
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 type { EvaluationContext } from '../../types';
|
|
8
|
+
import { contextMatchesConfiguration, normalizeWireContext } from '../context';
|
|
9
|
+
|
|
10
|
+
jest.mock('../../../InternalLog', () => {
|
|
11
|
+
return {
|
|
12
|
+
InternalLog: { log: jest.fn() },
|
|
13
|
+
DATADOG_MESSAGE_PREFIX: 'DATADOG:'
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('normalizeWireContext', () => {
|
|
18
|
+
it('maps a flat wire context to { targetingKey, attributes }', () => {
|
|
19
|
+
expect(
|
|
20
|
+
normalizeWireContext({
|
|
21
|
+
targetingKey: 'user-1',
|
|
22
|
+
country: 'US',
|
|
23
|
+
age: 25
|
|
24
|
+
})
|
|
25
|
+
).toEqual({
|
|
26
|
+
targetingKey: 'user-1',
|
|
27
|
+
attributes: { country: 'US', age: 25 }
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('defaults a missing targeting key to an empty string', () => {
|
|
32
|
+
expect(normalizeWireContext({ country: 'US' })).toEqual({
|
|
33
|
+
targetingKey: '',
|
|
34
|
+
attributes: { country: 'US' }
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('drops non-primitive attributes', () => {
|
|
39
|
+
expect(
|
|
40
|
+
normalizeWireContext({
|
|
41
|
+
targetingKey: 'user-1',
|
|
42
|
+
country: 'US',
|
|
43
|
+
nested: { a: 1 }
|
|
44
|
+
})
|
|
45
|
+
).toEqual({ targetingKey: 'user-1', attributes: { country: 'US' } });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('handles a "__proto__" attribute without polluting the prototype', () => {
|
|
49
|
+
const normalized = normalizeWireContext({
|
|
50
|
+
targetingKey: 'user-1',
|
|
51
|
+
['__proto__']: 'x'
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// A reserved "__proto__" attribute does not pollute the prototype: the normalized
|
|
55
|
+
// attributes keep `Object.prototype` and nothing leaks onto the global prototype.
|
|
56
|
+
// (Whether the key is retained or dropped is an implementation detail we don't assert.)
|
|
57
|
+
expect(Object.getPrototypeOf(normalized.attributes)).toBe(
|
|
58
|
+
Object.prototype
|
|
59
|
+
);
|
|
60
|
+
expect(({} as Record<string, unknown>).x).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('contextMatchesConfiguration', () => {
|
|
65
|
+
const active: EvaluationContext = {
|
|
66
|
+
targetingKey: 'user-1',
|
|
67
|
+
attributes: { country: 'US' }
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
it('matches any context when the config has no embedded context', () => {
|
|
71
|
+
expect(contextMatchesConfiguration(undefined, active)).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('matches an equal context', () => {
|
|
75
|
+
expect(
|
|
76
|
+
contextMatchesConfiguration(
|
|
77
|
+
{ targetingKey: 'user-1', country: 'US' },
|
|
78
|
+
active
|
|
79
|
+
)
|
|
80
|
+
).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('does not match a different targeting key', () => {
|
|
84
|
+
expect(
|
|
85
|
+
contextMatchesConfiguration(
|
|
86
|
+
{ targetingKey: 'user-2', country: 'US' },
|
|
87
|
+
active
|
|
88
|
+
)
|
|
89
|
+
).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('does not match a different attribute value', () => {
|
|
93
|
+
expect(
|
|
94
|
+
contextMatchesConfiguration(
|
|
95
|
+
{ targetingKey: 'user-1', country: 'CA' },
|
|
96
|
+
active
|
|
97
|
+
)
|
|
98
|
+
).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('does not match when the wire has an extra primitive attribute', () => {
|
|
102
|
+
expect(
|
|
103
|
+
contextMatchesConfiguration(
|
|
104
|
+
{ targetingKey: 'user-1', country: 'US', plan: 'pro' },
|
|
105
|
+
active
|
|
106
|
+
)
|
|
107
|
+
).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('ignores dropped non-primitive attributes on both sides', () => {
|
|
111
|
+
// The nested attribute is dropped by the same normalization applied to the
|
|
112
|
+
// active context, so a wire context that only differs by it still matches.
|
|
113
|
+
expect(
|
|
114
|
+
contextMatchesConfiguration(
|
|
115
|
+
{ targetingKey: 'user-1', country: 'US', nested: { a: 1 } },
|
|
116
|
+
active
|
|
117
|
+
)
|
|
118
|
+
).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,301 @@
|
|
|
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 { InternalLog } from '../../../InternalLog';
|
|
8
|
+
import {
|
|
9
|
+
UnsupportedConfigurationError,
|
|
10
|
+
decodePrecomputedFlags
|
|
11
|
+
} from '../precomputed';
|
|
12
|
+
import type {
|
|
13
|
+
PrecomputedConfigurationResponse,
|
|
14
|
+
PrecomputedFlag
|
|
15
|
+
} from '../types';
|
|
16
|
+
|
|
17
|
+
jest.mock('../../../InternalLog', () => {
|
|
18
|
+
return {
|
|
19
|
+
InternalLog: { log: jest.fn() },
|
|
20
|
+
DATADOG_MESSAGE_PREFIX: 'DATADOG:'
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const flag = (overrides: Partial<PrecomputedFlag>): PrecomputedFlag => ({
|
|
25
|
+
variationType: 'boolean',
|
|
26
|
+
variationValue: true,
|
|
27
|
+
variationKey: 'true',
|
|
28
|
+
allocationKey: 'alloc-1',
|
|
29
|
+
reason: 'STATIC',
|
|
30
|
+
doLog: false,
|
|
31
|
+
extraLogging: {},
|
|
32
|
+
...overrides
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const responseWith = (
|
|
36
|
+
flags: Record<string, PrecomputedFlag>,
|
|
37
|
+
obfuscated = false
|
|
38
|
+
): PrecomputedConfigurationResponse => ({
|
|
39
|
+
data: {
|
|
40
|
+
id: '2',
|
|
41
|
+
type: 'precomputed-assignments',
|
|
42
|
+
attributes: {
|
|
43
|
+
obfuscated,
|
|
44
|
+
createdAt: '2026-07-06T23:01:56.822171460Z',
|
|
45
|
+
format: 'PRECOMPUTED',
|
|
46
|
+
environment: { name: 'Staging' },
|
|
47
|
+
flags
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('decodePrecomputedFlags', () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
jest.clearAllMocks();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('maps each variation type to a FlagCacheEntry with the correct value + string form', () => {
|
|
58
|
+
const cache = decodePrecomputedFlags(
|
|
59
|
+
responseWith({
|
|
60
|
+
bool: flag({
|
|
61
|
+
variationType: 'boolean',
|
|
62
|
+
variationValue: false,
|
|
63
|
+
variationKey: 'false'
|
|
64
|
+
}),
|
|
65
|
+
str: flag({
|
|
66
|
+
variationType: 'string',
|
|
67
|
+
variationValue: 'hello',
|
|
68
|
+
variationKey: 'Hello'
|
|
69
|
+
}),
|
|
70
|
+
num: flag({
|
|
71
|
+
variationType: 'number',
|
|
72
|
+
variationValue: 42,
|
|
73
|
+
variationKey: '42'
|
|
74
|
+
}),
|
|
75
|
+
int: flag({
|
|
76
|
+
variationType: 'integer',
|
|
77
|
+
variationValue: 7,
|
|
78
|
+
variationKey: '7'
|
|
79
|
+
}),
|
|
80
|
+
flt: flag({
|
|
81
|
+
variationType: 'float',
|
|
82
|
+
variationValue: 1.5,
|
|
83
|
+
variationKey: '1.5'
|
|
84
|
+
}),
|
|
85
|
+
obj: flag({
|
|
86
|
+
variationType: 'object',
|
|
87
|
+
variationValue: { greeting: 'hi' },
|
|
88
|
+
variationKey: 'Greeting'
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(cache.get('bool')).toEqual({
|
|
94
|
+
key: 'bool',
|
|
95
|
+
value: false,
|
|
96
|
+
allocationKey: 'alloc-1',
|
|
97
|
+
variationKey: 'false',
|
|
98
|
+
variationType: 'boolean',
|
|
99
|
+
variationValue: 'false',
|
|
100
|
+
reason: 'STATIC',
|
|
101
|
+
doLog: false,
|
|
102
|
+
extraLogging: {}
|
|
103
|
+
});
|
|
104
|
+
expect(cache.get('str')?.value).toBe('hello');
|
|
105
|
+
expect(cache.get('str')?.variationValue).toBe('hello');
|
|
106
|
+
expect(cache.get('num')?.value).toBe(42);
|
|
107
|
+
expect(cache.get('num')?.variationValue).toBe('42');
|
|
108
|
+
// integer/float keep their wire variationType but decode to a JS number.
|
|
109
|
+
expect(cache.get('int')?.value).toBe(7);
|
|
110
|
+
expect(cache.get('int')?.variationType).toBe('integer');
|
|
111
|
+
expect(cache.get('int')?.variationValue).toBe('7');
|
|
112
|
+
expect(cache.get('flt')?.value).toBe(1.5);
|
|
113
|
+
expect(cache.get('flt')?.variationType).toBe('float');
|
|
114
|
+
expect(cache.get('flt')?.variationValue).toBe('1.5');
|
|
115
|
+
// objects are JSON-encoded for the string form; value stays an object.
|
|
116
|
+
expect(cache.get('obj')?.value).toEqual({ greeting: 'hi' });
|
|
117
|
+
expect(cache.get('obj')?.variationValue).toBe('{"greeting":"hi"}');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('uses the flag map key as the entry key', () => {
|
|
121
|
+
const cache = decodePrecomputedFlags(
|
|
122
|
+
responseWith({ 'my-feature': flag({}) })
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
expect(cache.get('my-feature')?.key).toBe('my-feature');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('defaults missing extraLogging to an empty object', () => {
|
|
129
|
+
const cache = decodePrecomputedFlags(
|
|
130
|
+
responseWith({ f: flag({ extraLogging: undefined }) })
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(cache.get('f')?.extraLogging).toEqual({});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('tolerates a null serialId', () => {
|
|
137
|
+
const cache = decodePrecomputedFlags(
|
|
138
|
+
responseWith({ f: flag({ serialId: null }) })
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
expect(cache.get('f')?.key).toBe('f');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('omits flags with an unsupported variation type and logs a warning', () => {
|
|
145
|
+
const cache = decodePrecomputedFlags(
|
|
146
|
+
responseWith({
|
|
147
|
+
good: flag({}),
|
|
148
|
+
bad: flag({ variationType: 'timestamp' })
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(cache.get('good')).toBeDefined();
|
|
153
|
+
expect(cache.get('bad')).toBeUndefined();
|
|
154
|
+
expect(InternalLog.log).toHaveBeenCalled();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('omits flags whose value does not match their variation type', () => {
|
|
158
|
+
const cache = decodePrecomputedFlags(
|
|
159
|
+
responseWith({
|
|
160
|
+
mismatched: flag({
|
|
161
|
+
variationType: 'number',
|
|
162
|
+
variationValue: 'not-a-number'
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
expect(cache.get('mismatched')).toBeUndefined();
|
|
168
|
+
expect(InternalLog.log).toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('omits a non-object flag entry and keeps the valid ones', () => {
|
|
172
|
+
const cache = decodePrecomputedFlags(
|
|
173
|
+
responseWith({
|
|
174
|
+
good: flag({}),
|
|
175
|
+
bad: (null as unknown) as PrecomputedFlag
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(cache.get('good')).toBeDefined();
|
|
180
|
+
expect(cache.get('bad')).toBeUndefined();
|
|
181
|
+
expect(InternalLog.log).toHaveBeenCalled();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('omits a flag with malformed metadata field types', () => {
|
|
185
|
+
const cache = decodePrecomputedFlags(
|
|
186
|
+
responseWith({
|
|
187
|
+
badReason: flag({ reason: (42 as unknown) as string }),
|
|
188
|
+
badDoLog: flag({ doLog: ('yes' as unknown) as boolean })
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(cache.get('badReason')).toBeUndefined();
|
|
193
|
+
expect(cache.get('badDoLog')).toBeUndefined();
|
|
194
|
+
expect(InternalLog.log).toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('omits a flag whose extraLogging is an array (not a key/value map)', () => {
|
|
198
|
+
const cache = decodePrecomputedFlags(
|
|
199
|
+
responseWith({
|
|
200
|
+
arr: flag({
|
|
201
|
+
extraLogging: ([] as unknown) as PrecomputedFlag['extraLogging']
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
// Arrays also satisfy `typeof === 'object'`; forwarding one to native exposure tracking
|
|
207
|
+
// (which expects an object map) would break it, so the entry is omitted.
|
|
208
|
+
expect(cache.get('arr')).toBeUndefined();
|
|
209
|
+
expect(InternalLog.log).toHaveBeenCalled();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('throws UnsupportedConfigurationError for an obfuscated response', () => {
|
|
213
|
+
expect(() =>
|
|
214
|
+
decodePrecomputedFlags(responseWith({ f: flag({}) }, true))
|
|
215
|
+
).toThrow(UnsupportedConfigurationError);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('returns an empty map when there are no flags', () => {
|
|
219
|
+
expect(decodePrecomputedFlags(responseWith({})).size).toBe(0);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('omits an integer flag with a fractional value', () => {
|
|
223
|
+
const cache = decodePrecomputedFlags(
|
|
224
|
+
responseWith({
|
|
225
|
+
frac: flag({ variationType: 'integer', variationValue: 7.9 })
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
expect(cache.get('frac')).toBeUndefined();
|
|
230
|
+
expect(InternalLog.log).toHaveBeenCalled();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('omits a number flag whose value is not finite', () => {
|
|
234
|
+
const cache = decodePrecomputedFlags(
|
|
235
|
+
responseWith({
|
|
236
|
+
inf: flag({ variationType: 'number', variationValue: Infinity })
|
|
237
|
+
})
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
expect(cache.get('inf')).toBeUndefined();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it.each([
|
|
244
|
+
['a null response', null],
|
|
245
|
+
['a non-object response', 'nonsense'],
|
|
246
|
+
['a missing data envelope', {}],
|
|
247
|
+
['a missing attributes envelope', { data: {} }],
|
|
248
|
+
['a missing flags map', { data: { attributes: {} } }],
|
|
249
|
+
['a null flags map', { data: { attributes: { flags: null } } }],
|
|
250
|
+
['an array flags map', { data: { attributes: { flags: [] } } }]
|
|
251
|
+
])('throws for a structurally malformed response (%s)', (_label, input) => {
|
|
252
|
+
expect(() =>
|
|
253
|
+
decodePrecomputedFlags(
|
|
254
|
+
(input as unknown) as Parameters<
|
|
255
|
+
typeof decodePrecomputedFlags
|
|
256
|
+
>[0]
|
|
257
|
+
)
|
|
258
|
+
).toThrow(UnsupportedConfigurationError);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('accepts any JSON value for an object flag (array, null, primitive)', () => {
|
|
262
|
+
// ffe-service enforces a top-level object at the API layer, but that is not a
|
|
263
|
+
// storage constraint, so the decoder accepts whatever JSON arrives here.
|
|
264
|
+
const cache = decodePrecomputedFlags(
|
|
265
|
+
responseWith({
|
|
266
|
+
arr: flag({
|
|
267
|
+
variationType: 'object',
|
|
268
|
+
variationValue: [1, 2, 3]
|
|
269
|
+
}),
|
|
270
|
+
nul: flag({
|
|
271
|
+
variationType: 'object',
|
|
272
|
+
variationValue: null
|
|
273
|
+
}),
|
|
274
|
+
str: flag({
|
|
275
|
+
variationType: 'object',
|
|
276
|
+
variationValue: 'hi'
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
expect(cache.get('arr')?.value).toEqual([1, 2, 3]);
|
|
282
|
+
expect(cache.get('arr')?.variationValue).toBe('[1,2,3]');
|
|
283
|
+
expect(cache.get('nul')?.value).toBeNull();
|
|
284
|
+
expect(cache.get('nul')?.variationValue).toBe('null');
|
|
285
|
+
expect(cache.get('str')?.value).toBe('hi');
|
|
286
|
+
expect(cache.get('str')?.variationValue).toBe('hi');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('stores a flag keyed "__proto__" as data without polluting the prototype', () => {
|
|
290
|
+
// Computed key mirrors how JSON.parse yields an own "__proto__" property.
|
|
291
|
+
const cache = decodePrecomputedFlags(
|
|
292
|
+
responseWith({ ['__proto__']: flag({ variationValue: true }) })
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
// A Map stores "__proto__" as an ordinary key, retrievable via .get(), and never
|
|
296
|
+
// touches Object.prototype.
|
|
297
|
+
expect(cache.get('__proto__')?.value).toBe(true);
|
|
298
|
+
// No global prototype pollution.
|
|
299
|
+
expect(({} as Record<string, unknown>).variationType).toBeUndefined();
|
|
300
|
+
});
|
|
301
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
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 type { ParsedFlagsConfiguration } from '../types';
|
|
8
|
+
import { configurationFromString, configurationToString } from '../wire';
|
|
9
|
+
|
|
10
|
+
const buildResponse = () => ({
|
|
11
|
+
data: {
|
|
12
|
+
id: '2',
|
|
13
|
+
type: 'precomputed-assignments',
|
|
14
|
+
attributes: {
|
|
15
|
+
obfuscated: false,
|
|
16
|
+
createdAt: '2026-07-06T23:01:56.822171460Z',
|
|
17
|
+
format: 'PRECOMPUTED',
|
|
18
|
+
environment: { name: 'Staging' },
|
|
19
|
+
flags: {
|
|
20
|
+
'a-flag': {
|
|
21
|
+
variationType: 'boolean',
|
|
22
|
+
variationValue: true,
|
|
23
|
+
variationKey: 'true',
|
|
24
|
+
allocationKey: 'alloc-1',
|
|
25
|
+
reason: 'STATIC',
|
|
26
|
+
doLog: false,
|
|
27
|
+
extraLogging: {}
|
|
28
|
+
},
|
|
29
|
+
'num-flag': {
|
|
30
|
+
variationType: 'number',
|
|
31
|
+
variationValue: 1.5,
|
|
32
|
+
variationKey: '1.5',
|
|
33
|
+
allocationKey: 'alloc-2',
|
|
34
|
+
reason: 'STATIC',
|
|
35
|
+
doLog: true,
|
|
36
|
+
extraLogging: {}
|
|
37
|
+
},
|
|
38
|
+
'obj-flag': {
|
|
39
|
+
variationType: 'object',
|
|
40
|
+
variationValue: { nested: { a: 1 }, list: [1, 2] },
|
|
41
|
+
variationKey: 'obj',
|
|
42
|
+
allocationKey: 'alloc-3',
|
|
43
|
+
reason: 'TARGETING_MATCH',
|
|
44
|
+
doLog: false,
|
|
45
|
+
extraLogging: { extra: 'x' }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const buildWire = (overrides: Record<string, unknown> = {}) =>
|
|
53
|
+
JSON.stringify({
|
|
54
|
+
version: 1,
|
|
55
|
+
precomputed: {
|
|
56
|
+
response: JSON.stringify(buildResponse()),
|
|
57
|
+
context: { targetingKey: 'user-1', country: 'US' },
|
|
58
|
+
fetchedAt: 1748449320785
|
|
59
|
+
},
|
|
60
|
+
...overrides
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('configurationFromString', () => {
|
|
64
|
+
it('parses a valid v1 wire with a precomputed branch', () => {
|
|
65
|
+
const config = configurationFromString(buildWire());
|
|
66
|
+
|
|
67
|
+
expect(config.precomputed).toBeDefined();
|
|
68
|
+
expect(config.precomputed?.context).toEqual({
|
|
69
|
+
targetingKey: 'user-1',
|
|
70
|
+
country: 'US'
|
|
71
|
+
});
|
|
72
|
+
expect(config.precomputed?.fetchedAt).toBe(1748449320785);
|
|
73
|
+
// The inner `response` string is parsed into an object.
|
|
74
|
+
expect(
|
|
75
|
+
config.precomputed?.response.data.attributes.flags['a-flag']
|
|
76
|
+
.variationValue
|
|
77
|
+
).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('returns an empty config for an unsupported version', () => {
|
|
81
|
+
const wire = JSON.stringify({
|
|
82
|
+
version: 2,
|
|
83
|
+
precomputed: { response: JSON.stringify(buildResponse()) }
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(configurationFromString(wire)).toEqual({});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('returns an empty config for invalid JSON', () => {
|
|
90
|
+
expect(configurationFromString('not json')).toEqual({});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('returns an empty config when the inner response is invalid JSON', () => {
|
|
94
|
+
const wire = JSON.stringify({
|
|
95
|
+
version: 1,
|
|
96
|
+
precomputed: { response: '{ not json' }
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(configurationFromString(wire)).toEqual({});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('returns a config with no precomputed branch when none is present', () => {
|
|
103
|
+
const wire = JSON.stringify({ version: 1 });
|
|
104
|
+
|
|
105
|
+
expect(configurationFromString(wire)).toEqual({});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('configurationToString round-trip', () => {
|
|
110
|
+
it('round-trips a precomputed configuration', () => {
|
|
111
|
+
const original = configurationFromString(buildWire());
|
|
112
|
+
|
|
113
|
+
const restored = configurationFromString(
|
|
114
|
+
configurationToString(original)
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(restored).toEqual(original);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('serializes an empty configuration to a v1 wire', () => {
|
|
121
|
+
const empty: ParsedFlagsConfiguration = {};
|
|
122
|
+
|
|
123
|
+
expect(configurationToString(empty)).toBe(
|
|
124
|
+
JSON.stringify({ version: 1 })
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
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 { processEvaluationContext } from '../internal';
|
|
8
|
+
import type { EvaluationContext, PrimitiveValue } from '../types';
|
|
9
|
+
|
|
10
|
+
import type { WireEvaluationContext } from './types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Normalize a wire (OpenFeature-flat) evaluation context into the SDK's internal
|
|
14
|
+
* `{ targetingKey, attributes }` shape, applying the **same** processing the active
|
|
15
|
+
* context went through (`processEvaluationContext`) so the two are comparable — the
|
|
16
|
+
* flat wire shape and the internal shape are otherwise never equal.
|
|
17
|
+
*/
|
|
18
|
+
export const normalizeWireContext = (
|
|
19
|
+
wireContext: WireEvaluationContext
|
|
20
|
+
): EvaluationContext => {
|
|
21
|
+
const { targetingKey, ...attributes } = wireContext;
|
|
22
|
+
|
|
23
|
+
return processEvaluationContext({
|
|
24
|
+
// The wire is untrusted, so a non-string targetingKey is treated as absent.
|
|
25
|
+
targetingKey: typeof targetingKey === 'string' ? targetingKey : '',
|
|
26
|
+
// `processEvaluationContext` drops non-primitive attributes; casting here mirrors
|
|
27
|
+
// how the active context's attributes are typed before that same processing.
|
|
28
|
+
attributes: attributes as Record<string, PrimitiveValue>
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether a precomputed configuration's embedded context matches the active evaluation
|
|
34
|
+
* context.
|
|
35
|
+
*
|
|
36
|
+
* - A configuration with **no** embedded context is context-agnostic and matches any
|
|
37
|
+
* active context.
|
|
38
|
+
* - Otherwise the embedded context must match the active context exactly (after
|
|
39
|
+
* normalizing both through the same processing).
|
|
40
|
+
*/
|
|
41
|
+
export const contextMatchesConfiguration = (
|
|
42
|
+
wireContext: WireEvaluationContext | undefined,
|
|
43
|
+
activeContext: EvaluationContext
|
|
44
|
+
): boolean => {
|
|
45
|
+
if (!wireContext) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return contextsEqual(normalizeWireContext(wireContext), activeContext);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const contextsEqual = (a: EvaluationContext, b: EvaluationContext): boolean => {
|
|
53
|
+
if (a.targetingKey !== b.targetingKey) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return attributesEqual(a.attributes ?? {}, b.attributes ?? {});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Compare two attribute maps. After `processEvaluationContext`, attribute values are
|
|
62
|
+
* primitives, so a key-set + strict-value comparison is sufficient.
|
|
63
|
+
*/
|
|
64
|
+
const attributesEqual = (
|
|
65
|
+
a: Record<string, PrimitiveValue>,
|
|
66
|
+
b: Record<string, PrimitiveValue>
|
|
67
|
+
): boolean => {
|
|
68
|
+
const aKeys = Object.keys(a);
|
|
69
|
+
const bKeys = Object.keys(b);
|
|
70
|
+
|
|
71
|
+
if (aKeys.length !== bKeys.length) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return aKeys.every(key => a[key] === b[key]);
|
|
76
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
// Module boundary for portable-configuration handling. The public entry point
|
|
8
|
+
// (`packages/core/src/index.tsx`) re-exports only the customer-facing surface —
|
|
9
|
+
// `configurationFromString`/`configurationToString` and the `ParsedFlagsConfiguration` type;
|
|
10
|
+
// the decoder and other helpers stay internal to this boundary. Keeping the surface contained
|
|
11
|
+
// here makes a future "port -> depend on a shared core" swap easier.
|
|
12
|
+
|
|
13
|
+
export { configurationFromString, configurationToString } from './wire';
|
|
14
|
+
export {
|
|
15
|
+
decodePrecomputedFlags,
|
|
16
|
+
UnsupportedConfigurationError
|
|
17
|
+
} from './precomputed';
|
|
18
|
+
// `contextMatchesConfiguration` is intentionally NOT re-exported — it is an internal
|
|
19
|
+
// helper consumed directly by `FlagsClient` (see its import from `./configuration/context`).
|
|
20
|
+
export { normalizeWireContext } from './context';
|
|
21
|
+
export type {
|
|
22
|
+
ParsedFlagsConfiguration,
|
|
23
|
+
ParsedPrecomputedConfiguration,
|
|
24
|
+
PrecomputedConfigurationResponse,
|
|
25
|
+
PrecomputedFlag,
|
|
26
|
+
WireEvaluationContext
|
|
27
|
+
} from './types';
|