@dashx/react-native 1.1.0 → 1.1.2

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 (136) hide show
  1. package/README.md +79 -7
  2. package/android/.gitignore +10 -0
  3. package/android/build/.transforms/9dceace6c3787533d2dbb1a387e9284c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/DashXReactNativeFirebaseMessagingService.dex +0 -0
  4. package/android/build/.transforms/9dceace6c3787533d2dbb1a387e9284c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/DashXReactNativeModule.dex +0 -0
  5. package/android/build/.transforms/9dceace6c3787533d2dbb1a387e9284c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/MessageReceivedEventHolder.dex +0 -0
  6. package/android/build/.transforms/9dceace6c3787533d2dbb1a387e9284c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/ReactNativeLibraryInfoProvider.dex +0 -0
  7. package/android/build/.transforms/9dceace6c3787533d2dbb1a387e9284c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/Utils$WhenMappings.dex +0 -0
  8. package/android/build/.transforms/9dceace6c3787533d2dbb1a387e9284c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/Utils.dex +0 -0
  9. package/android/build/.transforms/9dceace6c3787533d2dbb1a387e9284c/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  10. package/android/build/.transforms/f3c6049e7ab4bb564c79f3a246b8575e/transformed/classes/classes_dex/classes.dex +0 -0
  11. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +16 -0
  12. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  13. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
  14. package/android/build/intermediates/java_res/debug/processDebugJavaRes/out/META-INF/services/com.dashx.android.DashXLibraryInfoProvider +1 -0
  15. package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +31 -5
  16. package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +16 -0
  17. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/dashx/rn/sdk/DashXReactNativeFirebaseMessagingService.class +0 -0
  18. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/dashx/rn/sdk/DashXReactNativeModule.class +0 -0
  19. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/dashx/rn/sdk/MessageReceivedEventHolder.class +0 -0
  20. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/dashx/rn/sdk/ReactNativeLibraryInfoProvider.class +0 -0
  21. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/dashx/rn/sdk/util/Utils$WhenMappings.class +0 -0
  22. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/dashx/rn/sdk/util/Utils.class +0 -0
  23. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  24. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
  25. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
  26. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
  27. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
  28. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
  29. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
  30. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
  31. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
  32. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
  33. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
  34. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
  35. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
  36. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
  37. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
  38. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
  39. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
  40. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
  41. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
  42. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
  43. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
  44. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
  45. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
  46. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
  47. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
  48. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab +0 -0
  49. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.values.at +0 -0
  50. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
  51. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
  52. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
  53. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
  54. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  55. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
  56. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
  57. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
  58. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
  59. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
  60. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
  61. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
  62. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
  63. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
  64. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
  65. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
  66. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
  67. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
  68. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
  69. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
  70. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
  71. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
  72. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
  73. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
  74. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +1 -1
  75. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
  76. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
  77. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
  78. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
  79. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
  80. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
  81. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
  82. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
  83. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
  84. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
  85. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
  86. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
  87. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
  88. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
  89. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  90. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
  91. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
  92. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
  93. package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  94. package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
  95. package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  96. package/android/build/outputs/logs/manifest-merger-debug-report.txt +25 -3
  97. package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  98. package/android/build/tmp/kotlin-classes/debug/com/dashx/rn/sdk/DashXReactNativeFirebaseMessagingService.class +0 -0
  99. package/android/build/tmp/kotlin-classes/debug/com/dashx/rn/sdk/DashXReactNativeModule.class +0 -0
  100. package/android/build/tmp/kotlin-classes/debug/com/dashx/rn/sdk/MessageReceivedEventHolder.class +0 -0
  101. package/android/build/tmp/kotlin-classes/debug/com/dashx/rn/sdk/ReactNativeLibraryInfoProvider.class +0 -0
  102. package/android/build/tmp/kotlin-classes/debug/com/dashx/rn/sdk/util/Utils$WhenMappings.class +0 -0
  103. package/android/build/tmp/kotlin-classes/debug/com/dashx/rn/sdk/util/Utils.class +0 -0
  104. package/android/build.gradle +6 -4
  105. package/android/src/main/AndroidManifest.xml +15 -3
  106. package/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeFirebaseMessagingService.kt +72 -0
  107. package/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeModule.kt +97 -19
  108. package/android/src/main/java/com/dashx/rn/sdk/MessageReceivedEventHolder.kt +14 -0
  109. package/android/src/main/java/com/dashx/rn/sdk/ReactNativeLibraryInfoProvider.kt +8 -0
  110. package/android/src/main/java/com/dashx/rn/sdk/util/Utils.kt +14 -0
  111. package/android/src/main/resources/META-INF/services/com.dashx.android.DashXLibraryInfoProvider +1 -0
  112. package/index.d.ts +129 -0
  113. package/index.js +124 -63
  114. package/ios/DashXEventEmitter.swift +3 -2
  115. package/ios/DashXRCTAppDelegate.swift +38 -0
  116. package/ios/DashXReactNative.mm +4 -0
  117. package/ios/DashXReactNative.swift +15 -3
  118. package/package.json +7 -12
  119. package/yarn.lock +1555 -2562
  120. package/ContentOptionsBuilder.js +0 -62
  121. package/android/build/.transforms/103e3bf16f310520880af8bd348f4f94/results.bin +0 -1
  122. package/android/build/.transforms/103e3bf16f310520880af8bd348f4f94/transformed/classes/classes_dex/classes.dex +0 -0
  123. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/results.bin +0 -1
  124. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/BuildConfig.dex +0 -0
  125. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/DashXPackage.dex +0 -0
  126. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/DashXReactNativeModule.dex +0 -0
  127. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/ArrayUtil$1.dex +0 -0
  128. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/ArrayUtil.dex +0 -0
  129. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/MapUtil$1.dex +0 -0
  130. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/MapUtil.dex +0 -0
  131. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/Utils$WhenMappings.dex +0 -0
  132. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/dashx/rn/sdk/util/Utils.dex +0 -0
  133. package/android/build/.transforms/1a91a107d670af17a51b8ccf1674f99e/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  134. package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
  135. package/utils/RestAPIClient.js +0 -154
  136. package/utils.js +0 -21
