@datadog/mobile-react-native-openfeature 3.5.3 → 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 +77 -0
- package/lib/commonjs/coreProvider.js +79 -0
- package/lib/commonjs/coreProvider.js.map +1 -0
- package/lib/commonjs/index.js +14 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mappers.js +50 -0
- package/lib/commonjs/mappers.js.map +1 -0
- package/lib/commonjs/offlineProvider.js +149 -0
- package/lib/commonjs/offlineProvider.js.map +1 -0
- package/lib/commonjs/provider.js +9 -73
- package/lib/commonjs/provider.js.map +1 -1
- package/lib/module/coreProvider.js +72 -0
- package/lib/module/coreProvider.js.map +1 -0
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mappers.js +42 -0
- package/lib/module/mappers.js.map +1 -0
- package/lib/module/offlineProvider.js +143 -0
- package/lib/module/offlineProvider.js.map +1 -0
- package/lib/module/provider.js +7 -71
- package/lib/module/provider.js.map +1 -1
- package/lib/typescript/core/src/flags/FlagsClient.d.ts +96 -0
- package/lib/typescript/core/src/flags/FlagsClient.d.ts.map +1 -1
- package/lib/typescript/core/src/flags/configuration/context.d.ts +20 -0
- package/lib/typescript/core/src/flags/configuration/context.d.ts.map +1 -0
- package/lib/typescript/core/src/flags/configuration/index.d.ts +5 -0
- package/lib/typescript/core/src/flags/configuration/index.d.ts.map +1 -0
- package/lib/typescript/core/src/flags/configuration/precomputed.d.ts +25 -0
- package/lib/typescript/core/src/flags/configuration/precomputed.d.ts.map +1 -0
- package/lib/typescript/core/src/flags/configuration/types.d.ts +24 -0
- package/lib/typescript/core/src/flags/configuration/types.d.ts.map +1 -0
- package/lib/typescript/core/src/flags/configuration/wire.d.ts +2 -0
- package/lib/typescript/core/src/flags/configuration/wire.d.ts.map +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/index.d.ts +4 -2
- 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/coreProvider.d.ts +34 -0
- package/lib/typescript/react-native-openfeature/src/coreProvider.d.ts.map +1 -0
- package/lib/typescript/react-native-openfeature/src/index.d.ts +3 -1
- package/lib/typescript/react-native-openfeature/src/index.d.ts.map +1 -1
- package/lib/typescript/react-native-openfeature/src/mappers.d.ts +20 -0
- package/lib/typescript/react-native-openfeature/src/mappers.d.ts.map +1 -0
- package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts +59 -0
- package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts.map +1 -0
- package/lib/typescript/react-native-openfeature/src/provider.d.ts +8 -21
- package/lib/typescript/react-native-openfeature/src/provider.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/offlineProvider.integration.test.ts +271 -0
- package/src/__tests__/offlineProvider.test.ts +252 -0
- package/src/__tests__/provider.test.ts +74 -0
- package/src/coreProvider.ts +142 -0
- package/src/index.ts +8 -1
- package/src/mappers.ts +47 -0
- package/src/offlineProvider.ts +185 -0
- package/src/provider.ts +10 -139
package/README.md
CHANGED
|
@@ -112,6 +112,83 @@ function App() {
|
|
|
112
112
|
export default AppWithProviders;
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
### Offline initialization
|
|
116
|
+
|
|
117
|
+
If you fetch a flag configuration yourself (for example a precomputed-assignments payload
|
|
118
|
+
cached on disk, delivered via your own service, or bundled with the app), use
|
|
119
|
+
`DatadogOfflineOpenFeatureProvider` instead of `DatadogOpenFeatureProvider`. It evaluates flags
|
|
120
|
+
and reports exposures exactly like the online provider, but **never fetches configuration from
|
|
121
|
+
the network** — you supply it with `setConfiguration`.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import { DdFlags } from '@datadog/mobile-react-native';
|
|
125
|
+
import {
|
|
126
|
+
DatadogOfflineOpenFeatureProvider,
|
|
127
|
+
configurationFromString
|
|
128
|
+
} from '@datadog/mobile-react-native-openfeature';
|
|
129
|
+
import { OpenFeature } from '@openfeature/react-sdk';
|
|
130
|
+
|
|
131
|
+
await DdFlags.enable();
|
|
132
|
+
|
|
133
|
+
const provider = new DatadogOfflineOpenFeatureProvider();
|
|
134
|
+
|
|
135
|
+
// `wire` is a ConfigurationWire string you fetched yourself.
|
|
136
|
+
provider.setConfiguration(configurationFromString(wire));
|
|
137
|
+
|
|
138
|
+
// Set the provider after loading the configuration so it is ready with real flag values.
|
|
139
|
+
await OpenFeature.setProviderAndWait(provider);
|
|
140
|
+
|
|
141
|
+
// Evaluate flags — no network request is made.
|
|
142
|
+
const client = OpenFeature.getClient();
|
|
143
|
+
const isNewFeatureEnabled = client.getBooleanValue('new-feature-enabled', false);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The configuration carries the evaluation context it was computed for, and the provider adopts it
|
|
147
|
+
automatically. A precomputed configuration is a **single-subject snapshot**: it can only be served
|
|
148
|
+
against the context it was computed for. Per-context evaluation is a future (rules-based) capability.
|
|
149
|
+
|
|
150
|
+
> **Warning:** Do **not** call `OpenFeature.setContext` with a _different_ context for the offline
|
|
151
|
+
> precomputed flow. A runtime context that does not match the configuration's embedded context
|
|
152
|
+
> (compared after the SDK's context normalization, not raw deep-equality) cannot be served (offline
|
|
153
|
+
> never fetches), so the provider enters the OpenFeature **`ERROR`** state and evaluations fall back
|
|
154
|
+
> to your **coded default values** (evaluation `errorCode: INVALID_CONTEXT`). The provider recovers to
|
|
155
|
+
> `READY` once the effective context is empty or matches the snapshot again. Note that a blank
|
|
156
|
+
> `{ targetingKey: '' }` is **not** "empty" — an empty string is a real (anonymous) targeting key, a
|
|
157
|
+
> distinct subject that must match the snapshot; use `clearContext()` (or omit context) to fall back
|
|
158
|
+
> to the embedded context.
|
|
159
|
+
|
|
160
|
+
Recommended setup for a hybrid app that also uses other OpenFeature providers, hooks, or domains:
|
|
161
|
+
|
|
162
|
+
- **Bind the offline provider to a dedicated OpenFeature domain, and give that domain an explicit
|
|
163
|
+
empty context** at registration (`OpenFeature.setContext(domain, {})`) — which this provider reads
|
|
164
|
+
as "no override, use the embedded context". A domain with no context of its own **inherits the
|
|
165
|
+
global context**, so a global `OpenFeature.setContext` (or a mismatching global context) would
|
|
166
|
+
otherwise reach the provider and force it into `ERROR`.
|
|
167
|
+
- **Use a unique Datadog `clientName`** (`new DatadogOfflineOpenFeatureProvider({ clientName })`):
|
|
168
|
+
separate OpenFeature domains otherwise share the same underlying `DdFlags.getClient('default')`, and
|
|
169
|
+
an online provider on that shared client would discard the offline configuration.
|
|
170
|
+
|
|
171
|
+
Because you do not set an OpenFeature context, note the **context split**: OpenFeature hooks observe
|
|
172
|
+
the OpenFeature evaluation context (`{}` when unset), while Datadog exposure tracking attributes
|
|
173
|
+
evaluations to the configuration's embedded context.
|
|
174
|
+
|
|
175
|
+
> **Note (recovery caveat):** "clearing context recovers" holds only when the resulting *effective*
|
|
176
|
+
> context is empty or matches the snapshot. `OpenFeature.clearContext(domain)` removes the domain
|
|
177
|
+
> context and **falls back to the global context** — if that global context is non-empty and does not
|
|
178
|
+
> match, the provider stays in `ERROR`.
|
|
179
|
+
|
|
180
|
+
> **Note (startup order):** Load the configuration with `setConfiguration` _before_
|
|
181
|
+
> `setProviderAndWait`, as shown above. If you register the provider before any successful
|
|
182
|
+
> `setConfiguration`, it initializes to the `ERROR` state (there is nothing it can evaluate); loading a
|
|
183
|
+
> valid configuration afterwards recovers it to `READY`. **Do not use the non-awaiting
|
|
184
|
+
> `OpenFeature.setProvider(provider)` immediately followed by `setConfiguration`** — that ordering
|
|
185
|
+
> races (the pending initialization can **settle (reject)** after the recovery and overwrite the
|
|
186
|
+
> status back to `ERROR`). Configure first, or `await OpenFeature.setProviderAndWait(...)`.
|
|
187
|
+
|
|
188
|
+
This provider relies on the OpenFeature static-context lifecycle — the SDK owns the
|
|
189
|
+
`PROVIDER_RECONCILING`/`PROVIDER_CONTEXT_CHANGED` events on a context change — and requires
|
|
190
|
+
`@openfeature/web-sdk` `^1.8.0` (the version it is developed and verified against).
|
|
191
|
+
|
|
115
192
|
[1]: https://openfeature.dev/docs/reference/sdks/client/web/react/
|
|
116
193
|
[2]: https://docs.datadoghq.com/getting_started/feature_flags/
|
|
117
194
|
[3]: https://github.com/DataDog/dd-sdk-reactnative/tree/develop/packages/core
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DatadogCoreOpenFeatureProvider = void 0;
|
|
7
|
+
var _mobileReactNative = require("@datadog/mobile-react-native");
|
|
8
|
+
var _webSdk = require("@openfeature/web-sdk");
|
|
9
|
+
/*
|
|
10
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
11
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
12
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Shared base for the Datadog OpenFeature providers. It owns the `FlagsClient`, the event
|
|
17
|
+
* emitter, and evaluation (`resolveX`) — everything the online and offline providers have in
|
|
18
|
+
* common. It does not decide how the evaluation context is sourced (fetch vs. offline load);
|
|
19
|
+
* concrete providers implement `initialize`/`onContextChange`.
|
|
20
|
+
*
|
|
21
|
+
* Internal: not exported from the package entry point. Customers use
|
|
22
|
+
* `DatadogOpenFeatureProvider` (online) or `DatadogOfflineOpenFeatureProvider` (offline).
|
|
23
|
+
*/
|
|
24
|
+
class DatadogCoreOpenFeatureProvider {
|
|
25
|
+
runsOn = 'client';
|
|
26
|
+
events = new _webSdk.OpenFeatureEventEmitter();
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
if (!options.clientName) {
|
|
29
|
+
options.clientName = 'default';
|
|
30
|
+
}
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.flagsClient = _mobileReactNative.DdFlags.getClient(this.options.clientName);
|
|
33
|
+
}
|
|
34
|
+
resolveBooleanEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
35
|
+
const details = this.flagsClient.getBooleanDetails(flagKey, defaultValue);
|
|
36
|
+
return toFlagResolution(details);
|
|
37
|
+
}
|
|
38
|
+
resolveStringEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
39
|
+
const details = this.flagsClient.getStringDetails(flagKey, defaultValue);
|
|
40
|
+
return toFlagResolution(details);
|
|
41
|
+
}
|
|
42
|
+
resolveNumberEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
43
|
+
const details = this.flagsClient.getNumberDetails(flagKey, defaultValue);
|
|
44
|
+
return toFlagResolution(details);
|
|
45
|
+
}
|
|
46
|
+
resolveObjectEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
47
|
+
// The OpenFeature spec states that the return value can be any valid JSON value.
|
|
48
|
+
// However, the Datadog Flags feature only supports JSON objects for the JSON feature flag type.
|
|
49
|
+
// Thus, the user should always expect the returned value to be an object instead of any arbitrary JSON value.
|
|
50
|
+
// Also, the user is responsible for providing a proper `defaultValue` that's an object.
|
|
51
|
+
|
|
52
|
+
const details = this.flagsClient.getObjectDetails(flagKey, defaultValue);
|
|
53
|
+
return toFlagResolution(details);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.DatadogCoreOpenFeatureProvider = DatadogCoreOpenFeatureProvider;
|
|
57
|
+
const toFlagResolution = details => {
|
|
58
|
+
const {
|
|
59
|
+
value,
|
|
60
|
+
reason,
|
|
61
|
+
variant,
|
|
62
|
+
allocationKey,
|
|
63
|
+
errorCode,
|
|
64
|
+
errorMessage
|
|
65
|
+
} = details;
|
|
66
|
+
const parsedErrorCode = errorCode && (_webSdk.ErrorCode[errorCode] || _webSdk.ErrorCode.GENERAL);
|
|
67
|
+
const result = {
|
|
68
|
+
value,
|
|
69
|
+
reason,
|
|
70
|
+
variant,
|
|
71
|
+
flagMetadata: allocationKey ? {
|
|
72
|
+
allocationKey
|
|
73
|
+
} : undefined,
|
|
74
|
+
errorCode: parsedErrorCode,
|
|
75
|
+
errorMessage
|
|
76
|
+
};
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=coreProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_mobileReactNative","require","_webSdk","DatadogCoreOpenFeatureProvider","runsOn","events","OpenFeatureEventEmitter","constructor","options","clientName","flagsClient","DdFlags","getClient","resolveBooleanEvaluation","flagKey","defaultValue","_context","_logger","details","getBooleanDetails","toFlagResolution","resolveStringEvaluation","getStringDetails","resolveNumberEvaluation","getNumberDetails","resolveObjectEvaluation","getObjectDetails","exports","value","reason","variant","allocationKey","errorCode","errorMessage","parsedErrorCode","ErrorCode","GENERAL","result","flagMetadata","undefined"],"sourceRoot":"../../src","sources":["coreProvider.ts"],"mappings":";;;;;;AAMA,IAAAA,kBAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AARA;AACA;AACA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAeE,8BAA8B,CAAqB;EAC5DC,MAAM,GAAa,QAAQ;EAM3BC,MAAM,GAAyC,IAAIC,+BAAuB,CAAC,CAAC;EAErFC,WAAWA,CAACC,OAA0C,GAAG,CAAC,CAAC,EAAE;IACzD,IAAI,CAACA,OAAO,CAACC,UAAU,EAAE;MACrBD,OAAO,CAACC,UAAU,GAAG,SAAS;IAClC;IAEA,IAAI,CAACD,OAAO,GAAGA,OAAO;IAEtB,IAAI,CAACE,WAAW,GAAGC,0BAAO,CAACC,SAAS,CAAC,IAAI,CAACJ,OAAO,CAACC,UAAU,CAAC;EACjE;EAEAI,wBAAwBA,CACpBC,OAAe,EACfC,YAAqB,EACrBC,QAA6B,EAC7BC,OA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DP,SAAS,EAAEE,eAAe;IAC1BD;EACJ,CAAC;EAED,OAAOI,MAAM;AACjB,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,11 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "DatadogOfflineOpenFeatureProvider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _offlineProvider.DatadogOfflineOpenFeatureProvider;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "DatadogOpenFeatureProvider", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
9
15
|
return _provider.DatadogOpenFeatureProvider;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "configurationFromString", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _mobileReactNative.configurationFromString;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _mobileReactNative = require("@datadog/mobile-react-native");
|
|
25
|
+
var _offlineProvider = require("./offlineProvider");
|
|
12
26
|
var _provider = require("./provider");
|
|
13
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_mobileReactNative","require","_offlineProvider","_provider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAAA,kBAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toDdContext = exports.isEmptyContext = 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
|
+
* Convert an OpenFeature evaluation context into the Datadog Flags shape.
|
|
15
|
+
*/
|
|
16
|
+
const toDdContext = context => {
|
|
17
|
+
const {
|
|
18
|
+
targetingKey,
|
|
19
|
+
...attributes
|
|
20
|
+
} = context;
|
|
21
|
+
|
|
22
|
+
// Important ⚠️
|
|
23
|
+
// The Flags SDK doesn't support nested non-primitive values in the evaluation context as per OF.3 FFE SDK requirement.
|
|
24
|
+
// However, we let the SDK handle this inside of FlagsClient since it does this processing anyways.
|
|
25
|
+
const ddContextAttributes = attributes;
|
|
26
|
+
return {
|
|
27
|
+
// Allow flag evaluations without a provided targeting key.
|
|
28
|
+
targetingKey: targetingKey ?? '',
|
|
29
|
+
attributes: ddContextAttributes
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether an OpenFeature evaluation context carries no information — no targeting key and no
|
|
35
|
+
* attributes with a defined value (so `{}` and `{ targetingKey: undefined }` are both empty).
|
|
36
|
+
* Used by the offline provider to avoid overwriting a configuration's embedded context with an
|
|
37
|
+
* empty context stamped by the OpenFeature lifecycle.
|
|
38
|
+
*
|
|
39
|
+
* Note: an explicit `targetingKey: ''` is **not** empty. An empty string is a real (anonymous)
|
|
40
|
+
* targeting key — a distinct subject — not the absence of a context. Only a genuinely absent
|
|
41
|
+
* context (`{}` / `clearContext()`) re-adopts the configuration's embedded context; `{ targetingKey:
|
|
42
|
+
* '' }` is reconciled as a real context, so it must match the precomputed snapshot or the provider
|
|
43
|
+
* enters `ERROR` (serving coded defaults) rather than silently serving another subject's flags.
|
|
44
|
+
*/
|
|
45
|
+
exports.toDdContext = toDdContext;
|
|
46
|
+
const isEmptyContext = context => {
|
|
47
|
+
return Object.values(context).every(value => value === undefined);
|
|
48
|
+
};
|
|
49
|
+
exports.isEmptyContext = isEmptyContext;
|
|
50
|
+
//# sourceMappingURL=mappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["toDdContext","context","targetingKey","attributes","ddContextAttributes","exports","isEmptyContext","Object","values","every","value","undefined"],"sourceRoot":"../../src","sources":["mappers.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACO,MAAMA,WAAW,GACpBC,OAA4B,IACN;EACtB,MAAM;IAAEC,YAAY;IAAE,GAAGC;EAAW,CAAC,GAAGF,OAAO;;EAE/C;EACA;EACA;EACA,MAAMG,mBAAmB,GAAGD,UAA4C;EAExE,OAAO;IACH;IACAD,YAAY,EAAEA,YAAY,IAAI,EAAE;IAChCC,UAAU,EAAEC;EAChB,CAAC;AACL,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAXAC,OAAA,CAAAL,WAAA,GAAAA,WAAA;AAYO,MAAMM,cAAc,GAAIL,OAA4B,IAAc;EACrE,OAAOM,MAAM,CAACC,MAAM,CAACP,OAAO,CAAC,CAACQ,KAAK,CAACC,KAAK,IAAIA,KAAK,KAAKC,SAAS,CAAC;AACrE,CAAC;AAACN,OAAA,CAAAC,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DatadogOfflineOpenFeatureProvider = void 0;
|
|
7
|
+
var _webSdk = require("@openfeature/web-sdk");
|
|
8
|
+
var _coreProvider = require("./coreProvider");
|
|
9
|
+
var _mappers = require("./mappers");
|
|
10
|
+
/*
|
|
11
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
12
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
13
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// The outcome of a `FlagsClient` reconcile. Derived from the client so the provider maps it to
|
|
17
|
+
// OpenFeature transitions; not part of the package's public API.
|
|
18
|
+
|
|
19
|
+
// A `PROVIDER_ERROR` event payload carrying the spec's top-level error code (§5.1.5). The web-sdk
|
|
20
|
+
// `ErrorEvent` type omits `errorCode`, but the emitter accepts the extra field and
|
|
21
|
+
// `ProviderWrapper` reads it.
|
|
22
|
+
|
|
23
|
+
const OF_ERROR_CODE = {
|
|
24
|
+
INVALID_CONTEXT: _webSdk.ErrorCode.INVALID_CONTEXT,
|
|
25
|
+
PROVIDER_NOT_READY: _webSdk.ErrorCode.PROVIDER_NOT_READY,
|
|
26
|
+
GENERAL: _webSdk.ErrorCode.GENERAL
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An offline Datadog OpenFeature provider.
|
|
31
|
+
*
|
|
32
|
+
* It behaves like the online `DatadogOpenFeatureProvider` — same flag evaluation and
|
|
33
|
+
* exposure/RUM tracking — **except it never fetches configuration from the network**.
|
|
34
|
+
* Instead of fetching on `initialize`/`onContextChange`, it evaluates against a configuration
|
|
35
|
+
* supplied via {@link DatadogOfflineOpenFeatureProvider.setConfiguration}. A precomputed
|
|
36
|
+
* configuration carries the evaluation context it was computed for, so you should **not** call
|
|
37
|
+
* `OpenFeature.setContext` for the offline precomputed flow — see the class remarks.
|
|
38
|
+
*
|
|
39
|
+
* A runtime context that does not match the configuration's embedded context (compared after
|
|
40
|
+
* normalization) cannot be served (offline never fetches), so it puts the provider into the
|
|
41
|
+
* OpenFeature `ERROR` state and evaluations fall back to your coded defaults (`INVALID_CONTEXT`).
|
|
42
|
+
* An empty *effective* context re-adopts the embedded context and recovers — but note that
|
|
43
|
+
* `clearContext(domain)` falls back to the global context, which may itself be non-empty and
|
|
44
|
+
* mismatching (and would keep the provider in `ERROR`). Load the configuration before setting the
|
|
45
|
+
* provider so it is ready with real flag values from the start:
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { OpenFeature } from '@openfeature/web-sdk';
|
|
50
|
+
* import {
|
|
51
|
+
* DatadogOfflineOpenFeatureProvider,
|
|
52
|
+
* configurationFromString
|
|
53
|
+
* } from '@datadog/mobile-react-native-openfeature';
|
|
54
|
+
*
|
|
55
|
+
* const provider = new DatadogOfflineOpenFeatureProvider();
|
|
56
|
+
* provider.setConfiguration(configurationFromString(wire)); // no network
|
|
57
|
+
* await OpenFeature.setProviderAndWait(provider);
|
|
58
|
+
*
|
|
59
|
+
* const client = OpenFeature.getClient();
|
|
60
|
+
* const enabled = client.getBooleanValue('new-feature', false);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
class DatadogOfflineOpenFeatureProvider extends _coreProvider.DatadogCoreOpenFeatureProvider {
|
|
64
|
+
metadata = {
|
|
65
|
+
name: 'datadog-react-native-offline'
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Whether the provider is currently in an error state, so a successful `setConfiguration` must
|
|
69
|
+
// emit `PROVIDER_READY` to recover (a bare `CONFIGURATION_CHANGED` would not clear `ERROR`).
|
|
70
|
+
// It may be set before the provider is registered, so it does not necessarily mirror
|
|
71
|
+
// OpenFeature's status yet.
|
|
72
|
+
configurationInError = false;
|
|
73
|
+
async initialize(context = {}) {
|
|
74
|
+
const result = this.applyContext(context);
|
|
75
|
+
|
|
76
|
+
// OpenFeature derives the initial status from whether `initialize` settles: resolve =>
|
|
77
|
+
// READY, reject => ERROR. Reject when the provider cannot serve — an absent, invalid, or
|
|
78
|
+
// context-mismatched configuration — so it does not start in a misleading READY that only
|
|
79
|
+
// returns default values. Loading a valid configuration later recovers it.
|
|
80
|
+
if (result.status === 'error') {
|
|
81
|
+
throw this.toError(result.errorCode);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
onContextChange(_oldContext, newContext) {
|
|
85
|
+
// Synchronous on purpose. Reconciliation is synchronous, and a synchronous throw makes the
|
|
86
|
+
// Web SDK transition straight to ERROR (skipping the transient RECONCILING state) with no
|
|
87
|
+
// async window in which an interleaved `setConfiguration` could clobber the final status.
|
|
88
|
+
// Returning normally lets the Web SDK set READY — the automatic recovery path.
|
|
89
|
+
const result = this.applyContext(newContext);
|
|
90
|
+
if (result.status === 'error') {
|
|
91
|
+
throw this.toError(result.errorCode);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Load a configuration into the provider for offline evaluation.
|
|
97
|
+
*
|
|
98
|
+
* @param configuration A configuration parsed from a `ConfigurationWire` string via
|
|
99
|
+
* `configurationFromString`.
|
|
100
|
+
*/
|
|
101
|
+
setConfiguration(configuration) {
|
|
102
|
+
const result = this.flagsClient.setConfiguration(configuration);
|
|
103
|
+
if (result.status === 'ready') {
|
|
104
|
+
if (this.configurationInError) {
|
|
105
|
+
// Recover from a prior error: PROVIDER_READY clears the ERROR status (a bare
|
|
106
|
+
// CONFIGURATION_CHANGED would not).
|
|
107
|
+
this.configurationInError = false;
|
|
108
|
+
this.events.emit(_webSdk.ProviderEvents.Ready);
|
|
109
|
+
}
|
|
110
|
+
// The (re)loaded configuration changed the served flags.
|
|
111
|
+
this.events.emit(_webSdk.ProviderEvents.ConfigurationChanged);
|
|
112
|
+
} else {
|
|
113
|
+
this.configurationInError = true;
|
|
114
|
+
const details = {
|
|
115
|
+
message: 'The Datadog offline provider cannot serve the loaded configuration for the current context.',
|
|
116
|
+
errorCode: OF_ERROR_CODE[result.errorCode]
|
|
117
|
+
};
|
|
118
|
+
this.events.emit(_webSdk.ProviderEvents.Error, details);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
applyContext(context) {
|
|
122
|
+
// An empty context means "no external override": clear it so a loaded precomputed
|
|
123
|
+
// configuration is served against its embedded context. Order-independent — the synthetic
|
|
124
|
+
// `initialize({})`, `setContext({})`, and `clearContext()` all re-adopt the embedded
|
|
125
|
+
// context rather than being treated as a mismatch.
|
|
126
|
+
const result = (0, _mappers.isEmptyContext)(context) ? this.flagsClient.resetEvaluationContextWithoutFetching() : this.flagsClient.setEvaluationContextWithoutFetching((0, _mappers.toDdContext)(context));
|
|
127
|
+
this.configurationInError = result.status === 'error';
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Map a reconcile error code to the precise OpenFeature error type, so direct callers of
|
|
133
|
+
* `initialize`/`onContextChange` (and `setProviderAndWait`) receive the correct typed error.
|
|
134
|
+
* (Web SDK 1.8.0 drops the code from the lifecycle-generated error *event*, but the thrown
|
|
135
|
+
* error type is still accurate for callers.)
|
|
136
|
+
*/
|
|
137
|
+
toError(errorCode) {
|
|
138
|
+
switch (errorCode) {
|
|
139
|
+
case 'INVALID_CONTEXT':
|
|
140
|
+
return new _webSdk.InvalidContextError('The evaluation context does not match the offline precomputed configuration. Serving default values.');
|
|
141
|
+
case 'PROVIDER_NOT_READY':
|
|
142
|
+
return new _webSdk.ProviderNotReadyError('The Datadog offline provider has no configuration loaded. Provide one via setConfiguration.');
|
|
143
|
+
default:
|
|
144
|
+
return new _webSdk.GeneralError('The Datadog offline provider cannot serve the loaded configuration.');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.DatadogOfflineOpenFeatureProvider = DatadogOfflineOpenFeatureProvider;
|
|
149
|
+
//# sourceMappingURL=offlineProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_webSdk","require","_coreProvider","_mappers","OF_ERROR_CODE","INVALID_CONTEXT","ErrorCode","PROVIDER_NOT_READY","GENERAL","DatadogOfflineOpenFeatureProvider","DatadogCoreOpenFeatureProvider","metadata","name","configurationInError","initialize","context","result","applyContext","status","toError","errorCode","onContextChange","_oldContext","newContext","setConfiguration","configuration","flagsClient","events","emit","ProviderEvents","Ready","ConfigurationChanged","details","message","Error","isEmptyContext","resetEvaluationContextWithoutFetching","setEvaluationContextWithoutFetching","toDdContext","InvalidContextError","ProviderNotReadyError","GeneralError","exports"],"sourceRoot":"../../src","sources":["offlineProvider.ts"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AAaA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAxBA;AACA;AACA;AACA;AACA;;AAsBA;AACA;;AAOA;AACA;AACA;;AAGA,MAAMG,aAAwD,GAAG;EAC7DC,eAAe,EAAEC,iBAAS,CAACD,eAAe;EAC1CE,kBAAkB,EAAED,iBAAS,CAACC,kBAAkB;EAChDC,OAAO,EAAEF,iBAAS,CAACE;AACvB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,iCAAiC,SAASC,4CAA8B,CAAC;EACzEC,QAAQ,GAAqB;IAClCC,IAAI,EAAE;EACV,CAAC;;EAED;EACA;EACA;EACA;EACQC,oBAAoB,GAAG,KAAK;EAEpC,MAAMC,UAAUA,CAACC,OAA4B,GAAG,CAAC,CAAC,EAAiB;IAC/D,MAAMC,MAAM,GAAG,IAAI,CAACC,YAAY,CAACF,OAAO,CAAC;;IAEzC;IACA;IACA;IACA;IACA,IAAIC,MAAM,CAACE,MAAM,KAAK,OAAO,EAAE;MAC3B,MAAM,IAAI,CAACC,OAAO,CAACH,MAAM,CAACI,SAAS,CAAC;IACxC;EACJ;EAEAC,eAAeA,CACXC,WAAgC,EAChCC,UAA+B,EAC3B;IACJ;IACA;IACA;IACA;IACA,MAAMP,MAAM,GAAG,IAAI,CAACC,YAAY,CAACM,UAAU,CA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ACjE,QAAQA,SAAS;MACb,KAAK,iBAAiB;QAClB,OAAO,IAAImB,2BAAmB,CAC1B,sGACJ,CAAC;MACL,KAAK,oBAAoB;QACrB,OAAO,IAAIC,6BAAqB,CAC5B,6FACJ,CAAC;MACL;QACI,OAAO,IAAIC,oBAAY,CACnB,qEACJ,CAAC;IACT;EACJ;AACJ;AAACC,OAAA,CAAAjC,iCAAA,GAAAA,iCAAA","ignoreList":[]}
|
package/lib/commonjs/provider.js
CHANGED
|
@@ -4,35 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.DatadogOpenFeatureProvider = void 0;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
7
|
+
var _coreProvider = require("./coreProvider");
|
|
8
|
+
var _mappers = require("./mappers");
|
|
9
9
|
/*
|
|
10
10
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
11
11
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
12
12
|
* Copyright 2016-Present Datadog, Inc.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The online Datadog OpenFeature provider. Fetches precomputed flag assignments from Datadog
|
|
17
|
+
* whenever the evaluation context is set or changed.
|
|
18
|
+
*/
|
|
19
|
+
class DatadogOpenFeatureProvider extends _coreProvider.DatadogCoreOpenFeatureProvider {
|
|
17
20
|
metadata = {
|
|
18
21
|
name: 'datadog-react-native'
|
|
19
22
|
};
|
|
20
|
-
events = new _webSdk.OpenFeatureEventEmitter();
|
|
21
23
|
contextChangePromise = Promise.resolve();
|
|
22
|
-
constructor(options = {}) {
|
|
23
|
-
if (!options.clientName) {
|
|
24
|
-
options.clientName = 'default';
|
|
25
|
-
}
|
|
26
|
-
this.options = options;
|
|
27
|
-
this.flagsClient = _mobileReactNative.DdFlags.getClient(this.options.clientName);
|
|
28
|
-
}
|
|
29
24
|
async initialize(context = {}) {
|
|
30
|
-
const ddContext = toDdContext(context);
|
|
25
|
+
const ddContext = (0, _mappers.toDdContext)(context);
|
|
31
26
|
this.contextChangePromise = this.flagsClient.setEvaluationContext(ddContext);
|
|
32
27
|
await this.contextChangePromise;
|
|
33
28
|
}
|
|
34
29
|
async onContextChange(_oldContext, newContext) {
|
|
35
|
-
const newDdContext = toDdContext(newContext);
|
|
30
|
+
const newDdContext = (0, _mappers.toDdContext)(newContext);
|
|
36
31
|
|
|
37
32
|
// Promise chain in case `onContextChange` is called multiple times.
|
|
38
33
|
this.contextChangePromise = this.contextChangePromise.then(() => {
|
|
@@ -42,65 +37,6 @@ class DatadogOpenFeatureProvider {
|
|
|
42
37
|
// Wait for the current context change to complete.
|
|
43
38
|
await this.contextChangePromise;
|
|
44
39
|
}
|
|
45
|
-
resolveBooleanEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
46
|
-
const details = this.flagsClient.getBooleanDetails(flagKey, defaultValue);
|
|
47
|
-
return toFlagResolution(details);
|
|
48
|
-
}
|
|
49
|
-
resolveStringEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
50
|
-
const details = this.flagsClient.getStringDetails(flagKey, defaultValue);
|
|
51
|
-
return toFlagResolution(details);
|
|
52
|
-
}
|
|
53
|
-
resolveNumberEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
54
|
-
const details = this.flagsClient.getNumberDetails(flagKey, defaultValue);
|
|
55
|
-
return toFlagResolution(details);
|
|
56
|
-
}
|
|
57
|
-
resolveObjectEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
58
|
-
// The OpenFeature spec states that the return value can be any valid JSON value.
|
|
59
|
-
// However, the Datadog Flags feature only supports JSON objects for the JSON feature flag type.
|
|
60
|
-
// Thus, the user should always expect the returned value to be an object instead of any arbitrary JSON value.
|
|
61
|
-
// Also, the user is responsible for providing a proper `defaultValue` that's an object.
|
|
62
|
-
|
|
63
|
-
const details = this.flagsClient.getObjectDetails(flagKey, defaultValue);
|
|
64
|
-
return toFlagResolution(details);
|
|
65
|
-
}
|
|
66
40
|
}
|
|
67
41
|
exports.DatadogOpenFeatureProvider = DatadogOpenFeatureProvider;
|
|
68
|
-
const toDdContext = context => {
|
|
69
|
-
const {
|
|
70
|
-
targetingKey,
|
|
71
|
-
...attributes
|
|
72
|
-
} = context;
|
|
73
|
-
|
|
74
|
-
// Important ⚠️
|
|
75
|
-
// The Flags SDK doesn't support nested non-primitive values in the evaluation context as per OF.3 FFE SDK requirement.
|
|
76
|
-
// However, we let the SDK handle this inside of FlagsClient since it does this processing anyways.
|
|
77
|
-
const ddContextAttributes = attributes;
|
|
78
|
-
return {
|
|
79
|
-
// Allow flag evaluations without a provided targeting key.
|
|
80
|
-
targetingKey: targetingKey ?? '',
|
|
81
|
-
attributes: ddContextAttributes
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
const toFlagResolution = details => {
|
|
85
|
-
const {
|
|
86
|
-
value,
|
|
87
|
-
reason,
|
|
88
|
-
variant,
|
|
89
|
-
allocationKey,
|
|
90
|
-
errorCode,
|
|
91
|
-
errorMessage
|
|
92
|
-
} = details;
|
|
93
|
-
const parsedErrorCode = errorCode && (_webSdk.ErrorCode[errorCode] || _webSdk.ErrorCode.GENERAL);
|
|
94
|
-
const result = {
|
|
95
|
-
value,
|
|
96
|
-
reason,
|
|
97
|
-
variant,
|
|
98
|
-
flagMetadata: allocationKey ? {
|
|
99
|
-
allocationKey
|
|
100
|
-
} : undefined,
|
|
101
|
-
errorCode: parsedErrorCode,
|
|
102
|
-
errorMessage
|
|
103
|
-
};
|
|
104
|
-
return result;
|
|
105
|
-
};
|
|
106
42
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_coreProvider","require","_mappers","DatadogOpenFeatureProvider","DatadogCoreOpenFeatureProvider","metadata","name","contextChangePromise","Promise","resolve","initialize","context","ddContext","toDdContext","flagsClient","setEvaluationContext","onContextChange","_oldContext","newContext","newDdContext","then","exports"],"sourceRoot":"../../src","sources":["provider.ts"],"mappings":";;;;;;AAWA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAZA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACO,MAAME,0BAA0B,SAASC,4CAA8B,CAAC;EAClEC,QAAQ,GAAqB;IAClCC,IAAI,EAAE;EACV,CAAC;EAEOC,oBAAoB,GAAGC,OAAO,CAACC,OAAO,CAAC,CAAC;EAEhD,MAAMC,UAAUA,CAACC,OAA4B,GAAG,CAAC,CAAC,EAAiB;IAC/D,MAAMC,SAAS,GAAG,IAAAC,oBAAW,EAACF,OAAO,CAAC;IACtC,IAAI,CAACJ,oBAAoB,GAAG,IAAI,CAACO,WAAW,CAACC,oBAAoB,CAC7DH,SACJ,CAAC;IAED,MAAM,IAAI,CAACL,oBAAoB;EACnC;EAEA,MAAMS,eAAeA,CACjBC,WAAgC,EAChCC,UAA+B,EAClB;IACb,MAAMC,YAAY,GAAG,IAAAN,oBAAW,EAACK,UAAU,CAAC;;IAE5C;IACA,IAAI,CAACX,oBAAoB,GAAG,IAAI,CAACA,oBAAoB,CAACa,IAAI,CAAC,MAAM;MAC7D,OAAO,IAAI,CAACN,WAAW,CAACC,oBAAoB,CAACI,YAAY,CAAC;IAC9D,CAAC,CAAC;;IAEF;IACA,MAAM,IAAI,CAACZ,oBAAoB;EACnC;AACJ;AAACc,OAAA,CAAAlB,0BAAA,GAAAA,0BAAA","ignoreList":[]}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { DdFlags } from '@datadog/mobile-react-native';
|
|
8
|
+
import { OpenFeatureEventEmitter, ErrorCode } from '@openfeature/web-sdk';
|
|
9
|
+
/**
|
|
10
|
+
* Shared base for the Datadog OpenFeature providers. It owns the `FlagsClient`, the event
|
|
11
|
+
* emitter, and evaluation (`resolveX`) — everything the online and offline providers have in
|
|
12
|
+
* common. It does not decide how the evaluation context is sourced (fetch vs. offline load);
|
|
13
|
+
* concrete providers implement `initialize`/`onContextChange`.
|
|
14
|
+
*
|
|
15
|
+
* Internal: not exported from the package entry point. Customers use
|
|
16
|
+
* `DatadogOpenFeatureProvider` (online) or `DatadogOfflineOpenFeatureProvider` (offline).
|
|
17
|
+
*/
|
|
18
|
+
export class DatadogCoreOpenFeatureProvider {
|
|
19
|
+
runsOn = 'client';
|
|
20
|
+
events = new OpenFeatureEventEmitter();
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
if (!options.clientName) {
|
|
23
|
+
options.clientName = 'default';
|
|
24
|
+
}
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.flagsClient = DdFlags.getClient(this.options.clientName);
|
|
27
|
+
}
|
|
28
|
+
resolveBooleanEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
29
|
+
const details = this.flagsClient.getBooleanDetails(flagKey, defaultValue);
|
|
30
|
+
return toFlagResolution(details);
|
|
31
|
+
}
|
|
32
|
+
resolveStringEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
33
|
+
const details = this.flagsClient.getStringDetails(flagKey, defaultValue);
|
|
34
|
+
return toFlagResolution(details);
|
|
35
|
+
}
|
|
36
|
+
resolveNumberEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
37
|
+
const details = this.flagsClient.getNumberDetails(flagKey, defaultValue);
|
|
38
|
+
return toFlagResolution(details);
|
|
39
|
+
}
|
|
40
|
+
resolveObjectEvaluation(flagKey, defaultValue, _context, _logger) {
|
|
41
|
+
// The OpenFeature spec states that the return value can be any valid JSON value.
|
|
42
|
+
// However, the Datadog Flags feature only supports JSON objects for the JSON feature flag type.
|
|
43
|
+
// Thus, the user should always expect the returned value to be an object instead of any arbitrary JSON value.
|
|
44
|
+
// Also, the user is responsible for providing a proper `defaultValue` that's an object.
|
|
45
|
+
|
|
46
|
+
const details = this.flagsClient.getObjectDetails(flagKey, defaultValue);
|
|
47
|
+
return toFlagResolution(details);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const toFlagResolution = details => {
|
|
51
|
+
const {
|
|
52
|
+
value,
|
|
53
|
+
reason,
|
|
54
|
+
variant,
|
|
55
|
+
allocationKey,
|
|
56
|
+
errorCode,
|
|
57
|
+
errorMessage
|
|
58
|
+
} = details;
|
|
59
|
+
const parsedErrorCode = errorCode && (ErrorCode[errorCode] || ErrorCode.GENERAL);
|
|
60
|
+
const result = {
|
|
61
|
+
value,
|
|
62
|
+
reason,
|
|
63
|
+
variant,
|
|
64
|
+
flagMetadata: allocationKey ? {
|
|
65
|
+
allocationKey
|
|
66
|
+
} : undefined,
|
|
67
|
+
errorCode: parsedErrorCode,
|
|
68
|
+
errorMessage
|
|
69
|
+
};
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=coreProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DdFlags","OpenFeatureEventEmitter","ErrorCode","DatadogCoreOpenFeatureProvider","runsOn","events","constructor","options","clientName","flagsClient","getClient","resolveBooleanEvaluation","flagKey","defaultValue","_context","_logger","details","getBooleanDetails","toFlagResolution","resolveStringEvaluation","getStringDetails","resolveNumberEvaluation","getNumberDetails","resolveObjectEvaluation","getObjectDetails","value","reason","variant","allocationKey","errorCode","errorMessage","parsedErrorCode","GENERAL","result","flagMetadata","undefined"],"sourceRoot":"../../src","sources":["coreProvider.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,8BAA8B;AAEtD,SAASC,uBAAuB,EAAEC,SAAS,QAAQ,sBAAsB;AAwBzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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,OAAO,CAAC;EACpC;AACJ;AAEA,MAAME,gBAAgB,GAAOF,OAAuB,IAA2B;EAC3E,MAAM;IACFS,KAAK;IACLC,MAAM;IACNC,OAAO;IACPC,aAAa;IACbC,SAAS;IACTC;EACJ,CAAC,GAAGd,OAAO;EAEX,MAAMe,eAAe,GACjBF,SAAS,KAAK3B,SAAS,CAAC2B,SAAS,CAAc,IAAI3B,SAAS,CAAC8B,OAAO,CAAC;EAEzE,MAAMC,MAA4B,GAAG;IACjCR,KAAK;IACLC,MAAM;IACNC,OAAO;IACPO,YAAY,EAAEN,aAAa,GAAG;MAAEA;IAAc,CAAC,GAAGO,SAAS;IAC3DN,SAAS,EAAEE,eAAe;IAC1BD;EACJ,CAAC;EAED,OAAOG,MAAM;AACjB,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { configurationFromString } from '@datadog/mobile-react-native';
|
|
8
|
+
import { DatadogOfflineOpenFeatureProvider } from './offlineProvider';
|
|
7
9
|
import { DatadogOpenFeatureProvider } from './provider';
|
|
8
|
-
export { DatadogOpenFeatureProvider };
|
|
10
|
+
export { DatadogOpenFeatureProvider, DatadogOfflineOpenFeatureProvider, configurationFromString };
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DatadogOpenFeatureProvider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,0BAA0B,QAAQ,YAAY;AAGvD,
|
|
1
|
+
{"version":3,"names":["configurationFromString","DatadogOfflineOpenFeatureProvider","DatadogOpenFeatureProvider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,uBAAuB,QAAQ,8BAA8B;AAEtE,SAASC,iCAAiC,QAAQ,mBAAmB;AACrE,SAASC,0BAA0B,QAAQ,YAAY;AAGvD,SACIA,0BAA0B,EAC1BD,iCAAiC,EACjCD,uBAAuB","ignoreList":[]}
|