react-native-nami-sdk 3.3.3-4 → 3.3.3-5

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.
@@ -85,8 +85,8 @@ dependencies {
85
85
  implementation fileTree(dir: 'libs', include: ['*.jar'])
86
86
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
87
87
 
88
- playImplementation "com.namiml:sdk-android:3.3.3.3"
89
- amazonImplementation "com.namiml:sdk-amazon:3.3.3.3"
88
+ playImplementation "com.namiml:sdk-android:3.3.3.4"
89
+ amazonImplementation "com.namiml:sdk-amazon:3.3.3.4"
90
90
 
91
91
  implementation "com.facebook.react:react-native:+" // From node_modules
92
92
  coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.4"
@@ -3,6 +3,7 @@ package com.namiml.reactnative
3
3
  import android.app.Activity
4
4
  import android.net.Uri
5
5
  import android.util.Log
6
+ import androidx.core.net.toUri
6
7
  import com.facebook.react.bridge.*
7
8
  import com.facebook.react.module.annotations.ReactModule
8
9
  import com.facebook.react.modules.core.DeviceEventManagerModule
@@ -13,13 +14,12 @@ import com.namiml.campaign.NamiCampaign
13
14
  import com.namiml.campaign.NamiCampaignManager
14
15
  import com.namiml.paywall.model.NamiPaywallEvent
15
16
  import com.namiml.paywall.model.PaywallLaunchContext
16
- import androidx.core.net.toUri
17
17
 
18
18
  @ReactModule(name = NamiCampaignManagerBridgeModule.NAME)
19
19
  class NamiCampaignManagerBridgeModule internal constructor(
20
- private val reactContext: ReactApplicationContext
21
- ) : ReactContextBaseJavaModule(reactContext), TurboModule {
22
-
20
+ private val reactContext: ReactApplicationContext,
21
+ ) : ReactContextBaseJavaModule(reactContext),
22
+ TurboModule {
23
23
  companion object {
24
24
  const val NAME = "RNNamiCampaignManager"
25
25
  const val CAMPAIGN_ID = "campaignId"
@@ -42,10 +42,7 @@ class NamiCampaignManagerBridgeModule internal constructor(
42
42
  const val NAMI_PAYWALL_EVENT = "NamiPaywallEvent"
43
43
  }
44
44
 
45
-
46
- override fun getName(): String {
47
- return NAME
48
- }
45
+ override fun getName(): String = NAME
49
46
 
50
47
  private fun campaignToReadableMap(campaign: NamiCampaign): ReadableMap {
51
48
  val readableMap = Arguments.createMap()
@@ -94,7 +91,37 @@ class NamiCampaignManagerBridgeModule internal constructor(
94
91
  val keyIterator = attr.keySetIterator()
95
92
  while (keyIterator.hasNextKey()) {
96
93
  val key = keyIterator.nextKey()
97
- customAttributes[key] = attr.getString(key) ?: ""
94
+ try {
95
+ // Handle different data types and store with proper types
96
+ val value: Any =
97
+ when (attr.getType(key)) {
98
+ ReadableType.String -> attr.getString(key) ?: ""
99
+ ReadableType.Boolean -> attr.getBoolean(key)
100
+ ReadableType.Number -> {
101
+ // Try to get as int first, then as double
102
+ try {
103
+ attr.getInt(key)
104
+ } catch (e: Exception) {
105
+ attr.getDouble(key)
106
+ }
107
+ }
108
+ ReadableType.Null -> ""
109
+ ReadableType.Array -> attr.getArray(key)?.toArrayList() ?: emptyList<Any>()
110
+ ReadableType.Map -> attr.getMap(key)?.toHashMap() ?: emptyMap<String, Any>()
111
+ }
112
+ customAttributes[key] = value
113
+ } catch (e: Exception) {
114
+ // Log the error and try to store the value as a string representation
115
+ Log.w(NAME, "Error parsing customAttribute '$key': ${e.message}. Attempting string conversion.")
116
+ try {
117
+ // Fallback: try to get the dynamic value and convert to string
118
+ val dynamicValue = attr.getDynamic(key)
119
+ customAttributes[key] = dynamicValue.asString() ?: ""
120
+ } catch (fallbackError: Exception) {
121
+ // If all else fails, log and skip this attribute
122
+ Log.e(NAME, "Failed to parse customAttribute '$key': ${fallbackError.message}. Skipping.")
123
+ }
124
+ }
98
125
  }
99
126
  Log.d(NAME, "customAttributes $customAttributes")
100
127
  }
@@ -120,8 +147,7 @@ class NamiCampaignManagerBridgeModule internal constructor(
120
147
 
121
148
  if (theActivity != null) {
122
149
  reactApplicationContext.runOnUiQueueThread {
123
- val paywallActionCallback = {
124
- paywallEvent: NamiPaywallEvent ->
150
+ val paywallActionCallback = { paywallEvent: NamiPaywallEvent ->
125
151
  handlePaywallCallback(
126
152
  paywallEvent,
127
153
  actionCallback,
@@ -184,7 +210,13 @@ class NamiCampaignManagerBridgeModule internal constructor(
184
210
  putString("id", paywallEvent.sku?.id ?: "")
185
211
  putString("skuId", paywallEvent.sku?.skuId ?: "")
186
212
  putString("name", paywallEvent.sku?.name ?: "")
187
- putString("type", paywallEvent.sku?.type.toString().lowercase())
213
+ putString(
214
+ "type",
215
+ paywallEvent.sku
216
+ ?.type
217
+ .toString()
218
+ .lowercase(),
219
+ )
188
220
  }
189
221
  resultMap.putMap(SKU, skuMap)
190
222
  }
@@ -222,8 +254,8 @@ class NamiCampaignManagerBridgeModule internal constructor(
222
254
  emitEvent(NAMI_PAYWALL_EVENT, resultMap)
223
255
  }
224
256
 
225
- private fun createPurchaseArray(purchases: List<NamiPurchase>?): WritableArray {
226
- return WritableNativeArray().apply {
257
+ private fun createPurchaseArray(purchases: List<NamiPurchase>?): WritableArray =
258
+ WritableNativeArray().apply {
227
259
  purchases?.forEach { purchase ->
228
260
  try {
229
261
  pushMap(purchase.toPurchaseDict())
@@ -232,7 +264,6 @@ class NamiCampaignManagerBridgeModule internal constructor(
232
264
  }
233
265
  }
234
266
  }
235
- }
236
267
 
237
268
  private fun emitEvent(
238
269
  event: String,
@@ -279,8 +310,8 @@ class NamiCampaignManagerBridgeModule internal constructor(
279
310
  val isCampaignAvailable =
280
311
  when {
281
312
  campaignSource == null -> NamiCampaignManager.isCampaignAvailable()
282
- campaignSource.toUri().scheme != null -> NamiCampaignManager.isCampaignAvailable(
283
- campaignSource.toUri())
313
+ campaignSource.toUri().scheme != null ->
314
+ NamiCampaignManager.isCampaignAvailable(campaignSource.toUri())
284
315
  else -> NamiCampaignManager.isCampaignAvailable(campaignSource)
285
316
  }
286
317
  promise.resolve(isCampaignAvailable)
@@ -2,4 +2,4 @@
2
2
  * Auto-generated file. Do not edit manually.
3
3
  * React Native Nami SDK version.
4
4
  */
5
- export declare const NAMI_REACT_NATIVE_VERSION = "3.3.3-4";
5
+ export declare const NAMI_REACT_NATIVE_VERSION = "3.3.3-5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nami-sdk",
3
- "version": "3.3.3-4",
3
+ "version": "3.3.3-5",
4
4
  "description": "React Native SDK for Nami - No-code paywall management with A/B testing.",
5
5
  "main": "index.ts",
6
6
  "types": "dist/index.d.ts",
package/src/version.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * Auto-generated file. Do not edit manually.
3
3
  * React Native Nami SDK version.
4
4
  */
5
- export const NAMI_REACT_NATIVE_VERSION = '3.3.3-4';
5
+ export const NAMI_REACT_NATIVE_VERSION = '3.3.3-5';