@prelude.so/react-native-sdk 0.2.0 → 0.3.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 +34 -67
- package/android/src/main/java/so/prelude/reactnative/sdk/PreludeReactNativeSdkModule.kt +18 -29
- package/build/index.d.ts +3 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -4
- package/build/index.js.map +1 -1
- package/ios/PreludeReactNativeSdkModule.swift +5 -10
- package/package.json +3 -3
- package/src/index.ts +8 -12
- package/build/PreludeReactNativeSdk.types.d.ts +0 -10
- package/build/PreludeReactNativeSdk.types.d.ts.map +0 -1
- package/build/PreludeReactNativeSdk.types.js +0 -2
- package/build/PreludeReactNativeSdk.types.js.map +0 -1
- package/src/PreludeReactNativeSdk.types.ts +0 -10
package/README.md
CHANGED
|
@@ -1,59 +1,51 @@
|
|
|
1
1
|
# Readme
|
|
2
2
|
## Using the Expo React Native SDK
|
|
3
3
|
|
|
4
|
-
The Expo React Native SDK allows you to
|
|
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.
|
|
4
|
+
The Expo React Native SDK allows you to capture certain device signals (both in Android and iOS) that will be reported back to Prelude and perform silent verification of mobile devices.
|
|
8
5
|
|
|
9
6
|
It is provided as an Expo module that you can integrate into your React Native Expo Application.
|
|
10
7
|
|
|
11
|
-
The Android `minSdkVersion` value in the SDK is set to 26 (Android 8.0). If
|
|
12
|
-
|
|
13
|
-
#### Configuring the project
|
|
8
|
+
The Android `minSdkVersion` value in the SDK is set to 26 (Android 8.0). If your application has a lower value you may need to update it.
|
|
14
9
|
|
|
15
|
-
|
|
10
|
+
You can install the SDK dependency directly from npm:
|
|
16
11
|
|
|
17
12
|
```
|
|
18
13
|
npm install @prelude.so/react-native-sdk
|
|
19
14
|
```
|
|
20
15
|
|
|
21
|
-
|
|
16
|
+
You will need to have the Prelude SDK key that you generate in the Prelude dashboard for your account.
|
|
17
|
+
|
|
18
|
+
***Important: When you generate the SDK key in the Prelude dashboard you will be able to copy it and you should store it somewhere secure, as the dashboard will not allow you to display the same key again.***
|
|
19
|
+
|
|
20
|
+
### Gathering Device Signals
|
|
21
|
+
|
|
22
|
+
**Note**: Starting with v0.3.0 of the SDK, we have removed the status event and made the `dispatchSignals` function return a promise that resolves to the dispatch identifier, simplifying its usage.
|
|
23
|
+
|
|
24
|
+
To collect the device signals in your application you can use code like this:
|
|
22
25
|
|
|
23
26
|
```
|
|
24
27
|
...
|
|
25
|
-
// Import the react state types
|
|
26
|
-
import { useEffect, useState } from "react";
|
|
27
28
|
// Import the SDK types
|
|
28
29
|
import * as PreludeReactNativeSdk from '@prelude.so/react-native-sdk';
|
|
29
30
|
...
|
|
30
31
|
|
|
31
|
-
// Define a state to receive status updates
|
|
32
|
-
const [dispatchStatus, setDispatchStatus] = useState({ dispatchID: "", status: "" });
|
|
33
|
-
|
|
34
|
-
...
|
|
35
|
-
// Subscribe to the event
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
const subscription = PreludeReactNativeSdk.onDispatchingSignals((dispatchingSignalsStatus) => {
|
|
38
|
-
console.log("Dispatch status: " + dispatchingSignalsStatus.status + ". Id: " + dispatchingSignalsStatus.dispatchID);
|
|
39
|
-
setDispatchStatus(dispatchingSignalsStatus);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return () => {
|
|
43
|
-
subscription.remove();
|
|
44
|
-
}
|
|
45
|
-
}, [dispatchStatus]);
|
|
46
|
-
|
|
47
32
|
...
|
|
48
33
|
// Submit the signals in any of your app event handlers (here is a button example)
|
|
49
|
-
<Button title={`Dispatch Signals`} onPress={() =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
34
|
+
<Button title={`Dispatch Signals`} onPress={ async () =>
|
|
35
|
+
{
|
|
36
|
+
try {
|
|
37
|
+
const dispatchId = await PreludeReactNativeSdk.dispatchSignals({
|
|
38
|
+
sdk_key: "YOUR_SDK_KEY", // Replace with your Prelude SDK key
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Handle the dispatch ID as needed,
|
|
42
|
+
// e.g., store it or continue with verification here
|
|
43
|
+
alert(`Dispatch ID: ${dispatchId}`);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
alert(`Signals dispatch error: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
57
49
|
|
|
58
50
|
```
|
|
59
51
|
|
|
@@ -69,41 +61,16 @@ or
|
|
|
69
61
|
npx expo run:android
|
|
70
62
|
```
|
|
71
63
|
|
|
72
|
-
Once you get the dispatch
|
|
64
|
+
Once you get the dispatch identifier through the event, you can report it back to your own API to be forwarded in subsequent network calls.
|
|
73
65
|
|
|
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.
|
|
66
|
+
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.
|
|
75
67
|
|
|
76
|
-
|
|
68
|
+
The recommended way of integrating it is to call the `dispatchSignals` function before displaying the phone number verification screen in your application. This way you can ensure that the device signals are captured and the `dispatchID` can be sent to your back-end with the phone number. Your back-end will then perform the verification call to Prelude with the phone number and the dispatch identifier.
|
|
77
69
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
The SDK provides a simple API to initiate the verification process and handle the response.
|
|
70
|
+
### Silent Verification
|
|
81
71
|
|
|
82
|
-
|
|
72
|
+
The Silent Verification feature allows you to verify a phone number without requiring the user to manually enter a verification code.
|
|
83
73
|
|
|
84
|
-
|
|
74
|
+
It is available for certain carriers and requires a server-side service to handle the verification process. For this verification method to work properly, you *must* collect the device signals mentioned before and report the dispatch identifier to your back-end (usually in your APIs verification endpoint).
|
|
85
75
|
|
|
86
|
-
|
|
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
|
-
```
|
|
76
|
+
Please refer to the [Silent Verification documentation](https://docs.prelude.so/verify/silent/overview) for more information on how to implement this feature.
|
|
@@ -5,7 +5,6 @@ import expo.modules.kotlin.modules.Module
|
|
|
5
5
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
6
6
|
import so.prelude.android.sdk.Configuration
|
|
7
7
|
import so.prelude.android.sdk.Configuration.Companion.DEFAULT_REQUEST_TIMEOUT
|
|
8
|
-
import so.prelude.android.sdk.DispatchStatusListener
|
|
9
8
|
import so.prelude.android.sdk.Endpoint
|
|
10
9
|
import so.prelude.android.sdk.Prelude
|
|
11
10
|
import java.net.URL
|
|
@@ -14,9 +13,7 @@ class PreludeReactNativeSdkModule : Module() {
|
|
|
14
13
|
override fun definition() = ModuleDefinition {
|
|
15
14
|
Name("PreludeReactNativeSdk")
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
AsyncFunction("dispatchSignals") { sdkKey: String, endpointUrl: String?, timeoutMilliseconds: Long? ->
|
|
16
|
+
AsyncFunction("dispatchSignals") Coroutine { sdkKey: String, endpointUrl: String?, timeoutMilliseconds: Long? ->
|
|
20
17
|
dispatchSignals(endpointUrl, sdkKey, timeoutMilliseconds)
|
|
21
18
|
}
|
|
22
19
|
|
|
@@ -28,47 +25,39 @@ class PreludeReactNativeSdkModule : Module() {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
private fun dispatchSignals(
|
|
28
|
+
private suspend fun dispatchSignals(
|
|
32
29
|
endpointUrl: String?,
|
|
33
30
|
sdkKey: String,
|
|
34
31
|
timeoutMilliseconds: Long?
|
|
35
|
-
): String
|
|
32
|
+
): String {
|
|
36
33
|
val endpoint: Endpoint = endpointUrl?.let {
|
|
37
34
|
Endpoint.Custom(it)
|
|
38
35
|
} ?: Endpoint.Default
|
|
39
36
|
|
|
40
37
|
val context = appContext.reactContext
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Configuration(
|
|
44
|
-
it.applicationContext,
|
|
45
|
-
sdkKey,
|
|
46
|
-
endpoint,
|
|
47
|
-
requestTimeout = timeoutMilliseconds ?: DEFAULT_REQUEST_TIMEOUT
|
|
48
|
-
)
|
|
38
|
+
?: throw IllegalStateException(
|
|
39
|
+
"Invalid React Android Context. Cannot dispatch signals"
|
|
49
40
|
)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
|
|
42
|
+
val config = Configuration(
|
|
43
|
+
context.applicationContext,
|
|
44
|
+
sdkKey,
|
|
45
|
+
endpoint,
|
|
46
|
+
requestTimeout = timeoutMilliseconds ?: DEFAULT_REQUEST_TIMEOUT
|
|
47
|
+
)
|
|
48
|
+
val prelude = Prelude(config)
|
|
49
|
+
|
|
50
|
+
return prelude.dispatchSignals().getOrThrow()
|
|
59
51
|
}
|
|
60
52
|
|
|
61
53
|
private suspend fun verifySilent(
|
|
62
54
|
sdkKey: String,
|
|
63
55
|
requestUrl: String,
|
|
64
|
-
): String
|
|
56
|
+
): String {
|
|
65
57
|
val context = appContext.reactContext
|
|
66
|
-
|
|
67
|
-
if (context == null) {
|
|
68
|
-
throw IllegalStateException(
|
|
58
|
+
?: throw IllegalStateException(
|
|
69
59
|
"Invalid React Android Context. Cannot perform silent verification"
|
|
70
60
|
)
|
|
71
|
-
}
|
|
72
61
|
|
|
73
62
|
if (sdkKey.isBlank() || requestUrl.isBlank()) {
|
|
74
63
|
throw IllegalArgumentException("SDK Key and Request URL must both be provided.")
|
|
@@ -76,6 +65,6 @@ class PreludeReactNativeSdkModule : Module() {
|
|
|
76
65
|
|
|
77
66
|
val prelude = Prelude(context.applicationContext, sdkKey)
|
|
78
67
|
|
|
79
|
-
return prelude.verifySilent(URL(requestUrl)).
|
|
68
|
+
return prelude.verifySilent(URL(requestUrl)).getOrThrow()
|
|
80
69
|
}
|
|
81
70
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { EventSubscription } from 'expo-modules-core';
|
|
2
|
-
import { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';
|
|
3
1
|
export declare function dispatchSignals(configuration: {
|
|
4
2
|
sdk_key: string;
|
|
5
3
|
endpoint?: string;
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
timeout_milliseconds?: number;
|
|
5
|
+
}): Promise<string>;
|
|
8
6
|
export declare function verifySilent(configuration: {
|
|
9
7
|
sdk_key: string;
|
|
10
8
|
request_url: string;
|
|
11
|
-
}): Promise<
|
|
12
|
-
export { DispatchingSignalsStatus };
|
|
9
|
+
}): Promise<string>;
|
|
13
10
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,CACnC,aAAa,EAAE;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,CAEpB;AAED,wBAAsB,YAAY,CAAC,aAAa,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAE3G"}
|
package/build/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';
|
|
2
2
|
export async function dispatchSignals(configuration) {
|
|
3
|
-
return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);
|
|
4
|
-
}
|
|
5
|
-
export function onDispatchingSignals(listener) {
|
|
6
|
-
return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
|
|
3
|
+
return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint, configuration.timeout_milliseconds);
|
|
7
4
|
}
|
|
8
5
|
export async function verifySilent(configuration) {
|
|
9
6
|
return await PreludeReactNativeSdkModule.verifySilent(configuration.sdk_key, configuration.request_url);
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,MAAM,+BAA+B,CAAC;AAExE,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,aAIC;IACD,OAAO,MAAM,2BAA2B,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,QAAQ,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;AAC9I,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 PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';\n\nexport async function dispatchSignals(\n configuration: {\n sdk_key: string;\n endpoint?: string;\n timeout_milliseconds?: number;\n }): Promise<string> {\n return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint, configuration.timeout_milliseconds);\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"]}
|
|
@@ -4,24 +4,19 @@ public class PreludeReactNativeSdkModule: Module {
|
|
|
4
4
|
public func definition() -> ModuleDefinition {
|
|
5
5
|
Name("PreludeReactNativeSdk")
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
AsyncFunction("dispatchSignals") { (sdkKey: String, endpointUrl: String?) in
|
|
7
|
+
AsyncFunction("dispatchSignals") { (sdkKey: String, endpointUrl: String?, timeoutMilliseconds: Int64?) in
|
|
10
8
|
let endpoint = endpointUrl != nil ? Endpoint.custom(endpointUrl!) : .default
|
|
9
|
+
let timeout = timeoutMilliseconds != nil ? TimeInterval(timeoutMilliseconds!) / 1000 : 2.0
|
|
11
10
|
|
|
12
11
|
let configuration = Configuration(
|
|
13
12
|
sdkKey: sdkKey,
|
|
14
|
-
endpoint: endpoint
|
|
13
|
+
endpoint: endpoint,
|
|
14
|
+
timeout: timeout
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
let prelude = Prelude(configuration)
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
let dispatchID = try await prelude.dispatchSignals()
|
|
21
|
-
self.sendEvent("onDispatchingSignals", ["status": "SUCCESS", "dispatchID": dispatchID])
|
|
22
|
-
} catch {
|
|
23
|
-
self.sendEvent("onDispatchingSignals", ["status": "FAILURE", "dispatchID": error.localizedDescription])
|
|
24
|
-
}
|
|
19
|
+
return try await prelude.dispatchSignals()
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
AsyncFunction("verifySilent") { (sdkKey: String, requestUrl: String) in
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prelude.so/react-native-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Prelude SDK for React Native",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"homepage": "https://github.com/prelude-so/react-native-sdk#readme",
|
|
42
42
|
"dependencies": {},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/react": "
|
|
44
|
+
"@types/react": "^18.3.0",
|
|
45
45
|
"expo": "~52.0.46",
|
|
46
46
|
"expo-module-scripts": "^4.0.2",
|
|
47
|
-
"react": "18.3.
|
|
47
|
+
"react": "^18.3.0",
|
|
48
48
|
"react-native": "0.76.9"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { EventSubscription } from 'expo-modules-core';
|
|
2
|
-
|
|
3
1
|
import PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';
|
|
4
|
-
import { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';
|
|
5
|
-
|
|
6
|
-
export async function dispatchSignals(configuration: { sdk_key: string, endpoint?: string }): Promise<void> {
|
|
7
|
-
return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);
|
|
8
|
-
}
|
|
9
2
|
|
|
10
|
-
export function
|
|
11
|
-
|
|
3
|
+
export async function dispatchSignals(
|
|
4
|
+
configuration: {
|
|
5
|
+
sdk_key: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
timeout_milliseconds?: number;
|
|
8
|
+
}): Promise<string> {
|
|
9
|
+
return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint, configuration.timeout_milliseconds);
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
export async function verifySilent(configuration: { sdk_key: string, request_url: string }): Promise<
|
|
12
|
+
export async function verifySilent(configuration: { sdk_key: string, request_url: string }): Promise<string> {
|
|
15
13
|
return await PreludeReactNativeSdkModule.verifySilent(configuration.sdk_key, configuration.request_url);
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
export { DispatchingSignalsStatus };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PreludeReactNativeSdk.types.d.ts","sourceRoot":"","sources":["../src/PreludeReactNativeSdk.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PreludeReactNativeSdk.types.js","sourceRoot":"","sources":["../src/PreludeReactNativeSdk.types.ts"],"names":[],"mappings":"","sourcesContent":["export type DispatchingSignalsStatus = {\n status: string,\n dispatchID: string;\n};\n\nexport type Configuration = {\n sdk_key: string;\n endpoint?: string;\n timeout_milliseconds?: number;\n}"]}
|