@prelude.so/react-native-sdk 0.1.1 → 0.2.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.
- package/README.md +42 -4
- package/android/build.gradle +3 -3
- package/android/src/main/java/so/prelude/reactnative/sdk/PreludeReactNativeSdkModule.kt +58 -21
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/ios/PreludeReactNativeSdkModule.swift +25 -1
- package/package.json +9 -6
- package/src/index.ts +4 -0
package/README.md
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
# Readme
|
|
2
|
-
|
|
2
|
+
## Using the Expo React Native SDK
|
|
3
3
|
|
|
4
|
-
The Expo React Native SDK allows you to
|
|
4
|
+
The Expo React Native SDK allows you to gather device signals and perform silent verification of mobile devices.
|
|
5
|
+
|
|
6
|
+
### Gathering Device Signals
|
|
7
|
+
The SDK allows you to capture certain device signals (both in Android and iOS) that will be reported back to Prelude.
|
|
5
8
|
|
|
6
9
|
It is provided as an Expo module that you can integrate into your React Native Expo Application.
|
|
7
10
|
|
|
8
11
|
The Android `minSdkVersion` value in the SDK is set to 26 (Android 8.0). If you application has a lower value you may need to update it.
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
#### Configuring the project
|
|
11
14
|
|
|
12
15
|
First install the SDK dependency in your app:
|
|
13
16
|
|
|
@@ -68,4 +71,39 @@ npx expo run:android
|
|
|
68
71
|
|
|
69
72
|
Once you get the dispatch ID through the event, you can report it back to your own API to be forwarded in subsequent network calls.
|
|
70
73
|
|
|
71
|
-
There is no restriction on when to call this API, you just need to take this action before you need to report back the dispatch ID. It is advisable to make the request early on during the user onboarding process to have the dispatch id available when required.
|
|
74
|
+
There is no restriction on when to call this API, you just need to take this action before you need to report back the dispatch ID. It is advisable to make the request early on during the user onboarding process to have the dispatch id available when required.
|
|
75
|
+
|
|
76
|
+
### Silent Verification
|
|
77
|
+
|
|
78
|
+
The Silent Verification feature allows you to verify a phone number without requiring the user to enter a verification code. It is available for certain carriers and requires a server-side service to handle the verification process.
|
|
79
|
+
|
|
80
|
+
The SDK provides a simple API to initiate the verification process and handle the response.
|
|
81
|
+
|
|
82
|
+
We assume here that you have a server-side service that exposes the 2 endpoints, one to start the verification and another to check the final code. In this sample code we expose those endpoints via an `Api` module that will call each endpoint via a separate function.
|
|
83
|
+
|
|
84
|
+
When calling the verification API, you will need to provide the phone number to verify. The API will return a request URL that the SDK will navigate to in order to complete the verification process.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// Import the SDK types and your API module
|
|
88
|
+
import * as PreludeReactNativeSdk from '@prelude.so/react-native-sdk';
|
|
89
|
+
import * as Api from './YourBackendApi';
|
|
90
|
+
|
|
91
|
+
// Call the verification endpoint with the phone number.
|
|
92
|
+
// If the phone number is compatible with the Silent Verification feature,
|
|
93
|
+
// the API will return a request URL that the SDK will navigate to.
|
|
94
|
+
const request_url = await Api.verify(phone_number);
|
|
95
|
+
|
|
96
|
+
// Then call the verifySilent method with the SDK key and the request URL.
|
|
97
|
+
// If the verification is successful, the SDK will return a code that you
|
|
98
|
+
// can use to check the verification status.
|
|
99
|
+
var code = await PreludeReactNativeSdk.verifySilent({
|
|
100
|
+
sdk_key: sdk_key,
|
|
101
|
+
request_url: request_url,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Finally, call the checkSilent method with the phone number and the code
|
|
105
|
+
// Your API should handle the check and return the verification status.
|
|
106
|
+
const check_status = await Api.check(phone_number, code);
|
|
107
|
+
|
|
108
|
+
// Handle the verification status as needed in your application
|
|
109
|
+
```
|
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
|
|
3
3
|
group = 'so.prelude.reactnative.sdk'
|
|
4
|
-
version = '0.
|
|
4
|
+
version = '0.2.0'
|
|
5
5
|
|
|
6
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
7
|
apply from: expoModulesCorePlugin
|
|
@@ -35,7 +35,7 @@ android {
|
|
|
35
35
|
namespace "so.prelude.reactnative.sdk"
|
|
36
36
|
defaultConfig {
|
|
37
37
|
versionCode 1
|
|
38
|
-
versionName "0.
|
|
38
|
+
versionName "0.2.0"
|
|
39
39
|
}
|
|
40
40
|
lintOptions {
|
|
41
41
|
abortOnError false
|
|
@@ -43,5 +43,5 @@ android {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
dependencies {
|
|
46
|
-
implementation('so.prelude.android:sdk:0.
|
|
46
|
+
implementation('so.prelude.android:sdk:0.2.0')
|
|
47
47
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package so.prelude.reactnative.sdk
|
|
2
2
|
|
|
3
|
+
import expo.modules.kotlin.functions.Coroutine
|
|
3
4
|
import expo.modules.kotlin.modules.Module
|
|
4
5
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
6
|
import so.prelude.android.sdk.Configuration
|
|
@@ -7,6 +8,7 @@ import so.prelude.android.sdk.Configuration.Companion.DEFAULT_REQUEST_TIMEOUT
|
|
|
7
8
|
import so.prelude.android.sdk.DispatchStatusListener
|
|
8
9
|
import so.prelude.android.sdk.Endpoint
|
|
9
10
|
import so.prelude.android.sdk.Prelude
|
|
11
|
+
import java.net.URL
|
|
10
12
|
|
|
11
13
|
class PreludeReactNativeSdkModule : Module() {
|
|
12
14
|
override fun definition() = ModuleDefinition {
|
|
@@ -15,30 +17,65 @@ class PreludeReactNativeSdkModule : Module() {
|
|
|
15
17
|
Events("onDispatchingSignals")
|
|
16
18
|
|
|
17
19
|
AsyncFunction("dispatchSignals") { sdkKey: String, endpointUrl: String?, timeoutMilliseconds: Long? ->
|
|
20
|
+
dispatchSignals(endpointUrl, sdkKey, timeoutMilliseconds)
|
|
21
|
+
}
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
AsyncFunction("verifySilent") Coroutine { sdkKey: String, requestUrl: String ->
|
|
24
|
+
verifySilent(
|
|
25
|
+
sdkKey = sdkKey,
|
|
26
|
+
requestUrl = requestUrl
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private fun dispatchSignals(
|
|
32
|
+
endpointUrl: String?,
|
|
33
|
+
sdkKey: String,
|
|
34
|
+
timeoutMilliseconds: Long?
|
|
35
|
+
): String? {
|
|
36
|
+
val endpoint: Endpoint = endpointUrl?.let {
|
|
37
|
+
Endpoint.Custom(it)
|
|
38
|
+
} ?: Endpoint.Default
|
|
39
|
+
|
|
40
|
+
val context = appContext.reactContext
|
|
41
|
+
return context?.let {
|
|
42
|
+
Prelude(
|
|
43
|
+
Configuration(
|
|
44
|
+
it.applicationContext,
|
|
45
|
+
sdkKey,
|
|
46
|
+
endpoint,
|
|
47
|
+
requestTimeout = timeoutMilliseconds ?: DEFAULT_REQUEST_TIMEOUT
|
|
32
48
|
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
)
|
|
50
|
+
.dispatchSignals { status: DispatchStatusListener.Status, dispatchId ->
|
|
51
|
+
sendEvent(
|
|
52
|
+
"onDispatchingSignals", mapOf(
|
|
53
|
+
"status" to status,
|
|
54
|
+
"dispatchID" to dispatchId
|
|
39
55
|
)
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
)
|
|
57
|
+
}
|
|
42
58
|
}
|
|
43
59
|
}
|
|
60
|
+
|
|
61
|
+
private suspend fun verifySilent(
|
|
62
|
+
sdkKey: String,
|
|
63
|
+
requestUrl: String,
|
|
64
|
+
): String? {
|
|
65
|
+
val context = appContext.reactContext
|
|
66
|
+
|
|
67
|
+
if (context == null) {
|
|
68
|
+
throw IllegalStateException(
|
|
69
|
+
"Invalid React Android Context. Cannot perform silent verification"
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (sdkKey.isBlank() || requestUrl.isBlank()) {
|
|
74
|
+
throw IllegalArgumentException("SDK Key and Request URL must both be provided.")
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
val prelude = Prelude(context.applicationContext, sdkKey)
|
|
78
|
+
|
|
79
|
+
return prelude.verifySilent(URL(requestUrl)).getOrNull()
|
|
80
|
+
}
|
|
44
81
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -5,5 +5,9 @@ export declare function dispatchSignals(configuration: {
|
|
|
5
5
|
endpoint?: string;
|
|
6
6
|
}): Promise<void>;
|
|
7
7
|
export declare function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription;
|
|
8
|
+
export declare function verifySilent(configuration: {
|
|
9
|
+
sdk_key: string;
|
|
10
|
+
request_url: string;
|
|
11
|
+
}): Promise<String>;
|
|
8
12
|
export { DispatchingSignalsStatus };
|
|
9
13
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,wBAAsB,eAAe,CAAC,aAAa,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1G;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,GAAG,iBAAiB,CAE3G;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,wBAAsB,eAAe,CAAC,aAAa,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1G;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,GAAG,iBAAiB,CAE3G;AAED,wBAAsB,YAAY,CAAC,aAAa,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAE3G;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -5,4 +5,7 @@ export async function dispatchSignals(configuration) {
|
|
|
5
5
|
export function onDispatchingSignals(listener) {
|
|
6
6
|
return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
|
|
7
7
|
}
|
|
8
|
+
export async function verifySilent(configuration) {
|
|
9
|
+
return await PreludeReactNativeSdkModule.verifySilent(configuration.sdk_key, configuration.request_url);
|
|
10
|
+
}
|
|
8
11
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,MAAM,+BAA+B,CAAC;AAGxE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,aAAqD;IACzF,OAAO,MAAM,2BAA2B,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC1G,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAmD;IACtF,OAAO,2BAA2B,CAAC,WAAW,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;AACnF,CAAC","sourcesContent":["import { EventSubscription } from 'expo-modules-core';\n\nimport PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';\nimport { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';\n\nexport async function dispatchSignals(configuration: { sdk_key: string, endpoint?: string }): Promise<void> {\n return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);\n}\n\nexport function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription {\n return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);\n}\n\nexport { DispatchingSignalsStatus };\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,MAAM,+BAA+B,CAAC;AAGxE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,aAAqD;IACzF,OAAO,MAAM,2BAA2B,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC1G,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAmD;IACtF,OAAO,2BAA2B,CAAC,WAAW,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;AACnF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,aAAuD;IACxF,OAAO,MAAM,2BAA2B,CAAC,YAAY,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;AAC1G,CAAC","sourcesContent":["import { EventSubscription } from 'expo-modules-core';\n\nimport PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';\nimport { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';\n\nexport async function dispatchSignals(configuration: { sdk_key: string, endpoint?: string }): Promise<void> {\n return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);\n}\n\nexport function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription {\n return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);\n}\n\nexport async function verifySilent(configuration: { sdk_key: string, request_url: string }): Promise<String> {\n return await PreludeReactNativeSdkModule.verifySilent(configuration.sdk_key, configuration.request_url);\n}\n\nexport { DispatchingSignalsStatus };\n"]}
|
|
@@ -6,7 +6,7 @@ public class PreludeReactNativeSdkModule: Module {
|
|
|
6
6
|
|
|
7
7
|
Events("onDispatchingSignals")
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
AsyncFunction("dispatchSignals") { (sdkKey: String, endpointUrl: String?) in
|
|
10
10
|
let endpoint = endpointUrl != nil ? Endpoint.custom(endpointUrl!) : .default
|
|
11
11
|
|
|
12
12
|
let configuration = Configuration(
|
|
@@ -23,5 +23,29 @@ public class PreludeReactNativeSdkModule: Module {
|
|
|
23
23
|
self.sendEvent("onDispatchingSignals", ["status": "FAILURE", "dispatchID": error.localizedDescription])
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
AsyncFunction("verifySilent") { (sdkKey: String, requestUrl: String) in
|
|
28
|
+
if sdkKey.isEmpty || requestUrl.isEmpty {
|
|
29
|
+
throw Exception(name: "IllegalArguments",
|
|
30
|
+
description: "SDK Key and Request URL must both be provided.",
|
|
31
|
+
code: "ILLEGAL_ARGUMENTS_EMPTY_FIELD"
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let configuration = Configuration(
|
|
36
|
+
sdkKey: sdkKey,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
let prelude = Prelude(configuration)
|
|
40
|
+
|
|
41
|
+
guard let url = URL(string: requestUrl) else {
|
|
42
|
+
throw Exception(name: "IllegalArguments",
|
|
43
|
+
description: "Request URL must be a valid URL.",
|
|
44
|
+
code: "ILLEGAL_ARGUMENTS_INVALID_URL"
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return try await prelude.verifySilent(url: url)
|
|
49
|
+
}
|
|
26
50
|
}
|
|
27
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prelude.so/react-native-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Prelude SDK for React Native",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"prepare": "expo-module prepare",
|
|
13
13
|
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
14
|
"expo-module": "expo-module",
|
|
15
|
-
"postinstall": "node scripts/postinstall.js"
|
|
15
|
+
"postinstall": "node scripts/postinstall.js",
|
|
16
|
+
"android": "expo run:android",
|
|
17
|
+
"ios": "expo run:ios"
|
|
16
18
|
},
|
|
17
19
|
"keywords": [
|
|
18
20
|
"react-native",
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
"android/build.gradle",
|
|
25
27
|
"android/src/*",
|
|
26
28
|
"build/*",
|
|
27
|
-
"ios
|
|
29
|
+
"ios/Prelude*",
|
|
28
30
|
"scripts/*",
|
|
29
31
|
"src/*",
|
|
30
32
|
"expo-module.config.json",
|
|
@@ -40,9 +42,10 @@
|
|
|
40
42
|
"dependencies": {},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@types/react": "~18.3.12",
|
|
45
|
+
"expo": "~52.0.46",
|
|
43
46
|
"expo-module-scripts": "^4.0.2",
|
|
44
|
-
"
|
|
45
|
-
"react-native": "0.76.
|
|
47
|
+
"react": "18.3.12",
|
|
48
|
+
"react-native": "0.76.9"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
48
51
|
"expo": "*",
|
|
@@ -50,6 +53,6 @@
|
|
|
50
53
|
"react-native": "*"
|
|
51
54
|
},
|
|
52
55
|
"so_prelude": {
|
|
53
|
-
"apple_sdk_tag": "0.
|
|
56
|
+
"apple_sdk_tag": "0.2.1"
|
|
54
57
|
}
|
|
55
58
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,4 +11,8 @@ export function onDispatchingSignals(listener: (event: DispatchingSignalsStatus)
|
|
|
11
11
|
return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export async function verifySilent(configuration: { sdk_key: string, request_url: string }): Promise<String> {
|
|
15
|
+
return await PreludeReactNativeSdkModule.verifySilent(configuration.sdk_key, configuration.request_url);
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
export { DispatchingSignalsStatus };
|