@prelude.so/react-native-sdk 0.1.1 → 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,56 +1,51 @@
1
1
  # Readme
2
- ### Using the Expo React Native SDK
2
+ ## Using the Expo React Native SDK
3
3
 
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.
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.
5
5
 
6
6
  It is provided as an Expo module that you can integrate into your React Native Expo Application.
7
7
 
8
- 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.
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.
9
9
 
10
- ## Configuring the project
11
-
12
- First install the SDK dependency in your app:
10
+ You can install the SDK dependency directly from npm:
13
11
 
14
12
  ```
15
13
  npm install @prelude.so/react-native-sdk
16
14
  ```
17
15
 
18
- 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:
19
25
 
20
26
  ```
21
27
  ...
22
- // Import the react state types
23
- import { useEffect, useState } from "react";
24
28
  // Import the SDK types
25
29
  import * as PreludeReactNativeSdk from '@prelude.so/react-native-sdk';
26
30
  ...
27
31
 
28
- // Define a state to receive status updates
29
- const [dispatchStatus, setDispatchStatus] = useState({ dispatchID: "", status: "" });
30
-
31
- ...
32
- // Subscribe to the event
33
- useEffect(() => {
34
- const subscription = PreludeReactNativeSdk.onDispatchingSignals((dispatchingSignalsStatus) => {
35
- console.log("Dispatch status: " + dispatchingSignalsStatus.status + ". Id: " + dispatchingSignalsStatus.dispatchID);
36
- setDispatchStatus(dispatchingSignalsStatus);
37
- });
38
-
39
- return () => {
40
- subscription.remove();
41
- }
42
- }, [dispatchStatus]);
43
-
44
32
  ...
45
33
  // Submit the signals in any of your app event handlers (here is a button example)
46
- <Button title={`Dispatch Signals`} onPress={() =>
47
- PreludeReactNativeSdk.dispatchSignals({
48
- sdk_key: "YOUR-SDK-KEY"
49
- })
50
- .catch((error) => {
51
- console.log("Dispatch error: " + error);
52
- })
53
- } />
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
+ />
54
49
 
55
50
  ```
56
51
 
@@ -66,6 +61,16 @@ or
66
61
  npx expo run:android
