react-native-sdk-pianoio 0.3.6 → 0.3.8

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.
@@ -1,6 +1,7 @@
1
1
  package com.sdkpianoio
2
2
 
3
3
  import android.content.Context
4
+ import android.util.Log
4
5
  import com.facebook.react.bridge.Promise
5
6
  import io.piano.android.composer.Composer
6
7
  import io.piano.android.composer.listeners.EventTypeListener
@@ -31,6 +32,7 @@ class ComposerPianoImpl {
31
32
 
32
33
  companion object {
33
34
  var aid: String = ""
35
+ private const val TAG = "ComposerPianoImpl"
34
36
  }
35
37
 
36
38
  // MARK: - Configuration Properties
@@ -45,7 +47,7 @@ class ComposerPianoImpl {
45
47
  // MARK: - Initialization
46
48
 
47
49
  constructor() {
48
- println("ComposerPianoImpl: Constructor initialized")
50
+ Log.d(TAG, "Constructor initialized")
49
51
  }
50
52
 
51
53
  /**
@@ -54,35 +56,36 @@ class ComposerPianoImpl {
54
56
  * @param context The Android application context.
55
57
  * @param aid The Piano Application ID.
56
58
  */
57
- fun initializeComposer(context: Context, aid: String) {
58
- println("ComposerPianoImpl: Initializing composer with AID: $aid")
59
+ fun initializeComposer(context: Context, aid: String, isSandbox: Boolean) {
60
+ Log.d(TAG, "Initializing composer with AID: $aid, isSandbox: $isSandbox")
59
61
 
60
62
  // Validate input parameter
61
63
  if (aid.isBlank()) {
64
+ Log.e(TAG, "AID cannot be empty")
62
65
  throw IllegalArgumentException("AID cannot be empty")
63
66
  }
64
67
 
65
68
  // Configure static AID for the whole class
66
69
  ComposerPianoImpl.aid = aid
67
- println("ComposerPianoImpl: Static AID configured: ${ComposerPianoImpl.aid}")
70
+ Log.d(TAG, "Static AID configured: ${ComposerPianoImpl.aid}")
68
71
 
69
72
  try {
70
- // 1. Initialize the Composer SDK statically using the official API
71
- Composer.init(context, aid, Composer.Endpoint.PRODUCTION)
72
- println("ComposerPianoImpl: Composer SDK initialized for PRODUCTION")
73
+ val endpoint =
74
+ if (isSandbox) Composer.Endpoint.SANDBOX else Composer.Endpoint.PRODUCTION
75
+ Log.d(TAG, "Using endpoint: $endpoint")
76
+ Composer.init(context, aid, endpoint)
77
+ Log.d(TAG, "Composer SDK initialized")
73
78
 
74
- // 2. Get the singleton instance and store it
75
79
  this.composer = Composer.getInstance()
76
- println("ComposerPianoImpl: Composer instance retrieved")
80
+ Log.d(TAG, "Composer instance retrieved")
77
81
 
78
- // 3. Initialize the TokenService and store it as a property
79
82
  this.tokenService = TokenService()
80
83
  this.tokenService?.initialize(aid)
81
- println("ComposerPianoImpl: TokenService initialized")
84
+ Log.d(TAG, "TokenService initialized")
82
85
 
83
- println("ComposerPianoImpl: Initialization completed successfully")
86
+ Log.d(TAG, "Initialization completed successfully")
84
87
  } catch (e: Exception) {
85
- println("ComposerPianoImpl: Error during initialization: ${e.message}")
88
+ Log.e(TAG, "Error during initialization", e)
86
89
  throw e
87
90
  }
88
91
  }
@@ -124,12 +127,14 @@ class ComposerPianoImpl {
124
127
  // MARK: - Configuration Methods (Setters)
125
128
 
126
129
  fun addTag(tag: String) {
130
+ Log.d(TAG, "Adding tag: $tag")
127
131
  if (!this.tags.contains(tag)) {
128
132
  this.tags.add(tag)
129
133
  }
130
134
  }
131
135
 
132
136
  fun addTags(tags: List<String>) {
137
+ Log.d(TAG, "Adding tags: $tags")
133
138
  for (tag in tags) {
134
139
  if (!this.tags.contains(tag)) {
135
140
  this.tags.add(tag)
@@ -138,27 +143,33 @@ class ComposerPianoImpl {
138
143
  }
139
144
 
140
145
  fun setZoneId(zoneId: String) {
146
+ Log.d(TAG, "Setting zoneId: $zoneId")
141
147
  this.zoneId = zoneId
142
148
  }
143
149
 
144
150
  fun setReferrer(referrer: String) {
151
+ Log.d(TAG, "Setting referrer: $referrer")
145
152
  this.referrer = referrer
146
153
  }
147
154
 
148
155
  fun setUrl(url: String) {
156
+ Log.d(TAG, "Setting url: $url")
149
157
  this.url = url
150
158
  }
151
159
 
152
160
  fun setUserToken(token: String) {
161
+ Log.d(TAG, "Setting userToken")
153
162
  this.userToken = token
154
163
  composer?.userToken(token)
155
164
  }
156
165
 
157
166
  fun addCustomVariable(key: String, value: String) {
167
+ Log.d(TAG, "Adding custom variable: $key = $value")
158
168
  this.customVariables[key] = value
159
169
  }
160
170
 
161
171
  fun setCustomVariables(variables: Map<String, String>) {
172
+ Log.d(TAG, "Setting custom variables")
162
173
  this.customVariables.clear()
163
174
  this.customVariables.putAll(variables)
164
175
  }
@@ -166,22 +177,27 @@ class ComposerPianoImpl {
166
177
  // MARK: - Cleanup Methods
167
178
 
168
179
  fun clearTags() {
180
+ Log.d(TAG, "Clearing tags")
169
181
  this.tags.clear()
170
182
  }
171
183
 
172
184
  fun clearCustomVariables() {
185
+ Log.d(TAG, "Clearing custom variables")
173
186
  this.customVariables.clear()
174
187
  }
175
188
 
176
189
  fun removeTag(tag: String) {
190
+ Log.d(TAG, "Removing tag: $tag")
177
191
  this.tags.remove(tag)
178
192
  }
179
193
 
180
194
  fun removeCustomVariable(key: String) {
195
+ Log.d(TAG, "Removing custom variable: $key")
181
196
  this.customVariables.remove(key)
182
197
  }
183
198
 
184
199
  fun clearConfiguration() {
200
+ Log.d(TAG, "Clearing all configurations")
185
201
  this.clearTags()
186
202
  this.clearCustomVariables()
187
203
  this.zoneId = null
@@ -199,25 +215,25 @@ class ComposerPianoImpl {
199
215
  * @throws IllegalStateException if the composer has not been initialized.
200
216
  */
201
217
  fun executeComposer(promise: Promise) {
202
- println("ComposerPianoImpl: Starting composer execution")
218
+ Log.d(TAG, "Starting composer execution")
203
219
 
204
- // 1. Validate that the composer has been initialized
205
220
  val composerInstance = composer
206
221
  if (composerInstance == null) {
207
222
  val error =
208
223
  IllegalStateException(
209
224
  "Composer not initialized. Call initializeComposer() first."
210
225
  )
211
- println("ComposerPianoImpl: Error - Composer not initialized")
226
+ Log.e(TAG, "executeComposer failed: Composer not initialized")
212
227
  promise.reject("INIT_ERROR", error.message, error)
213
228
  return
214
229
  }
215
230
 
216
231
  try {
217
232
  val customParams = CustomParameters()
233
+ Log.d(TAG, "Custom params are: $customParams")
218
234
  this.customVariables.forEach { (key, value) -> customParams.request(key, value) }
235
+ Log.d(TAG, "Custom variables are $customVariables")
219
236
 
220
- // 2. Build the ExperienceRequest with all stored configurations
221
237
  val request =
222
238
  ExperienceRequest.Builder()
223
239
  .tags(this.tags)
@@ -227,38 +243,46 @@ class ComposerPianoImpl {
227
243
  .customParams(customParams)
228
244
  .debug(false)
229
245
  .build()
230
- println("ComposerPianoImpl: ExperienceRequest created successfully")
246
+ Log.d(TAG, "ExperienceRequest created successfully")
231
247
 
232
- // 3. Define the listeners to handle events from the SDK
233
248
  val listeners: List<EventTypeListener<*>> =
234
249
  listOf(
235
250
  UserSegmentListener { event ->
236
- println("UserSegmentListener event: ${event.eventData}")
237
- // You can process user segment data here if needed
251
+ Log.d(
252
+ TAG,
253
+ "Listener received: UserSegmentListener event: ${event.eventData}"
254
+ )
238
255
  },
239
256
  MeterListener { event ->
240
- println("MeterListener event: ${event.eventData}")
257
+ Log.d(
258
+ TAG,
259
+ "Listener received: MeterListener event: ${event.eventData}"
260
+ )
241
261
  promise.resolve(event.eventData.toString())
242
262
  },
243
263
  ShowTemplateListener { event: Event<ShowTemplate> ->
244
- println("ShowTemplateListener event: ${event.eventData}")
264
+ Log.d(
265
+ TAG,
266
+ "Listener received: ShowTemplateListener event: ${event.eventData}"
267
+ )
245
268
  promise.resolve(event.eventData.toString())
246
269
  },
247
270
  NonSiteListener { event ->
248
- println("NonSiteListener event: ${event.eventData}")
271
+ Log.d(
272
+ TAG,
273
+ "Listener received: NonSiteListener event: ${event.eventData}"
274
+ )
249
275
  }
250
276
  )
277
+ Log.d(TAG, "Event listeners created")
251
278
 
252
- println("ComposerPianoImpl: Event listeners created")
253
-
254
- // 4. Execute the experience request using the real Piano SDK method
255
279
  composerInstance.getExperience(request, listeners) { exception ->
256
- println("ComposerPianoImpl: SDK returned an exception: ${exception.message}")
280
+ Log.e(TAG, "getExperience failed with exception", exception)
257
281
  promise.reject("EXECUTION_ERROR", exception.message, exception)
258
282
  }
259
- println("ComposerPianoImpl: getExperience() called successfully")
283
+ Log.d(TAG, "getExperience() called successfully")
260
284
  } catch (e: Exception) {
261
- println("ComposerPianoImpl: Error during execution setup: ${e.message}")
285
+ Log.e(TAG, "Error during execution setup", e)
262
286
  promise.reject("SETUP_ERROR", e.message, e)
263
287
  }
264
288
  }
@@ -1,5 +1,6 @@
1
1
  package com.sdkpianoio
2
2
 
3
+ import android.util.Log
3
4
  import androidx.activity.ComponentActivity
4
5
  import androidx.activity.result.ActivityResultLauncher
5
6
  import com.facebook.react.bridge.Arguments
@@ -22,74 +23,91 @@ import io.piano.android.id.models.PianoIdAuthSuccessResult
22
23
  * This module serves as the bridge between JavaScript and the native Android implementation.
23
24
  */
24
25
  @ReactModule(name = SdkPianoioModule.NAME)
25
- class SdkPianoioModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
26
-
26
+ class SdkPianoioModule(private val reactContext: ReactApplicationContext) :
27
+ ReactContextBaseJavaModule(reactContext) {
28
+
27
29
  private var composerImpl: ComposerPianoImpl? = null
28
30
  private var isInitialized: Boolean = false
29
31
  private var signInPromise: Promise? = null
30
32
 
31
33
  private lateinit var authResultLauncher: ActivityResultLauncher<PianoIdClient.SignInContext>
32
34
 
35
+ companion object {
36
+ const val NAME = "SdkPianoio"
37
+ private const val TAG = "SdkPianoioModule"
38
+ }
39
+
33
40
  init {
34
- // The ActivityResultLauncher must be registered in the init block or onCreate.
35
- // We need to ensure we have a ComponentActivity to access the registry.
41
+ Log.d(TAG, "Initializing SdkPianoioModule")
36
42
  val activity = reactContext.currentActivity
37
43
  if (activity is ComponentActivity) {
38
- authResultLauncher = activity.activityResultRegistry.register(
39
- "piano-id-login",
40
- PianoIdAuthResultContract()
41
- ) { result ->
42
- val promise = signInPromise
43
- signInPromise = null // Clean up promise immediately
44
- when (result) {
45
- is PianoIdAuthSuccessResult -> {
46
- val token = result.token
47
- composerImpl?.tokenService?.setToken(token)
48
- val user = composerImpl?.tokenService?.getCurrentUser()
49
- if (user != null) {
50
- val resultMap = Arguments.createMap().apply {
51
- putBoolean("success", true)
52
- putString("userId", user.id)
53
- putString("userEmail", user.email)
54
- putString("accessToken", user.accessToken)
44
+ authResultLauncher =
45
+ activity.activityResultRegistry.register(
46
+ "piano-id-login",
47
+ PianoIdAuthResultContract()
48
+ ) { result ->
49
+ Log.d(TAG, "ActivityResultLauncher received a result.")
50
+ val promise = signInPromise
51
+ signInPromise = null
52
+ when (result) {
53
+ is PianoIdAuthSuccessResult -> {
54
+ Log.d(TAG, "Sign-in successful.")
55
+ val token = result.token
56
+ composerImpl?.tokenService?.setToken(token)
57
+ val user = composerImpl?.tokenService?.getCurrentUser()
58
+ if (user != null) {
59
+ val resultMap =
60
+ Arguments.createMap().apply {
61
+ putBoolean("success", true)
62
+ putString("userId", user.id)
63
+ putString("userEmail", user.email)
64
+ putString("accessToken", user.accessToken)
65
+ }
66
+ promise?.resolve(resultMap)
67
+ } else {
68
+ Log.e(TAG, "Failed to construct user after login.")
69
+ promise?.reject(
70
+ "SIGNIN_ERROR",
71
+ "Failed to construct user after login."
72
+ )
73
+ }
74
+ }
75
+ is PianoIdAuthFailureResult -> {
76
+ val exception = result.exception
77
+ Log.e(TAG, "Sign-in failed", exception)
78
+ promise?.reject("SIGNIN_ERROR", exception.message, exception)
79
+ }
80
+ null -> {
81
+ Log.w(TAG, "Sign-in cancelled by user.")
82
+ promise?.reject("CANCELLED", "User cancelled the sign-in process.")
55
83
  }
56
- promise?.resolve(resultMap)
57
- } else {
58
- promise?.reject("SIGNIN_ERROR", "Failed to construct user after login.")
59
84
  }
60
85
  }
61
- is PianoIdAuthFailureResult -> {
62
- val exception = result.exception
63
- promise?.reject("SIGNIN_ERROR", exception.message, exception)
64
- }
65
- null -> {
66
- // This handles the case where the user cancels the flow
67
- promise?.reject("CANCELLED", "User cancelled the sign-in process.")
68
- }
69
- }
70
- }
71
86
  } else {
72
- // This is a fallback, though in a normal RN app, currentActivity should be a ComponentActivity.
73
- // You might want to log a warning here.
87
+ Log.e(TAG, "Activity not available for registration. SignIn will not work.")
74
88
  }
75
89
  }
76
-
90
+
77
91
  override fun getName(): String {
78
92
  return NAME
79
93
  }
80
-
94
+
81
95
  @ReactMethod
82
- fun initialize(aid: String, promise: Promise) {
96
+ fun initialize(aid: String, isSandbox: Boolean, promise: Promise) {
97
+ Log.d(TAG, "initialize called with AID: $aid, isSandbox: $isSandbox")
83
98
  try {
84
99
  if (isInitialized) {
100
+ Log.d(TAG, "Already initialized.")
85
101
  promise.resolve(true)
86
102
  return
87
103
  }
88
104
  composerImpl = ComposerPianoImpl()
89
- composerImpl?.initializeComposer(reactContext, aid)
105
+ composerImpl?.initializeComposer(reactContext, aid, isSandbox)
90
106
  isInitialized = true
107
+ Log.d(TAG, "Initialization successful.")
91
108
  promise.resolve(true)
92
109
  } catch (e: Exception) {
110
+ Log.e(TAG, "Initialization failed", e)
93
111
  promise.reject("INIT_ERROR", "Failed to initialize Piano SDK", e)
94
112
  }
95
113
  }
@@ -98,86 +116,103 @@ class SdkPianoioModule(private val reactContext: ReactApplicationContext) : Reac
98
116
 
99
117
  @ReactMethod
100
118
  fun addTag(tag: String, promise: Promise) {
119
+ Log.d(TAG, "addTag called with: $tag")
101
120
  try {
102
121
  if (!validateInitialization(promise) || !validateParameter(tag, "tag", promise)) return
103
122
  composerImpl?.addTag(tag)
104
123
  promise.resolve(true)
105
124
  } catch (e: Exception) {
125
+ Log.e(TAG, "addTag failed", e)
106
126
  promise.reject("ADD_TAG_ERROR", "Error adding tag", e)
107
127
  }
108
128
  }
109
129
 
110
130
  @ReactMethod
111
131
  fun addTags(tagsArray: ReadableArray, promise: Promise) {
132
+ Log.d(TAG, "addTags called")
112
133
  try {
113
- if (!validateInitialization(promise) || !validateArray(tagsArray, "tagsArray", promise)) return
134
+ if (!validateInitialization(promise) || !validateArray(tagsArray, "tagsArray", promise))
135
+ return
114
136
  val tags = tagsArray.toArrayList().mapNotNull { it?.toString() }
115
137
  composerImpl?.addTags(tags)
116
138
  promise.resolve(true)
117
139
  } catch (e: Exception) {
140
+ Log.e(TAG, "addTags failed", e)
118
141
  promise.reject("ADD_TAGS_ERROR", "Error adding tags", e)
119
142
  }
120
143
  }
121
144
 
122
145
  @ReactMethod
123
146
  fun setZoneId(zoneId: String, promise: Promise) {
147
+ Log.d(TAG, "setZoneId called with: $zoneId")
124
148
  try {
125
149
  if (!validateInitialization(promise)) return
126
150
  composerImpl?.setZoneId(zoneId)
127
151
  promise.resolve(true)
128
152
  } catch (e: Exception) {
153
+ Log.e(TAG, "setZoneId failed", e)
129
154
  promise.reject("SET_ZONEID_ERROR", "Error setting Zone ID", e)
130
155
  }
131
156
  }
132
157
 
133
158
  @ReactMethod
134
159
  fun setReferrer(referrer: String, promise: Promise) {
160
+ Log.d(TAG, "setReferrer called with: $referrer")
135
161
  try {
136
162
  if (!validateInitialization(promise)) return
137
163
  composerImpl?.setReferrer(referrer)
138
164
  promise.resolve(true)
139
165
  } catch (e: Exception) {
166
+ Log.e(TAG, "setReferrer failed", e)
140
167
  promise.reject("SET_REFERRER_ERROR", "Error setting referrer", e)
141
168
  }
142
169
  }
143
170
 
144
171
  @ReactMethod
145
172
  fun setUrl(url: String, promise: Promise) {
173
+ Log.d(TAG, "setUrl called with: $url")
146
174
  try {
147
175
  if (!validateInitialization(promise)) return
148
176
  composerImpl?.setUrl(url)
149
177
  promise.resolve(true)
150
178
  } catch (e: Exception) {
179
+ Log.e(TAG, "setUrl failed", e)
151
180
  promise.reject("SET_URL_ERROR", "Error setting URL", e)
152
181
  }
153
182
  }
154
183
 
155
184
  @ReactMethod
156
185
  fun setUserToken(token: String, promise: Promise) {
186
+ Log.d(TAG, "setUserToken called")
157
187
  try {
158
188
  if (!validateInitialization(promise)) return
159
189
  composerImpl?.setUserToken(token)
160
190
  promise.resolve(true)
161
191
  } catch (e: Exception) {
192
+ Log.e(TAG, "setUserToken failed", e)
162
193
  promise.reject("SET_TOKEN_ERROR", "Error setting user token", e)
163
194
  }
164
195
  }
165
196
 
166
197
  @ReactMethod
167
198
  fun addCustomVariable(key: String, value: String, promise: Promise) {
199
+ Log.d(TAG, "addCustomVariable called with: $key = $value")
168
200
  try {
169
201
  if (!validateInitialization(promise)) return
170
202
  composerImpl?.addCustomVariable(key, value)
171
203
  promise.resolve(true)
172
204
  } catch (e: Exception) {
205
+ Log.e(TAG, "addCustomVariable failed", e)
173
206
  promise.reject("ADD_CUSTOMVAR_ERROR", "Error adding custom variable", e)
174
207
  }
175
208
  }
176
-
209
+
177
210
  @ReactMethod
178
211
  fun setCustomVariables(variables: ReadableMap, promise: Promise) {
212
+ Log.d(TAG, "setCustomVariables called")
179
213
  try {
180
- if (!validateInitialization(promise) || !validateMap(variables, "variables", promise)) return
214
+ if (!validateInitialization(promise) || !validateMap(variables, "variables", promise))
215
+ return
181
216
  val map = mutableMapOf<String, String>()
182
217
  val iterator = variables.keySetIterator()
183
218
  while (iterator.hasNextKey()) {
@@ -194,6 +229,7 @@ class SdkPianoioModule(private val reactContext: ReactApplicationContext) : Reac
194
229
  composerImpl?.setCustomVariables(map)
195
230
  promise.resolve(true)
196
231
  } catch (e: Exception) {
232
+ Log.e(TAG, "setCustomVariables failed", e)
197
233
  promise.reject("SET_CUSTOMVARS_ERROR", "Error setting custom variables", e)
198
234
  }
199
235
  }
@@ -202,81 +238,97 @@ class SdkPianoioModule(private val reactContext: ReactApplicationContext) : Reac
202
238
 
203
239
  @ReactMethod
204
240
  fun executeExperience(promise: Promise) {
241
+ Log.d(TAG, "executeExperience called")
205
242
  try {
206
243
  if (!validateInitialization(promise)) return
207
244
  composerImpl?.executeComposer(promise)
208
245
  } catch (e: Exception) {
246
+ Log.e(TAG, "executeExperience failed", e)
209
247
  promise.reject("EXECUTION_ERROR", "Error executing experience", e)
210
248
  }
211
249
  }
212
250
 
213
251
  // MARK: - Authentication Methods
214
-
252
+
215
253
  @ReactMethod
216
254
  fun signIn(promise: Promise) {
255
+ Log.d(TAG, "signIn called")
217
256
  if (signInPromise != null) {
257
+ Log.w(TAG, "Sign-in already in progress.")
218
258
  promise.reject("IN_PROGRESS", "Another sign-in operation is already in progress.")
219
259
  return
220
260
  }
221
261
  try {
222
262
  if (!validateInitialization(promise)) return
223
263
  this.signInPromise = promise
264
+ Log.d(TAG, "Launching sign-in flow via TokenService")
224
265
  composerImpl?.tokenService?.signIn(authResultLauncher)
225
266
  } catch (e: Exception) {
267
+ Log.e(TAG, "signIn failed", e)
226
268
  promise.reject("SIGNIN_ERROR", "Error during sign in", e)
227
269
  this.signInPromise = null
228
270
  }
229
271
  }
230
-
272
+
231
273
  @ReactMethod
232
274
  fun signOut(promise: Promise) {
275
+ Log.d(TAG, "signOut called")
233
276
  try {
234
277
  if (!validateInitialization(promise)) return
235
278
  composerImpl?.tokenService?.signOut { success ->
236
279
  if (success) {
280
+ Log.d(TAG, "signOut successful")
237
281
  promise.resolve(Arguments.createMap().apply { putBoolean("success", true) })
238
282
  } else {
283
+ Log.w(TAG, "signOut failed")
239
284
  promise.reject("SIGNOUT_ERROR", "Sign out failed")
240
285
  }
241
286
  }
242
287
  } catch (e: Exception) {
288
+ Log.e(TAG, "signOut failed", e)
243
289
  promise.reject("SIGNOUT_ERROR", "Error during sign out", e)
244
290
  }
245
291
  }
246
-
292
+
247
293
  @ReactMethod
248
294
  fun getCurrentUser(promise: Promise) {
295
+ Log.d(TAG, "getCurrentUser called")
249
296
  try {
250
297
  if (!validateInitialization(promise)) return
251
298
  val user = composerImpl?.tokenService?.getCurrentUser()
252
299
  if (user != null) {
253
- val result = Arguments.createMap().apply {
254
- putBoolean("success", true)
255
- putString("userId", user.id)
256
- putString("userEmail", user.email)
257
- putString("accessToken", user.accessToken)
258
- putBoolean("authenticated", true)
259
- }
300
+ val result =
301
+ Arguments.createMap().apply {
302
+ putBoolean("success", true)
303
+ putString("userId", user.id)
304
+ putString("userEmail", user.email)
305
+ putString("accessToken", user.accessToken)
306
+ putBoolean("authenticated", true)
307
+ }
260
308
  promise.resolve(result)
261
309
  } else {
262
- val result = Arguments.createMap().apply {
263
- putBoolean("success", true)
264
- putBoolean("authenticated", false)
265
- }
310
+ val result =
311
+ Arguments.createMap().apply {
312
+ putBoolean("success", true)
313
+ putBoolean("authenticated", false)
314
+ }
266
315
  promise.resolve(result)
267
316
  }
268
317
  } catch (e: Exception) {
318
+ Log.e(TAG, "getCurrentUser failed", e)
269
319
  promise.reject("USER_ERROR", "Error getting current user", e)
270
320
  }
271
321
  }
272
-
322
+
273
323
  @ReactMethod
274
324
  fun isAuthenticated(promise: Promise) {
325
+ Log.d(TAG, "isAuthenticated called")
275
326
  try {
276
327
  if (!validateInitialization(promise)) return
277
328
  val isAuth = composerImpl?.tokenService?.isAuthenticated() ?: false
278
329
  promise.resolve(Arguments.createMap().apply { putBoolean("authenticated", isAuth) })
279
330
  } catch (e: Exception) {
331
+ Log.e(TAG, "isAuthenticated failed", e)
280
332
  promise.reject("AUTH_ERROR", "Error checking authentication", e)
281
333
  }
282
334
  }
@@ -285,18 +337,21 @@ class SdkPianoioModule(private val reactContext: ReactApplicationContext) : Reac
285
337
 
286
338
  @ReactMethod
287
339
  fun clearConfiguration(promise: Promise) {
340
+ Log.d(TAG, "clearConfiguration called")
288
341
  try {
289
342
  if (!validateInitialization(promise)) return
290
343
  composerImpl?.clearTags()
291
344
  composerImpl?.clearCustomVariables()
292
345
  promise.resolve(true)
293
346
  } catch (e: Exception) {
347
+ Log.e(TAG, "clearConfiguration failed", e)
294
348
  promise.reject("CLEAR_ERROR", "Error clearing configurations", e)
295
349
  }
296
350
  }
297
351
 
298
352
  private fun validateInitialization(promise: Promise): Boolean {
299
353
  if (!isInitialized || composerImpl == null) {
354
+ Log.w(TAG, "Validation failed: SDK not initialized.")
300
355
  promise.reject("NOT_INITIALIZED", "Piano SDK not initialized. Call initialize() first.")
301
356
  return false
302
357
  }
@@ -305,6 +360,7 @@ class SdkPianoioModule(private val reactContext: ReactApplicationContext) : Reac
305
360
 
306
361
  private fun validateParameter(value: String?, paramName: String, promise: Promise): Boolean {
307
362
  if (value.isNullOrBlank()) {
363
+ Log.w(TAG, "Validation failed: Parameter '$paramName' is null or blank.")
308
364
  promise.reject("INVALID_PARAMETER", "Parameter '$paramName' cannot be empty")
309
365
  return false
310
366
  }
@@ -313,6 +369,7 @@ class SdkPianoioModule(private val reactContext: ReactApplicationContext) : Reac
313
369
 
314
370
  private fun validateArray(array: ReadableArray?, paramName: String, promise: Promise): Boolean {
315
371
  if (array == null || array.size() == 0) {
372
+ Log.w(TAG, "Validation failed: Array '$paramName' is null or empty.")
316
373
  promise.reject("INVALID_PARAMETER", "Array '$paramName' cannot be empty")
317
374
  return false
318
375
  }
@@ -321,13 +378,10 @@ class SdkPianoioModule(private val reactContext: ReactApplicationContext) : Reac
321
378
 
322
379
  private fun validateMap(map: ReadableMap?, paramName: String, promise: Promise): Boolean {
323
380
  if (map == null) {
381
+ Log.w(TAG, "Validation failed: Map '$paramName' is null.")
324
382
  promise.reject("INVALID_PARAMETER", "Map '$paramName' cannot be empty")
325
383
  return false
326
384
  }
327
385
  return true
328
386
  }
329
-
330
- companion object {
331
- const val NAME = "SdkPianoio"
332
- }
333
387
  }