@@ -0,0 +1,72 @@
1
+ package com.dashx.rn.sdk
2
+
3
+ import com.dashx.android.DashXFirebaseMessagingService
4
+ import com.dashx.android.DashXLog
5
+ import com.facebook.react.bridge.Arguments
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.WritableMap
8
+ import com.facebook.react.modules.core.DeviceEventManagerModule
9
+ import com.google.firebase.messaging.RemoteMessage
10
+
11
+ /**
12
+ * Extends dashx-android's FCM service to also emit "messageReceived" to the React Native JS layer
13
+ * so that DashX.onMessageReceived() callbacks receive push notifications.
14
+ */
15
+ class DashXReactNativeFirebaseMessagingService : DashXFirebaseMessagingService() {
16
+
17
+ private val tag = DashXReactNativeFirebaseMessagingService::class.java.simpleName
18
+
19
+ override fun onMessageReceived(remoteMessage: RemoteMessage) {
20
+ // Preserve dashx-android behavior (notification display + tracking)
21
+ super.onMessageReceived(remoteMessage)
22
+
23
+ val context = MessageReceivedEventHolder.reactContext ?: run {
24
+ DashXLog.d(tag, "React context not available, skipping JS emit")
25
+ return
26
+ }
27
+
28
+ if (!context.hasActiveReactInstance()) {
29
+ DashXLog.d(tag, "No active React instance, skipping JS emit")
30
+ return
31
+ }
32
+
33
+ val payload = remoteMessageToWritableMap(remoteMessage)
34
+ context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
35
+ .emit("messageReceived", payload)
36
+ }
37
+
38
+ private fun remoteMessageToWritableMap(remoteMessage: RemoteMessage): WritableMap {
39
+ val map = Arguments.createMap()
40
+
41
+ // Data payload (always present as Map<String, String>)
42
+ remoteMessage.data.let { data ->
43
+ if (!data.isNullOrEmpty()) {
44
+ val dataMap = Arguments.createMap()
45
+ for ((key, value) in data) {
46
+ dataMap.putString(key, value)
47
+ }
48
+ map.putMap("data", dataMap)
49
+ }
50
+ }
51
+
52
+ // Notification payload (if present)
53
+ remoteMessage.notification?.let { notification ->
54
+ val notifMap = Arguments.createMap()
55
+ notification.title?.let { notifMap.putString("title", it) }
56
+ notification.body?.let { notifMap.putString("body", it) }
57
+ notification.bodyLocalizationKey?.let { notifMap.putString("bodyLocalizationKey", it) }
58
+ notification.titleLocalizationKey?.let { notifMap.putString("titleLocalizationKey", it) }
59
+ notification.channelId?.let { notifMap.putString("channelId", it) }
60
+ notification.clickAction?.let { notifMap.putString("clickAction", it) }
61
+ notification.tag?.let { notifMap.putString("tag", it) }
62
+ notification.imageUrl?.toString()?.let { notifMap.putString("imageUrl", it) }
63
+ map.putMap("notification", notifMap)
64
+ }
65
+
66
+ remoteMessage.messageId?.let { map.putString("messageId", it) }
67
+ remoteMessage.senderId?.let { map.putString("senderId", it) }
68
+ remoteMessage.from?.let { map.putString("from", it) }
69
+
70
+ return map
71
+ }
72
+ }
@@ -1,6 +1,5 @@
1
1
  package com.dashx.rn.sdk