67
62
  ```
68
63
 
69
- 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.
65
+
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.
67
+
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.
69
+
70
+ ### Silent Verification
71
+
72
+ The Silent Verification feature allows you to verify a phone number without requiring the user to manually enter a verification code.
73
+
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).
70
75
 
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.
76
+ Please refer to the [Silent Verification documentation](https://docs.prelude.so/verify/silent/overview) for more information on how to implement this feature.
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'so.prelude.reactnative.sdk'
4
- version = '0.1.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.1.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.1.0')
46
+ implementation('so.prelude.android:sdk:0.2.0')
47
47
  }
@@ -1,44 +1,70 @@
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
6
7
  import so.prelude.android.sdk.Configuration.Companion.DEFAULT_REQUEST_TIMEOUT
7
- import so.prelude.android.sdk.DispatchStatusListener
8
8
  import so.prelude.android.sdk.Endpoint
9
9
  import so.prelude.android.sdk.Prelude
10
+ import java.net.URL
10
11
 
11
12
  class PreludeReactNativeSdkModule : Module() {
12
13
  override fun definition() = ModuleDefinition {
13
14
  Name("PreludeReactNativeSdk")
14
15
 
15
- Events("onDispatchingSignals")
16
-
17
- AsyncFunction("dispatchSignals") { sdkKey: String, endpointUrl: String?, timeoutMilliseconds: Long? ->
18
-
19
- val endpoint: Endpoint = endpointUrl?.let {
20
- Endpoint.Custom(it)
21
- } ?: Endpoint.Default
22
-
23
- val context = appContext.reactContext
24
- context?.let {
25
- Prelude(
26
- Configuration(
27
- it.applicationContext,
28
- sdkKey,
29
- endpoint,
30
- requestTimeout = timeoutMilliseconds ?: DEFAULT_REQUEST_TIMEOUT
31
- )
32
- )
33
- .dispatchSignals { status: DispatchStatusListener.Status, dispatchId ->
34
- sendEvent(
35
- "onDispatchingSignals", mapOf(
36
- "status" to status,
37
- "dispatchID" to dispatchId
38
- )
39
- )
40
- }
41
- }
16
+ AsyncFunction("dispatchSignals") Coroutine { sdkKey: String, endpointUrl: String?, timeoutMilliseconds: Long? ->
17
+ dispatchSignals(endpointUrl, sdkKey, timeoutMilliseconds)
42
18
  }
19
+
20
+ AsyncFunction("verifySilent") Coroutine { sdkKey: String, requestUrl: String ->
21
+ verifySilent(
22
+ sdkKey = sdkKey,
23
+ requestUrl = requestUrl
24
+ )
25
+ }
26
+ }
27
+
28
+ private suspend fun dispatchSignals(
29
+ endpointUrl: String?,
30
+ sdkKey: String,
31
+ timeoutMilliseconds: Long?
32
+ ): String {
33
+ val endpoint: Endpoint = endpointUrl?.let {
34
+ Endpoint.Custom(it)
35
+ } ?: Endpoint.Default
36
+
37
+ val context = appContext.reactContext
38
+ ?: throw IllegalStateException(
39
+ "Invalid React Android Context. Cannot dispatch signals"
40
+ )
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()
51
+ }
52
+
53
+ private suspend fun verifySilent(
54
+ sdkKey: String,
55
+ requestUrl: String,
56
+ ): String {
57
+ val context = appContext.reactContext
58
+ ?: throw IllegalStateException(
59
+ "Invalid React Android Context. Cannot perform silent verification"
60
+ )
61
+
62
+ if (sdkKey.isBlank() || requestUrl.isBlank()) {
63
+ throw IllegalArgumentException("SDK Key and Request URL must both be provided.")
64
+ }
65
+
66
+ val prelude = Prelude(context.applicationContext, sdkKey)
67
+
68
+ return prelude.verifySilent(URL(requestUrl)).getOrThrow()
43
69
  }
44
70
  }
package/build/index.d.ts CHANGED
@@ -1,9 +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;
8
- export { DispatchingSignalsStatus };
4
+ timeout_milliseconds?: number;
5
+ }): Promise<string>;
6
+ export declare function verifySilent(configuration: {
7
+ sdk_key: string;
8
+ request_url: string;
9
+ }): Promise<string>;
9
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,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,8 +1,8 @@
1
1
  import PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';
2
2
  export async function dispatchSignals(configuration) {
3
- return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);
3
+ return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint, configuration.timeout_milliseconds);
4
4
  }
5
- export function onDispatchingSignals(listener) {
6
- return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
5
+ export async function verifySilent(configuration) {
6
+ return await PreludeReactNativeSdkModule.verifySilent(configuration.sdk_key, configuration.request_url);
7
7
  }
8
8
  //# sourceMappingURL=index.js.map
@@ -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":"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,43 @@ 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])
19
+ return try await prelude.dispatchSignals()
20
+ }
21
+
22
+ AsyncFunction("verifySilent") { (sdkKey: String, requestUrl: String) in
23
+ if sdkKey.isEmpty || requestUrl.isEmpty {
24
+ throw Exception(name: "IllegalArguments",
25
+ description: "SDK Key and Request URL must both be provided.",
26
+ code: "ILLEGAL_ARGUMENTS_EMPTY_FIELD"
27
+ )
24
28
  }
29
+
30
+ let configuration = Configuration(
31
+ sdkKey: sdkKey,
32
+ )
33
+
34
+ let prelude = Prelude(configuration)
35
+
36
+ guard let url = URL(string: requestUrl) else {
37
+ throw Exception(name: "IllegalArguments",
38
+ description: "Request URL must be a valid URL.",
39
+ code: "ILLEGAL_ARGUMENTS_INVALID_URL"
40
+ )
41
+ }
42
+
43
+ return try await prelude.verifySilent(url: url)
25
44
  }
26
45
  }
27
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prelude.so/react-native-sdk",
3
- "version": "0.1.1",
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",
@@ -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",
@@ -39,10 +41,11 @@
39
41
  "homepage": "https://github.com/prelude-so/react-native-sdk#readme",
40
42
  "dependencies": {},
41
43
  "devDependencies": {
42
- "@types/react": "~18.3.12",
44
+ "@types/react": "^18.3.0",
45
+ "expo": "~52.0.46",
43
46
  "expo-module-scripts": "^4.0.2",
44
- "expo": "~52.0.9",
45
- "react-native": "0.76.2"
47
+ "react": "^18.3.0",
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.1.1"
56
+ "apple_sdk_tag": "0.2.1"
54
57
  }
55
58
  }
package/src/index.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { EventSubscription } from 'expo-modules-core';
2
-
3
1
  import PreludeReactNativeSdkModule from './PreludeReactNativeSdkModule';
4
- import { DispatchingSignalsStatus } from './PreludeReactNativeSdk.types';
5
2
 
6
- export async function dispatchSignals(configuration: { sdk_key: string, endpoint?: string }): Promise<void> {
7
- return await PreludeReactNativeSdkModule.dispatchSignals(configuration.sdk_key, configuration.endpoint);
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);
8
10
  }
9
11
 
10
- export function onDispatchingSignals(listener: (event: DispatchingSignalsStatus) => void): EventSubscription {
11
- return PreludeReactNativeSdkModule.addListener('onDispatchingSignals', listener);
12
+ export async function verifySilent(configuration: { sdk_key: string, request_url: string }): Promise<string> {
13
+ return await PreludeReactNativeSdkModule.verifySilent(configuration.sdk_key, configuration.request_url);
12
14
  }
13
-
14
- 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
- }