react-native-otp-auto-verify 0.1.8 → 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 +452 -466
- package/android/src/main/java/com/otpautoverify/OtpAutoVerifyModule.kt +12 -5
- package/lib/module/NativeOtpAutoVerify.ts +17 -3
- package/lib/module/index.js +41 -22
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeOtpAutoVerify.d.ts +2 -2
- package/lib/typescript/src/NativeOtpAutoVerify.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +11 -5
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +175 -183
- package/src/NativeOtpAutoVerify.ts +17 -3
- package/src/index.tsx +197 -172
|
@@ -100,18 +100,25 @@ class OtpAutoVerifyModule(reactContext: ReactApplicationContext) :
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
private fun unregisterReceiver() {
|
|
103
|
+
if (!isReceiverRegistered || smsReceiver == null) {
|
|
104
|
+
isListening = false
|
|
105
|
+
return
|
|
106
|
+
}
|
|
103
107
|
val activity = currentActivity
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
try {
|
|
109
|
+
if (activity != null) {
|
|
106
110
|
activity.unregisterReceiver(smsReceiver)
|
|
107
111
|
Log.d(TAG, "SMS receiver unregistered")
|
|
108
|
-
} catch (e: Exception) {
|
|
109
|
-
Log.e(TAG, "Failed to unregister SMS receiver", e)
|
|
110
112
|
}
|
|
113
|
+
} catch (e: IllegalArgumentException) {
|
|
114
|
+
Log.w(TAG, "Receiver already unregistered", e)
|
|
115
|
+
} catch (e: Exception) {
|
|
116
|
+
Log.e(TAG, "Failed to unregister SMS receiver", e)
|
|
117
|
+
} finally {
|
|
111
118
|
isReceiverRegistered = false
|
|
112
119
|
smsReceiver = null
|
|
120
|
+
isListening = false
|
|
113
121
|
}
|
|
114
|
-
isListening = false
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
override fun addListener(eventName: String) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
1
|
+
import { NativeModules, TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface OtpAutoVerifySpec extends TurboModule {
|
|
4
4
|
getConstants(): { OTP_RECEIVED_EVENT: string };
|
|
5
5
|
getHash(): Promise<ReadonlyArray<string>>;
|
|
6
6
|
startSmsRetriever(): Promise<boolean>;
|
|
@@ -8,4 +8,18 @@ export interface Spec extends TurboModule {
|
|
|
8
8
|
removeListeners(count: number): void;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function getNativeModule(): OtpAutoVerifySpec {
|
|
12
|
+
try {
|
|
13
|
+
return TurboModuleRegistry.getEnforcing<OtpAutoVerifySpec>('OtpAutoVerify');
|
|
14
|
+
} catch {
|
|
15
|
+
const legacy = NativeModules.OtpAutoVerify;
|
|
16
|
+
if (!legacy) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'OtpAutoVerify native module is not available. Ensure the library is properly linked.'
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return legacy as OtpAutoVerifySpec;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default getNativeModule();
|
package/lib/module/index.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { NativeEventEmitter,
|
|
4
|
+
import { NativeEventEmitter, Platform } from 'react-native';
|
|
5
5
|
import NativeOtpAutoVerify from './NativeOtpAutoVerify';
|
|
6
|
-
const
|
|
7
|
-
OtpAutoVerify
|
|
8
|
-
} = NativeModules;
|
|
9
|
-
const eventEmitter = Platform.OS === 'android' && OtpAutoVerify ? new NativeEventEmitter(OtpAutoVerify) : null;
|
|
6
|
+
const eventEmitter = Platform.OS === 'android' && NativeOtpAutoVerify ? new NativeEventEmitter(NativeOtpAutoVerify) : null;
|
|
10
7
|
const OTP_RECEIVED_EVENT = NativeOtpAutoVerify.getConstants?.()?.OTP_RECEIVED_EVENT ?? 'otpReceived';
|
|
11
|
-
const TIMEOUT_MESSAGE = 'Timeout Error.';
|
|
8
|
+
export const TIMEOUT_MESSAGE = 'Timeout Error.';
|
|
12
9
|
const DEFAULT_DIGITS = 6;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
10
|
+
const MIN_OTP_DIGITS = 4;
|
|
11
|
+
const MAX_OTP_DIGITS = 8;
|
|
12
|
+
function getOtpRegex(digits) {
|
|
13
|
+
if (digits < MIN_OTP_DIGITS || digits > MAX_OTP_DIGITS) {
|
|
14
|
+
return new RegExp(`\\b(\\d{${DEFAULT_DIGITS}})\\b`);
|
|
15
|
+
}
|
|
16
|
+
return new RegExp(`\\b(\\d{${digits}})\\b`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extracts a numeric OTP of 4–8 digits from SMS text.
|
|
20
|
+
*/
|
|
19
21
|
export function extractOtp(sms, numberOfDigits = DEFAULT_DIGITS) {
|
|
20
22
|
if (!sms || typeof sms !== 'string') return null;
|
|
21
23
|
const trimmed = sms.trim();
|
|
22
24
|
if (!trimmed) return null;
|
|
23
|
-
const
|
|
25
|
+
const regex = getOtpRegex(numberOfDigits);
|
|
26
|
+
const match = trimmed.match(regex);
|
|
24
27
|
return match ? match[1] : null;
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -31,10 +34,15 @@ export async function getHash() {
|
|
|
31
34
|
return Array.from(arr);
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
/**
|
|
37
|
+
/** No-op subscription for platforms where SMS Retriever is not supported (e.g. iOS). */
|
|
38
|
+
const NOOP_SUBSCRIPTION = {
|
|
39
|
+
remove: () => {}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Starts SMS Retriever and subscribes to OTP events. Returns subscription with remove(). On iOS, returns no-op (call remove() safely). */
|
|
35
43
|
export async function activateOtpListener(handler, options) {
|
|
36
44
|
if (Platform.OS !== 'android' || !eventEmitter) {
|
|
37
|
-
|
|
45
|
+
return NOOP_SUBSCRIPTION;
|
|
38
46
|
}
|
|
39
47
|
const numberOfDigits = options?.numberOfDigits ?? DEFAULT_DIGITS;
|
|
40
48
|
const subscription = eventEmitter.addListener(OTP_RECEIVED_EVENT, (...args) => {
|
|
@@ -50,7 +58,10 @@ export async function activateOtpListener(handler, options) {
|
|
|
50
58
|
};
|
|
51
59
|
}
|
|
52
60
|
|
|
53
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Stops SMS listening and removes all listeners.
|
|
63
|
+
* The native module ignores the count parameter and always unregisters the SMS receiver.
|
|
64
|
+
*/
|
|
54
65
|
export function removeListener() {
|
|
55
66
|
if (Platform.OS === 'android') {
|
|
56
67
|
NativeOtpAutoVerify.removeListeners(0);
|
|
@@ -66,24 +77,30 @@ export function useOtpVerification(options = {}) {
|
|
|
66
77
|
const [timeoutError, setTimeoutError] = React.useState(false);
|
|
67
78
|
const [error, setError] = React.useState(null);
|
|
68
79
|
const subscriptionRef = React.useRef(null);
|
|
80
|
+
const isStartingRef = React.useRef(false);
|
|
69
81
|
const stopListening = React.useCallback(() => {
|
|
70
82
|
subscriptionRef.current?.remove();
|
|
71
83
|
subscriptionRef.current = null;
|
|
84
|
+
isStartingRef.current = false;
|
|
72
85
|
removeListener();
|
|
73
86
|
}, []);
|
|
74
87
|
const startListening = React.useCallback(async () => {
|
|
75
88
|
if (Platform.OS !== 'android') return;
|
|
89
|
+
if (isStartingRef.current) return;
|
|
90
|
+
isStartingRef.current = true;
|
|
91
|
+
subscriptionRef.current?.remove();
|
|
92
|
+
subscriptionRef.current = null;
|
|
76
93
|
setOtp(null);
|
|
77
94
|
setSms(null);
|
|
78
95
|
setTimeoutError(false);
|
|
79
96
|
setError(null);
|
|
80
97
|
try {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
98
|
+
try {
|
|
99
|
+
const hashes = await getHash();
|
|
100
|
+
setHashCode(hashes[0] ?? '');
|
|
101
|
+
} catch (err) {
|
|
102
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
103
|
+
}
|
|
87
104
|
const sub = await activateOtpListener((smsText, extractedOtp) => {
|
|
88
105
|
setSms(smsText);
|
|
89
106
|
if (smsText === TIMEOUT_MESSAGE) {
|
|
@@ -102,6 +119,8 @@ export function useOtpVerification(options = {}) {
|
|
|
102
119
|
});
|
|
103
120
|
setError(wrapped);
|
|
104
121
|
throw wrapped;
|
|
122
|
+
} finally {
|
|
123
|
+
isStartingRef.current = false;
|
|
105
124
|
}
|
|
106
125
|
}, [numberOfDigits]);
|
|
107
126
|
React.useEffect(() => () => stopListening(), [stopListening]);
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","NativeEventEmitter","
|
|
1
|
+
{"version":3,"names":["React","NativeEventEmitter","Platform","NativeOtpAutoVerify","eventEmitter","OS","OTP_RECEIVED_EVENT","getConstants","TIMEOUT_MESSAGE","DEFAULT_DIGITS","MIN_OTP_DIGITS","MAX_OTP_DIGITS","getOtpRegex","digits","RegExp","extractOtp","sms","numberOfDigits","trimmed","trim","regex","match","getHash","arr","Array","from","NOOP_SUBSCRIPTION","remove","activateOtpListener","handler","options","subscription","addListener","args","smsText","String","startSmsRetriever","removeListeners","removeListener","useOtpVerification","hashCode","setHashCode","useState","otp","setOtp","setSms","timeoutError","setTimeoutError","error","setError","subscriptionRef","useRef","isStartingRef","stopListening","useCallback","current","startListening","hashes","err","Error","sub","extractedOtp","wrapped","cause","useEffect","useMemo"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,kBAAkB,EAAEC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EE,KAAK,EAAEQ,cAAc,EAAEH,aAAa,CACzE,CAAC;AACH;AAEA,SAAS/C,kBAAkB","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TurboModule } from 'react-native';
|
|
2
|
-
export interface
|
|
2
|
+
export interface OtpAutoVerifySpec extends TurboModule {
|
|
3
3
|
getConstants(): {
|
|
4
4
|
OTP_RECEIVED_EVENT: string;
|
|
5
5
|
};
|
|
@@ -8,6 +8,6 @@ export interface Spec extends TurboModule {
|
|
|
8
8
|
addListener(eventName: string): void;
|
|
9
9
|
removeListeners(count: number): void;
|
|
10
10
|
}
|
|
11
|
-
declare const _default:
|
|
11
|
+
declare const _default: OtpAutoVerifySpec;
|
|
12
12
|
export default _default;
|
|
13
13
|
//# sourceMappingURL=NativeOtpAutoVerify.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeOtpAutoVerify.d.ts","sourceRoot":"","sources":["../../../src/NativeOtpAutoVerify.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"NativeOtpAutoVerify.d.ts","sourceRoot":"","sources":["../../../src/NativeOtpAutoVerify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpF,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,YAAY,IAAI;QAAE,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAgBD,wBAAiC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
declare const OTP_RECEIVED_EVENT: string;
|
|
2
|
-
export
|
|
2
|
+
export declare const TIMEOUT_MESSAGE = "Timeout Error.";
|
|
3
|
+
export type OtpDigits = 4 | 5 | 6 | 7 | 8;
|
|
3
4
|
export interface UseOtpVerificationOptions {
|
|
4
|
-
/** Extract OTP with this many digits (4
|
|
5
|
+
/** Extract OTP with this many digits (4–8). OTP is set when SMS is received. */
|
|
5
6
|
numberOfDigits?: OtpDigits;
|
|
6
7
|
}
|
|
7
8
|
export interface UseOtpVerificationResult {
|
|
@@ -23,15 +24,20 @@ export interface UseOtpVerificationResult {
|
|
|
23
24
|
export interface OtpListenerSubscription {
|
|
24
25
|
remove: () => void;
|
|
25
26
|
}
|
|
26
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Extracts a numeric OTP of 4–8 digits from SMS text.
|
|
29
|
+
*/
|
|
27
30
|
export declare function extractOtp(sms: string, numberOfDigits?: OtpDigits): string | null;
|
|
28
31
|
/** Returns app hash strings for the current app. Android only; iOS returns []. */
|
|
29
32
|
export declare function getHash(): Promise<string[]>;
|
|
30
|
-
/** Starts SMS Retriever and subscribes to OTP events. Returns subscription with remove(). */
|
|
33
|
+
/** Starts SMS Retriever and subscribes to OTP events. Returns subscription with remove(). On iOS, returns no-op (call remove() safely). */
|
|
31
34
|
export declare function activateOtpListener(handler: (sms: string, extractedOtp?: string | null) => void, options?: {
|
|
32
35
|
numberOfDigits?: OtpDigits;
|
|
33
36
|
}): Promise<OtpListenerSubscription>;
|
|
34
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Stops SMS listening and removes all listeners.
|
|
39
|
+
* The native module ignores the count parameter and always unregisters the SMS receiver.
|
|
40
|
+
*/
|
|
35
41
|
export declare function removeListener(): void;
|
|
36
42
|
/** Hook for OTP verification. Call startListening() to begin; listener is stopped on unmount. */
|
|
37
43
|
export declare function useOtpVerification(options?: UseOtpVerificationOptions): UseOtpVerificationResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AASA,QAAA,MAAM,kBAAkB,QAET,CAAC;AAEhB,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAMhD,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAS1C,MAAM,WAAW,yBAAyB;IACxC,gFAAgF;IAChF,cAAc,CAAC,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,wBAAwB;IACvC,oFAAoF;IACpF,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,mCAAmC;IACnC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,6DAA6D;IAC7D,YAAY,EAAE,OAAO,CAAC;IACtB,oHAAoH;IACpH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,mEAAmE;IACnE,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,oDAAoD;IACpD,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,cAAc,GAAE,SAA0B,GACzC,MAAM,GAAG,IAAI,CAOf;AAED,kFAAkF;AAClF,wBAAsB,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAIjD;AAOD,2IAA2I;AAC3I,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,EAC5D,OAAO,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,SAAS,CAAA;CAAE,GACvC,OAAO,CAAC,uBAAuB,CAAC,CAqBlC;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAIrC;AAED,iGAAiG;AACjG,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,wBAAwB,CAyE1B;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,183 +1,175 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-native-otp-auto-verify",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "react-native-otp-auto-verify is a React Native library for automatic OTP verification on Android and iOS. It uses the Google SMS Retriever API to detect OTP codes automatically without requiring the READ_SMS permission. The library is fully Play Store compliant, improves user login experience, supports TurboModule, and works with the React Native New Architecture",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"react-native",
|
|
7
|
-
"react-native-library",
|
|
8
|
-
"react-native-otp",
|
|
9
|
-
"react-native-otp-auto-verify",
|
|
10
|
-
"react-native-sms",
|
|
11
|
-
"otp",
|
|
12
|
-
"otp-verification",
|
|
13
|
-
"otp-auto-verify",
|
|
14
|
-
"otp-auto-read",
|
|
15
|
-
"sms",
|
|
16
|
-
"sms-retriever",
|
|
17
|
-
"google-sms-retriever",
|
|
18
|
-
"android-otp",
|
|
19
|
-
"ios-otp",
|
|
20
|
-
"otp-without-permission",
|
|
21
|
-
"play-store-compliant",
|
|
22
|
-
"react-native-new-architecture",
|
|
23
|
-
"turbo-module"
|
|
24
|
-
],
|
|
25
|
-
"homepage": "https://github.com/kailas-rathod/react-native-otp-auto-verify?tab=readme-ov-file",
|
|
26
|
-
"bugs": {
|
|
27
|
-
"url": "https://github.com/kailas-rathod/react-native-otp-auto-verify/issues"
|
|
28
|
-
},
|
|
29
|
-
"repository": {
|
|
30
|
-
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/kailas-rathod/react-native-otp-auto-verify.git"
|
|
32
|
-
},
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"author": "Kailas Rathod (https://github.com/kailas-rathod)",
|
|
35
|
-
"type": "commonjs",
|
|
36
|
-
"main": "./lib/module/index.js",
|
|
37
|
-
"types": "./lib/typescript/src/index.d.ts",
|
|
38
|
-
"files": [
|
|
39
|
-
"src",
|
|
40
|
-
"lib",
|
|
41
|
-
"android",
|
|
42
|
-
"ios",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"!
|
|
47
|
-
"!android/
|
|
48
|
-
"!android/
|
|
49
|
-
"!android/gradlew",
|
|
50
|
-
"!android/
|
|
51
|
-
"
|
|
52
|
-
"!**/
|
|
53
|
-
"!**/
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"@
|
|
67
|
-
"@eslint/
|
|
68
|
-
"@eslint/
|
|
69
|
-
"@
|
|
70
|
-
"@react-native/
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"@types/
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"eslint": "^10.
|
|
77
|
-
"eslint-
|
|
78
|
-
"eslint-plugin-
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"react": "
|
|
83
|
-
"react-native": "0.
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"react": "*"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"
|
|
97
|
-
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
"
|
|
139
|
-
"
|
|
140
|
-
"
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
"
|
|
147
|
-
"
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
"@release-it/conventional-changelog": {
|
|
177
|
-
"preset": {
|
|
178
|
-
"name": "angular"
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-otp-auto-verify",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "react-native-otp-auto-verify is a React Native library for automatic OTP verification on Android and iOS. It uses the Google SMS Retriever API to detect OTP codes automatically without requiring the READ_SMS permission. The library is fully Play Store compliant, improves user login experience, supports TurboModule, and works with the React Native New Architecture",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react-native",
|
|
7
|
+
"react-native-library",
|
|
8
|
+
"react-native-otp",
|
|
9
|
+
"react-native-otp-auto-verify",
|
|
10
|
+
"react-native-sms",
|
|
11
|
+
"otp",
|
|
12
|
+
"otp-verification",
|
|
13
|
+
"otp-auto-verify",
|
|
14
|
+
"otp-auto-read",
|
|
15
|
+
"sms",
|
|
16
|
+
"sms-retriever",
|
|
17
|
+
"google-sms-retriever",
|
|
18
|
+
"android-otp",
|
|
19
|
+
"ios-otp",
|
|
20
|
+
"otp-without-permission",
|
|
21
|
+
"play-store-compliant",
|
|
22
|
+
"react-native-new-architecture",
|
|
23
|
+
"turbo-module"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/kailas-rathod/react-native-otp-auto-verify?tab=readme-ov-file",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/kailas-rathod/react-native-otp-auto-verify/issues"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/kailas-rathod/react-native-otp-auto-verify.git"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"author": "Kailas Rathod (https://github.com/kailas-rathod)",
|
|
35
|
+
"type": "commonjs",
|
|
36
|
+
"main": "./lib/module/index.js",
|
|
37
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
38
|
+
"files": [
|
|
39
|
+
"src",
|
|
40
|
+
"lib",
|
|
41
|
+
"android",
|
|
42
|
+
"ios",
|
|
43
|
+
"*.podspec",
|
|
44
|
+
"react-native.config.js",
|
|
45
|
+
"!ios/build",
|
|
46
|
+
"!android/build",
|
|
47
|
+
"!android/gradle",
|
|
48
|
+
"!android/gradlew",
|
|
49
|
+
"!android/gradlew.bat",
|
|
50
|
+
"!android/local.properties",
|
|
51
|
+
"!**/__tests__",
|
|
52
|
+
"!**/__fixtures__",
|
|
53
|
+
"!**/__mocks__",
|
|
54
|
+
"!**/.*"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"prepare": "bob build",
|
|
58
|
+
"typecheck": "tsc",
|
|
59
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
60
|
+
"test": "jest",
|
|
61
|
+
"check": "yarn typecheck && yarn lint && yarn test",
|
|
62
|
+
"release": "release-it --only-version"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
66
|
+
"@eslint/compat": "^1.3.2",
|
|
67
|
+
"@eslint/eslintrc": "^3.3.4",
|
|
68
|
+
"@eslint/js": "^9.35.0",
|
|
69
|
+
"@react-native/babel-preset": "0.83.0",
|
|
70
|
+
"@react-native-community/eslint-config": "^3.2.0",
|
|
71
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
72
|
+
"@types/jest": "^29.5.14",
|
|
73
|
+
"@types/react": "^19.2.0",
|
|
74
|
+
"commitlint": "^19.8.1",
|
|
75
|
+
"eslint": "^10.0.2",
|
|
76
|
+
"eslint-config-prettier": "^10.1.8",
|
|
77
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
78
|
+
"eslint-plugin-react-native": "^5.0.0",
|
|
79
|
+
"jest": "^30.2.0",
|
|
80
|
+
"prettier": "^2.8.8",
|
|
81
|
+
"react": "19.2.4",
|
|
82
|
+
"react-native": "0.83.0",
|
|
83
|
+
"react-native-builder-bob": "0.39.1",
|
|
84
|
+
"release-it": "^19.0.4",
|
|
85
|
+
"typescript": "^5.9.3"
|
|
86
|
+
},
|
|
87
|
+
"peerDependencies": {
|
|
88
|
+
"react": "*",
|
|
89
|
+
"react-native": "*"
|
|
90
|
+
},
|
|
91
|
+
"publishConfig": {
|
|
92
|
+
"registry": "https://registry.npmjs.org/"
|
|
93
|
+
},
|
|
94
|
+
"eslintConfig": {
|
|
95
|
+
"root": true,
|
|
96
|
+
"extends": [
|
|
97
|
+
"@react-native-community",
|
|
98
|
+
"prettier"
|
|
99
|
+
],
|
|
100
|
+
"rules": {
|
|
101
|
+
"prettier/prettier": [
|
|
102
|
+
"error",
|
|
103
|
+
{
|
|
104
|
+
"quoteProps": "consistent",
|
|
105
|
+
"singleQuote": true,
|
|
106
|
+
"tabWidth": 2,
|
|
107
|
+
"trailingComma": "es5",
|
|
108
|
+
"useTabs": false
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"eslintIgnore": [
|
|
114
|
+
"node_modules/",
|
|
115
|
+
"lib/"
|
|
116
|
+
],
|
|
117
|
+
"packageManager": "yarn@4.11.0",
|
|
118
|
+
"react-native-builder-bob": {
|
|
119
|
+
"source": "src",
|
|
120
|
+
"output": "lib",
|
|
121
|
+
"targets": [
|
|
122
|
+
[
|
|
123
|
+
"module",
|
|
124
|
+
{
|
|
125
|
+
"esm": true
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
"typescript",
|
|
130
|
+
{
|
|
131
|
+
"project": "tsconfig.build.json"
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
"codegenConfig": {
|
|
137
|
+
"name": "OtpAutoVerifySpec",
|
|
138
|
+
"type": "modules",
|
|
139
|
+
"jsSrcsDir": "src",
|
|
140
|
+
"android": {
|
|
141
|
+
"javaPackageName": "com.otpautoverify"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"prettier": {
|
|
145
|
+
"quoteProps": "consistent",
|
|
146
|
+
"singleQuote": true,
|
|
147
|
+
"tabWidth": 2,
|
|
148
|
+
"trailingComma": "es5",
|
|
149
|
+
"useTabs": false
|
|
150
|
+
},
|
|
151
|
+
"commitlint": {
|
|
152
|
+
"extends": [
|
|
153
|
+
"@commitlint/config-conventional"
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
"release-it": {
|
|
157
|
+
"git": {
|
|
158
|
+
"commitMessage": "chore: release ${version}",
|
|
159
|
+
"tagName": "v${version}"
|
|
160
|
+
},
|
|
161
|
+
"npm": {
|
|
162
|
+
"publish": true
|
|
163
|
+
},
|
|
164
|
+
"github": {
|
|
165
|
+
"release": true
|
|
166
|
+
},
|
|
167
|
+
"plugins": {
|
|
168
|
+
"@release-it/conventional-changelog": {
|
|
169
|
+
"preset": {
|
|
170
|
+
"name": "angular"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|