Skip to content

Commit 96bad06

Browse files
authored
Merge branch 'main' into mob-1640-ios-share-extension-photos-are-copied-and-never-deleted
2 parents abe40bb + 0e8e00e commit 96bad06

9 files changed

Lines changed: 122 additions & 150 deletions

File tree

__mocks__/react-native-sensitive-info.ts

Lines changed: 52 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,100 +15,77 @@ try {
1515
console.warn( "Could not import clearAuthCache, using no-op function", error );
1616
}
1717

18-
class RNSInfo {
19-
static stores = new Map();
18+
const stores = new Map();
2019

21-
static getServiceName( o = {} ) {
22-
return o.sharedPreferencesName
23-
|| o.keychainService
20+
function getServiceName( o = {} ) {
21+
return o.service
2422
|| "default";
25-
}
26-
27-
static validateString( s ) {
28-
if ( typeof s !== "string" ) { throw new Error( "Invalid string:", s ); }
29-
}
30-
31-
static clearAllStores = jest.fn( () => {
32-
RNSInfo.stores.clear();
33-
clearAuthCache();
34-
} );
35-
36-
static clearAuthCache = jest.fn( () => {
37-
clearAuthCache();
38-
} );
39-
40-
static hasItem = jest.fn( async ( k, o ) => {
41-
RNSInfo.validateString( k );
42-
43-
const serviceName = RNSInfo.getServiceName( o );
44-
const service = RNSInfo.stores.get( serviceName );
45-
46-
if ( service ) { return service.has( k ); }
47-
return false;
48-
} );
49-
50-
static getItem = jest.fn( async ( k, o ) => {
51-
RNSInfo.validateString( k );
23+
}
5224

53-
const serviceName = RNSInfo.getServiceName( o );
54-
const service = RNSInfo.stores.get( serviceName );
25+
function validateString( s ) {
26+
if ( typeof s !== "string" ) { throw new Error( "Invalid string:", s ); }
27+
}
5528

56-
if ( service ) { return service.get( k ) || null; }
57-
return null;
58-
} );
29+
const clearAuthCacheInternal = jest.fn( () => {
30+
clearAuthCache();
31+
} );
5932

60-
static getAllItems = jest.fn( async o => {
61-
const serviceName = RNSInfo.getServiceName( o );
62-
const service = RNSInfo.stores.get( serviceName );
63-
let mappedValues = [];
33+
const hasItem = jest.fn( async ( k, o ) => {
34+
validateString( k );
6435

65-
if ( service?.size ) {
66-
mappedValues = Array.from( service.entries() ).map(
67-
( [key, value] ) => ( { key, value, service: serviceName } ),
68-
);
69-
}
36+
const serviceName = getServiceName( o );
37+
const service = stores.get( serviceName );
7038

71-
return mappedValues;
72-
} );
39+
if ( service ) { return service.has( k ); }
40+
return false;
41+
} );
7342

74-
static setItem = jest.fn( async ( k, v, o ) => {
75-
RNSInfo.validateString( k );
76-
RNSInfo.validateString( v );
43+
const getItem = jest.fn( async ( k, o ) => {
44+
validateString( k );
7745

78-
const serviceName = RNSInfo.getServiceName( o );
79-
let service = RNSInfo.stores.get( serviceName );
46+
const serviceName = getServiceName( o );
47+
const service = stores.get( serviceName );
8048

81-
if ( !service ) {
82-
RNSInfo.stores.set( serviceName, new Map() );
83-
service = RNSInfo.stores.get( serviceName );
84-
}
49+
if ( service ) { return { value: service.get( k ) || null }; }
50+
return null;
51+
} );
8552

86-
service.set( k, v );
53+
const setItem = jest.fn( async ( k, v, o ) => {
54+
validateString( k );
55+
validateString( v );
8756

88-
clearAuthCache( );
57+
const serviceName = getServiceName( o );
58+
let service = stores.get( serviceName );
8959

90-
return null;
91-
} );
60+
if ( !service ) {
61+
stores.set( serviceName, new Map() );
62+
service = stores.get( serviceName );
63+
}
9264

93-
static deleteItem = jest.fn( async ( k, o ) => {
94-
RNSInfo.validateString( k );
65+
service.set( k, v );
9566

96-
const serviceName = RNSInfo.getServiceName( o );
97-
const service = RNSInfo.stores.get( serviceName );
67+
clearAuthCacheInternal( );
9868

99-
if ( service ) { service.delete( k ); }
69+
return null;
70+
} );
10071

101-
clearAuthCache( );
72+
const deleteItem = jest.fn( async ( k, o ) => {
73+
validateString( k );
10274

103-
return null;
104-
} );
75+
const serviceName = getServiceName( o );
76+
const service = stores.get( serviceName );
10577

106-
static hasEnrolledFingerprints = jest.fn( async () => true );
78+
if ( service ) { service.delete( k ); }
10779

108-
static setInvalidatedByBiometricEnrollment = jest.fn();
80+
clearAuthCacheInternal( );
10981

110-
// "Touch ID" | "Face ID" | false
111-
static isSensorAvailable = jest.fn( async () => "Face ID" );
112-
}
82+
return null;
83+
} );
11384

