@datadog/mobile-react-native 3.5.2 → 3.5.4
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 +2 -2
- package/android/build.gradle +8 -7
- package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +1 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +0 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +10 -3
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +0 -1
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +124 -49
- package/ios/Sources/DdLogsImplementation.swift +2 -2
- package/ios/Sources/DdSdkConfiguration.swift +0 -1
- package/ios/Sources/SdkVersion.swift +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/version.js +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/version.js +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/version.d.ts +1 -1
- package/package.json +3 -2
- 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/version.ts +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SUPPORTED_VARIATION_TYPES = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
9
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
10
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The flag `variationType`s the decoder accepts. `@datadog/flagging-core` models the
|
|
15
|
+
* type as OpenFeature's `boolean | string | number | object`, and the CDN confirms only
|
|
16
|
+
* those are emitted. `integer`/`float` are kept here defensively — the decoder validates
|
|
17
|
+
* untrusted payloads and treats both as JavaScript `number`s.
|
|
18
|
+
*/
|
|
19
|
+
const SUPPORTED_VARIATION_TYPES = exports.SUPPORTED_VARIATION_TYPES = new Set(['boolean', 'string', 'number', 'integer', 'float', 'object']);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The context an evaluation is performed against, as it appears **on the wire**.
|
|
23
|
+
*
|
|
24
|
+
* This is the OpenFeature-shaped context: a flat object with an optional
|
|
25
|
+
* `targetingKey` and arbitrary sibling attributes. It is intentionally different
|
|
26
|
+
* from the SDK's internal `EvaluationContext` (`{ targetingKey, attributes }`);
|
|
27
|
+
* callers must normalize before comparing the two.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
// The wire/precomputed types are re-exported from `@datadog/flagging-core` so this SDK
|
|
31
|
+
// shares the canonical shapes instead of maintaining its own copies. Local names are
|
|
32
|
+
// kept so the rest of the SDK is insulated from the upstream naming.
|
|
33
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SUPPORTED_VARIATION_TYPES","exports","Set"],"sourceRoot":"../../../../src","sources":["flags/configuration/types.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,yBAA8C,GAAAC,OAAA,CAAAD,yBAAA,GAAG,IAAIE,GAAG,CAAC,CAClE,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,CACX,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "configurationFromString", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _flaggingCore.configurationFromString;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "configurationToString", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _flaggingCore.configurationToString;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _flaggingCore = require("@datadog/flagging-core");
|
|
19
|
+
//# sourceMappingURL=wire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_flaggingCore","require"],"sourceRoot":"../../../../src","sources":["flags/configuration/wire.ts"],"mappings":";;;;;;;;;;;;;;;;;AAWA,IAAAA,aAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -19,7 +19,11 @@ const processEvaluationContext = context => {
|
|
|
19
19
|
|
|
20
20
|
// We should ignore non-primitive values in the context as per FFE SDK requirements OF.3.
|
|
21
21
|
const providedAttributes = context.attributes ?? {};
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
// Accumulate in a Map so reserved keys such as "__proto__" are handled as data
|
|
24
|
+
// instead of hitting the Object.prototype setter (which would silently drop them or
|
|
25
|
+
// pollute the prototype). Object.fromEntries then materializes own properties safely.
|
|
26
|
+
const attributes = new Map();
|
|
23
27
|
for (const [key, value] of Object.entries(providedAttributes)) {
|
|
24
28
|
const isPrimitiveValue = typeof value === 'boolean' || typeof value === 'string' || typeof value === 'number' || value === undefined || value === null;
|
|
25
29
|
if (!isPrimitiveValue) {
|
|
@@ -29,11 +33,11 @@ const processEvaluationContext = context => {
|
|
|
29
33
|
if (value === undefined) {
|
|
30
34
|
continue;
|
|
31
35
|
}
|
|
32
|
-
attributes
|
|
36
|
+
attributes.set(key, value);
|
|
33
37
|
}
|
|
34
38
|
return {
|
|
35
39
|
targetingKey,
|
|
36
|
-
attributes
|
|
40
|
+
attributes: Object.fromEntries(attributes)
|
|
37
41
|
};
|
|
38
42
|
};
|
|
39
43
|
exports.processEvaluationContext = processEvaluationContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_InternalLog","require","_SdkVerbosity","processEvaluationContext","context","targetingKey","providedAttributes","attributes","key","value","Object","entries","isPrimitiveValue","undefined","InternalLog","log","SdkVerbosity","WARN","exports"],"sourceRoot":"../../../src","sources":["flags/internal.ts"],"mappings":";;;;;;AAMA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAPA;AACA;AACA;AACA;AACA;;AAmBO,MAAME,wBAAwB,GACjCC,OAA0B,IACN;EACpB,MAAM;IAAEC;EAAa,CAAC,GAAGD,OAAO;;EAEhC;EACA,MAAME,kBAA2C,GAC7CF,OAAO,CAACG,UAAU,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"names":["_InternalLog","require","_SdkVerbosity","processEvaluationContext","context","targetingKey","providedAttributes","attributes","Map","key","value","Object","entries","isPrimitiveValue","undefined","InternalLog","log","SdkVerbosity","WARN","set","fromEntries","exports"],"sourceRoot":"../../../src","sources":["flags/internal.ts"],"mappings":";;;;;;AAMA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAPA;AACA;AACA;AACA;AACA;;AAmBO,MAAME,wBAAwB,GACjCC,OAA0B,IACN;EACpB,MAAM;IAAEC;EAAa,CAAC,GAAGD,OAAO;;EAEhC;EACA,MAAME,kBAA2C,GAC7CF,OAAO,CAACG,UAAU,IAAI,CAAC,CAAC;;EAE5B;EACA;EACA;EACA,MAAMA,UAAU,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAEpD,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACN,kBAAkB,CAAC,EAAE;IAC3D,MAAMO,gBAAgB,GAClB,OAAOH,KAAK,KAAK,SAAS,IAC1B,OAAOA,KAAK,KAAK,QAAQ,IACzB,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAKI,SAAS,IACnBJ,KAAK,KAAK,IAAI;IAElB,IAAI,CAACG,gBAAgB,EAAE;MACnBE,wBAAW,CAACC,GAAG,CACX,sCAAsCP,GAAG,0EAA0E,EACnHQ,0BAAY,CAACC,IACjB,CAAC;MAED;IACJ;IAEA,IAAIR,KAAK,KAAKI,SAAS,EAAE;MACrB;IACJ;IAEAP,UAAU,CAACY,GAAG,CAACV,GAAG,EAAEC,KAAuB,CAAC;EAChD;EAEA,OAAO;IACHL,YAAY;IACZE,UAAU,EAAEI,MAAM,CAACS,WAAW,CAACb,UAAU;EAC7C,CAAC;AACL,CAAC;AAACc,OAAA,CAAAlB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -243,6 +243,18 @@ Object.defineProperty(exports, "__ddExtractText", {
|
|
|
243
243
|
return _ddBabelUtils.__ddExtractText;
|
|
244
244
|
}
|
|
245
245
|
});
|
|
246
|
+
Object.defineProperty(exports, "configurationFromString", {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
get: function () {
|
|
249
|
+
return _configuration.configurationFromString;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(exports, "configurationToString", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
get: function () {
|
|
255
|
+
return _configuration.configurationToString;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
246
258
|
var _DdSdkReactNative = require("./DdSdkReactNative");
|
|
247
259
|
var _InternalLog = require("./InternalLog");
|
|
248
260
|
var _DatadogProviderConfiguration = require("./config/DatadogProviderConfiguration");
|
|
@@ -256,6 +268,7 @@ var _SdkVerbosity = require("./config/types/SdkVerbosity");
|
|
|
256
268
|
var _TrackingConsent = require("./config/types/TrackingConsent");
|
|
257
269
|
var _types = require("./config/types");
|
|
258
270
|
var _DdFlags = require("./flags/DdFlags");
|
|
271
|
+
var _configuration = require("./flags/configuration");
|
|
259
272
|
var _DdLogs = require("./logs/DdLogs");
|
|
260
273
|
var _DdRum = require("./rum/DdRum");
|
|
261
274
|
var _DdBabelInteractionTracking = require("./rum/instrumentation/interactionTracking/DdBabelInteractionTracking");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_DdSdkReactNative","require","_InternalLog","_DatadogProviderConfiguration","_FileBasedConfiguration","_CoreConfiguration","_LogsConfiguration","_RumConfiguration","_TraceConfiguration","_ProxyConfiguration","_SdkVerbosity","_TrackingConsent","_types","_DdFlags","_DdLogs","_DdRum","_DdBabelInteractionTracking","_ddBabelUtils","_DatadogTracingContext","_DatadogTracingIdentifier","_TracingIdentifier","_graphqlHeaders","_types2","_DatadogProvider","_DdSdk","_DdTrace","_types3","_DefaultTimeProvider","_TimeProvider"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_DdSdkReactNative","require","_InternalLog","_DatadogProviderConfiguration","_FileBasedConfiguration","_CoreConfiguration","_LogsConfiguration","_RumConfiguration","_TraceConfiguration","_ProxyConfiguration","_SdkVerbosity","_TrackingConsent","_types","_DdFlags","_configuration","_DdLogs","_DdRum","_DdBabelInteractionTracking","_ddBabelUtils","_DatadogTracingContext","_DatadogTracingIdentifier","_TracingIdentifier","_graphqlHeaders","_types2","_DatadogProvider","_DdSdk","_DdTrace","_types3","_DefaultTimeProvider","_TimeProvider"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,6BAAA,GAAAF,OAAA;AACA,IAAAG,uBAAA,GAAAH,OAAA;AAIA,IAAAI,kBAAA,GAAAJ,OAAA;AAEA,IAAAK,kBAAA,GAAAL,OAAA;AAEA,IAAAM,iBAAA,GAAAN,OAAA;AAEA,IAAAO,mBAAA,GAAAP,OAAA;AACA,IAAAQ,mBAAA,GAAAR,OAAA;AAIA,IAAAS,aAAA,GAAAT,OAAA;AACA,IAAAU,gBAAA,GAAAV,OAAA;AACA,IAAAW,MAAA,GAAAX,OAAA;AAOA,IAAAY,QAAA,GAAAZ,OAAA;AAEA,IAAAa,cAAA,GAAAb,OAAA;AAWA,IAAAc,OAAA,GAAAd,OAAA;AACA,IAAAe,MAAA,GAAAf,OAAA;AACA,IAAAgB,2BAAA,GAAAhB,OAAA;AACA,IAAAiB,aAAA,GAAAjB,OAAA;AACA,IAAAkB,sBAAA,GAAAlB,OAAA;AACA,IAAAmB,yBAAA,GAAAnB,OAAA;AACA,IAAAoB,kBAAA,GAAApB,OAAA;AAIA,IAAAqB,eAAA,GAAArB,OAAA;AAQA,IAAAsB,OAAA,GAAAtB,OAAA;AACA,IAAAuB,gBAAA,GAAAvB,OAAA;AACA,IAAAwB,MAAA,GAAAxB,OAAA;AACA,IAAAyB,QAAA,GAAAzB,OAAA;AACA,IAAA0B,OAAA,GAAA1B,OAAA;AACA,IAAA2B,oBAAA,GAAA3B,OAAA;AAEA,IAAA4B,aAAA,GAAA5B,OAAA","ignoreList":[]}
|
package/lib/commonjs/version.js
CHANGED
|
@@ -6,12 +6,70 @@
|
|
|
6
6
|
|
|
7
7
|
import { InternalLog } from '../InternalLog';
|
|
8
8
|
import { SdkVerbosity } from '../config/types/SdkVerbosity';
|
|
9
|
+
// Imported directly (not via the module index): context matching is an internal helper,
|
|
10
|
+
// used here only to detect a runtime context an offline precomputed configuration cannot honor.
|
|
11
|
+
import { contextMatchesConfiguration } from './configuration/context';
|
|
12
|
+
import { decodePrecomputedFlags, normalizeWireContext } from './configuration';
|
|
9
13
|
import { processEvaluationContext } from './internal';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Error codes an offline configuration result can carry:
|
|
17
|
+
* - `INVALID_CONTEXT`: the active context does not match the precomputed snapshot.
|
|
18
|
+
* - `PROVIDER_NOT_READY`: an offline operation ran with no configuration loaded.
|
|
19
|
+
* - `GENERAL`: the loaded configuration is unusable (malformed/unsupported/undecodable).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Outcome of loading a configuration or reconciling it against the active evaluation context,
|
|
24
|
+
* returned by the offline APIs ({@link FlagsClient.setConfiguration},
|
|
25
|
+
* {@link FlagsClient.setEvaluationContextWithoutFetching},
|
|
26
|
+
* {@link FlagsClient.resetEvaluationContextWithoutFetching}).
|
|
27
|
+
*
|
|
28
|
+
* `'ready'` means the configuration can be served against the active context; `'error'` carries
|
|
29
|
+
* the precise reason so the OpenFeature provider surfaces the correct code and evaluation returns
|
|
30
|
+
* that code with the coded default.
|
|
31
|
+
*
|
|
32
|
+
* @internal Consumers observe OpenFeature provider events/evaluation details, not this result.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The decoded outcome of the last loaded offline configuration. Load validity (`kind`) is stored
|
|
37
|
+
* separately from context compatibility so that later context changes reconcile against a decoded
|
|
38
|
+
* snapshot **without re-decoding** and can never promote an invalid load to a servable state.
|
|
39
|
+
*
|
|
40
|
+
* `'none'` = no offline configuration engaged (the online/fetch path, or nothing loaded yet).
|
|
41
|
+
*/
|
|
42
|
+
|
|
10
43
|
export class FlagsClient {
|
|
11
44
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
12
45
|
nativeFlags = require('../specs/NativeDdFlags').default;
|
|
46
|
+
// The context the app explicitly set — the online fetch context, or the offline override via
|
|
47
|
+
// {@link setEvaluationContextWithoutFetching}. `undefined` means "no external override": an
|
|
48
|
+
// offline precomputed configuration is then served against its own embedded context. Tracked
|
|
49
|
+
// separately from {@link evaluationContext} so that adopting a configuration's embedded context
|
|
50
|
+
// is never mistaken for an app-set override (which would spuriously fail a later replacement).
|
|
51
|
+
externalContext = undefined;
|
|
52
|
+
|
|
53
|
+
// The effective context evaluation and exposure tracking run against: the external override
|
|
54
|
+
// when set, otherwise the loaded configuration's embedded context.
|
|
13
55
|
evaluationContext = undefined;
|
|
14
|
-
|
|
56
|
+
|
|
57
|
+
// The servable flag cache. On the online path it holds the native-fetched flags; on the
|
|
58
|
+
// offline path it mirrors the decoded snapshot when the configuration is servable. A Map
|
|
59
|
+
// (not a plain object) so a flag keyed like an inherited property ("toString",
|
|
60
|
+
// "__proto__") is looked up as data via `.get()` and never resolves an `Object.prototype`
|
|
61
|
+
// member — important now the cache can be fed from untrusted wire data.
|
|
62
|
+
flagsCache = new Map();
|
|
63
|
+
|
|
64
|
+
// The decoded outcome of the last loaded offline configuration (see the type).
|
|
65
|
+
loadedConfiguration = {
|
|
66
|
+
kind: 'none'
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Internal serving status. `'none'` = online path (serve `flagsCache`); `'ready'` = serve
|
|
70
|
+
// the offline snapshot; `'error'` = serve coded defaults with `configurationError`.
|
|
71
|
+
configurationStatus = 'none';
|
|
72
|
+
configurationError = undefined;
|
|
15
73
|
constructor(clientName = 'default') {
|
|
16
74
|
this.clientName = clientName;
|
|
17
75
|
}
|
|
@@ -42,17 +100,212 @@ export class FlagsClient {
|
|
|
42
100
|
setEvaluationContext = async context => {
|
|
43
101
|
// Make sure to process the incoming context because we don't support nested object values in context.
|
|
44
102
|
const processedContext = processEvaluationContext(context);
|
|
103
|
+
|
|
104
|
+
// Entering online mode drops any offline overlay *before* fetching, so a failed fetch falls
|
|
105
|
+
// back to coded defaults rather than continuing to serve a stale offline snapshot. Using one
|
|
106
|
+
// client for both online and offline is unsupported (give the offline provider its own
|
|
107
|
+
// `clientName`), so warn when an offline configuration is discarded here. Online-only clients
|
|
108
|
+
// have no overlay, so this does not touch their keep-last-known-flags-on-failure behavior.
|
|
109
|
+
if (this.loadedConfiguration.kind !== 'none') {
|
|
110
|
+
InternalLog.log(`An offline configuration was loaded for '${this.clientName}' but an online fetch was requested; discarding it and serving default values on failure. Use a separate client for the offline provider.`, SdkVerbosity.WARN);
|
|
111
|
+
this.loadedConfiguration = {
|
|
112
|
+
kind: 'none'
|
|
113
|
+
};
|
|
114
|
+
this.configurationStatus = 'none';
|
|
115
|
+
this.configurationError = undefined;
|
|
116
|
+
this.flagsCache = new Map();
|
|
117
|
+
this.evaluationContext = undefined;
|
|
118
|
+
this.externalContext = undefined;
|
|
119
|
+
}
|
|
45
120
|
try {
|
|
46
121
|
const result = await this.nativeFlags.setEvaluationContext(this.clientName, processedContext.targetingKey, processedContext.attributes ?? {});
|
|
122
|
+
this.externalContext = processedContext;
|
|
47
123
|
this.evaluationContext = processedContext;
|
|
48
|
-
this.flagsCache = result;
|
|
124
|
+
this.flagsCache = new Map(Object.entries(result));
|
|
125
|
+
|
|
126
|
+
// A successful online fetch is authoritative: reset to the clean online state so a
|
|
127
|
+
// prior offline error status (e.g. PROVIDER_NOT_READY from an offline op with no
|
|
128
|
+
// configuration loaded) can't keep serving coded defaults over the fetched flags.
|
|
129
|
+
this.loadedConfiguration = {
|
|
130
|
+
kind: 'none'
|
|
131
|
+
};
|
|
132
|
+
this.configurationStatus = 'none';
|
|
133
|
+
this.configurationError = undefined;
|
|
49
134
|
} catch (error) {
|
|
135
|
+
// A failed fetch leaves the previous online cache in place (keep-last-known); any offline
|
|
136
|
+
// overlay was already dropped above, so no stale offline snapshot is served.
|
|
50
137
|
if (error instanceof Error) {
|
|
51
138
|
InternalLog.log(`Error setting flag evaluation context: ${error.message}`, SdkVerbosity.WARN);
|
|
52
139
|
}
|
|
53
140
|
throw error;
|
|
54
141
|
}
|
|
55
142
|
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Set the evaluation context **without** fetching a configuration from the network, then
|
|
146
|
+
* reconcile the loaded configuration against it.
|
|
147
|
+
*
|
|
148
|
+
* The offline counterpart to {@link setEvaluationContext}: records the active context and
|
|
149
|
+
* reconciles with no native request. A precomputed configuration is single-subject, so a
|
|
150
|
+
* context that does not match the one it was computed for reconciles to an error
|
|
151
|
+
* (`INVALID_CONTEXT`) and evaluation serves defaults. With no configuration loaded the
|
|
152
|
+
* result is `PROVIDER_NOT_READY`. Intended for offline providers that own their
|
|
153
|
+
* configuration via `setConfiguration` and must not fetch on a context change.
|
|
154
|
+
*
|
|
155
|
+
* @param context The evaluation context to associate with the current client.
|
|
156
|
+
*/
|
|
157
|
+
setEvaluationContextWithoutFetching = context => {
|
|
158
|
+
this.externalContext = processEvaluationContext(context);
|
|
159
|
+
return this.reconcile();
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Clear any externally-set evaluation context and reconcile.
|
|
164
|
+
*
|
|
165
|
+
* This is the offline counterpart to clearing/omitting an OpenFeature context: it drops the
|
|
166
|
+
* external override so a loaded precomputed configuration is served against **its embedded
|
|
167
|
+
* context** again. Clearing the override (rather than skipping) matters so that a
|
|
168
|
+
* configuration loaded *after* a clear is not judged against a stale override. With no
|
|
169
|
+
* configuration loaded the result is `PROVIDER_NOT_READY`.
|
|
170
|
+
*/
|
|
171
|
+
resetEvaluationContextWithoutFetching = () => {
|
|
172
|
+
this.externalContext = undefined;
|
|
173
|
+
return this.reconcile();
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Load a configuration (parsed from a `ConfigurationWire` string via
|
|
178
|
+
* `configurationFromString`) into the client for offline evaluation, then reconcile it
|
|
179
|
+
* against the active context.
|
|
180
|
+
*
|
|
181
|
+
* For a precomputed configuration this decodes the snapshot once and adopts its embedded
|
|
182
|
+
* evaluation context when none is set — **no network request is made**. An unusable
|
|
183
|
+
* configuration reconciles to an error (`GENERAL`); a context mismatch to `INVALID_CONTEXT`.
|
|
184
|
+
*
|
|
185
|
+
* @param configuration The configuration to load.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* const configuration = configurationFromString(wire);
|
|
190
|
+
* flagsClient.setConfiguration(configuration);
|
|
191
|
+
*
|
|
192
|
+
* const value = flagsClient.getBooleanValue('new-feature', false);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
setConfiguration = configuration => {
|
|
196
|
+
this.loadedConfiguration = this.loadConfiguration(configuration);
|
|
197
|
+
return this.reconcile();
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Decode a supplied configuration into a {@link LoadedConfigurationState} **once**, capturing
|
|
202
|
+
* whether the load itself is valid (independent of the active context). Later context changes
|
|
203
|
+
* reconcile against this stored state without re-decoding, and can never turn an invalid load
|
|
204
|
+
* into a servable one.
|
|
205
|
+
*
|
|
206
|
+
* FORWARD-COMPAT SEAM: when a rules-based configuration is supported, it must be handled here
|
|
207
|
+
* BEFORE the precomputed guard — rules are context-agnostic and must NOT be classified invalid.
|
|
208
|
+
*/
|
|
209
|
+
loadConfiguration = configuration => {
|
|
210
|
+
const precomputed = configuration?.precomputed;
|
|
211
|
+
|
|
212
|
+
// An empty configuration (a failed/lenient wire parse, or a wire with no precomputed
|
|
213
|
+
// branch) is unusable. `configurationFromString` collapses malformed input and
|
|
214
|
+
// unsupported versions to the same empty shape, so this is classified as `GENERAL`.
|
|
215
|
+
if (!precomputed) {
|
|
216
|
+
InternalLog.log(`No usable precomputed configuration was provided for '${this.clientName}'.`, SdkVerbosity.WARN);
|
|
217
|
+
return {
|
|
218
|
+
kind: 'invalid',
|
|
219
|
+
errorCode: 'GENERAL'
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const flags = decodePrecomputedFlags(precomputed.response);
|
|
224
|
+
return {
|
|
225
|
+
kind: 'precomputed',
|
|
226
|
+
configuration: precomputed,
|
|
227
|
+
flags
|
|
228
|
+
};
|
|
229
|
+
} catch (error) {
|
|
230
|
+
// Decoding rejects unsupported payloads (e.g. obfuscated) — an unsupported kind,
|
|
231
|
+
// classified as `GENERAL`.
|
|
232
|
+
if (error instanceof Error) {
|
|
233
|
+
InternalLog.log(`Unsupported flags configuration for '${this.clientName}': ${error.message}`, SdkVerbosity.WARN);
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
kind: 'invalid',
|
|
237
|
+
errorCode: 'GENERAL'
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Reconcile the stored {@link LoadedConfigurationState} against the active evaluation context
|
|
244
|
+
* and (re)compute the servable flag cache and configuration status/result.
|
|
245
|
+
*
|
|
246
|
+
* The stored load validity is consulted **before** context compatibility, so a context change
|
|
247
|
+
* can never promote an invalid (or absent) load to `ready`.
|
|
248
|
+
*/
|
|
249
|
+
reconcile = () => {
|
|
250
|
+
const loaded = this.loadedConfiguration;
|
|
251
|
+
|
|
252
|
+
// No offline configuration engaged: an offline operation with nothing loaded is not ready.
|
|
253
|
+
if (loaded.kind === 'none') {
|
|
254
|
+
return this.enterError('PROVIDER_NOT_READY', `The evaluation context is not usable for '${this.clientName}': no configuration is loaded. Provide a configuration via setConfiguration.`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// The load itself failed (malformed/unsupported/undecodable) — independent of context.
|
|
258
|
+
if (loaded.kind === 'invalid') {
|
|
259
|
+
return this.enterError(loaded.errorCode, `The loaded configuration for '${this.clientName}' is not usable. Provide a valid precomputed configuration.`);
|
|
260
|
+
}
|
|
261
|
+
const {
|
|
262
|
+
configuration,
|
|
263
|
+
flags
|
|
264
|
+
} = loaded;
|
|
265
|
+
|
|
266
|
+
// A precomputed snapshot is bound to the subject it was computed for. If the app set an
|
|
267
|
+
// *external* context that does not match, it cannot be served (offline never fetches), so
|
|
268
|
+
// it is an error and evaluation serves coded defaults. Only an external override is checked
|
|
269
|
+
// here — the configuration's own embedded context (adopted below when no override is set)
|
|
270
|
+
// matches by construction, so replacing one snapshot with another for a different subject
|
|
271
|
+
// stays `ready`. The decoded snapshot is retained for a later matching context.
|
|
272
|
+
if (this.externalContext && !contextMatchesConfiguration(configuration.context, this.externalContext)) {
|
|
273
|
+
return this.enterError('INVALID_CONTEXT', `The evaluation context does not match the precomputed configuration for '${this.clientName}'. Serving default values. Set a matching context, or use a rules-based configuration for per-context evaluation.`);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Serve against the external override when set, otherwise the configuration's embedded
|
|
277
|
+
// context (a context-agnostic configuration falls back to an empty context).
|
|
278
|
+
this.evaluationContext = this.externalContext ?? this.embeddedContext(configuration);
|
|
279
|
+
this.flagsCache = flags;
|
|
280
|
+
this.configurationStatus = 'ready';
|
|
281
|
+
this.configurationError = undefined;
|
|
282
|
+
return {
|
|
283
|
+
status: 'ready'
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/** The evaluation context a precomputed configuration was computed for (empty if agnostic). */
|
|
288
|
+
embeddedContext = configuration => {
|
|
289
|
+
return configuration.context ? normalizeWireContext(configuration.context) : {
|
|
290
|
+
targetingKey: '',
|
|
291
|
+
attributes: {}
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/** Record an error status + message, clear the servable cache, and return the result. */
|
|
296
|
+
enterError = (errorCode, errorMessage) => {
|
|
297
|
+
this.flagsCache = new Map();
|
|
298
|
+
this.configurationStatus = 'error';
|
|
299
|
+
this.configurationError = {
|
|
300
|
+
errorCode,
|
|
301
|
+
errorMessage
|
|
302
|
+
};
|
|
303
|
+
InternalLog.log(errorMessage, SdkVerbosity.WARN);
|
|
304
|
+
return {
|
|
305
|
+
status: 'error',
|
|
306
|
+
errorCode
|
|
307
|
+
};
|
|
308
|
+
};
|
|
56
309
|
track = (flag, context) => {
|
|
57
310
|
// A non-blocking call; don't await this.
|
|
58
311
|
this.nativeFlags.trackEvaluation(this.clientName, flag.key, flag, context.targetingKey, context.attributes ?? {}).catch(error => {
|
|
@@ -62,6 +315,18 @@ export class FlagsClient {
|
|
|
62
315
|
});
|
|
63
316
|
};
|
|
64
317
|
getDetails = (key, defaultValue, type) => {
|
|
318
|
+
// An offline configuration that cannot be served against the active context surfaces the
|
|
319
|
+
// precise error code (INVALID_CONTEXT / GENERAL / PROVIDER_NOT_READY) with the coded
|
|
320
|
+
// default. The OpenFeature provider maps this to a PROVIDER_ERROR / ERROR state.
|
|
321
|
+
if (this.configurationStatus === 'error' && this.configurationError) {
|
|
322
|
+
return {
|
|
323
|
+
key,
|
|
324
|
+
value: defaultValue,
|
|
325
|
+
reason: 'ERROR',
|
|
326
|
+
errorCode: this.configurationError.errorCode,
|
|
327
|
+
errorMessage: this.configurationError.errorMessage
|
|
328
|
+
};
|
|
329
|
+
}
|
|
65
330
|
if (!this.evaluationContext) {
|
|
66
331
|
return {
|
|
67
332
|
key,
|
|
@@ -73,7 +338,7 @@ export class FlagsClient {
|
|
|
73
338
|
}
|
|
74
339
|
|
|
75
340
|
// Retrieve the flag from the cache.
|
|
76
|
-
const flag = this.flagsCache
|
|
341
|
+
const flag = this.flagsCache.get(key);
|
|
77
342
|
if (!flag) {
|
|
78
343
|
return {
|
|
79
344
|
key,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["InternalLog","SdkVerbosity","processEvaluationContext","FlagsClient","nativeFlags","require","default","
|
|
1
|
+
{"version":3,"names":["InternalLog","SdkVerbosity","contextMatchesConfiguration","decodePrecomputedFlags","normalizeWireContext","processEvaluationContext","FlagsClient","nativeFlags","require","default","externalContext","undefined","evaluationContext","flagsCache","Map","loadedConfiguration","kind","configurationStatus","configurationError","constructor","clientName","setEvaluationContext","context","processedContext","log","WARN","result","targetingKey","attributes","Object","entries","error","Error","message","setEvaluationContextWithoutFetching","reconcile","resetEvaluationContextWithoutFetching","setConfiguration","configuration","loadConfiguration","precomputed","errorCode","flags","response","loaded","enterError","embeddedContext","status","errorMessage","track","flag","trackEvaluation","key","catch","getDetails","defaultValue","type","value","reason","get","actualType","details","variant","variationKey","allocationKey","getBooleanDetails","getStringDetails","getNumberDetails","getObjectDetails","getBooleanValue","getStringValue","getNumberValue","getObjectValue"],"sourceRoot":"../../../src","sources":["flags/FlagsClient.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,YAAY,QAAQ,8BAA8B;AAG3D;AACA;AACA,SAASC,2BAA2B,QAAQ,yBAAyB;AACrE,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,iBAAiB;AAK9E,SAASC,wBAAwB,QAAQ,YAAY;;AAIrD;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,OAAO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ACA;AACA;EACIa,gBAAgB,GAAGA,CACfhB,GAAW,EACXG,YAAe,KACE;IACjB,OAAO,IAAI,CAACD,UAAU,CAACF,GAAG,EAAEG,YAAY,EAAE,QAAQ,CAAC;EACvD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIc,eAAe,GAAGA,CAACjB,GAAW,EAAEG,YAAqB,KAAc;IAC/D,OAAO,IAAI,CAACU,iBAAiB,CAACb,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EAC1D,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIa,cAAc,GAAGA,CAAClB,GAAW,EAAEG,YAAoB,KAAa;IAC5D,OAAO,IAAI,CAACW,gBAAgB,CAACd,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIc,cAAc,GAAGA,CAACnB,GAAW,EAAEG,YAAoB,KAAa;IAC5D,OAAO,IAAI,CAACY,gBAAgB,CAACf,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIe,cAAc,GAAGA,CAAsBpB,GAAW,EAAEG,YAAe,KAAQ;IACvE,OAAO,IAAI,CAACa,gBAAgB,CAAChB,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;AACL","ignoreList":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Normalize a wire (OpenFeature-flat) evaluation context into the SDK's internal
|
|
10
|
+
* `{ targetingKey, attributes }` shape, applying the **same** processing the active
|
|
11
|
+
* context went through (`processEvaluationContext`) so the two are comparable — the
|
|
12
|
+
* flat wire shape and the internal shape are otherwise never equal.
|
|
13
|
+
*/
|
|
14
|
+
export const normalizeWireContext = wireContext => {
|
|
15
|
+
const {
|
|
16
|
+
targetingKey,
|
|
17
|
+
...attributes
|
|
18
|
+
} = wireContext;
|
|
19
|
+
return processEvaluationContext({
|
|
20
|
+
// The wire is untrusted, so a non-string targetingKey is treated as absent.
|
|
21
|
+
targetingKey: typeof targetingKey === 'string' ? targetingKey : '',
|
|
22
|
+
// `processEvaluationContext` drops non-primitive attributes; casting here mirrors
|
|
23
|
+
// how the active context's attributes are typed before that same processing.
|
|
24
|
+
attributes: attributes
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether a precomputed configuration's embedded context matches the active evaluation
|
|
30
|
+
* context.
|
|
31
|
+
*
|
|
32
|
+
* - A configuration with **no** embedded context is context-agnostic and matches any
|
|
33
|
+
* active context.
|
|
34
|
+
* - Otherwise the embedded context must match the active context exactly (after
|
|
35
|
+
* normalizing both through the same processing).
|
|
36
|
+
*/
|
|
37
|
+
export const contextMatchesConfiguration = (wireContext, activeContext) => {
|
|
38
|
+
if (!wireContext) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return contextsEqual(normalizeWireContext(wireContext), activeContext);
|
|
42
|
+
};
|
|
43
|
+
const contextsEqual = (a, b) => {
|
|
44
|
+
if (a.targetingKey !== b.targetingKey) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return attributesEqual(a.attributes ?? {}, b.attributes ?? {});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Compare two attribute maps. After `processEvaluationContext`, attribute values are
|
|
52
|
+
* primitives, so a key-set + strict-value comparison is sufficient.
|
|
53
|
+
*/
|
|
54
|
+
const attributesEqual = (a, b) => {
|
|
55
|
+
const aKeys = Object.keys(a);
|
|
56
|
+
const bKeys = Object.keys(b);
|
|
57
|
+
if (aKeys.length !== bKeys.length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return aKeys.every(key => a[key] === b[key]);
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["processEvaluationContext","normalizeWireContext","wireContext","targetingKey","attributes","contextMatchesConfiguration","activeContext","contextsEqual","a","b","attributesEqual","aKeys","Object","keys","bKeys","length","every","key"],"sourceRoot":"../../../../src","sources":["flags/configuration/context.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,wBAAwB,QAAQ,aAAa;AAKtD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAC7BC,WAAkC,IACd;EACpB,MAAM;IAAEC,YAAY;IAAE,GAAGC;EAAW,CAAC,GAAGF,WAAW;EAEnD,OAAOF,wBAAwB,CAAC;IAC5B;IACAG,YAAY,EAAE,OAAOA,YAAY,KAAK,QAAQ,GAAGA,YAAY,GAAG,EAAE;IAClE;IACA;IACAC,UAAU,EAAEA;EAChB,CAAC,CAAC;AACN,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAGA,CACvCH,WAA8C,EAC9CI,aAAgC,KACtB;EACV,IAAI,CAACJ,WAAW,EAAE;IACd,OAAO,IAAI;EACf;EAEA,OAAOK,aAAa,CAACN,oBAAoB,CAACC,WAAW,CAAC,EAAEI,aAAa,CAAC;AAC1E,CAAC;AAED,MAAMC,aAAa,GAAGA,CAACC,CAAoB,EAAEC,CAAoB,KAAc;EAC3E,IAAID,CAAC,CAACL,YAAY,KAAKM,CAAC,CAACN,YAAY,EAAE;IACnC,OAAO,KAAK;EAChB;EAEA,OAAOO,eAAe,CAACF,CAAC,CAACJ,UAAU,IAAI,CAAC,CAAC,EAAEK,CAAC,CAACL,UAAU,IAAI,CAAC,CAAC,CAAC;AAClE,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMM,eAAe,GAAGA,CACpBF,CAAiC,EACjCC,CAAiC,KACvB;EACV,MAAME,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACL,CAAC,CAAC;EAC5B,MAAMM,KAAK,GAAGF,MAAM,CAACC,IAAI,CAACJ,CAAC,CAAC;EAE5B,IAAIE,KAAK,CAACI,MAAM,KAAKD,KAAK,CAACC,MAAM,EAAE;IAC/B,OAAO,KAAK;EAChB;EAEA,OAAOJ,KAAK,CAACK,KAAK,CAACC,GAAG,IAAIT,CAAC,CAACS,GAAG,CAAC,KAAKR,CAAC,CAACQ,GAAG,CAAC,CAAC;AAChD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { decodePrecomputedFlags, UnsupportedConfigurationError } from './precomputed';
|
|
15
|
+
// `contextMatchesConfiguration` is intentionally NOT re-exported — it is an internal
|
|
16
|
+
// helper consumed directly by `FlagsClient` (see its import from `./configuration/context`).
|
|
17
|
+
export { normalizeWireContext } from './context';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["configurationFromString","configurationToString","decodePrecomputedFlags","UnsupportedConfigurationError","normalizeWireContext"],"sourceRoot":"../../../../src","sources":["flags/configuration/index.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,SAASA,uBAAuB,EAAEC,qBAAqB,QAAQ,QAAQ;AACvE,SACIC,sBAAsB,EACtBC,6BAA6B,QAC1B,eAAe;AACtB;AACA;AACA,SAASC,oBAAoB,QAAQ,WAAW","ignoreList":[]}
|