import { Platform } from 'react-native' ; import sensitiveInfo , { RNSensitiveInfoOptions , } from 'react-native-sensitive-info' ; type TValue = string | null ; type TCallback = ( err : any , data : TValue | any [ ] ) => void ; const extractKeys = Platform . select ( { ios : ( items ) => items [ 0 ] . map ( item => item . key ) , android : Object . keys , } ) ; const noop = ( ) => null ; param options const createSensitiveStorage = ( sensitiveOpts = { } ) => { return { async getItem ( key , callback = noop ) { try { let result = await sensitiveInfo . getItem ( key , sensitiveOpts ) ; if ( typeof result === 'undefined' ) { result = null ; } callback ( null , result ) ; return result ; } catch ( error ) { callback ( error , null ) ; throw error ; } } , async setItem ( key , value , callback = noop ) { try { await sensitiveInfo . setItem ( key , value , sensitiveOpts ) ; callback ( null , value ) ; } catch ( error ) { callback ( error , null ) ; throw error ; } } , async removeItem ( key , callback = noop ) { try { await sensitiveInfo . deleteItem ( key , sensitiveOpts ) ; callback ( null , null ) ; } catch ( error ) { callback ( error , null ) ; throw error ; } } , async getAllKeys ( callback = noop ) { try { const values = ( await sensitiveInfo . getAllItems ( sensitiveOpts ) ) as any ; const result = extractKeys ( values ) ; callback ( null , result ) ; return result ; } catch ( error ) { callback ( error , null ) ; throw error ; } } , } ; } ; export default createSensitiveStorage ;