114-
module.exports = RNSInfo;
85+
module.exports = {
86+
deleteItem,
87+
setItem,
88+
getItem,
89+
hasItem,
90+
stores,
91+
};

ios/Podfile.lock

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,17 +3919,19 @@ PODS:
39193919
- ReactCommon/turbomodule/core
39203920
- SocketRocket
39213921
- Yoga
3922-
- SensitiveInfo (5.6.2):
3922+
- SensitiveInfo (6.1.5):
39233923
- boost
39243924
- DoubleConversion
39253925
- fast_float
39263926
- fmt
39273927
- glog
39283928
- hermes-engine
3929+
- NitroModules
39293930
- RCT-Folly
39303931
- RCT-Folly/Fabric
39313932
- RCTRequired
39323933
- RCTTypeSafety
3934+
- React-callinvoker
39333935
- React-Core
39343936
- React-debug
39353937
- React-Fabric
@@ -4561,7 +4563,7 @@ SPEC CHECKSUMS:
45614563
RNStoreReview: 8f6061907efb6474757db004ee8faac728fd2ada
45624564
RNSVG: c7b9ee1f2352f984e79d6e3238645b81ced60516
45634565
RNWorklets: a3184955a41f2be46898a937e2821469c8c8da42
4564-
SensitiveInfo: 09107b865dc23b4e9c0a61ec01385387bf3391a8
4566+
SensitiveInfo: ddf05bc892a97c058f167057582e6a2d05e99c54
45654567
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
45664568
VisionCamera: 0044a94f7489f19e19d5938e97dfc36f4784af3c
45674569
VisionCameraPluginInatVision: 3b006a7a434ddfc23d789729b6d98e451f90c4e4

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"react-native-restart": "^0.0.27",
139139
"react-native-safe-area-context": "^5.8.0",
140140
"react-native-screens": "4.15.4",
141-
"react-native-sensitive-info": "^5.6.2",
141+
"react-native-sensitive-info": "^6.1.5",
142142
"react-native-share-menu": "github:inaturalist/react-native-share-menu#892d4ffcad6e48607679c519be2448a3a878834a",
143143
"react-native-store-review": "^0.4.3",
144144
"react-native-svg": "^15.15.0",

src/components/Developer/logManagementHelpers.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,6 @@ export async function cleanupLogFiles() {
6363
await Promise.allSettled( olderLogs.map( ( { path } ) => unlink( path ) ) );
6464
}
6565

66-
export async function deleteLegacyLogFile() {
67-
try {
68-
await unlink( legacyLogfilePath );
69-
} catch ( deleteFileError ) {
70-
if ( deleteFileError instanceof Error && deleteFileError.message.match( /no such file/ ) ) {
71-
return;
72-
}
73-
throw deleteFileError;
74-
}
75-
}
76-
7766
const appVersion = getVersion();
7867
const buildVersion = getBuildNumber();
7968
const device = getSystemName();
@@ -129,10 +118,6 @@ async function emailLogFile( path: string ) {
129118
);
130119
}
131120

132-
export async function getLegacyLogfileExists() {
133-
return exists( legacyLogfilePath );
134-
}
135-
136121
export const temporaryLogForSharingPath
137122
= `${TemporaryDirectoryPath}/${logFileNamePrefix}-recent.txt`;
138123

src/components/LoginSignUp/AuthenticationService.ts

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ import { Alert, Platform } from "react-native";
1919
import Config from "react-native-config";
2020
import * as RNLocalize from "react-native-localize";
2121
import RNRestart from "react-native-restart";
22-
import type { SensitiveInfoError } from "react-native-sensitive-info";
23-
import RNSInfo, { ErrorCode, isSensitiveInfoError } from "react-native-sensitive-info";
22+
import {
23+
deleteItem,
24+
ErrorCode,
25+
getItem,
26+
hasItem,
27+
SensitiveInfoError,
28+
setItem,
29+
} from "react-native-sensitive-info";
2430
import Realm, { UpdateMode } from "realm";
2531
import realmConfig from "realmModels/index";
2632
import changeLanguage from "sharedHelpers/changeLanguage";
@@ -58,7 +64,7 @@ interface AuthCache {
5864
}
5965