2
2
 
3
- import android.net.Uri
4
3
  import com.dashx.rn.sdk.util.*
5
4
  import com.dashx.android.DashX
6
5
  import com.dashx.android.DashXLog
@@ -14,6 +13,16 @@ import kotlinx.serialization.json.JsonObject
14
13
  class DashXReactNativeModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
15
14
  private val tag = DashXReactNativeModule::class.java.simpleName
16
15
 
16
+ override fun initialize() {
17
+ super.initialize()
18
+ MessageReceivedEventHolder.reactContext = reactContext
19
+ }
20
+
21
+ override fun invalidate() {
22
+ MessageReceivedEventHolder.reactContext = null
23
+ super.invalidate()
24
+ }
25
+
17
26
  override fun getName(): String {
18
27
  return "DashXReactNative"
19
28
  }
@@ -37,7 +46,9 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
37
46
  @ReactMethod
38
47
  fun identify(options: ReadableMap?) {
39
48
  val optionsHashMap = options?.toHashMap()
40
- DashX.identify(optionsHashMap as HashMap<String, String>?)
49
+ ?.filterValues { it != null }
50
+ ?.mapValues { it.value.toString() }
51
+ DashX.identify(optionsHashMap?.let { HashMap(it) })
41
52
  }
42
53
 
43
54
  @ReactMethod
@@ -53,7 +64,10 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
53
64
  @ReactMethod
