react-native-storage-inspector 1.0.0 → 1.0.2
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 +12 -0
- package/dist/index.d.mts +83 -16
- package/dist/index.d.ts +83 -16
- package/dist/index.js +64 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
package/dist/index.mjs
CHANGED
|
@@ -36,62 +36,61 @@ function createMMKVAdapter(instance, name) {
|
|
|
36
36
|
|
|
37
37
|
// src/adapters/async-storage.ts
|
|
38
38
|
var asyncStorage = null;
|
|
39
|
-
function
|
|
40
|
-
if (asyncStorage) return asyncStorage;
|
|
39
|
+
function getAsyncStorageFromRequire() {
|
|
41
40
|
try {
|
|
42
|
-
|
|
43
|
-
return
|
|
41
|
+
const mod = require("@react-native-async-storage/async-storage");
|
|
42
|
+
return mod.default ?? mod;
|
|
44
43
|
} catch {
|
|
45
44
|
return null;
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
function createAsyncStorageAdapter() {
|
|
47
|
+
function createAsyncStorageAdapter(instance) {
|
|
48
|
+
const getStorage = () => instance ?? (asyncStorage ?? (asyncStorage = getAsyncStorageFromRequire()));
|
|
49
49
|
return {
|
|
50
50
|
type: "async-storage",
|
|
51
51
|
name: "Async Storage",
|
|
52
52
|
async getAllKeys() {
|
|
53
|
-
const storage =
|
|
53
|
+
const storage = getStorage();
|
|
54
54
|
if (!storage) return [];
|
|
55
55
|
return storage.getAllKeys();
|
|
56
56
|
},
|
|
57
57
|
async getItem(key) {
|
|
58
|
-
const storage =
|
|
58
|
+
const storage = getStorage();
|
|
59
59
|
if (!storage) return null;
|
|
60
60
|
return storage.getItem(key);
|
|
61
61
|
},
|
|
62
62
|
async setItem(key, value) {
|
|
63
|
-
const storage =
|
|
63
|
+
const storage = getStorage();
|
|
64
64
|
if (!storage) throw new Error("AsyncStorage is not available");
|
|
65
65
|
await storage.setItem(key, value);
|
|
66
66
|
},
|
|
67
67
|
async removeItem(key) {
|
|
68
|
-
const storage =
|
|
68
|
+
const storage = getStorage();
|
|
69
69
|
if (!storage) throw new Error("AsyncStorage is not available");
|
|
70
70
|
await storage.removeItem(key);
|
|
71
71
|
},
|
|
72
72
|
isAvailable() {
|
|
73
|
-
return
|
|
73
|
+
return getStorage() !== null;
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/adapters/keychain.ts
|
|
79
79
|
var keychain = null;
|
|
80
|
-
function
|
|
81
|
-
if (keychain) return keychain;
|
|
80
|
+
function getKeychainFromRequire() {
|
|
82
81
|
try {
|
|
83
|
-
|
|
84
|
-
return keychain;
|
|
82
|
+
return require("react-native-keychain");
|
|
85
83
|
} catch {
|
|
86
84
|
return null;
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
|
-
function createKeychainAdapter(knownKeys = []) {
|
|
87
|
+
function createKeychainAdapter(knownKeys = [], instance) {
|
|
88
|
+
const getKc = () => instance ?? (keychain ?? (keychain = getKeychainFromRequire()));
|
|
90
89
|
return {
|
|
91
90
|
type: "keychain",
|
|
92
91
|
name: "Keychain",
|
|
93
92
|
async getAllKeys() {
|
|
94
|
-
const kc =
|
|
93
|
+
const kc = getKc();
|
|
95
94
|
if (!kc) return [...knownKeys];
|
|
96
95
|
const genericServices = [];
|
|
97
96
|
if (typeof kc.getAllGenericPasswordServices === "function") {
|
|
@@ -105,7 +104,7 @@ function createKeychainAdapter(knownKeys = []) {
|
|
|
105
104
|
return Array.from(merged);
|
|
106
105
|
},
|
|
107
106
|
async getItem(key) {
|
|
108
|
-
const kc =
|
|
107
|
+
const kc = getKc();
|
|
109
108
|
if (!kc) return null;
|
|
110
109
|
if (typeof kc.getGenericPassword === "function") {
|
|
111
110
|
try {
|
|
@@ -120,7 +119,7 @@ function createKeychainAdapter(knownKeys = []) {
|
|
|
120
119
|
return creds?.password ?? null;
|
|
121
120
|
},
|
|
122
121
|
async setItem(key, value) {
|
|
123
|
-
const kc =
|
|
122
|
+
const kc = getKc();
|
|
124
123
|
if (!kc) throw new Error("react-native-keychain is not available");
|
|
125
124
|
if (typeof kc.setGenericPassword === "function") {
|
|
126
125
|
const result2 = await kc.setGenericPassword(key, value, { service: key });
|
|
@@ -131,7 +130,7 @@ function createKeychainAdapter(knownKeys = []) {
|
|
|
131
130
|
if (result === false) throw new Error("Keychain set failed");
|
|
132
131
|
},
|
|
133
132
|
async removeItem(key) {
|
|
134
|
-
const kc =
|
|
133
|
+
const kc = getKc();
|
|
135
134
|
if (!kc) throw new Error("react-native-keychain is not available");
|
|
136
135
|
if (typeof kc.resetGenericPassword === "function") {
|
|
137
136
|
await kc.resetGenericPassword({ service: key });
|
|
@@ -139,23 +138,22 @@ function createKeychainAdapter(knownKeys = []) {
|
|
|
139
138
|
await kc.resetInternetCredentials(key);
|
|
140
139
|
},
|
|
141
140
|
isAvailable() {
|
|
142
|
-
return
|
|
141
|
+
return getKc() !== null;
|
|
143
142
|
}
|
|
144
143
|
};
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
// src/adapters/secure-store.ts
|
|
148
147
|
var secureStore = null;
|
|
149
|
-
function
|
|
150
|
-
if (secureStore) return secureStore;
|
|
148
|
+
function getSecureStoreFromRequire() {
|
|
151
149
|
try {
|
|
152
|
-
|
|
153
|
-
return secureStore;
|
|
150
|
+
return require("expo-secure-store");
|
|
154
151
|
} catch {
|
|
155
152
|
return null;
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
function createSecureStoreAdapter(knownKeys = []) {
|
|
155
|
+
function createSecureStoreAdapter(knownKeys = [], instance) {
|
|
156
|
+
const getStore = () => instance ?? (secureStore ?? (secureStore = getSecureStoreFromRequire()));
|
|
159
157
|
return {
|
|
160
158
|
type: "expo-secure-store",
|
|
161
159
|
name: "Secure Store",
|
|
@@ -163,22 +161,22 @@ function createSecureStoreAdapter(knownKeys = []) {
|
|
|
163
161
|
return [...knownKeys];
|
|
164
162
|
},
|
|
165
163
|
async getItem(key) {
|
|
166
|
-
const store =
|
|
164
|
+
const store = getStore();
|
|
167
165
|
if (!store) return null;
|
|
168
166
|
return store.getItemAsync(key);
|
|
169
167
|
},
|
|
170
168
|
async setItem(key, value) {
|
|
171
|
-
const store =
|
|
169
|
+
const store = getStore();
|
|
172
170
|
if (!store) throw new Error("expo-secure-store is not available");
|
|
173
171
|
await store.setItemAsync(key, value);
|
|
174
172
|
},
|
|
175
173
|
async removeItem(key) {
|
|
176
|
-
const store =
|
|
174
|
+
const store = getStore();
|
|
177
175
|
if (!store) throw new Error("expo-secure-store is not available");
|
|
178
176
|
await store.deleteItemAsync(key);
|
|
179
177
|
},
|
|
180
178
|
isAvailable() {
|
|
181
|
-
return
|
|
179
|
+
return getStore() !== null;
|
|
182
180
|
}
|
|
183
181
|
};
|
|
184
182
|
}
|
|
@@ -1056,11 +1054,10 @@ function StorageSection({
|
|
|
1056
1054
|
return next;
|
|
1057
1055
|
});
|
|
1058
1056
|
};
|
|
1059
|
-
return /* @__PURE__ */ React6.createElement(
|
|
1057
|
+
return /* @__PURE__ */ React6.createElement(View, { key: item.key, style: styles2.itemRow }, /* @__PURE__ */ React6.createElement(
|
|
1060
1058
|
TouchableOpacity,
|
|
1061
1059
|
{
|
|
1062
1060
|
key: item.key,
|
|
1063
|
-
style: styles2.itemRow,
|
|
1064
1061
|
onPress: toggleItemExpanded,
|
|
1065
1062
|
activeOpacity: 0.7
|
|
1066
1063
|
},
|
|
@@ -1081,17 +1078,24 @@ function StorageSection({
|
|
|
1081
1078
|
size: LAYOUT.chevronSize,
|
|
1082
1079
|
tintColor: theme.colors.text
|
|
1083
1080
|
}
|
|
1084
|
-
)))
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1081
|
+
)))
|
|
1082
|
+
), isItemExpanded && /* @__PURE__ */ React6.createElement(View, { style: styles2.itemRowExpanded }, /* @__PURE__ */ React6.createElement(
|
|
1083
|
+
TouchableOpacity,
|
|
1084
|
+
{
|
|
1085
|
+
onPress: () => handleEdit(item),
|
|
1086
|
+
style: styles2.valueBox
|
|
1087
|
+
},
|
|
1088
|
+
/* @__PURE__ */ React6.createElement(Text, { style: styles2.valueBoxLabel }, strings.valueLabel),
|
|
1089
|
+
/* @__PURE__ */ React6.createElement(Text, { style: styles2.valueBoxText, selectable: true }, item.value || strings.emptyValue)
|
|
1090
|
+
), /* @__PURE__ */ React6.createElement(
|
|
1091
|
+
ItemRowActions,
|
|
1092
|
+
{
|
|
1093
|
+
item,
|
|
1094
|
+
onCopy: handleCopy,
|
|
1095
|
+
onEdit: handleEdit,
|
|
1096
|
+
onDelete: setDeleteItem
|
|
1097
|
+
}
|
|
1098
|
+
)));
|
|
1095
1099
|
}), !loading && items.length === 0 && !showKeychainHint && !showSecureStoreHint ? /* @__PURE__ */ React6.createElement(View, { style: styles2.empty }, /* @__PURE__ */ React6.createElement(Text, { style: styles2.emptyText }, strings.noItems)) : null), /* @__PURE__ */ React6.createElement(
|
|
1096
1100
|
ItemForm,
|
|
1097
1101
|
{
|
|
@@ -1128,8 +1132,11 @@ function StorageSection({
|
|
|
1128
1132
|
// src/components/StorageInspector.tsx
|
|
1129
1133
|
function StorageInspector({
|
|
1130
1134
|
mmkvInstances = [],
|
|
1135
|
+
asyncStorageInstance,
|
|
1131
1136
|
keychainKeys: keychainKeysProp,
|
|
1137
|
+
keychainInstance,
|
|
1132
1138
|
secureStoreKeys: secureStoreKeysProp,
|
|
1139
|
+
secureStoreInstance,
|
|
1133
1140
|
customAdapters = []
|
|
1134
1141
|
}) {
|
|
1135
1142
|
const [keychainKeysAdded, setKeychainKeysAdded] = useState([]);
|
|
@@ -1152,15 +1159,26 @@ function StorageInspector({
|
|
|
1152
1159
|
createMMKVAdapter(inst, mmkvInstances.length > 1 ? `MMKV ${i + 1}` : "MMKV")
|
|
1153
1160
|
);
|
|
1154
1161
|
});
|
|
1155
|
-
const asyncAdapter = createAsyncStorageAdapter();
|
|
1162
|
+
const asyncAdapter = createAsyncStorageAdapter(asyncStorageInstance);
|
|
1156
1163
|
if (asyncAdapter.isAvailable()) list.push(asyncAdapter);
|
|
1157
|
-
const keychainAdapter = createKeychainAdapter(keychainKeys);
|
|
1164
|
+
const keychainAdapter = createKeychainAdapter(keychainKeys, keychainInstance);
|
|
1158
1165
|
if (keychainAdapter.isAvailable()) list.push(keychainAdapter);
|
|
1159
|
-
const secureStoreAdapter = createSecureStoreAdapter(
|
|
1166
|
+
const secureStoreAdapter = createSecureStoreAdapter(
|
|
1167
|
+
secureStoreKeys,
|
|
1168
|
+
secureStoreInstance
|
|
1169
|
+
);
|
|
1160
1170
|
if (secureStoreAdapter.isAvailable()) list.push(secureStoreAdapter);
|
|
1161
1171
|
list.push(...customAdapters);
|
|
1162
1172
|
return list;
|
|
1163
|
-
}, [
|
|
1173
|
+
}, [
|
|
1174
|
+
mmkvInstances,
|
|
1175
|
+
asyncStorageInstance,
|
|
1176
|
+
keychainKeys,
|
|
1177
|
+
keychainInstance,
|
|
1178
|
+
secureStoreKeys,
|
|
1179
|
+
secureStoreInstance,
|
|
1180
|
+
customAdapters
|
|
1181
|
+
]);
|
|
1164
1182
|
const handleKeychainKeyAdded = (key) => {
|
|
1165
1183
|
setKeychainKeysAdded(
|
|
1166
1184
|
(prev) => prev.includes(key) ? prev : [...prev, key]
|