Skip to content

Commit 0a9c4a1

Browse files
committed
Add use of capability access token
Add callback parameter to fetch provider information from the host app Update breaking changes in the use of the v0.2.1 of module apis
1 parent 22f219c commit 0a9c4a1

File tree

14 files changed

+472
-99
lines changed

14 files changed

+472
-99
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.1
2+
3+
- Updated breaking changes in the use of the v0.2.1 of module apis
4+
- Add use of capability access token
5+
- Add callback parameter to fetch provider information from the host app
6+
17
## 0.1.7
28

39
- Replace getDouble with getNumber for better type safety for numbers in android library

InappRnSdk.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616

1717
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
1818
s.private_header_files = "ios/generated/**/*.h"
19-
s.dependency "ReclaimInAppSdk"
19+
s.dependency "ReclaimInAppSdk", "~> 0.2.1"
2020

2121
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
2222
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ add the following to the end of settings.gradle:
5959
dependencyResolutionManagement {
6060
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
6161
String flutterStorageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
62-
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.1.2/repo"
62+
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.2.1/repo"
6363
repositories {
6464
google()
6565
mavenCentral()
@@ -78,7 +78,7 @@ or alternatively add the following repositories to the relevant repositories blo
7878

7979
```groovy
8080
String flutterStorageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
81-
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.1.2/repo"
81+
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.2.1/repo"
8282
maven {
8383
url "$reclaimStorageUrl"
8484
}
@@ -108,13 +108,13 @@ Ignore if you already have this declaration in your `Podfile`.
108108

109109
```ruby
110110
# Cocoapods is the recommended way to install the SDK.
111-
pod 'ReclaimInAppSdk', '~> 0.1.4'
111+
pod 'ReclaimInAppSdk', '~> 0.2.1'
112112
```
113113

114114
##### From a specific tag
115115

116116
```ruby
117-
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :tag => '0.1.4'
117+
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :tag => '0.2.1'
118118
```
119119

120120
##### From git HEAD
@@ -126,7 +126,7 @@ pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp
126126
##### From a specific commit
127127

128128
```ruby
129-
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :commit => '184d41628026768feb703dc7bb9a3d913c6b271e'
129+
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :commit => 'eeb5a5484a5927217065e5c988fab8201cb2db2e'
130130
```
131131

132132
##### From a specific branch
@@ -151,7 +151,7 @@ target 'InappRnSdkExample' do
151151
)
152152

153153
# This is the line that you may need to add in your podfile.
154-
pod 'ReclaimInAppSdk', '~> 0.1.4'
154+
pod 'ReclaimInAppSdk', '~> 0.2.1'
155155

156156
pre_install do |installer|
157157
system("cd ../../ && npx bob build --target codegen")

android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['InappRnSdk_' + name]
44
}
55
String flutterStorageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
6-
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.1.2/repo"
6+
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.2.1/repo"
77
repositories {
88
google()
99
mavenCentral()
@@ -98,7 +98,7 @@ android {
9898
}
9999

100100
String flutterStorageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
101-
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.1.2/repo"
101+
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.2.1/repo"
102102

103103
repositories {
104104
mavenCentral()
@@ -118,7 +118,7 @@ dependencies {
118118
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
119119

120120
//noinspection UseTomlInstead
121-
implementation "org.reclaimprotocol:inapp_sdk:0.1.2"
121+
implementation "org.reclaimprotocol:inapp_sdk:0.2.1"
122122
}
123123

124124
if (isNewArchitectureEnabled()) {

android/src/main/java/com/reclaimprotocol/inapp_rn_sdk/InappRnSdkModule.kt

Lines changed: 99 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.reclaimprotocol.inapp_rn_sdk
22

3-
import java.util.UUID
43
import android.util.Log
54
import com.facebook.react.bridge.Arguments
65
import com.facebook.react.bridge.Promise
@@ -12,6 +11,7 @@ import com.facebook.react.module.annotations.ReactModule
1211
import org.reclaimprotocol.inapp_sdk.ReclaimOverrides
1312
import org.reclaimprotocol.inapp_sdk.ReclaimSessionStatus
1413
import org.reclaimprotocol.inapp_sdk.ReclaimVerification
14+
import java.util.UUID
1515

1616
@ReactModule(name = InappRnSdkModule.NAME)
1717
class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
@@ -39,7 +39,10 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
3939
userInfoMap.putString("errorType", errorType)
4040
userInfoMap.putString("sessionId", exception.sessionId)
4141
userInfoMap.putBoolean("didSubmitManualVerification", exception.didSubmitManualVerification)
42-
userInfoMap.putString("reason", if (exception is ReclaimVerification.ReclaimVerificationException.Failed) exception.reason else null)
42+
userInfoMap.putString(
43+
"reason",
44+
if (exception is ReclaimVerification.ReclaimVerificationException.Failed) exception.reason else null
45+
)
4346
promise?.reject("VERIFICATION_ERROR", "Verification Error", exception, userInfoMap)
4447
}
4548

@@ -68,12 +71,12 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
6871
}
6972
val handler = ReclaimVerificationResultHandlerImpl(promise)
7073
reactContext.runOnUiQueueThread {
71-
val appId =getString(request,"appId")
72-
val secret = getString(request,"secret")
74+
val appId = getString(request, "appId")
75+
val secret = getString(request, "secret")
7376
val verificationRequest: ReclaimVerification.Request
7477
val session = request.getMap("session")
7578
val parametersRN = request.getMap("parameters")?.toHashMap()
76-
val parameters = mutableMapOf<String, String>()
79+
val parameters = mutableMapOf<String, String>()
7780
if (parametersRN != null) {
7881
for (key in parametersRN.keys) {
7982
val value = parametersRN[key]
@@ -82,7 +85,6 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
8285
}
8386
}
8487
}
85-
val hideLanding = getBoolean(request, "hideLanding")
8688
val autoSubmit = getBoolean(request, "autoSubmit")
8789
val acceptAiProviders = getBoolean(request, "acceptAiProviders")
8890
val webhookUrl = getString(request, "webhookUrl")
@@ -97,7 +99,6 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
9799
signature = getString(session, "signature") ?: "",
98100
),
99101
parameters = parameters,
100-
hideLanding = hideLanding ?: true,
101102
autoSubmit = autoSubmit ?: false,
102103
acceptAiProviders = acceptAiProviders ?: false,
103104
webhookUrl = webhookUrl,
@@ -114,16 +115,13 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
114115
signature = getString(session, "signature") ?: "",
115116
),
116117
parameters = parameters,
117-
hideLanding = hideLanding ?: true,
118118
autoSubmit = autoSubmit ?: false,
119119
acceptAiProviders = acceptAiProviders ?: false,
120120
webhookUrl = webhookUrl,
121121
)
122122
}
123123
ReclaimVerification.startVerification(
124-
context = reactContext.applicationContext,
125-
request = verificationRequest,
126-
handler = handler
124+
context = reactContext.applicationContext, request = verificationRequest, handler = handler
127125
)
128126
}
129127
}
@@ -151,36 +149,74 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
151149
logConsumer = getMap(overrides, "logConsumer"),
152150
sessionManagement = getMap(overrides, "sessionManagement"),
153151
appInfo = getMap(overrides, "appInfo"),
152+
capabilityAccessToken = getString(overrides, "capabilityAccessToken"),
154153
promise,
155154
)
156155
}
157156

158-
private val replyHandlers: MutableMap<String, (Result<Boolean>) -> Unit> = mutableMapOf()
157+
override fun clearAllOverrides(promise: Promise?) {
158+
reactContext.runOnUiQueueThread {
159+
ReclaimVerification.clearAllOverrides(
160+
context = reactContext.applicationContext,
161+
) { result ->
162+
result.onSuccess {
163+
promise?.resolve(null)
164+
}.onFailure { error ->
165+
onPlatformException(promise, error)
166+
}
167+
}
168+
}
169+
}
159170

160171
private fun setOverrides(
161172
provider: ReadableMap?,
162173
featureOptions: ReadableMap?,
163174
logConsumer: ReadableMap?,
164175
sessionManagement: ReadableMap?,
165176
appInfo: ReadableMap?,
177+
capabilityAccessToken: String?,
166178
promise: Promise?
167179
) {
168180
reactContext.runOnUiQueueThread {
169181
ReclaimVerification.setOverrides(
170182
context = reactContext.applicationContext,
171183
provider = if (provider == null) null else (
172-
if (!hasValue(provider, "url"))
184+
if (hasValue(provider, "jsonString"))
173185
ReclaimOverrides.ProviderInformation.FromJsonString(
174186
requireString(
175187
provider, "jsonString"
176188
)
177189
)
178-
else
190+
else if (hasValue(provider, "url"))
179191
ReclaimOverrides.ProviderInformation.FromUrl(
180192
requireString(
181193
provider, "url"
182194
)
183195
)
196+
else if (getBoolean(provider, "canFetchProviderInformationFromHost") == true)
197+
ReclaimOverrides.ProviderInformation.FromCallback(object : ReclaimOverrides.ProviderInformation.FromCallbackHandler {
198+
override fun fetchProviderInformation(
199+
appId: String,
200+
providerId: String,
201+
sessionId: String,
202+
signature: String,
203+
timestamp: String,
204+
callback: (Result<String>) -> Unit
205+
) {
206+
val args = Arguments.createMap()
207+
args.putString("appId", appId)
208+
args.putString("providerId", providerId)
209+
args.putString("sessionId", sessionId)
210+
args.putString("signature", signature)
211+
args.putString("timestamp", timestamp)
212+
val replyId = UUID.randomUUID().toString()
213+
args.putString("replyId", replyId)
214+
replyWithProviderInformationHandlers[replyId] = callback
215+
emitOnProviderInformationRequest(args)
216+
}
217+
})
218+
else
219+
(throw IllegalStateException("Invalid provider information. canFetchProviderInformationFromHost was not true and jsonString, url were also not provided."))
184220
),
185221
featureOptions = if (featureOptions == null) null else ReclaimOverrides.FeatureOptions(
186222
cookiePersist = getBoolean(featureOptions, "cookiePersist"),
@@ -257,31 +293,73 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
257293
appImageUrl = requireString(appInfo, "appImageUrl"),
258294
isRecurring = getBoolean(appInfo, "isRecurring") ?: false,
259295
),
296+
capabilityAccessToken = capabilityAccessToken
260297
) { result ->
261298
result.onSuccess {
262-
promise?.resolve(true)
263-
}.onFailure { error ->
264-
promise?.reject(error)
299+
try {
300+
Log.d(NAME, "(setOverrides) Success")
301+
promise?.resolve(null)
302+
} catch (e: Throwable) {
303+
Log.e(NAME, "(setOverrides) Error resolving promise")
304+
}
305+
306+
}.onFailure { error ->
307+
try {
308+
Log.d(NAME, "(setOverrides) Failure")
309+
onPlatformException(promise, error)
310+
} catch (e: Throwable) {
311+
Log.e(NAME, "(setOverrides) Error rejecting promise", e)
265312
}
313+
}
266314
}
267315
}
268316
}
269317

318+
private val replyHandlers: MutableMap<String, (Result<Boolean>) -> Unit> = mutableMapOf()
270319
override fun reply(replyId: String?, reply: Boolean) {
271320
if (replyId == null) {
272-
Log.w(NAME, "Missing arg replyId")
321+
Log.w(NAME, "(reply) Missing arg replyId")
273322
return
274323
}
275324
reactContext.runOnUiQueueThread {
276325
val callback = replyHandlers[replyId]
277326
if (callback != null) {
278327
callback(Result.success(reply))
279328
} else {
280-
Log.w(NAME, "Missing reply handler for id: $replyId")
329+
Log.w(NAME, "(reply) Missing reply handler for id: $replyId")
281330
}
282331
}
283332
}
284333

334+
private val replyWithProviderInformationHandlers: MutableMap<String, (Result<String>) -> Unit> =
335+
mutableMapOf()
336+
337+
override fun replyWithProviderInformation(replyId: String?, providerInformation: String?) {
338+
if (replyId == null) {
339+
Log.w(NAME, "(replyWithProviderInformation) Missing arg replyId")
340+
return
341+
}
342+
reactContext.runOnUiQueueThread {
343+
val callback = replyWithProviderInformationHandlers[replyId]
344+
if (callback != null) {
345+
callback(Result.success(providerInformation ?: ""))
346+
} else {
347+
Log.w(NAME, "(replyWithProviderInformation) Missing reply handler for id: $replyId")
348+
}
349+
}
350+
}
351+
352+
private fun onPlatformException(promise: Promise?, exception: Throwable) {
353+
if (exception is ReclaimVerification.ReclaimPlatformException) {
354+
val userInfoMap = Arguments.createMap()
355+
userInfoMap.putString("message", exception.internalErrorMessage)
356+
userInfoMap.putString("errorCode", exception.errorCode)
357+
promise?.reject("PLATFORM_ERROR", exception.message, exception, userInfoMap)
358+
} else {
359+
promise?.reject("PLATFORM_ERROR", "Unexpected Error", exception)
360+
}
361+
}
362+
285363
@Suppress("SameParameterValue")
286364
private fun hasValue(map: ReadableMap, key: String): Boolean {
287365
return map.hasKey(key) && !map.isNull(key)
@@ -315,7 +393,8 @@ class InappRnSdkModule(private val reactContext: ReactApplicationContext) :
315393
throw TypeCastException("Value for key $key is not a Number")
316394
}
317395

318-
private fun getString(map: ReadableMap, key: String): String? {
396+
private fun getString(map: ReadableMap?, key: String): String? {
397+
if (map == null) return null
319398
return if (!map.hasKey(key) || map.isNull(key)) {
320399
null
321400
} else {

documentation/migration.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Migration
2+
3+
## 0.2.1
4+
5+
- Some overrides now require a valid `capabilityAccessToken`. Provide this when calling the `setOverrides` method.
6+
7+
### Android
8+
9+
#### Update repository URL
10+
11+
- Update the version in `RECLAIM_STORAGE_BASE_URL` to `0.2.1`
12+
- With this change, repositories in your build.gradle or settings.gradle may look like this:
13+
14+
```groovy
15+
dependencyResolutionManagement {
16+
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
17+
String flutterStorageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
18+
- String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.1.2/repo"
19+
+ String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.2.1/repo"
20+
repositories {
21+
google()
22+
mavenCentral()
23+
maven {
24+
url "$reclaimStorageUrl"
25+
}
26+
maven {
27+
url "$flutterStorageUrl/download.flutter.io"
28+
}
29+
}
30+
}
31+
```
32+
33+
- Build your android project again
34+
- Refer: https://github.com/reclaimprotocol/reclaim-inapp-reactnative-sdk/blob/main/README.md#android-setup
35+
36+
### iOS
37+
38+
- Make sure if you are using the latest versions of `ReclaimInAppSdk` cocoapod if you have overriden this dependency in your `Podfile`. Latest version on [cocoapods.org is 0.2.1](https://cocoapods.org/pods/ReclaimInAppSdk).
39+
- Run a `pod install --repo-update`. If this fails for reasons related to the `ReclaimInAppSdk`, try running `pod update ReclaimInAppSdk`.
40+
- Refer: https://github.com/reclaimprotocol/reclaim-inapp-reactnative-sdk/blob/main/README.md#android-setup

example/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ includeBuild('../node_modules/@react-native/gradle-plugin')
77
dependencyResolutionManagement {
88
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
99
String flutterStorageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
10-
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.1.2/repo"
10+
String reclaimStorageUrl = System.env.RECLAIM_STORAGE_BASE_URL ?: "https://reclaim-inapp-sdk.s3.ap-south-1.amazonaws.com/android/0.2.1/repo"
1111
repositories {
1212
google()
1313
mavenCentral()

0 commit comments

Comments
 (0)