54
65
  fun track(event: String, data: ReadableMap?) {
55
66
  val jsonData = try {
56
- data?.toHashMap() as HashMap<String, String>?
67
+ data?.toHashMap()
68
+ ?.filterValues { it != null }
69
+ ?.mapValues { it.value.toString() }
70
+ ?.let { HashMap(it) }
57
71
  } catch (e: Exception) {
58
72
  DashXLog.d(tag, e.message)
59
73
  return
@@ -64,15 +78,47 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
64
78
 
65
79
  @ReactMethod
66
80
  fun screen(screenName: String, data: ReadableMap?) {
67
- DashX.screen(screenName, data?.toHashMap() as HashMap<String, String>)
81
+ val screenData = data?.toHashMap()
82
+ ?.filterValues { it != null }
83
+ ?.mapValues { it.value.toString() }
84
+ ?.let { HashMap(it) }
85
+ ?: HashMap()
86
+ DashX.screen(screenName, screenData)
68
87
  }
69
88
 
70
89
  @ReactMethod
71
- fun fetchContent(urn: String, options: ReadableMap?, promise: Promise) {
90
+ fun fetchRecord(urn: String, options: ReadableMap?, promise: Promise) {
91
+ val preview = options?.getBooleanIfPresent("preview")
92
+ val language = options?.getStringIfPresent("language")
93
+ val fields = try {
94
+ convertReadableArrayToKJsonList(options?.getArray("fields"))
95
+ } catch (e: Exception) {
96
+ DashXLog.d(tag, e.message)
97
+ promise.reject("EUNSPECIFIED", "Error parsing fields: ${e.message}")
98
+ return
99
+ }
100
+ val include = try {
101
+ convertReadableArrayToKJsonList(options?.getArray("include"))
102
+ } catch (e: Exception) {
103
+ DashXLog.d(tag, e.message)
104
+ promise.reject("EUNSPECIFIED", "Error parsing include: ${e.message}")
105
+ return
106
+ }
107
+ val exclude = try {
108
+ convertReadableArrayToKJsonList(options?.getArray("exclude"))
109
+ } catch (e: Exception) {
110
+ DashXLog.d(tag, e.message)
111
+ promise.reject("EUNSPECIFIED", "Error parsing exclude: ${e.message}")
112
+ return
113
+ }
114
+
72
115
  DashX.fetchRecord(
73
- urn,
74
- options?.getBooleanIfPresent("preview"),
75
- options?.getStringIfPresent("language"),
116
+ urn = urn,
117
+ preview = preview,
118
+ language = language,
119
+ fields = fields,
120
+ include = include,
121
+ exclude = exclude,
76
122
  onError = {
77
123
  promise.reject("EUNSPECIFIED", it.message)
78
124
  },
@@ -83,30 +129,62 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
83
129
  }
84
130
 
85
131
  @ReactMethod
86
- fun searchContent(contentType: String, options: ReadableMap?, promise: Promise) {
132
+ fun searchRecords(resource: String, options: ReadableMap?, promise: Promise) {
87
133
  val jsonFilter = try {
88
- convertMapToJson(options?.getMap("filter"))
134
+ convertMapToJson(options?.getMap("filter"))?.let { convertJsonToKJson(it) }
89
135
  } catch (e: Exception) {
90
136
  DashXLog.d(tag, e.message)
91
- throw Exception("Encountered an error while parsing filter")
137
+ promise.reject("EUNSPECIFIED", "Error parsing filter: ${e.message}")
138
+ return
92
139
  }
93
-
94
- val jsonOrder = try {
95
- convertMapToJson(options?.getMap("order"))
140
+ val order = try {
141
+ convertReadableArrayToKJsonList(options?.getArray("order"))
142
+ } catch (e: Exception) {
143
+ DashXLog.d(tag, e.message)
144
+ promise.reject("EUNSPECIFIED", "Error parsing order: ${e.message}")
145
+ return
146
+ }
147
+ val limit = options?.getIntIfPresent("limit")
148
+ val preview = options?.getBooleanIfPresent("preview")
149
+ val language = options?.getStringIfPresent("language")
150
+ val fields = try {
151
+ convertReadableArrayToKJsonList(options?.getArray("fields"))
152
+ } catch (e: Exception) {
153
+ DashXLog.d(tag, e.message)
154
+ promise.reject("EUNSPECIFIED", "Error parsing fields: ${e.message}")
155
+ return
156
+ }
157
+ val include = try {
158
+ convertReadableArrayToKJsonList(options?.getArray("include"))
159
+ } catch (e: Exception) {
160
+ DashXLog.d(tag, e.message)
161
+ promise.reject("EUNSPECIFIED", "Error parsing include: ${e.message}")
162
+ return
163
+ }
164
+ val exclude = try {
165
+ convertReadableArrayToKJsonList(options?.getArray("exclude"))
96
166
  } catch (e: Exception) {
97
167
  DashXLog.d(tag, e.message)
98
- throw Exception("Encountered an error while parsing order")
168
+ promise.reject("EUNSPECIFIED", "Error parsing exclude: ${e.message}")
169
+ return
99
170
  }
100
171
 
101
172
  DashX.searchRecords(
102
- contentType,
103
- convertJsonToKJson(jsonFilter),
173
+ resource = resource,
174
+ filter = jsonFilter,
175
+ order = order,
176
+ limit = limit,
177
+ preview = preview,
178
+ language = language,
179
+ fields = fields,
180
+ include = include,
181
+ exclude = exclude,
104
182
  onError = {
105
183
  promise.reject("EUNSPECIFIED", it.message)
106
184
  },
107
- onSuccess = { content ->
185
+ onSuccess = { records ->
108
186
  val readableArray = Arguments.createArray()
109
- content.forEach {
187
+ records.forEach {
110
188
  readableArray.pushMap(convertJsonToMap(convertKJsonToJson(it)))
111
189
  }
112
190
  promise.resolve(readableArray)
@@ -0,0 +1,14 @@
1
+ package com.dashx.rn.sdk
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ /**
6
+ * Holds a reference to the React context so that [DashXReactNativeFirebaseMessagingService]
7
+ * can emit "messageReceived" events to JS when FCM messages arrive.
8
+ * Set by [DashXReactNativeModule], cleared when the module is invalidated.
9
+ */
10
+ object MessageReceivedEventHolder {
11
+ @Volatile
12
+ var reactContext: ReactApplicationContext? = null
13
+ internal set
14
+ }
@@ -0,0 +1,8 @@
1
+ package com.dashx.rn.sdk
2
+
3
+ import com.dashx.android.DashXLibraryInfoProvider
4
+
5
+ class ReactNativeLibraryInfoProvider : DashXLibraryInfoProvider {
6
+ override val name = "@dashx/react-native"
7
+ override val version: String = BuildConfig.VERSION_NAME
8
+ }
@@ -26,6 +26,20 @@ fun convertJsonToKJson(jsonObject: JsonObject?): KJsonObject? {
26
26
  return Json.decodeFromString(jsonString)
27
27
  }
28
28
 
29
+ /**
30
+ * Converts a ReadableArray of maps to a list of kotlinx JsonObjects for DashX.searchRecords options (order, fields, include, exclude).
31
+ */
32
+ @Throws(JSONException::class)
33
+ fun convertReadableArrayToKJsonList(readableArray: ReadableArray?): List<KJsonObject>? {
34
+ if (readableArray == null || readableArray.size() == 0) return null
35
+ return (0 until readableArray.size()).mapNotNull { i ->
36
+ when (readableArray.getType(i)) {
37
+ ReadableType.Map -> readableArray.getMap(i)?.let { convertMapToJson(it)?.let { gson -> convertJsonToKJson(gson) } }
38
+ else -> null
39
+ }
40
+ }.ifEmpty { null }
41
+ }
42
+
29
43
  @Throws(JSONException::class)
30
44
  fun convertMapToJson(readableMap: ReadableMap?): JsonObject? {
31
45
  val iterator = readableMap?.keySetIterator() ?: return null
@@ -0,0 +1 @@
1
+ com.dashx.rn.sdk.ReactNativeLibraryInfoProvider
package/index.d.ts ADDED
@@ -0,0 +1,129 @@
1
+ import { EmitterSubscription } from 'react-native';
2
+
3
+ export interface ConfigureOptions {
4
+ publicKey: string;
5
+ baseURI?: string;
6
+ targetEnvironment?: string;
7
+ }
8
+
9
+ export interface IdentifyOptions {
10
+ firstName?: string;
11
+ lastName?: string;
12
+ email?: string;
13
+ phone?: string;
14
+ [key: string]: string | undefined;
15
+ }
16
+
17
+ export type LogLevel = 0 | 1 | 2;
18
+
19
+ export interface FetchRecordOptions {
20
+ preview?: boolean;
21
+ language?: string;
22
+ fields?: Record<string, unknown>[];
23
+ include?: Record<string, unknown>[];
24
+ exclude?: Record<string, unknown>[];
25
+ }
26
+
27
+ export interface SearchRecordsOptions {
28
+ filter?: Record<string, unknown>;
29
+ order?: Record<string, unknown>[];
30
+ limit?: number;
31
+ preview?: boolean;
32
+ language?: string;
33
+ fields?: Record<string, unknown>[];
34
+ include?: Record<string, unknown>[];
35
+ exclude?: Record<string, unknown>[];
36
+ }
37
+
38
+ export interface NotificationMessage {
39
+ [key: string]: unknown;
40
+ }
41
+
42
+ export interface DashXInstance {
43
+ /**
44
+ * Initialize the SDK with your public key and optional configuration.
45
+ * Call this as early as possible, e.g. in your root component.
46
+ */
47
+ configure(options: ConfigureOptions): void;
48
+
49
+ /**
50
+ * Identify the current user with traits such as name and email.
51
+ */
52
+ identify(options: IdentifyOptions): void;
53
+
54
+ /**
55
+ * Set user identity using a UID and authentication token.
56
+ */
57
+ setIdentity(uid: string, token: string): void;
58
+
59
+ /**
60
+ * Clear the current user identity and reset SDK state.
61
+ */
62
+ reset(): void;
63
+
64
+ /**
65
+ * Track a named event with optional metadata.
66
+ */
67
+ track(event: string, data?: Record<string, unknown>): void;
68
+
69
+ /**
70
+ * Track a screen view with optional metadata.
71
+ */
72
+ screen(screenName: string, data?: Record<string, unknown>): void;
73
+
74
+ /**
75
+ * Fetch a single record by URN (e.g. "article/123") with optional preview, language, fields, include, exclude.
76
+ * Returns a promise resolving to the record object.
77
+ */
78
+ fetchRecord(
79
+ urn: string,
80
+ options?: FetchRecordOptions
81
+ ): Promise<Record<string, unknown>>;
82
+
83
+ /**
84
+ * Search records by resource with optional filter, order, limit, preview, language, fields, include, exclude.
85
+ * Returns a promise resolving to an array of record objects.
86
+ */
87
+ searchRecords(
88
+ resource: string,
89
+ options?: SearchRecordsOptions
90
+ ): Promise<Record<string, unknown>[]>;
91
+
92
+ /**
93
+ * Subscribe the current device to push notifications.
94
+ */
95
+ subscribe(): void;
96
+
97
+ /**
98
+ * Unsubscribe the current device from push notifications.
99
+ */
100
+ unsubscribe(): void;
101
+
102
+ /**
103
+ * Fetch stored notification preferences for the current user.
104
+ */
105
+ fetchStoredPreferences(): Promise<Record<string, unknown>>;
106
+
107
+ /**
108
+ * Save notification preferences for the current user.
109
+ */
110
+ saveStoredPreferences(
111
+ data: Record<string, unknown>
112
+ ): Promise<Record<string, unknown>>;
113
+
114
+ /**
115
+ * Set SDK log verbosity. 0 = off, 1 = errors, 2 = debug.
116
+ */
117
+ setLogLevel(level: LogLevel): void;
118
+
119
+ /**
120
+ * Register a listener for incoming push notification messages.
121
+ * Returns a subscription that can be removed via `.remove()`.
122
+ */
123
+ onMessageReceived(
124
+ callback: (message: NotificationMessage) => void
125
+ ): EmitterSubscription;
126
+ }
127
+
128
+ declare const DashX: DashXInstance;
129
+ export default DashX;
package/index.js CHANGED
@@ -1,78 +1,139 @@
1
- import { NativeModules, Platform } from 'react-native';
2
-
3
- const LINKING_ERROR =
4
- `The package 'dashx-react-native' doesn't seem to be linked. Make sure: \n\n` +
5
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
- '- You rebuilt the app after installing the package\n' +
7
- '- You are not using Expo Go\n';
8
-
9
- const DashX = NativeModules.DashXReactNative
10
- ? NativeModules.DashXReactNative
11
- : new Proxy(
12
- {},
13
- {
14
- get() {
15
- throw new Error(LINKING_ERROR);
16
- },
17
- }
1
+ import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
+
3
+ function getLinkingError() {
4
+ return (
5
+ `The package 'dashx-react-native' doesn't seem to be linked. Make sure: \n\n` +
6
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
7
+ '- You rebuilt the app after installing the package\n' +
8
+ '- You are not using Expo Go\n'
18
9
  );
10
+ }
19
11
 
20
- const {
21
- configure,
22
- identify,
23
- setIdentity,
24
- reset,
25
- track,
26
- screen,
27
- fetchStoredPreferences,
28
- saveStoredPreferences,
29
- subscribe,
30
- unsubscribe,
31
- setLogLevel,
32
- } = DashX;
33
-
34
- DashX.configure = (options) => {
35
- return configure(options);
12
+ let _nativeDashX = null;
13
+ function getNativeDashX() {
14
+ if (!_nativeDashX) {
15
+ _nativeDashX = NativeModules.DashXReactNative
16
+ ? NativeModules.DashXReactNative
17
+ : new Proxy(
18
+ {},
19
+ {
20
+ get() {
21
+ throw new Error(getLinkingError());
22
+ },
23
+ }
24
+ );
25
+ }
26
+ return _nativeDashX;
36
27
  }
37
28
 
38
- DashX.identify = (options) => {
39
- return identify(options);
40
- };
29
+ let _eventEmitter = null;
30
+ function getEventEmitter() {
31
+ if (!_eventEmitter) {
32
+ _eventEmitter = new NativeEventEmitter(getNativeDashX());
33
+ }
34
+ return _eventEmitter;
35
+ }
41
36
 
42
- DashX.setIdentity = (uid, token) => {
43
- return setIdentity(uid, token);
44
- };
37
+ const DashX = {
38
+ configure(options) {
39
+ if (!options || typeof options !== 'object') {
40
+ throw new Error('DashX.configure: options must be an object');
41
+ }
42
+ if (!options.publicKey || typeof options.publicKey !== 'string') {
43
+ throw new Error('DashX.configure: publicKey is required and must be a string');
44
+ }
45
+ return getNativeDashX().configure(options);
46
+ },
45
47
 
46
- DashX.reset = () => {
47
- return reset();
48
- }
48
+ identify(options) {
49
+ if (!options || typeof options !== 'object') {
50
+ throw new Error('DashX.identify: options must be an object');
51
+ }
52
+ return getNativeDashX().identify(options);
53
+ },
49
54
 
50
- DashX.track = (event, data) => {
51
- return track(event, data || null);
52
- }
55
+ setIdentity(uid, token) {
56
+ if (!uid || typeof uid !== 'string') {
57
+ throw new Error('DashX.setIdentity: uid is required and must be a string');
58
+ }
59
+ if (!token || typeof token !== 'string') {
60
+ throw new Error('DashX.setIdentity: token is required and must be a string');
61
+ }
62
+ return getNativeDashX().setIdentity(uid, token);
63
+ },
53
64
 
54
- DashX.screen = (screenName, data) => {
55
- return screen(screenName, data || null)
56
- }
65
+ reset() {
66
+ return getNativeDashX().reset();
67
+ },
57
68
 
58
- DashX.fetchStoredPreferences = () => {
59
- return fetchStoredPreferences();
60
- };
69
+ track(event, data) {
70
+ if (!event || typeof event !== 'string') {
71
+ throw new Error('DashX.track: event is required and must be a string');
72
+ }
73
+ return getNativeDashX().track(event, data || null);
74
+ },
61
75
 
62
- DashX.saveStoredPreferences = (preferenceData) => {
63
- return saveStoredPreferences(preferenceData);
64
- };
76
+ screen(screenName, data) {
77
+ if (!screenName || typeof screenName !== 'string') {
78
+ throw new Error('DashX.screen: screenName is required and must be a string');
79
+ }
80
+ return getNativeDashX().screen(screenName, data || null);
81
+ },
65
82
 
66
- DashX.subscribe = () => {
67
- return subscribe();
68
- }
83
+ fetchRecord(urn, options = {}) {
84
+ if (!urn || typeof urn !== 'string') {
85
+ throw new Error('DashX.fetchRecord: urn is required and must be a string (e.g. "article/123")');
86
+ }
87
+ if (options !== null && typeof options !== 'object') {
88
+ throw new Error('DashX.fetchRecord: options must be an object');
89
+ }
90
+ return getNativeDashX().fetchRecord(urn, options || null);
91
+ },
69
92
 
70
- DashX.unsubscribe = () => {
71
- return unsubscribe();
72
- }
93
+ searchRecords(resource, options = {}) {
94
+ if (!resource || typeof resource !== 'string') {
95
+ throw new Error('DashX.searchRecords: resource is required and must be a string');
96
+ }
97
+ if (options !== null && typeof options !== 'object') {
98
+ throw new Error('DashX.searchRecords: options must be an object');
99
+ }
100
+ return getNativeDashX().searchRecords(resource, options || null);
101
+ },
73
102
 
74
- DashX.setLogLevel = (level) => {
75
- return setLogLevel(level);
76
- }
103
+ fetchStoredPreferences() {
104
+ return getNativeDashX().fetchStoredPreferences();
105
+ },
106
+
107
+ saveStoredPreferences(preferenceData) {
108
+ if (!preferenceData || typeof preferenceData !== 'object') {
109
+ throw new Error(
110
+ 'DashX.saveStoredPreferences: preferenceData is required and must be an object'
111
+ );
112
+ }
113
+ return getNativeDashX().saveStoredPreferences(preferenceData);
114
+ },
115
+
116
+ subscribe() {
117
+ return getNativeDashX().subscribe();
118
+ },
119
+
120
+ unsubscribe() {
121
+ return getNativeDashX().unsubscribe();
122
+ },
123
+
124
+ setLogLevel(level) {
125
+ if (typeof level !== 'number') {
126
+ throw new Error('DashX.setLogLevel: level must be a number');
127
+ }
128
+ return getNativeDashX().setLogLevel(level);
129
+ },
130
+
131
+ onMessageReceived(callback) {
132
+ if (typeof callback !== 'function') {
133
+ throw new Error('DashX.onMessageReceived: callback must be a function');
134
+ }
135
+ return getEventEmitter().addListener('messageReceived', callback);
136
+ },
137
+ };
77
138
 
78
139
  export default DashX;
@@ -1,6 +1,6 @@
1
1
  class DashXEventEmitter {
2
2
  static let instance = DashXEventEmitter()
3
- private static var eventEmitter: DashXReactNative!
3
+ private static var eventEmitter: DashXReactNative?
4
4
 
5
5
  private init() {}
6
6
 
@@ -9,6 +9,7 @@ class DashXEventEmitter {
9
9
  }
10
10
 
11
11
  func dispatch(name: String, body: Any?) {
12
- DashXEventEmitter.eventEmitter.sendEvent(withName: name, body: body)
12
+ guard let emitter = DashXEventEmitter.eventEmitter else { return }
13
+ emitter.sendEvent(withName: name, body: body)
13
14
  }
14
15
  }