6066
/**
61-
* Cache for isLoggedIn, to avoid making too many calls to RNSInfo.getItem
67+
* Cache for isLoggedIn, to avoid making too many calls to getItem
6268
*/
6369
const authCache: AuthCache = {
6470
isLoggedIn: null,
@@ -88,17 +94,16 @@ const clearAuthCache = ( ): void => {
8894
async function getSensitiveItem(
8995
key: string,
9096
options = {
91-
keychainService: "app" as const,
97+
service: "app" as const,
9298
},
9399
) {
94100
let exists;
95101
try {
96-
exists = await RNSInfo.hasItem( key, options );
102+
exists = await hasItem( key, options );
97103
} catch ( e ) {
98-
if ( isSensitiveInfoError( e ) ) {
99-
const hasItemError = e as SensitiveInfoError;
104+
if ( e instanceof SensitiveInfoError ) {
100105
localLogger.info(
101-
`RNSInfo.hasItem error for ${key}: ${hasItemError.message}`,
106+
`hasItem error for ${key}: ${e.message}`,
102107
);
103108
}
104109
throw e;
@@ -108,20 +113,18 @@ async function getSensitiveItem(
108113
}
109114

110115
try {
111-
return await RNSInfo.getItem( key, options );
116+
const item = await getItem( key, options );
117+
return item?.value ?? null;
112118
} catch ( e ) {
113-
if ( isSensitiveInfoError( e ) ) {
114-
const getItemError = e as SensitiveInfoError;
115-
if ( isDebugModeSync() ) {
116-
switch ( getItemError.code ) {
117-
case ErrorCode.NOT_FOUND:
118-
// Value doesn't exist
119-
localLogger.info( `RNSInfo.getItem not available for ${key}` );
120-
break;
121-
default:
122-
localLogger.info( `RNSInfo.getItem unknown error for ${key}: ${getItemError.message}` );
123-
break;
124-
}
119+
if ( e instanceof SensitiveInfoError && isDebugModeSync() ) {
120+
switch ( e.code ) {
121+
case ErrorCode.NotFound:
122+
// Value doesn't exist
123+
localLogger.info( `getItem not available for ${key}` );
124+
break;
125+
default:
126+
localLogger.info( `getItem unknown error for ${key}: ${e.message}` );
127+
break;
125128
}
126129
}
127130
throw e;
@@ -132,22 +135,19 @@ async function setSensitiveItem( key: string, value: string, options = {} ) {
132135
const actualOptions = {
133136
// I put the key as overridable by actual options propped in,
134137
// in case someone wants to build a separate slice at one point.
135-
keychainService: "app" as const,
138+
service: "app" as const,
136139
...options,
137140
accessControl: "none" as const,
138141
};
139142
try {
140-
const result = await RNSInfo.setItem( key, value, actualOptions );
143+
const result = await setItem( key, value, actualOptions );
141144
clearAuthCache( );
142145
return result;
143146
} catch ( e ) {
144-
if ( isSensitiveInfoError( e ) ) {
145-
const setItemError = e as SensitiveInfoError;
146-
if ( isDebugModeSync( ) ) {
147-
localLogger.info(
148-
`RNSInfo.setItem error for ${key}, ${setItemError.code} ${setItemError.message}`,
149-
);
150-
}
147+
if ( e instanceof SensitiveInfoError && isDebugModeSync( ) ) {
148+
localLogger.info(
149+
`setItem error for ${key}, ${e.code} ${e.message}`,
150+
);
151151
}
152152
throw e;
153153
}
@@ -156,21 +156,18 @@ async function setSensitiveItem( key: string, value: string, options = {} ) {
156156
async function deleteSensitiveItem(
157157
key: string,
158158
options = {
159-
keychainService: "app" as const,
159+
service: "app" as const,
160160
},
161161
) {
162162
try {
163-
const result = await RNSInfo.deleteItem( key, options );
163+
const result = await deleteItem( key, options );
164164
clearAuthCache( );
165165
return result;
166166
} catch ( e ) {
167-
if ( isSensitiveInfoError( e ) ) {
168-
const deleteItemError = e as SensitiveInfoError;
169-
if ( isDebugModeSync() ) {
170-
localLogger.info(
171-
`RNSInfo.deleteItem error for ${key}, ${deleteItemError.code} ${deleteItemError.message}`,
172-
);
173-
}
167+
if ( e instanceof SensitiveInfoError && isDebugModeSync() ) {
168+
localLogger.info(
169+
`deleteItem error for ${key}, ${e.code} ${e.message}`,
170+
);
174171
}
175172
throw e;
176173
}

0 commit comments

Comments
 (0)