@datadog/mobile-react-native 3.0.2 → 3.1.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/DatadogSDKReactNative.podspec +10 -9
- package/android/build.gradle +11 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdFlagsImplementation.kt +237 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkBridgeExt.kt +262 -78
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +1 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -1
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdFlags.kt +66 -0
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdFlags.kt +63 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkBridgeExtTest.kt +242 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +28 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +38 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +3 -0
- package/ios/Sources/DatadogSDKReactNative.h +2 -0
- package/ios/Sources/DdFlags.h +24 -0
- package/ios/Sources/DdFlags.mm +83 -0
- package/ios/Sources/DdFlagsImplementation.swift +263 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +2 -1
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/flags/DdFlags.js +51 -0
- package/lib/commonjs/flags/DdFlags.js.map +1 -0
- package/lib/commonjs/flags/FlagsClient.js +218 -0
- package/lib/commonjs/flags/FlagsClient.js.map +1 -0
- package/lib/commonjs/flags/internal.js +40 -0
- package/lib/commonjs/flags/internal.js.map +1 -0
- package/lib/commonjs/flags/types.js +6 -0
- package/lib/commonjs/flags/types.js.map +1 -0
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeDdFlags.js +19 -0
- package/lib/commonjs/specs/NativeDdFlags.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/flags/DdFlags.js +45 -0
- package/lib/module/flags/DdFlags.js.map +1 -0
- package/lib/module/flags/FlagsClient.js +211 -0
- package/lib/module/flags/FlagsClient.js.map +1 -0
- package/lib/module/flags/internal.js +33 -0
- package/lib/module/flags/internal.js.map +1 -0
- package/lib/module/flags/types.js +2 -0
- package/lib/module/flags/types.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeDdFlags.js +17 -0
- package/lib/module/specs/NativeDdFlags.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/flags/DdFlags.d.ts +3 -0
- package/lib/typescript/flags/DdFlags.d.ts.map +1 -0
- package/lib/typescript/flags/FlagsClient.d.ts +114 -0
- package/lib/typescript/flags/FlagsClient.d.ts.map +1 -0
- package/lib/typescript/flags/internal.d.ts +14 -0
- package/lib/typescript/flags/internal.d.ts.map +1 -0
- package/lib/typescript/flags/types.d.ts +202 -0
- package/lib/typescript/flags/types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/nativeModulesTypes.d.ts +5 -0
- package/lib/typescript/nativeModulesTypes.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdFlags.d.ts +15 -0
- package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/flags/DdFlags.ts +59 -0
- package/src/flags/FlagsClient.ts +266 -0
- package/src/flags/__tests__/DdFlags.test.ts +65 -0
- package/src/flags/__tests__/FlagsClient.test.ts +320 -0
- package/src/flags/internal.ts +63 -0
- package/src/flags/types.ts +215 -0
- package/src/index.tsx +15 -1
- package/src/nativeModulesTypes.ts +6 -0
- package/src/specs/NativeDdFlags.ts +35 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,263 @@
|
|
|
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 Foundation
|
|
8
|
+
import DatadogInternal
|
|
9
|
+
@_spi(Internal)
|
|
10
|
+
import DatadogFlags
|
|
11
|
+
|
|
12
|
+
@objc
|
|
13
|
+
public class DdFlagsImplementation: NSObject {
|
|
14
|
+
private let core: DatadogCoreProtocol
|
|
15
|
+
|
|
16
|
+
internal var clientProviders: [String: () -> FlagsClientProtocol] = [:]
|
|
17
|
+
|
|
18
|
+
/// Exposing this initializer for testing purposes. React Native will always use the default initializer.
|
|
19
|
+
internal init(core: DatadogCoreProtocol) {
|
|
20
|
+
self.core = core
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@objc
|
|
24
|
+
public override convenience init() {
|
|
25
|
+
self.init(core: CoreRegistry.default)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc
|
|
29
|
+
public func enable(_ configuration: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
30
|
+
// Client providers become stale upon subsequent enable calls (which can happen e.g. in case of a React Native hot reload).
|
|
31
|
+
clientProviders.removeAll()
|
|
32
|
+
|
|
33
|
+
if let config = configuration.asFlagsConfiguration() {
|
|
34
|
+
Flags.enable(with: config)
|
|
35
|
+
} else {
|
|
36
|
+
consolePrint("Invalid configuration provided for Flags. Feature initialization skipped.", .error)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
resolve(nil)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// Retrieve a `FlagsClient` instance in a non-interruptive way for usage in methods bridged to React Native.
|
|
43
|
+
///
|
|
44
|
+
/// We create a simple registry of client providers by client name holding closures for retrieving a client since client references are kept internally in the flagging SDK.
|
|
45
|
+
/// This is motivated by the fact that it is impossible to create a bridged synchronous `FlagsClient` creation; thus, we create a client instance dynamically on-demand.
|
|
46
|
+
private func getClient(name: String) -> FlagsClientProtocol {
|
|
47
|
+
if let provider = clientProviders[name] {
|
|
48
|
+
return provider()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let client = FlagsClient.create(name: name, in: self.core)
|
|
52
|
+
clientProviders[name] = { FlagsClient.shared(named: name, in: self.core) }
|
|
53
|
+
return client
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Using @escaping RCTPromiseResolveBlock type will result in an issue when compiling the Swift header file.
|
|
57
|
+
@objc
|
|
58
|
+
public func setEvaluationContext(_ clientName: String, targetingKey: String, attributes: NSDictionary, resolve: @escaping ((Any?) -> Void), reject: @escaping ((String?, String?, NSError?) -> Void)) {
|
|
59
|
+
let client = getClient(name: clientName)
|
|
60
|
+
guard let clientInternal = client as? FlagsClientInternal else {
|
|
61
|
+
reject("CLIENT_NOT_INITIALIZED", "Flags client '\(clientName)' is not properly initialized. Make sure the Datadog SDK has been initialized and Flags.enable() has been called.", nil)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let evaluationContext = buildEvaluationContext(targetingKey: targetingKey, attributes: attributes)
|
|
66
|
+
|
|
67
|
+
client.setEvaluationContext(evaluationContext) { result in
|
|
68
|
+
switch result {
|
|
69
|
+
case .success:
|
|
70
|
+
guard let flagsSnapshot = clientInternal.getFlagAssignments() else {
|
|
71
|
+
reject("CLIENT_NOT_INITIALIZED", "Failed to retrieve feature flags for client '\(clientName)'. Make sure the client has been properly initialized.", nil)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let serializedFlagsSnapshot = Dictionary(
|
|
76
|
+
uniqueKeysWithValues: flagsSnapshot.map { key, flagAssignment in
|
|
77
|
+
(key, flagAssignment.asDictionary(flagKey: key))
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
resolve(serializedFlagsSnapshot)
|
|
82
|
+
case .failure(let error):
|
|
83
|
+
var errorCode: String
|
|
84
|
+
var errorMessage: String
|
|
85
|
+
switch (error) {
|
|
86
|
+
case .clientNotInitialized:
|
|
87
|
+
errorCode = "CLIENT_NOT_INITIALIZED"
|
|
88
|
+
errorMessage = "Failed to retrieve feature flags for client '\(clientName)'. Make sure the client has been properly initialized."
|
|
89
|
+
case .invalidConfiguration:
|
|
90
|
+
errorCode = "INVALID_CONFIGURATION"
|
|
91
|
+
errorMessage = "The flags configuration for client '\(clientName)' is invalid. Check that all required parameters are provided."
|
|
92
|
+
case .invalidResponse:
|
|
93
|
+
errorCode = "INVALID_RESPONSE"
|
|
94
|
+
errorMessage = "The flags service returned an invalid response for client '\(clientName)'."
|
|
95
|
+
case .networkError:
|
|
96
|
+
errorCode = "NETWORK_ERROR"
|
|
97
|
+
errorMessage = "A network error occurred while fetching feature flags for client '\(clientName)'."
|
|
98
|
+
}
|
|
99
|
+
reject(errorCode, errorMessage, error as NSError)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@objc
|
|
105
|
+
public func trackEvaluation(_ clientName: String, key: String, rawFlag: NSDictionary, targetingKey: String, attributes: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
106
|
+
guard let client = getClient(name: clientName) as? FlagsClientInternal else {
|
|
107
|
+
reject("CLIENT_NOT_INITIALIZED", "Flags client '\(clientName)' is not properly initialized. Make sure the Datadog SDK has been initialized and Flags.enable() has been called.", nil)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
guard let flagAssignment = rawFlag.asFlagAssignment() else {
|
|
111
|
+
reject("INVALID_FLAG_ASSIGNMENT", "Failed to parse correct flag assignment from the provided raw flag data.", nil)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let evaluationContext = buildEvaluationContext(targetingKey: targetingKey, attributes: attributes)
|
|
116
|
+
|
|
117
|
+
client.sendFlagEvaluation(key: key, assignment: flagAssignment, context: evaluationContext)
|
|
118
|
+
|
|
119
|
+
resolve(nil)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Construct an `FlagsEvaluationContext` from a targeting key and a dictionary of attributes.
|
|
123
|
+
private func buildEvaluationContext(targetingKey: String, attributes: NSDictionary) -> FlagsEvaluationContext {
|
|
124
|
+
let dict = attributes as? [String: Any] ?? [:]
|
|
125
|
+
|
|
126
|
+
let parsedAttributes = dict.compactMapValues { value in AnyValue.wrap(value) }
|
|
127
|
+
|
|
128
|
+
return FlagsEvaluationContext(targetingKey: targetingKey, attributes: parsedAttributes)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
extension NSDictionary {
|
|
133
|
+
func asFlagsConfiguration() -> Flags.Configuration? {
|
|
134
|
+
let enabled = object(forKey: "enabled") as? Bool ?? false
|
|
135
|
+
|
|
136
|
+
if !enabled {
|
|
137
|
+
return nil
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Hard set `gracefulModeEnabled` to `true` because this misconfiguration is handled on JS side.
|
|
141
|
+
let gracefulModeEnabled = true
|
|
142
|
+
|
|
143
|
+
let trackExposures = object(forKey: "trackExposures") as? Bool
|
|
144
|
+
let rumIntegrationEnabled = object(forKey: "rumIntegrationEnabled") as? Bool
|
|
145
|
+
|
|
146
|
+
var customFlagsEndpointURL: URL? = nil
|
|
147
|
+
if let customFlagsEndpoint = object(forKey: "customFlagsEndpoint") as? String {
|
|
148
|
+
customFlagsEndpointURL = URL(string: "\(customFlagsEndpoint)/precompute-assignments" as String)
|
|
149
|
+
}
|
|
150
|
+
var customExposureEndpointURL: URL? = nil
|
|
151
|
+
if let customExposureEndpoint = object(forKey: "customExposureEndpoint") as? String {
|
|
152
|
+
customExposureEndpointURL = URL(string: "\(customExposureEndpoint)/api/v2/exposures" as String)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return Flags.Configuration(
|
|
156
|
+
gracefulModeEnabled: gracefulModeEnabled,
|
|
157
|
+
customFlagsEndpoint: customFlagsEndpointURL,
|
|
158
|
+
customExposureEndpoint: customExposureEndpointURL,
|
|
159
|
+
trackExposures: trackExposures ?? true,
|
|
160
|
+
rumIntegrationEnabled: rumIntegrationEnabled ?? true
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
extension FlagAssignment {
|
|
166
|
+
public func asDictionary(flagKey: String) -> [String: Any] {
|
|
167
|
+
let value = switch self.variation {
|
|
168
|
+
case .boolean(let v): v
|
|
169
|
+
case .string(let v): v
|
|
170
|
+
case .integer(let v): v
|
|
171
|
+
case .double(let v): v
|
|
172
|
+
case .object(let v): v.unwrap()
|
|
173
|
+
case .unknown: NSNull()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return [
|
|
177
|
+
"key": flagKey,
|
|
178
|
+
"value": value,
|
|
179
|
+
"allocationKey": allocationKey,
|
|
180
|
+
"variationKey": variationKey,
|
|
181
|
+
"reason": reason,
|
|
182
|
+
"doLog": doLog,
|
|
183
|
+
// Parity with Android. We don't use the following properties in iOS SDK.
|
|
184
|
+
"variationType": "",
|
|
185
|
+
"variationValue": "",
|
|
186
|
+
"extraLogging": [:],
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
extension NSDictionary {
|
|
192
|
+
func asFlagAssignment() -> FlagAssignment? {
|
|
193
|
+
guard
|
|
194
|
+
let allocationKey = object(forKey: "allocationKey") as? String,
|
|
195
|
+
let variationKey = object(forKey: "variationKey") as? String,
|
|
196
|
+
let reason = object(forKey: "reason") as? String,
|
|
197
|
+
let doLog = object(forKey: "doLog") as? Bool,
|
|
198
|
+
let value = object(forKey: "value")
|
|
199
|
+
else {
|
|
200
|
+
return nil
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let variation: FlagAssignment.Variation = switch value {
|
|
204
|
+
case let boolValue as Bool: .boolean(boolValue)
|
|
205
|
+
case let stringValue as String: .string(stringValue)
|
|
206
|
+
case let intValue as Int: .integer(intValue)
|
|
207
|
+
case let doubleValue as Double: .double(doubleValue)
|
|
208
|
+
case let dictValue as [String: Any]: .object(AnyValue.wrap(dictValue))
|
|
209
|
+
default: .unknown(String(describing: value))
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return FlagAssignment(
|
|
213
|
+
allocationKey: allocationKey,
|
|
214
|
+
variationKey: variationKey,
|
|
215
|
+
variation: variation,
|
|
216
|
+
reason: reason,
|
|
217
|
+
doLog: doLog
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
extension AnyValue {
|
|
223
|
+
static func wrap(_ value: Any) -> AnyValue {
|
|
224
|
+
if value is NSNull {
|
|
225
|
+
return .null
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if let value = value as? String {
|
|
229
|
+
return .string(value)
|
|
230
|
+
} else if let value = value as? Bool {
|
|
231
|
+
return .bool(value)
|
|
232
|
+
} else if let value = value as? Int {
|
|
233
|
+
return .int(value)
|
|
234
|
+
} else if let value = value as? Double {
|
|
235
|
+
return .double(value)
|
|
236
|
+
} else if let value = value as? [String: Any] {
|
|
237
|
+
return .dictionary(value.mapValues(AnyValue.wrap))
|
|
238
|
+
} else if let value = value as? [Any] {
|
|
239
|
+
return .array(value.map(AnyValue.wrap))
|
|
240
|
+
} else {
|
|
241
|
+
return .null
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
func unwrap() -> Any {
|
|
246
|
+
switch self {
|
|
247
|
+
case .string(let value):
|
|
248
|
+
return value
|
|
249
|
+
case .bool(let value):
|
|
250
|
+
return value
|
|
251
|
+
case .int(let value):
|
|
252
|
+
return value
|
|
253
|
+
case .double(let value):
|
|
254
|
+
return value
|
|
255
|
+
case .dictionary(let dict):
|
|
256
|
+
return dict.mapValues { $0.unwrap() }
|
|
257
|
+
case .array(let array):
|
|
258
|
+
return array.map { $0.unwrap() }
|
|
259
|
+
case .null:
|
|
260
|
+
return NSNull()
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import DatadogCore
|
|
8
|
+
import DatadogFlags
|
|
8
9
|
import DatadogInternal
|
|
9
10
|
import DatadogRUM
|
|
10
11
|
import Foundation
|
|
@@ -178,7 +179,7 @@ extension NSDictionary {
|
|
|
178
179
|
reactNativeVersion: reactNativeVersion
|
|
179
180
|
)
|
|
180
181
|
}
|
|
181
|
-
|
|
182
|
+
|
|
182
183
|
func asProxyConfiguration() -> [AnyHashable: Any]? {
|
|
183
184
|
guard let address = object(forKey: "address") as? String else {
|
|
184
185
|
return nil
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DdFlags = void 0;
|
|
7
|
+
var _InternalLog = require("../InternalLog");
|
|
8
|
+
var _SdkVerbosity = require("../config/types/SdkVerbosity");
|
|
9
|
+
var _singletonUtils = require("../utils/singletonUtils");
|
|
10
|
+
var _FlagsClient = require("./FlagsClient");
|
|
11
|
+
/*
|
|
12
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
13
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
14
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const FLAGS_MODULE = 'com.datadog.reactnative.flags';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Implementation class for {@link DdFlagsType}. Please see the interface for documentation.
|
|
21
|
+
*/
|
|
22
|
+
class DdFlagsWrapper {
|
|
23
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
24
|
+
nativeFlags = require('../specs/NativeDdFlags').default;
|
|
25
|
+
isFeatureEnabled = false;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A map of client names to their corresponding {@link FlagsClient} instances.
|
|
29
|
+
*
|
|
30
|
+
* Each of these clients hold their own context and flags state.
|
|
31
|
+
*/
|
|
32
|
+
clients = {};
|
|
33
|
+
enable = async (configuration = {}) => {
|
|
34
|
+
await this.nativeFlags.enable({
|
|
35
|
+
enabled: true,
|
|
36
|
+
...configuration
|
|
37
|
+
});
|
|
38
|
+
this.isFeatureEnabled = true;
|
|
39
|
+
};
|
|
40
|
+
getClient = (clientName = 'default') => {
|
|
41
|
+
if (!this.isFeatureEnabled) {
|
|
42
|
+
_InternalLog.InternalLog.log('`DdFlags.getClient()` called before Datadog Flags feature have been enabled. Client will fall back to serving default flag values.', _SdkVerbosity.SdkVerbosity.ERROR);
|
|
43
|
+
}
|
|
44
|
+
if (!this.clients[clientName]) {
|
|
45
|
+
this.clients[clientName] = new _FlagsClient.FlagsClient(clientName);
|
|
46
|
+
}
|
|
47
|
+
return this.clients[clientName];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const DdFlags = exports.DdFlags = (0, _singletonUtils.getGlobalInstance)(FLAGS_MODULE, () => new DdFlagsWrapper());
|
|
51
|
+
//# sourceMappingURL=DdFlags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_InternalLog","require","_SdkVerbosity","_singletonUtils","_FlagsClient","FLAGS_MODULE","DdFlagsWrapper","nativeFlags","default","isFeatureEnabled","clients","enable","configuration","enabled","getClient","clientName","InternalLog","log","SdkVerbosity","ERROR","FlagsClient","DdFlags","exports","getGlobalInstance"],"sourceRoot":"../../../src","sources":["flags/DdFlags.ts"],"mappings":";;;;;;AAMA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAXA;AACA;AACA;AACA;AACA;;AAUA,MAAMI,YAAY,GAAG,+BAA+B;;AAEpD;AACA;AACA;AACA,MAAMC,cAAc,CAAwB;EACxC;EACQC,WAAW,GAAsBN,OAAO,CAAC,wBAAwB,CAAC,CACrEO,OAAO;EAEJC,gBAAgB,GAAG,KAAK;;EAEhC;AACJ;AACA;AACA;AACA;EACYC,OAAO,GAAgC,CAAC,CAAC;EAEjDC,MAAM,GAAG,MAAAA,CAAOC,aAAiC,GAAG,CAAC,CAAC,KAAoB;IACtE,MAAM,IAAI,CAACL,WAAW,CAACI,MAAM,CAAC;MAAEE,OAAO,EAAE,IAAI;MAAE,GAAGD;IAAc,CAAC,CAAC;IAElE,IAAI,CAACH,gBAAgB,GAAG,IAAI;EAChC,CAAC;EAEDK,SAAS,GAAGA,CAACC,UAAkB,GAAG,SAAS,KAAkB;IACzD,IAAI,CAAC,IAAI,CAACN,gBAAgB,EAAE;MACxBO,wBAAW,CAACC,GAAG,CACX,oIAAoI,EACpIC,0BAAY,CAACC,KACjB,CAAC;IACL;IAEA,IAAI,CAAC,IAAI,CAACT,OAAO,CAACK,UAAU,CAAC,EAAE;MAC3B,IAAI,CAACL,OAAO,CAACK,UAAU,CAAC,GAAG,IAAIK,wBAAW,CAACL,UAAU,CAAC;IAC1D;IAEA,OAAO,IAAI,CAACL,OAAO,CAACK,UAAU,CAAC;EACnC,CAAC;AACL;AAEO,MAAMM,OAAoB,GAAAC,OAAA,CAAAD,OAAA,GAAG,IAAAE,iCAAiB,EACjDlB,YAAY,EACZ,MAAM,IAAIC,cAAc,CAAC,CAC7B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FlagsClient = void 0;
|
|
7
|
+
var _InternalLog = require("../InternalLog");
|
|
8
|
+
var _SdkVerbosity = require("../config/types/SdkVerbosity");
|
|
9
|
+
var _internal = require("./internal");
|
|
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
|
+
class FlagsClient {
|
|
17
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
18
|
+
nativeFlags = require('../specs/NativeDdFlags').default;
|
|
19
|
+
evaluationContext = undefined;
|
|
20
|
+
flagsCache = {};
|
|
21
|
+
constructor(clientName = 'default') {
|
|
22
|
+
this.clientName = clientName;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sets the evaluation context for the client.
|
|
27
|
+
*
|
|
28
|
+
* Should be called before evaluating any flags. Otherwise, the client will fall back to serving default flag values.
|
|
29
|
+
*
|
|
30
|
+
* Throws an error if there is an error setting the evaluation context and logs an error message.
|
|
31
|
+
*
|
|
32
|
+
* @param context The evaluation context to associate with the current client.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const flagsClient = DdFlags.getClient();
|
|
37
|
+
*
|
|
38
|
+
* await flagsClient.setEvaluationContext({
|
|
39
|
+
* targetingKey: 'user-123',
|
|
40
|
+
* attributes: {
|
|
41
|
+
* favoriteFruit: 'apple'
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* const flagValue = flagsClient.getBooleanValue('new-feature', false);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
setEvaluationContext = async context => {
|
|
49
|
+
// Make sure to process the incoming context because we don't support nested object values in context.
|
|
50
|
+
const processedContext = (0, _internal.processEvaluationContext)(context);
|
|
51
|
+
try {
|
|
52
|
+
const result = await this.nativeFlags.setEvaluationContext(this.clientName, processedContext.targetingKey, processedContext.attributes ?? {});
|
|
53
|
+
this.evaluationContext = processedContext;
|
|
54
|
+
this.flagsCache = result;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error instanceof Error) {
|
|
57
|
+
_InternalLog.InternalLog.log(`Error setting flag evaluation context: ${error.message}`, _SdkVerbosity.SdkVerbosity.WARN);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
track = (flag, context) => {
|
|
63
|
+
// A non-blocking call; don't await this.
|
|
64
|
+
this.nativeFlags.trackEvaluation(this.clientName, flag.key, flag, context.targetingKey, context.attributes ?? {}).catch(error => {
|
|
65
|
+
if (error instanceof Error) {
|
|
66
|
+
_InternalLog.InternalLog.log(`Error tracking flag evaluation: ${error.message}`, _SdkVerbosity.SdkVerbosity.WARN);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
getDetails = (key, defaultValue, type) => {
|
|
71
|
+
if (!this.evaluationContext) {
|
|
72
|
+
return {
|
|
73
|
+
key,
|
|
74
|
+
value: defaultValue,
|
|
75
|
+
reason: 'ERROR',
|
|
76
|
+
errorCode: 'PROVIDER_NOT_READY',
|
|
77
|
+
errorMessage: `The evaluation context is not set for '${this.clientName}'. Please, set context before evaluating any flags.`
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Retrieve the flag from the cache.
|
|
82
|
+
const flag = this.flagsCache[key];
|
|
83
|
+
if (!flag) {
|
|
84
|
+
return {
|
|
85
|
+
key,
|
|
86
|
+
value: defaultValue,
|
|
87
|
+
reason: 'ERROR',
|
|
88
|
+
errorCode: 'FLAG_NOT_FOUND'
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Validate the expected type against the actual flag value type.
|
|
93
|
+
const actualType = typeof flag.value;
|
|
94
|
+
if (actualType !== type) {
|
|
95
|
+
return {
|
|
96
|
+
key,
|
|
97
|
+
value: defaultValue,
|
|
98
|
+
reason: 'ERROR',
|
|
99
|
+
errorCode: 'TYPE_MISMATCH',
|
|
100
|
+
errorMessage: `Flag "${key}" returned a value of type "${typeof flag.value}". Use the corresponding method instead of the one expecting "${type}".`
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
this.track(flag, this.evaluationContext);
|
|
104
|
+
const details = {
|
|
105
|
+
key: flag.key,
|
|
106
|
+
value: flag.value,
|
|
107
|
+
variant: flag.variationKey,
|
|
108
|
+
allocationKey: flag.allocationKey,
|
|
109
|
+
reason: flag.reason
|
|
110
|
+
};
|
|
111
|
+
return details;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Evaluate a boolean feature flag with detailed evaluation information.
|
|
116
|
+
*
|
|
117
|
+
* @param key The key of the flag to evaluate.
|
|
118
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
119
|
+
*/
|
|
120
|
+
getBooleanDetails = (key, defaultValue) => {
|
|
121
|
+
return this.getDetails(key, defaultValue, 'boolean');
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Evaluate a string feature flag with detailed evaluation information.
|
|
126
|
+
*
|
|
127
|
+
* @param key The key of the flag to evaluate.
|
|
128
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
129
|
+
*/
|
|
130
|
+
getStringDetails = (key, defaultValue) => {
|
|
131
|
+
return this.getDetails(key, defaultValue, 'string');
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Evaluate a number feature flag with detailed evaluation information.
|
|
136
|
+
*
|
|
137
|
+
* @param key The key of the flag to evaluate.
|
|
138
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
139
|
+
*/
|
|
140
|
+
getNumberDetails = (key, defaultValue) => {
|
|
141
|
+
return this.getDetails(key, defaultValue, 'number');
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Evaluate a JSON feature flag with detailed evaluation information.
|
|
146
|
+
*
|
|
147
|
+
* Even though the `defaultValue` is typed as `JsonValue`, the flag value should be a valid JSON object.
|
|
148
|
+
* Please use other typed methods to evaluate flags with primitive values.
|
|
149
|
+
*
|
|
150
|
+
* @param key The key of the flag to evaluate.
|
|
151
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
152
|
+
*/
|
|
153
|
+
getObjectDetails = (key, defaultValue) => {
|
|
154
|
+
return this.getDetails(key, defaultValue, 'object');
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Evaluate a boolean feature flag value.
|
|
159
|
+
*
|
|
160
|
+
* @param key The key of the flag to evaluate.
|
|
161
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const isNewFeatureEnabled = flagsClient.getBooleanValue('new-feature-enabled', false);
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
getBooleanValue = (key, defaultValue) => {
|
|
169
|
+
return this.getBooleanDetails(key, defaultValue).value;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Evaluate a string feature flag value.
|
|
174
|
+
*
|
|
175
|
+
* @param key The key of the flag to evaluate.
|
|
176
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const appTheme = flagsClient.getStringValue('app-theme', 'light');
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
getStringValue = (key, defaultValue) => {
|
|
184
|
+
return this.getStringDetails(key, defaultValue).value;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Evaluate a number feature flag value.
|
|
189
|
+
*
|
|
190
|
+
* @param key The key of the flag to evaluate.
|
|
191
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const ctaButtonSize = flagsClient.getNumberValue('cta-button-size', 16);
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
getNumberValue = (key, defaultValue) => {
|
|
199
|
+
return this.getNumberDetails(key, defaultValue).value;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Evaluate an object feature flag value.
|
|
204
|
+
*
|
|
205
|
+
* @param key The key of the flag to evaluate.
|
|
206
|
+
* @param defaultValue Fallback value for when flag evaluation fails, flag is not found, or the client does not have an evaluation context set.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* const pageCalloutOptions = flagsClient.getObjectValue('page-callout', { color: 'purple', text: 'Woof!' });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
getObjectValue = (key, defaultValue) => {
|
|
214
|
+
return this.getObjectDetails(key, defaultValue).value;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
exports.FlagsClient = FlagsClient;
|
|
218
|
+
//# sourceMappingURL=FlagsClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_InternalLog","require","_SdkVerbosity","_internal","FlagsClient","nativeFlags","default","evaluationContext","undefined","flagsCache","constructor","clientName","setEvaluationContext","context","processedContext","processEvaluationContext","result","targetingKey","attributes","error","Error","InternalLog","log","message","SdkVerbosity","WARN","track","flag","trackEvaluation","key","catch","getDetails","defaultValue","type","value","reason","errorCode","errorMessage","actualType","details","variant","variationKey","allocationKey","getBooleanDetails","getStringDetails","getNumberDetails","getObjectDetails","getBooleanValue","getStringValue","getNumberValue","getObjectValue","exports"],"sour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AG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIe,cAAc,GAAGA,CAACpB,GAAW,EAAEG,YAAoB,KAAa;IAC5D,OAAO,IAAI,CAACa,gBAAgB,CAAChB,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIgB,cAAc,GAAGA,CAAsBrB,GAAW,EAAEG,YAAe,KAAQ;IACvE,OAAO,IAAI,CAACc,gBAAgB,CAACjB,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;AACL;AAACiB,OAAA,CAAA/C,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.processEvaluationContext = void 0;
|
|
7
|
+
var _InternalLog = require("../InternalLog");
|
|
8
|
+
var _SdkVerbosity = require("../config/types/SdkVerbosity");
|
|
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
|
+
const processEvaluationContext = context => {
|
|
16
|
+
const {
|
|
17
|
+
targetingKey
|
|
18
|
+
} = context;
|
|
19
|
+
|
|
20
|
+
// We should ignore non-primitive values in the context as per FFE SDK requirements OF.3.
|
|
21
|
+
const providedAttributes = context.attributes ?? {};
|
|
22
|
+
const attributes = {};
|
|
23
|
+
for (const [key, value] of Object.entries(providedAttributes)) {
|
|
24
|
+
const isPrimitiveValue = typeof value === 'boolean' || typeof value === 'string' || typeof value === 'number' || value === undefined || value === null;
|
|
25
|
+
if (!isPrimitiveValue) {
|
|
26
|
+
_InternalLog.InternalLog.log(`Non-primitive context value under "${key}" is not supported. Omitting this attribute from the evaluation context.`, _SdkVerbosity.SdkVerbosity.WARN);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
attributes[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
targetingKey,
|
|
36
|
+
attributes
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.processEvaluationContext = processEvaluationContext;
|
|
40
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +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;EAE5B,MAAMA,UAA0C,GAAG,CAAC,CAAC;EAErD,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,kBAAkB,CAAC,EAAE;IAC3D,MAAMM,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;IAEAN,UAAU,CAACC,GAAG,CAAC,GAAGC,KAAK;EAC3B;EAEA,OAAO;IACHJ,YAAY;IACZE;EACJ,CAAC;AACL,CAAC;AAACW,OAAA,CAAAf,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["flags/types.ts"],"mappings":"","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -69,6 +69,12 @@ Object.defineProperty(exports, "DdBabelInteractionTracking", {
|
|
|
69
69
|
return _DdBabelInteractionTracking.DdBabelInteractionTracking;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
+
Object.defineProperty(exports, "DdFlags", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _DdFlags.DdFlags;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
72
78
|
Object.defineProperty(exports, "DdLogs", {
|
|
73
79
|
enumerable: true,
|
|
74
80
|
get: function () {
|
|
@@ -237,6 +243,7 @@ var _ProxyConfiguration = require("./config/types/ProxyConfiguration");
|
|
|
237
243
|
var _SdkVerbosity = require("./config/types/SdkVerbosity");
|
|
238
244
|
var _TrackingConsent = require("./config/types/TrackingConsent");
|
|
239
245
|
var _types = require("./config/types");
|
|
246
|
+
var _DdFlags = require("./flags/DdFlags");
|
|
240
247
|
var _DdLogs = require("./logs/DdLogs");
|
|
241
248
|
var _DdRum = require("./rum/DdRum");
|
|
242
249
|
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","_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","_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,mBA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