react-native-otp-auto-verify 0.1.9 → 0.2.1
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 +467 -452
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/otpautoverify/OtpAutoVerifyModule.kt +14 -12
- package/lib/module/NativeOtpAutoVerify.ts +29 -5
- package/lib/module/index.js +77 -33
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeOtpAutoVerify.d.ts +3 -3
- package/lib/typescript/src/NativeOtpAutoVerify.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +7 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +183 -175
- package/src/NativeOtpAutoVerify.ts +29 -5
- package/src/index.tsx +89 -40
package/android/build.gradle
CHANGED
|
@@ -83,12 +83,6 @@ class OtpAutoVerifyModule(reactContext: ReactApplicationContext) :
|
|
|
83
83
|
null,
|
|
84
84
|
android.content.Context.RECEIVER_EXPORTED
|
|
85
85
|
)
|
|
86
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
87
|
-
activity.registerReceiver(
|
|
88
|
-
smsReceiver,
|
|
89
|
-
filter,
|
|
90
|
-
android.content.Context.RECEIVER_EXPORTED
|
|
91
|
-
)
|
|
92
86
|
} else {
|
|
93
87
|
activity.registerReceiver(smsReceiver, filter)
|
|
94
88
|
}
|
|
@@ -100,18 +94,25 @@ class OtpAutoVerifyModule(reactContext: ReactApplicationContext) :
|
|
|
100
94
|
}
|
|
101
95
|
|
|
102
96
|
private fun unregisterReceiver() {
|
|
97
|
+
if (!isReceiverRegistered || smsReceiver == null) {
|
|
98
|
+
isListening = false
|
|
99
|
+
return
|
|
100
|
+
}
|
|
103
101
|
val activity = currentActivity
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
try {
|
|
103
|
+
if (activity != null) {
|
|
106
104
|
activity.unregisterReceiver(smsReceiver)
|
|
107
105
|
Log.d(TAG, "SMS receiver unregistered")
|
|
108
|
-
} catch (e: Exception) {
|
|
109
|
-
Log.e(TAG, "Failed to unregister SMS receiver", e)
|
|
110
106
|
}
|
|
107
|
+
} catch (e: IllegalArgumentException) {
|
|
108
|
+
Log.w(TAG, "Receiver already unregistered", e)
|
|
109
|
+
} catch (e: Exception) {
|
|
110
|
+
Log.e(TAG, "Failed to unregister SMS receiver", e)
|
|
111
|
+
} finally {
|
|
111
112
|
isReceiverRegistered = false
|
|
112
113
|
smsReceiver = null
|
|
114
|
+
isListening = false
|
|
113
115
|
}
|
|
114
|
-
isListening = false
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
override fun addListener(eventName: String) {
|
|
@@ -130,7 +131,8 @@ class OtpAutoVerifyModule(reactContext: ReactApplicationContext) :
|
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
override fun onHostPause() {
|
|
133
|
-
|
|
134
|
+
// Keep the SMS receiver registered while paused so OTP can still arrive if the user
|
|
135
|
+
// briefly switches away (e.g. to read the SMS). Teardown happens in onHostDestroy / invalidate.
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
override fun onHostDestroy() {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
TurboModuleRegistry,
|
|
4
|
+
type TurboModule,
|
|
5
|
+
} from 'react-native';
|
|
2
6
|
|
|
3
|
-
export interface
|
|
7
|
+
export interface Spec extends TurboModule {
|
|
4
8
|
getConstants(): { OTP_RECEIVED_EVENT: string };
|
|
5
9
|
getHash(): Promise<ReadonlyArray<string>>;
|
|
6
10
|
startSmsRetriever(): Promise<boolean>;
|
|
@@ -8,6 +12,26 @@ export interface OtpAutoVerifySpec extends TurboModule {
|
|
|
8
12
|
removeListeners(count: number): void;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
);
|
|
15
|
+
function loadNativeModule(): Spec {
|
|
16
|
+
try {
|
|
17
|
+
return TurboModuleRegistry.getEnforcing<Spec>('OtpAutoVerify');
|
|
18
|
+
} catch {
|
|
19
|
+
const legacy = NativeModules.OtpAutoVerify;
|
|
20
|
+
if (!legacy) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'OtpAutoVerify native module is not available. Ensure the library is properly linked.'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return legacy as Spec;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let cachedModule: Spec | null = null;
|
|
30
|
+
|
|
31
|
+
/** Resolves the native module on first use so importing this package does not throw before APIs run. */
|
|
32
|
+
export function getOtpNativeModule(): Spec {
|
|
33
|
+
if (cachedModule === null) {
|
|
34
|
+
cachedModule = loadNativeModule();
|
|
35
|
+
}
|
|
36
|
+
return cachedModule;
|
|
37
|
+
}
|
package/lib/module/index.js
CHANGED
|
@@ -1,54 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { NativeEventEmitter,
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const OTP_RECEIVED_EVENT = NativeOtpAutoVerify.getConstants?.()?.OTP_RECEIVED_EVENT ?? 'otpReceived';
|
|
11
|
-
const TIMEOUT_MESSAGE = 'Timeout Error.';
|
|
4
|
+
import { NativeEventEmitter, Platform } from 'react-native';
|
|
5
|
+
import { getOtpNativeModule } from './NativeOtpAutoVerify';
|
|
6
|
+
|
|
7
|
+
/** Must match native `OTP_RECEIVED_EVENT` (Android/iOS). */
|
|
8
|
+
export const OTP_RECEIVED_EVENT = 'otpReceived';
|
|
9
|
+
export const TIMEOUT_MESSAGE = 'Timeout Error.';
|
|
12
10
|
const DEFAULT_DIGITS = 6;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const MIN_OTP_DIGITS = 4;
|
|
12
|
+
const MAX_OTP_DIGITS = 8;
|
|
13
|
+
let androidEventEmitter;
|
|
14
|
+
function getAndroidEventEmitter() {
|
|
15
|
+
if (Platform.OS !== 'android') return null;
|
|
16
|
+
if (androidEventEmitter !== undefined) {
|
|
17
|
+
return androidEventEmitter;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
androidEventEmitter = new NativeEventEmitter(getOtpNativeModule());
|
|
21
|
+
return androidEventEmitter;
|
|
22
|
+
} catch {
|
|
23
|
+
androidEventEmitter = null;
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function getOtpRegex(digits) {
|
|
28
|
+
const d = digits >= MIN_OTP_DIGITS && digits <= MAX_OTP_DIGITS ? digits : DEFAULT_DIGITS;
|
|
29
|
+
// Prefer non-`\b` boundaries so OTPs still match after ":" and similar (e.g. "OTP:123456").
|
|
30
|
+
return new RegExp(`(^|[^0-9])(\\d{${d}})(?!\\d)`);
|
|
31
|
+
}
|
|
18
32
|
/**
|
|
19
|
-
* Extracts a numeric OTP of 4
|
|
20
|
-
* Only these lengths are supported (numberOfDigits: 4 | 5 | 6).
|
|
33
|
+
* Extracts a numeric OTP of 4–8 digits from SMS text.
|
|
21
34
|
*/
|
|
22
35
|
export function extractOtp(sms, numberOfDigits = DEFAULT_DIGITS) {
|
|
23
36
|
if (!sms || typeof sms !== 'string') return null;
|
|
24
37
|
const trimmed = sms.trim();
|
|
25
38
|
if (!trimmed) return null;
|
|
26
|
-
const
|
|
27
|
-
|
|
39
|
+
const regex = getOtpRegex(numberOfDigits);
|
|
40
|
+
const match = trimmed.match(regex);
|
|
41
|
+
return match ? match[2] : null;
|
|
28
42
|
}
|
|
29
43
|
|
|
30
44
|
/** Returns app hash strings for the current app. Android only; iOS returns []. */
|
|
31
45
|
export async function getHash() {
|
|
32
46
|
if (Platform.OS !== 'android') return [];
|
|
33
|
-
const arr = await
|
|
47
|
+
const arr = await getOtpNativeModule().getHash();
|
|
34
48
|
return Array.from(arr);
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
/**
|
|
51
|
+
/** No-op subscription for platforms where SMS Retriever is not supported (e.g. iOS). */
|
|
52
|
+
const NOOP_SUBSCRIPTION = {
|
|
53
|
+
remove: () => {}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** Starts SMS Retriever and subscribes to OTP events. Returns subscription with remove(). On iOS, returns no-op (call remove() safely). */
|
|
38
57
|
export async function activateOtpListener(handler, options) {
|
|
39
|
-
if (Platform.OS !== 'android'
|
|
40
|
-
|
|
58
|
+
if (Platform.OS !== 'android') {
|
|
59
|
+
return NOOP_SUBSCRIPTION;
|
|
60
|
+
}
|
|
61
|
+
const emitter = getAndroidEventEmitter();
|
|
62
|
+
if (!emitter) {
|
|
63
|
+
return NOOP_SUBSCRIPTION;
|
|
41
64
|
}
|
|
42
65
|
const numberOfDigits = options?.numberOfDigits ?? DEFAULT_DIGITS;
|
|
43
|
-
const subscription =
|
|
66
|
+
const subscription = emitter.addListener(OTP_RECEIVED_EVENT, (...args) => {
|
|
44
67
|
const smsText = String(args[0] ?? '');
|
|
45
68
|
handler(smsText, extractOtp(smsText, numberOfDigits));
|
|
46
69
|
});
|
|
47
|
-
|
|
70
|
+
try {
|
|
71
|
+
await getOtpNativeModule().startSmsRetriever();
|
|
72
|
+
} catch (err) {
|
|
73
|
+
subscription.remove();
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
48
76
|
return {
|
|
49
77
|
remove: () => {
|
|
50
78
|
subscription.remove();
|
|
51
|
-
|
|
79
|
+
try {
|
|
80
|
+
getOtpNativeModule().removeListeners(0);
|
|
81
|
+
} catch {
|
|
82
|
+
// Native may be unavailable during teardown
|
|
83
|
+
}
|
|
52
84
|
}
|
|
53
85
|
};
|
|
54
86
|
}
|
|
@@ -58,8 +90,11 @@ export async function activateOtpListener(handler, options) {
|
|
|
58
90
|
* The native module ignores the count parameter and always unregisters the SMS receiver.
|
|
59
91
|
*/
|
|
60
92
|
export function removeListener() {
|
|
61
|
-
if (Platform.OS
|
|
62
|
-
|
|
93
|
+
if (Platform.OS !== 'android') return;
|
|
94
|
+
try {
|
|
95
|
+
getOtpNativeModule().removeListeners(0);
|
|
96
|
+
} catch {
|
|
97
|
+
// Native not linked or already torn down
|
|
63
98
|
}
|
|
64
99
|
}
|
|
65
100
|
|
|
@@ -72,24 +107,32 @@ export function useOtpVerification(options = {}) {
|
|
|
72
107
|
const [timeoutError, setTimeoutError] = React.useState(false);
|
|
73
108
|
const [error, setError] = React.useState(null);
|
|
74
109
|
const subscriptionRef = React.useRef(null);
|
|
110
|
+
const isStartingRef = React.useRef(false);
|
|
75
111
|
const stopListening = React.useCallback(() => {
|
|
76
112
|
subscriptionRef.current?.remove();
|
|
77
113
|
subscriptionRef.current = null;
|
|
114
|
+
isStartingRef.current = false;
|
|
78
115
|
removeListener();
|
|
79
116
|
}, []);
|
|
80
117
|
const startListening = React.useCallback(async () => {
|
|
81
118
|
if (Platform.OS !== 'android') return;
|
|
119
|
+
if (isStartingRef.current) return;
|
|
120
|
+
isStartingRef.current = true;
|
|
121
|
+
subscriptionRef.current?.remove();
|
|
122
|
+
subscriptionRef.current = null;
|
|
82
123
|
setOtp(null);
|
|
83
124
|
setSms(null);
|
|
84
125
|
setTimeoutError(false);
|
|
85
126
|
setError(null);
|
|
86
127
|
try {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
128
|
+
try {
|
|
129
|
+
const hashes = await getHash();
|
|
130
|
+
setHashCode(hashes[0] ?? '');
|
|
131
|
+
} catch (err) {
|
|
132
|
+
const wrapped = err instanceof Error ? err : new Error(String(err));
|
|
133
|
+
setError(wrapped);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
93
136
|
const sub = await activateOtpListener((smsText, extractedOtp) => {
|
|
94
137
|
setSms(smsText);
|
|
95
138
|
if (smsText === TIMEOUT_MESSAGE) {
|
|
@@ -108,6 +151,8 @@ export function useOtpVerification(options = {}) {
|
|
|
108
151
|
});
|
|
109
152
|
setError(wrapped);
|
|
110
153
|
throw wrapped;
|
|
154
|
+
} finally {
|
|
155
|
+
isStartingRef.current = false;
|
|
111
156
|
}
|
|
112
157
|
}, [numberOfDigits]);
|
|
113
158
|
React.useEffect(() => () => stopListening(), [stopListening]);
|
|
@@ -121,5 +166,4 @@ export function useOtpVerification(options = {}) {
|
|
|
121
166
|
stopListening
|
|
122
167
|
}), [hashCode, otp, sms, timeoutError, error, startListening, stopListening]);
|
|
123
168
|
}
|
|
124
|
-
export { OTP_RECEIVED_EVENT };
|
|
125
169
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","NativeEventEmitter","
|
|
1
|
+
{"version":3,"names":["React","NativeEventEmitter","Platform","getOtpNativeModule","OTP_RECEIVED_EVENT","TIMEOUT_MESSAGE","DEFAULT_DIGITS","MIN_OTP_DIGITS","MAX_OTP_DIGITS","androidEventEmitter","getAndroidEventEmitter","OS","undefined","getOtpRegex","digits","d","RegExp","extractOtp","sms","numberOfDigits","trimmed","trim","regex","match","getHash","arr","Array","from","NOOP_SUBSCRIPTION","remove","activateOtpListener","handler","options","emitter","subscription","addListener","args","smsText","String","startSmsRetriever","err","removeListeners","removeListener","useOtpVerification","hashCode","setHashCode","useState","otp","setOtp","setSms","timeoutError","setTimeoutError","error","setError","subscriptionRef","useRef","isStartingRef","stopListening","useCallback","current","startListening","hashes","wrapped","Error","sub","extractedOtp","cause","useEffect","useMemo"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAC3D,SAASC,kBAAkB,QAAQ,uBAAuB;;AAE1D;AACA,OAAO,MAAMC,kBAAkB,GAAG,aAAa;AAE/C,OAAO,MAAMC,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jB,MAAMA,OAAO;IACf,CAAC,SAAS;MACRN,aAAa,CAACG,OAAO,GAAG,KAAK;IAC/B;EACF,CAAC,EAAE,CAACxC,cAAc,CAAC,CAAC;EAEpBnB,KAAK,CAACmE,SAAS,CAAC,MAAM,MAAMV,aAAa,CAAC,CAAC,EAAE,CAACA,aAAa,CAAC,CAAC;EAE7D,OAAOzD,KAAK,CAACoE,OAAO,CAClB,OAAO;IACLxB,QAAQ;IACRG,GAAG;IACH7B,GAAG;IACHgC,YAAY;IACZE,KAAK;IACLQ,cAAc;IACdH;EACF,CAAC,CAAC,EACF,CAACb,QAAQ,EAAEG,GAAG,EAAE7B,GAAG,EAAEgC,YAAY,EAAEE,KAAK,EAAEQ,cAAc,EAAEH,aAAa,CACzE,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TurboModule } from 'react-native';
|
|
2
|
-
export interface
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
3
|
getConstants(): {
|
|
4
4
|
OTP_RECEIVED_EVENT: string;
|
|
5
5
|
};
|
|
@@ -8,6 +8,6 @@ export interface OtpAutoVerifySpec extends TurboModule {
|
|
|
8
8
|
addListener(eventName: string): void;
|
|
9
9
|
removeListeners(count: number): void;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
export
|
|
11
|
+
/** Resolves the native module on first use so importing this package does not throw before APIs run. */
|
|
12
|
+
export declare function getOtpNativeModule(): Spec;
|
|
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,EAGL,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,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;AAkBD,wGAAwG;AACxG,wBAAgB,kBAAkB,IAAI,IAAI,CAKzC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
/** Must match native `OTP_RECEIVED_EVENT` (Android/iOS). */
|
|
2
|
+
export declare const OTP_RECEIVED_EVENT = "otpReceived";
|
|
3
|
+
export declare const TIMEOUT_MESSAGE = "Timeout Error.";
|
|
4
|
+
export type OtpDigits = 4 | 5 | 6 | 7 | 8;
|
|
3
5
|
export interface UseOtpVerificationOptions {
|
|
4
|
-
/** Extract OTP with this many digits (4
|
|
6
|
+
/** Extract OTP with this many digits (4–8). OTP is set when SMS is received. */
|
|
5
7
|
numberOfDigits?: OtpDigits;
|
|
6
8
|
}
|
|
7
9
|
export interface UseOtpVerificationResult {
|
|
@@ -24,13 +26,12 @@ export interface OtpListenerSubscription {
|
|
|
24
26
|
remove: () => void;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
|
-
* Extracts a numeric OTP of 4
|
|
28
|
-
* Only these lengths are supported (numberOfDigits: 4 | 5 | 6).
|
|
29
|
+
* Extracts a numeric OTP of 4–8 digits from SMS text.
|
|
29
30
|
*/
|
|
30
31
|
export declare function extractOtp(sms: string, numberOfDigits?: OtpDigits): string | null;
|
|
31
32
|
/** Returns app hash strings for the current app. Android only; iOS returns []. */
|
|
32
33
|
export declare function getHash(): Promise<string[]>;
|
|
33
|
-
/** Starts SMS Retriever and subscribes to OTP events. Returns subscription with remove(). */
|
|
34
|
+
/** Starts SMS Retriever and subscribes to OTP events. Returns subscription with remove(). On iOS, returns no-op (call remove() safely). */
|
|
34
35
|
export declare function activateOtpListener(handler: (sms: string, extractedOtp?: string | null) => void, options?: {
|
|
35
36
|
numberOfDigits?: OtpDigits;
|
|
36
37
|
}): Promise<OtpListenerSubscription>;
|
|
@@ -41,5 +42,4 @@ export declare function activateOtpListener(handler: (sms: string, extractedOtp?
|
|
|
41
42
|
export declare function removeListener(): void;
|
|
42
43
|
/** Hook for OTP verification. Call startListening() to begin; listener is stopped on unmount. */
|
|
43
44
|
export declare function useOtpVerification(options?: UseOtpVerificationOptions): UseOtpVerificationResult;
|
|
44
|
-
export { OTP_RECEIVED_EVENT };
|
|
45
45
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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":"AAIA,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAMhD,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AA2B1C,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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