@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.
Files changed (69) hide show
  1. package/DatadogSDKReactNative.podspec +10 -9
  2. package/android/build.gradle +10 -8
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdFlagsImplementation.kt +237 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkBridgeExt.kt +262 -78
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -1
  6. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  7. package/android/src/newarch/kotlin/com/datadog/reactnative/DdFlags.kt +66 -0
  8. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdFlags.kt +63 -0
  9. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkBridgeExtTest.kt +242 -0
  10. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +38 -0
  11. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +3 -0
  12. package/ios/Sources/DatadogSDKReactNative.h +2 -0
  13. package/ios/Sources/DdFlags.h +24 -0
  14. package/ios/Sources/DdFlags.mm +83 -0
  15. package/ios/Sources/DdFlagsImplementation.swift +263 -0
  16. package/ios/Sources/RNDdSdkConfiguration.swift +2 -1
  17. package/ios/Sources/SdkVersion.swift +1 -1
  18. package/lib/commonjs/flags/DdFlags.js +51 -0
  19. package/lib/commonjs/flags/DdFlags.js.map +1 -0
  20. package/lib/commonjs/flags/FlagsClient.js +218 -0
  21. package/lib/commonjs/flags/FlagsClient.js.map +1 -0
  22. package/lib/commonjs/flags/internal.js +40 -0
  23. package/lib/commonjs/flags/internal.js.map +1 -0
  24. package/lib/commonjs/flags/types.js +6 -0
  25. package/lib/commonjs/flags/types.js.map +1 -0
  26. package/lib/commonjs/index.js +7 -0
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/specs/NativeDdFlags.js +19 -0
  29. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -0
  30. package/lib/commonjs/version.js +1 -1
  31. package/lib/module/flags/DdFlags.js +45 -0
  32. package/lib/module/flags/DdFlags.js.map +1 -0
  33. package/lib/module/flags/FlagsClient.js +211 -0
  34. package/lib/module/flags/FlagsClient.js.map +1 -0
  35. package/lib/module/flags/internal.js +33 -0
  36. package/lib/module/flags/internal.js.map +1 -0
  37. package/lib/module/flags/types.js +2 -0
  38. package/lib/module/flags/types.js.map +1 -0
  39. package/lib/module/index.js +2 -1
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/specs/NativeDdFlags.js +17 -0
  42. package/lib/module/specs/NativeDdFlags.js.map +1 -0
  43. package/lib/module/version.js +1 -1
  44. package/lib/typescript/flags/DdFlags.d.ts +3 -0
  45. package/lib/typescript/flags/DdFlags.d.ts.map +1 -0
  46. package/lib/typescript/flags/FlagsClient.d.ts +114 -0
  47. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -0
  48. package/lib/typescript/flags/internal.d.ts +14 -0
  49. package/lib/typescript/flags/internal.d.ts.map +1 -0
  50. package/lib/typescript/flags/types.d.ts +202 -0
  51. package/lib/typescript/flags/types.d.ts.map +1 -0
  52. package/lib/typescript/index.d.ts +5 -2
  53. package/lib/typescript/index.d.ts.map +1 -1
  54. package/lib/typescript/nativeModulesTypes.d.ts +5 -0
  55. package/lib/typescript/nativeModulesTypes.d.ts.map +1 -1
  56. package/lib/typescript/specs/NativeDdFlags.d.ts +15 -0
  57. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -0
  58. package/lib/typescript/version.d.ts +1 -1
  59. package/package.json +2 -2
  60. package/src/flags/DdFlags.ts +59 -0
  61. package/src/flags/FlagsClient.ts +266 -0
  62. package/src/flags/__tests__/DdFlags.test.ts +65 -0
  63. package/src/flags/__tests__/FlagsClient.test.ts +320 -0
  64. package/src/flags/internal.ts +63 -0
  65. package/src/flags/types.ts +215 -0
  66. package/src/index.tsx +15 -1
  67. package/src/nativeModulesTypes.ts +6 -0
  68. package/src/specs/NativeDdFlags.ts +35 -0
  69. 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
- return this.toWritableArray(
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 -> writableArray.pushNull()
43
- is Int -> writableArray.pushInt(it)
44
- is Long -> writableArray.pushDouble(it.toDouble())
45
- is Float -> writableArray.pushDouble(it.toDouble())
46
- is Double -> writableArray.pushDouble(it)
47
- is String -> writableArray.pushString(it)
48
- is Boolean -> writableArray.pushBoolean(it)
49
- is List<*> -> writableArray.pushArray(
50
- it.toWritableArray(
51
- createWritableMap,
52
- createWritableArray
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
- is Map<*, *> -> writableArray.pushMap(
56
- it.toWritableMap(
57
- createWritableMap,
58
- createWritableArray
80
+ }
81
+
82
+ is Map<*, *> -> {
83
+ writableArray.pushMap(
84
+ it.toWritableMap(
85
+ createWritableMap,
86
+ createWritableArray,
87
+ ),
59
88
  )
60
- )
61
- else -> Log.e(
62
- javaClass.simpleName,
63
- "toWritableArray(): Unhandled type ${it.javaClass.simpleName} has been ignored"
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
- return this.toWritableMap(
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 -> map.putNull(key)
96
- is Int -> map.putInt(key, v)
97
- is Long -> map.putDouble(key, v.toDouble())
98
- is Float -> map.putDouble(key, v.toDouble())
99
- is Double -> map.putDouble(key, v)
100
- is String -> map.putString(key, v)
101
- is Boolean -> map.putBoolean(key, v)
102
- is List<*> -> map.putArray(
103
- key,
104
- v.toWritableArray(
105
- createWritableMap,
106
- createWritableArray
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
- is Map<*, *> -> map.putMap(
110
- key,
111
- v.toWritableMap(
112
- createWritableMap,
113
- createWritableArray
163
+ }
164
+
165
+ is Map<*, *> -> {
166
+ map.putMap(
167
+ key,
168
+ v.toWritableMap(
169
+ createWritableMap,
170
+ createWritableArray,
171
+ ),
114
172
  )
115
- )
116
- else -> Log.e(
117
- javaClass.simpleName,
118
- "toWritableMap(): Unhandled type ${v.javaClass.simpleName} has been ignored"
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 = this.toHashMap()
132
- .filterValues { it != null }
133
- .mapValues { it.value!! }
134
- .toMap(HashMap())
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(key: String, value: Any?) {
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 -> updateMap(key, getMap(key)?.toMap())
154
- ReadableType.Array -> updateMap(key, getArray(key)?.toList())
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 -> list.add(null)
190
- ReadableType.Boolean -> list.add(getBoolean(i))
191
- ReadableType.Number -> list.add(getDouble(i))
192
- ReadableType.String -> list.add(getString(i))
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
- else -> Log.e(
206
- javaClass.simpleName,
207
- "toList(): Unhandled ReadableType: ${type.name}."
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
- return if (hasKey(key)) {
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
- return if (hasKey(key)) {
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,
@@ -7,4 +7,4 @@
7
7
  package com.datadog.reactnative
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- internal const val SDK_VERSION = "3.0.3"
10
+ internal const val SDK_VERSION = "3.1.0"
@@ -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
+ }