otpless-headless-rn 1.0.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/src/index.tsx ADDED
@@ -0,0 +1,74 @@
1
+ import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
2
+
3
+
4
+ const LINKING_ERROR =
5
+ `The package 'otpless-headless-rn' doesn't seem to be linked. Make sure: \n\n` +
6
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
7
+ '- You rebuilt the app after installing the package\n' +
8
+ '- You are not using Expo Go\n';
9
+
10
+ const OtplessHeadlessRN = NativeModules.OtplessHeadlessRN
11
+ ? NativeModules.OtplessHeadlessRN
12
+ : new Proxy(
13
+ {},
14
+ {
15
+ get() {
16
+ throw new Error(LINKING_ERROR);
17
+ },
18
+ }
19
+ );
20
+
21
+ interface OtplessResultCallback {
22
+ (result: any): void;
23
+ }
24
+
25
+ class OtplessHeadlessModule {
26
+ private eventEmitter: NativeEventEmitter | null = null;
27
+
28
+ constructor() {
29
+ this.eventEmitter = null;
30
+ }
31
+
32
+ clearListener() {
33
+ this.eventEmitter?.removeAllListeners('OTPlessEventResult');
34
+ }
35
+
36
+ initialize(appId: String, loginUri: string | null = null) {
37
+ if (this.eventEmitter == null) {
38
+ this.eventEmitter = new NativeEventEmitter(OtplessHeadlessRN);
39
+ }
40
+ // call the native method
41
+ OtplessHeadlessRN.initialize(appId, loginUri);
42
+ }
43
+
44
+ setResponseCallback(callback: OtplessResultCallback) {
45
+ this.eventEmitter!!.addListener('OTPlessEventResult', callback);
46
+ // call the native method
47
+ OtplessHeadlessRN.setResponseCallback()
48
+ }
49
+
50
+ start(input: any) {
51
+ OtplessHeadlessRN.start(input);
52
+ }
53
+
54
+ commitResponse(response: any) {
55
+ OtplessHeadlessRN.commitResponse(response);
56
+ }
57
+
58
+ performOneTap(data: any) {
59
+ OtplessHeadlessRN.performOneTap(data);
60
+ }
61
+
62
+ // Checks if whatsapp is installed on android device
63
+ isWhatsappInstalled(callback: (hasWhatsapp: boolean) => void) {
64
+ if (Platform.OS === 'android') {
65
+ OtplessHeadlessRN.isWhatsappInstalled((result: any) => {
66
+ const hasWhatsapp = result.hasWhatsapp === true;
67
+ callback(hasWhatsapp);
68
+ });
69
+ return
70
+ }
71
+ }
72
+ }
73
+
74
+ export { OtplessHeadlessModule };