@datadog/mobile-react-native 3.0.3 → 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 +10 -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/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/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
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
+
@file:Suppress("TooManyFunctions")
|
|
6
7
|
|
|
7
8
|
package com.datadog.reactnative
|
|
8
9
|
|
|
@@ -15,53 +16,84 @@ import com.facebook.react.bridge.WritableArray
|
|
|
15
16
|
import com.facebook.react.bridge.WritableMap
|
|
16
17
|
import com.facebook.react.bridge.WritableNativeArray
|
|
17
18
|
import com.facebook.react.bridge.WritableNativeMap
|
|
19
|
+
import org.json.JSONArray
|
|
20
|
+
import org.json.JSONObject
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
23
|
* Converts the [List] to a [WritableNativeArray].
|
|
21
24
|
*/
|
|
22
|
-
internal fun List<*>.toWritableArray(): WritableArray
|
|
23
|
-
|
|
25
|
+
internal fun List<*>.toWritableArray(): WritableArray =
|
|
26
|
+
this.toWritableArray(
|
|
24
27
|
createWritableMap = { WritableNativeMap() },
|
|
25
|
-
createWritableArray = { WritableNativeArray() }
|
|
28
|
+
createWritableArray = { WritableNativeArray() },
|
|
26
29
|
)
|
|
27
|
-
}
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Converts the [List] to a [WritableArray].
|
|
31
33
|
* @param createWritableMap a function to provide a concrete instance of new WritableMap(s)
|
|
32
34
|
* @param createWritableArray a function to provide a concrete instance of new WritableArray(s)
|
|
33
35
|
*/
|
|
36
|
+
@Suppress("CyclomaticComplexMethod")
|
|
34
37
|
internal fun List<*>.toWritableArray(
|
|
35
38
|
createWritableMap: () -> WritableMap,
|
|
36
|
-
createWritableArray: () -> WritableArray
|
|
39
|
+
createWritableArray: () -> WritableArray,
|
|
37
40
|
): WritableArray {
|
|
38
41
|
val writableArray = createWritableArray()
|
|
39
42
|
|
|
40
43
|
for (it in iterator()) {
|
|
41
44
|
when (it) {
|
|
42
|
-
null ->
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
is
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
null -> {
|
|
46
|
+
writableArray.pushNull()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
is Int -> {
|
|
50
|
+
writableArray.pushInt(it)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
is Long -> {
|
|
54
|
+
writableArray.pushDouble(it.toDouble())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
is Float -> {
|
|
58
|
+
writableArray.pushDouble(it.toDouble())
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
is Double -> {
|
|
62
|
+
writableArray.pushDouble(it)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
is String -> {
|
|
66
|
+
writableArray.pushString(it)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
is Boolean -> {
|
|
70
|
+
writableArray.pushBoolean(it)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
is List<*> -> {
|
|
74
|
+
writableArray.pushArray(
|
|
75
|
+
it.toWritableArray(
|
|
76
|
+
createWritableMap,
|
|
77
|
+
createWritableArray,
|
|
78
|
+
),
|
|
53
79
|
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
is Map<*, *> -> {
|
|
83
|
+
writableArray.pushMap(
|
|
84
|
+
it.toWritableMap(
|
|
85
|
+
createWritableMap,
|
|
86
|
+
createWritableArray,
|
|
87
|
+
),
|
|
59
88
|
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
else -> {
|
|
92
|
+
Log.e(
|
|
93
|
+
javaClass.simpleName,
|
|
94
|
+
"toWritableArray(): Unhandled type ${it.javaClass.simpleName} has been ignored",
|
|
95
|
+
)
|
|
96
|
+
}
|
|
65
97
|
}
|
|
66
98
|
}
|
|
67
99
|
|
|
@@ -71,52 +103,81 @@ internal fun List<*>.toWritableArray(
|
|
|
71
103
|
/**
|
|
72
104
|
* Converts the [Map] to a [WritableNativeMap].
|
|
73
105
|
*/
|
|
74
|
-
internal fun Map<*, *>.toWritableMap(): WritableMap
|
|
75
|
-
|
|
106
|
+
internal fun Map<*, *>.toWritableMap(): WritableMap =
|
|
107
|
+
this.toWritableMap(
|
|
76
108
|
createWritableMap = { WritableNativeMap() },
|
|
77
|
-
createWritableArray = { WritableNativeArray() }
|
|
109
|
+
createWritableArray = { WritableNativeArray() },
|
|
78
110
|
)
|
|
79
|
-
}
|
|
80
111
|
|
|
81
112
|
/**
|
|
82
113
|
* Converts the [Map] to a [WritableMap].
|
|
83
114
|
* @param createWritableMap a function to provide a concrete instance for WritableMap(s)
|
|
84
115
|
* @param createWritableArray a function to provide a concrete instance for WritableArray(s)
|
|
85
116
|
*/
|
|
117
|
+
@Suppress("CyclomaticComplexMethod")
|
|
86
118
|
internal fun Map<*, *>.toWritableMap(
|
|
87
119
|
createWritableMap: () -> WritableMap,
|
|
88
|
-
createWritableArray: () -> WritableArray
|
|
120
|
+
createWritableArray: () -> WritableArray,
|
|
89
121
|
): WritableMap {
|
|
90
122
|
val map = createWritableMap()
|
|
91
123
|
|
|
92
124
|
for ((k, v) in iterator()) {
|
|
93
125
|
val key = (k as? String) ?: k.toString()
|
|
94
126
|
when (v) {
|
|
95
|
-
null ->
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
is
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
v.
|
|
105
|
-
|
|
106
|
-
|
|
127
|
+
null -> {
|
|
128
|
+
map.putNull(key)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
is Int -> {
|
|
132
|
+
map.putInt(key, v)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
is Long -> {
|
|
136
|
+
map.putDouble(key, v.toDouble())
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
is Float -> {
|
|
140
|
+
map.putDouble(key, v.toDouble())
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
is Double -> {
|
|
144
|
+
map.putDouble(key, v)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
is String -> {
|
|
148
|
+
map.putString(key, v)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
is Boolean -> {
|
|
152
|
+
map.putBoolean(key, v)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
is List<*> -> {
|
|
156
|
+
map.putArray(
|
|
157
|
+
key,
|
|
158
|
+
v.toWritableArray(
|
|
159
|
+
createWritableMap,
|
|
160
|
+
createWritableArray,
|
|
161
|
+
),
|
|
107
162
|
)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
is Map<*, *> -> {
|
|
166
|
+
map.putMap(
|
|
167
|
+
key,
|
|
168
|
+
v.toWritableMap(
|
|
169
|
+
createWritableMap,
|
|
170
|
+
createWritableArray,
|
|
171
|
+
),
|
|
114
172
|
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
else -> {
|
|
176
|
+
Log.e(
|
|
177
|
+
javaClass.simpleName,
|
|
178
|
+
"toWritableMap(): Unhandled type ${v.javaClass.simpleName} has been ignored",
|
|
179
|
+
)
|
|
180
|
+
}
|
|
120
181
|
}
|
|
121
182
|
}
|
|
122
183
|
|
|
@@ -128,20 +189,25 @@ internal fun Map<*, *>.toWritableMap(
|
|
|
128
189
|
* such as [List], [Map] and the raw types.
|
|
129
190
|
*/
|
|
130
191
|
internal fun ReadableMap.toMap(): Map<String, Any> {
|
|
131
|
-
val map =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
192
|
+
val map =
|
|
193
|
+
this
|
|
194
|
+
.toHashMap()
|
|
195
|
+
.filterValues { it != null }
|
|
196
|
+
.mapValues { it.value!! }
|
|
197
|
+
.toMap(HashMap())
|
|
135
198
|
val iterator = map.keys.iterator()
|
|
136
199
|
|
|
137
|
-
fun updateMap(
|
|
200
|
+
fun updateMap(
|
|
201
|
+
key: String,
|
|
202
|
+
value: Any?,
|
|
203
|
+
) {
|
|
138
204
|
if (value != null) {
|
|
139
205
|
map[key] = value
|
|
140
206
|
} else {
|
|
141
207
|
map.remove(key)
|
|
142
208
|
Log.e(
|
|
143
209
|
javaClass.simpleName,
|
|
144
|
-
"toMap(): Cannot convert nested object for key: $key"
|
|
210
|
+
"toMap(): Cannot convert nested object for key: $key",
|
|
145
211
|
)
|
|
146
212
|
}
|
|
147
213
|
}
|
|
@@ -150,14 +216,21 @@ internal fun ReadableMap.toMap(): Map<String, Any> {
|
|
|
150
216
|
val key = iterator.next()
|
|
151
217
|
try {
|
|
152
218
|
when (val type = getType(key)) {
|
|
153
|
-
ReadableType.Map ->
|
|
154
|
-
|
|
219
|
+
ReadableType.Map -> {
|
|
220
|
+
updateMap(key, getMap(key)?.toMap())
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
ReadableType.Array -> {
|
|
224
|
+
updateMap(key, getArray(key)?.toList())
|
|
225
|
+
}
|
|
226
|
+
|
|
155
227
|
ReadableType.Null, ReadableType.Boolean, ReadableType.Number, ReadableType.String -> {}
|
|
228
|
+
|
|
156
229
|
else -> {
|
|
157
230
|
map.remove(key)
|
|
158
231
|
Log.e(
|
|
159
232
|
javaClass.simpleName,
|
|
160
|
-
"toMap(): Skipping unhandled type [${type.name}] for key: $key"
|
|
233
|
+
"toMap(): Skipping unhandled type [${type.name}] for key: $key",
|
|
161
234
|
)
|
|
162
235
|
}
|
|
163
236
|
}
|
|
@@ -166,7 +239,7 @@ internal fun ReadableMap.toMap(): Map<String, Any> {
|
|
|
166
239
|
Log.e(
|
|
167
240
|
javaClass.simpleName,
|
|
168
241
|
"toMap(): Could not convert object for key: $key",
|
|
169
|
-
err
|
|
242
|
+
err,
|
|
170
243
|
)
|
|
171
244
|
}
|
|
172
245
|
}
|
|
@@ -179,6 +252,7 @@ internal fun ReadableMap.toMap(): Map<String, Any> {
|
|
|
179
252
|
* such as [List], [Map] and the raw types.
|
|
180
253
|
* or [List], instead of [ReadableMap] and [ReadableArray] respectively).
|
|
181
254
|
*/
|
|
255
|
+
@Suppress("CyclomaticComplexMethod")
|
|
182
256
|
internal fun ReadableArray.toList(): List<*> {
|
|
183
257
|
val list = mutableListOf<Any?>()
|
|
184
258
|
for (i in 0 until size()) {
|
|
@@ -186,32 +260,48 @@ internal fun ReadableArray.toList(): List<*> {
|
|
|
186
260
|
@Suppress("TooGenericExceptionCaught")
|
|
187
261
|
try {
|
|
188
262
|
when (val type = getType(i)) {
|
|
189
|
-
ReadableType.Null ->
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
263
|
+
ReadableType.Null -> {
|
|
264
|
+
list.add(null)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
ReadableType.Boolean -> {
|
|
268
|
+
list.add(getBoolean(i))
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
ReadableType.Number -> {
|
|
272
|
+
list.add(getDouble(i))
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
ReadableType.String -> {
|
|
276
|
+
list.add(getString(i))
|
|
277
|
+
}
|
|
278
|
+
|
|
193
279
|
ReadableType.Map -> {
|
|
194
280
|
// getMap() return type is nullable in previous RN versions
|
|
195
281
|
@Suppress("USELESS_ELVIS")
|
|
196
282
|
val readableMap = getMap(i) ?: Arguments.createMap()
|
|
197
283
|
list.add(readableMap.toMap())
|
|
198
284
|
}
|
|
285
|
+
|
|
199
286
|
ReadableType.Array -> {
|
|
200
287
|
// getArray() return type is nullable in previous RN versions
|
|
201
288
|
@Suppress("USELESS_ELVIS")
|
|
202
289
|
val readableArray = getArray(i) ?: Arguments.createArray()
|
|
203
290
|
list.add(readableArray.toList())
|
|
204
291
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
292
|
+
|
|
293
|
+
else -> {
|
|
294
|
+
Log.e(
|
|
295
|
+
javaClass.simpleName,
|
|
296
|
+
"toList(): Unhandled ReadableType: ${type.name}.",
|
|
297
|
+
)
|
|
298
|
+
}
|
|
209
299
|
}
|
|
210
300
|
} catch (err: NullPointerException) {
|
|
211
301
|
Log.e(
|
|
212
302
|
javaClass.simpleName,
|
|
213
303
|
"toList(): Could not convert object at index: $i.",
|
|
214
|
-
err
|
|
304
|
+
err,
|
|
215
305
|
)
|
|
216
306
|
}
|
|
217
307
|
}
|
|
@@ -223,22 +313,116 @@ internal fun ReadableArray.toList(): List<*> {
|
|
|
223
313
|
* Returns the boolean for the given key, or null if the entry is
|
|
224
314
|
* not in the map.
|
|
225
315
|
*/
|
|
226
|
-
internal fun ReadableMap.getBooleanOrNull(key: String): Boolean?
|
|
227
|
-
|
|
316
|
+
internal fun ReadableMap.getBooleanOrNull(key: String): Boolean? =
|
|
317
|
+
if (hasKey(key)) {
|
|
228
318
|
getBoolean(key)
|
|
229
319
|
} else {
|
|
230
320
|
null
|
|
231
321
|
}
|
|
232
|
-
}
|
|
233
322
|
|
|
234
323
|
/**
|
|
235
324
|
* Returns the double for the given key, or null if the entry is
|
|
236
325
|
* not in the map.
|
|
237
326
|
*/
|
|
238
|
-
internal fun ReadableMap.getDoubleOrNull(key: String): Double?
|
|
239
|
-
|
|
327
|
+
internal fun ReadableMap.getDoubleOrNull(key: String): Double? =
|
|
328
|
+
if (hasKey(key)) {
|
|
240
329
|
getDouble(key)
|
|
241
330
|
} else {
|
|
242
331
|
null
|
|
243
332
|
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Converts a [JSONObject] to a [WritableMap].
|
|
336
|
+
*/
|
|
337
|
+
internal fun JSONObject.toWritableMap(): WritableMap = this.toMap().toWritableMap()
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Converts a [JSONObject] to a [Map].
|
|
341
|
+
*/
|
|
342
|
+
internal fun JSONObject.toMap(): Map<String, Any?> {
|
|
343
|
+
val map = mutableMapOf<String, Any?>()
|
|
344
|
+
val keys = this.keys()
|
|
345
|
+
|
|
346
|
+
while (keys.hasNext()) {
|
|
347
|
+
val key = keys.next()
|
|
348
|
+
val value = this.opt(key)
|
|
349
|
+
|
|
350
|
+
map[key] =
|
|
351
|
+
when (value) {
|
|
352
|
+
null, JSONObject.NULL -> null
|
|
353
|
+
is JSONObject -> value.toMap()
|
|
354
|
+
is JSONArray -> value.toList()
|
|
355
|
+
else -> value
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return map
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Converts a [JSONArray] to a [List].
|
|
364
|
+
*/
|
|
365
|
+
internal fun JSONArray.toList(): List<Any?> {
|
|
366
|
+
val list = mutableListOf<Any?>()
|
|
367
|
+
|
|
368
|
+
for (i in 0 until this.length()) {
|
|
369
|
+
val value = this.opt(i)
|
|
370
|
+
|
|
371
|
+
list.add(
|
|
372
|
+
when (value) {
|
|
373
|
+
null, JSONObject.NULL -> null
|
|
374
|
+
is JSONObject -> value.toMap()
|
|
375
|
+
is JSONArray -> value.toList()
|
|
376
|
+
else -> value
|
|
377
|
+
},
|
|
378
|
+
)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return list
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Converts a [ReadableMap] to a [JSONObject].
|
|
386
|
+
*/
|
|
387
|
+
internal fun ReadableMap.toJSONObject(): JSONObject = this.toMap().toJSONObject()
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Converts a [Map] to a [JSONObject].
|
|
391
|
+
*/
|
|
392
|
+
@Suppress("UNCHECKED_CAST")
|
|
393
|
+
internal fun Map<String, Any>.toJSONObject(): JSONObject {
|
|
394
|
+
val jsonObject = JSONObject()
|
|
395
|
+
|
|
396
|
+
for ((key, value) in this) {
|
|
397
|
+
jsonObject.put(
|
|
398
|
+
key,
|
|
399
|
+
when (value) {
|
|
400
|
+
is Map<*, *> -> (value as Map<String, Any>).toJSONObject()
|
|
401
|
+
is List<*> -> value.toJSONArray()
|
|
402
|
+
else -> value
|
|
403
|
+
},
|
|
404
|
+
)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return jsonObject
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Converts a [List] to a [JSONArray].
|
|
412
|
+
*/
|
|
413
|
+
@Suppress("UNCHECKED_CAST")
|
|
414
|
+
internal fun List<*>.toJSONArray(): JSONArray {
|
|
415
|
+
val jsonArray = JSONArray()
|
|
416
|
+
|
|
417
|
+
for (value in this) {
|
|
418
|
+
jsonArray.put(
|
|
419
|
+
when (value) {
|
|
420
|
+
is Map<*, *> -> (value as Map<String, Any>).toJSONObject()
|
|
421
|
+
is List<*> -> value.toJSONArray()
|
|
422
|
+
else -> value
|
|
423
|
+
},
|
|
424
|
+
)
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return jsonArray
|
|
244
428
|
}
|
|
@@ -25,6 +25,7 @@ class DdSdkReactNativePackage : TurboReactPackage() {
|
|
|
25
25
|
DdRumImplementation.NAME -> DdRum(reactContext, sdkWrapper)
|
|
26
26
|
DdTraceImplementation.NAME -> DdTrace(reactContext)
|
|
27
27
|
DdLogsImplementation.NAME -> DdLogs(reactContext, sdkWrapper)
|
|
28
|
+
DdFlagsImplementation.NAME -> DdFlags(reactContext)
|
|
28
29
|
else -> null
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -36,7 +37,8 @@ class DdSdkReactNativePackage : TurboReactPackage() {
|
|
|
36
37
|
DdSdkImplementation.NAME,
|
|
37
38
|
DdRumImplementation.NAME,
|
|
38
39
|
DdTraceImplementation.NAME,
|
|
39
|
-
DdLogsImplementation.NAME
|
|
40
|
+
DdLogsImplementation.NAME,
|
|
41
|
+
DdFlagsImplementation.NAME
|
|
40
42
|
).associateWith {
|
|
41
43
|
ReactModuleInfo(
|
|
42
44
|
it,
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
package com.datadog.reactnative
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.Promise
|
|
10
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
|
+
import com.facebook.react.bridge.ReactMethod
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap
|
|
13
|
+
|
|
14
|
+
/** The entry point to use Datadog's Flags feature. */
|
|
15
|
+
class DdFlags(
|
|
16
|
+
reactContext: ReactApplicationContext,
|
|
17
|
+
) : NativeDdFlagsSpec(reactContext) {
|
|
18
|
+
private val implementation = DdFlagsImplementation()
|
|
19
|
+
|
|
20
|
+
override fun getName(): String = DdFlagsImplementation.NAME
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Enable the Flags feature with the provided configuration.
|
|
24
|
+
* @param configuration The configuration for Flags.
|
|
25
|
+
*/
|
|
26
|
+
@ReactMethod
|
|
27
|
+
override fun enable(
|
|
28
|
+
configuration: ReadableMap,
|
|
29
|
+
promise: Promise,
|
|
30
|
+
) {
|
|
31
|
+
implementation.enable(configuration, promise)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Set the evaluation context for a specific client.
|
|
36
|
+
* @param clientName The name of the client.
|
|
37
|
+
* @param targetingKey The targeting key.
|
|
38
|
+
* @param attributes The attributes for the evaluation context.
|
|
39
|
+
*/
|
|
40
|
+
@ReactMethod
|
|
41
|
+
override fun setEvaluationContext(
|
|
42
|
+
clientName: String,
|
|
43
|
+
targetingKey: String,
|
|
44
|
+
attributes: ReadableMap,
|
|
45
|
+
promise: Promise,
|
|
46
|
+
) {
|
|
47
|
+
implementation.setEvaluationContext(clientName, targetingKey, attributes, promise)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Track the evaluation of a flag.
|
|
52
|
+
* @param clientName The name of the client.
|
|
53
|
+
* @param key The key of the flag.
|
|
54
|
+
*/
|
|
55
|
+
@ReactMethod
|
|
56
|
+
override fun trackEvaluation(
|
|
57
|
+
clientName: String,
|
|
58
|
+
key: String,
|
|
59
|
+
rawFlag: ReadableMap,
|
|
60
|
+
targetingKey: String,
|
|
61
|
+
attributes: ReadableMap,
|
|
62
|
+
promise: Promise,
|
|
63
|
+
) {
|
|
64
|
+
implementation.trackEvaluation(clientName, key, rawFlag, targetingKey, attributes, promise)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
package com.datadog.reactnative
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.Promise
|
|
10
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
12
|
+
import com.facebook.react.bridge.ReactMethod
|
|
13
|
+
import com.facebook.react.bridge.ReadableMap
|
|
14
|
+
|
|
15
|
+
/** The entry point to use Datadog's Flags feature. */
|
|
16
|
+
class DdFlags(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
17
|
+
|
|
18
|
+
private val implementation = DdFlagsImplementation()
|
|
19
|
+
|
|
20
|
+
override fun getName(): String = DdFlagsImplementation.NAME
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Enable the Flags feature with the provided configuration.
|
|
24
|
+
* @param configuration The configuration for Flags.
|
|
25
|
+
*/
|
|
26
|
+
@ReactMethod
|
|
27
|
+
fun enable(configuration: ReadableMap, promise: Promise) {
|
|
28
|
+
implementation.enable(configuration, promise)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Set the evaluation context for a specific client.
|
|
33
|
+
* @param clientName The name of the client.
|
|
34
|
+
* @param targetingKey The targeting key.
|
|
35
|
+
* @param attributes The attributes for the evaluation context.
|
|
36
|
+
*/
|
|
37
|
+
@ReactMethod
|
|
38
|
+
fun setEvaluationContext(
|
|
39
|
+
clientName: String,
|
|
40
|
+
targetingKey: String,
|
|
41
|
+
attributes: ReadableMap,
|
|
42
|
+
promise: Promise
|
|
43
|
+
) {
|
|
44
|
+
implementation.setEvaluationContext(clientName, targetingKey, attributes, promise)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Track the evaluation of a flag.
|
|
49
|
+
* @param clientName The name of the client.
|
|
50
|
+
* @param key The key of the flag.
|
|
51
|
+
*/
|
|
52
|
+
@ReactMethod
|
|
53
|
+
fun trackEvaluation(
|
|
54
|
+
clientName: String,
|
|
55
|
+
key: String,
|
|
56
|
+
rawFlag: ReadableMap,
|
|
57
|
+
targetingKey: String,
|
|
58
|
+
attributes: ReadableMap,
|
|
59
|
+
promise: Promise
|
|
60
|
+
) {
|
|
61
|
+
implementation.trackEvaluation(clientName, key, rawFlag, targetingKey, attributes, promise)
|
|
62
|
+
}
|
|
63
|
+
}
|