@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 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 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.
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 you application has a lower value you may need to update it.
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
- First install the SDK dependency in your app:
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
- Then, where ever in your application you want to report the device signals you can use code like this:
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
- PreludeReactNativeSdk.dispatchSignals({
51
- sdk_key: "YOUR-SDK-KEY"
52
- })
53
- .catch((error) => {
54
- console.log("Dispatch error: " + error);
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 ID through the event, you can report it back to your own API to be forwarded in subsequent network calls.
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. It is advisable to make the request early on during the user onboarding process to have the dispatch id available when required.
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
- ### Silent Verification
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
- 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.
70
+ ### Silent Verification
81
71
 
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.
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
- 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.
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
- ```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
- ```
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
- Events("onDispatchingSignals")
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
- return context?.let {
42
- Prelude(
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
- .dispatchSignals { status: DispatchStatusListener.Status, dispatchId ->
51
- sendEvent(
52
- "onDispatchingSignals", mapOf(
53
- "status" to status,
54
- "dispatchID" to dispatchId
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)).getOrNull()
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
- }): Promise<void>;
7
- export declare function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription;
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<String>;
12
- export { DispatchingSignalsStatus };
9
+ }): Promise<string>;
13
10
  //# sourceMappingURL=index.d.ts.map
@@ -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,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"}
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);
@@ -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;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"]}
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
- Events("onDispatchingSignals")
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
- do {
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.2.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": "~18.3.12",
44
+ "@types/react": "^18.3.0",
45
45
  "expo": "~52.0.46",
46
46
  "expo-module-scripts": "^4.0.2",
47
- "react": "18.3.12",
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 onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription {
11
- return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
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<String> {
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,10 +0,0 @@
1
- export type DispatchingSignalsStatus = {
2
- status: string;
3
- dispatchID: string;
4
- };
5
- export type Configuration = {
6
- sdk_key: string;
7
- endpoint?: string;
8
- timeout_milliseconds?: number;
9
- };
10
- //# sourceMappingURL=PreludeReactNativeSdk.types.d.ts.map
@@ -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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=PreludeReactNativeSdk.types.js.map
@@ -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}"]}
@@ -1,10 +0,0 @@
1
- export type DispatchingSignalsStatus = {
2
- status: string,
3
- dispatchID: string;
4
- };
5
-
6
- export type Configuration = {
7
- sdk_key: string;
8
- endpoint?: string;
9
- timeout_milliseconds?: number;
10
- }