strata-storage 2.0.3 → 2.0.4
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/android/src/main/java/com/strata/storage/EncryptedStorage.java +44 -3
- package/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -5
- package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +43 -3
- package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +12 -3
- package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +44 -3
- package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -5
- package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +43 -3
- package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +12 -3
- package/dist/capacitor.d.ts.map +1 -1
- package/dist/capacitor.js +4 -3
- package/dist/core/Strata.d.ts +133 -2
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +133 -2
- package/dist/firebase.d.ts.map +1 -1
- package/dist/firebase.js +21 -1
- package/dist/ios/Plugin/KeychainStorage.swift +31 -9
- package/dist/ios/Plugin/SQLiteStorage.swift +29 -6
- package/dist/ios/Plugin/UserDefaultsStorage.swift +25 -7
- package/dist/package.json +5 -5
- package/dist/plugin/web.d.ts +10 -6
- package/dist/plugin/web.d.ts.map +1 -1
- package/dist/plugin/web.js +42 -13
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -3
- package/ios/Plugin/KeychainStorage.swift +31 -9
- package/ios/Plugin/SQLiteStorage.swift +29 -6
- package/ios/Plugin/UserDefaultsStorage.swift +25 -7
- package/package.json +15 -15
- package/dist/README.md +0 -179
|
@@ -6,14 +6,20 @@ import android.os.Build;
|
|
|
6
6
|
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
7
7
|
import androidx.security.crypto.MasterKey;
|
|
8
8
|
import java.util.Set;
|
|
9
|
+
import java.util.HashSet;
|
|
9
10
|
import java.util.Map;
|
|
10
11
|
|
|
11
12
|
public class EncryptedStorage {
|
|
12
13
|
private SharedPreferences encryptedPrefs;
|
|
13
14
|
private SharedPreferences.Editor editor;
|
|
15
|
+
private static final String DEFAULT_NAME = "StrataSecureStorage";
|
|
16
|
+
|
|
17
|
+
public EncryptedStorage(Context context) throws Exception {
|
|
18
|
+
this(context, DEFAULT_NAME);
|
|
19
|
+
}
|
|
14
20
|
|
|
15
21
|
public EncryptedStorage(Context context, String name) throws Exception {
|
|
16
|
-
String fileName = name != null ? name :
|
|
22
|
+
String fileName = name != null ? name : DEFAULT_NAME;
|
|
17
23
|
|
|
18
24
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
19
25
|
MasterKey masterKey = new MasterKey.Builder(context)
|
|
@@ -51,12 +57,47 @@ public class EncryptedStorage {
|
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
public boolean clear() {
|
|
54
|
-
|
|
60
|
+
return clear(null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public boolean clear(String prefix) {
|
|
64
|
+
if (prefix != null) {
|
|
65
|
+
// Clear only keys with the given prefix
|
|
66
|
+
Set<String> keysToRemove = new HashSet<>();
|
|
67
|
+
for (String key : encryptedPrefs.getAll().keySet()) {
|
|
68
|
+
if (key.startsWith(prefix) || key.contains(prefix)) {
|
|
69
|
+
keysToRemove.add(key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (String key : keysToRemove) {
|
|
73
|
+
editor.remove(key);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
// Clear all keys
|
|
77
|
+
editor.clear();
|
|
78
|
+
}
|
|
55
79
|
return editor.commit();
|
|
56
80
|
}
|
|
57
81
|
|
|
58
82
|
public Set<String> keys() {
|
|
59
|
-
return
|
|
83
|
+
return keys(null);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public Set<String> keys(String pattern) {
|
|
87
|
+
Set<String> allKeys = encryptedPrefs.getAll().keySet();
|
|
88
|
+
|
|
89
|
+
if (pattern == null) {
|
|
90
|
+
return allKeys;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Filter keys by pattern
|
|
94
|
+
Set<String> filteredKeys = new HashSet<>();
|
|
95
|
+
for (String key : allKeys) {
|
|
96
|
+
if (key.startsWith(pattern) || key.contains(pattern)) {
|
|
97
|
+
filteredKeys.add(key);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return filteredKeys;
|
|
60
101
|
}
|
|
61
102
|
|
|
62
103
|
public boolean has(String key) {
|
|
@@ -13,6 +13,7 @@ import java.util.Map;
|
|
|
13
13
|
public class SQLiteStorage extends SQLiteOpenHelper {
|
|
14
14
|
private static final int DATABASE_VERSION = 1;
|
|
15
15
|
private static final String TABLE_NAME = "strata_storage";
|
|
16
|
+
private static final String DEFAULT_DB_NAME = "strata.db";
|
|
16
17
|
|
|
17
18
|
private static final String KEY_ID = "key";
|
|
18
19
|
private static final String KEY_VALUE = "value";
|
|
@@ -22,8 +23,12 @@ public class SQLiteStorage extends SQLiteOpenHelper {
|
|
|
22
23
|
private static final String KEY_TAGS = "tags";
|
|
23
24
|
private static final String KEY_METADATA = "metadata";
|
|
24
25
|
|
|
26
|
+
public SQLiteStorage(Context context) {
|
|
27
|
+
this(context, DEFAULT_DB_NAME);
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
public SQLiteStorage(Context context, String dbName) {
|
|
26
|
-
super(context, dbName != null ? dbName :
|
|
31
|
+
super(context, dbName != null ? dbName : DEFAULT_DB_NAME, null, DATABASE_VERSION);
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
@Override
|
|
@@ -112,18 +117,43 @@ public class SQLiteStorage extends SQLiteOpenHelper {
|
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
public boolean clear() {
|
|
120
|
+
return clear(null);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public boolean clear(String prefix) {
|
|
115
124
|
SQLiteDatabase db = this.getWritableDatabase();
|
|
116
|
-
|
|
125
|
+
int result;
|
|
126
|
+
|
|
127
|
+
if (prefix != null) {
|
|
128
|
+
// Clear only keys with the given prefix
|
|
129
|
+
result = db.delete(TABLE_NAME, KEY_ID + " LIKE ?", new String[]{prefix + "%"});
|
|
130
|
+
} else {
|
|
131
|
+
// Clear all keys
|
|
132
|
+
result = db.delete(TABLE_NAME, null, null);
|
|
133
|
+
}
|
|
134
|
+
|
|
117
135
|
db.close();
|
|
118
|
-
return
|
|
136
|
+
return result >= 0;
|
|
119
137
|
}
|
|
120
138
|
|
|
121
139
|
public List<String> keys() {
|
|
140
|
+
return keys(null);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public List<String> keys(String pattern) {
|
|
122
144
|
List<String> keys = new ArrayList<>();
|
|
123
|
-
String selectQuery
|
|
145
|
+
String selectQuery;
|
|
146
|
+
String[] selectionArgs = null;
|
|
147
|
+
|
|
148
|
+
if (pattern != null) {
|
|
149
|
+
selectQuery = "SELECT " + KEY_ID + " FROM " + TABLE_NAME + " WHERE " + KEY_ID + " LIKE ?";
|
|
150
|
+
selectionArgs = new String[]{"% " + pattern + "%"};
|
|
151
|
+
} else {
|
|
152
|
+
selectQuery = "SELECT " + KEY_ID + " FROM " + TABLE_NAME;
|
|
153
|
+
}
|
|
124
154
|
|
|
125
155
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
126
|
-
Cursor cursor = db.rawQuery(selectQuery,
|
|
156
|
+
Cursor cursor = db.rawQuery(selectQuery, selectionArgs);
|
|
127
157
|
|
|
128
158
|
if (cursor.moveToFirst()) {
|
|
129
159
|
do {
|
|
@@ -11,9 +11,14 @@ import org.json.JSONArray;
|
|
|
11
11
|
public class SharedPreferencesStorage {
|
|
12
12
|
private final SharedPreferences prefs;
|
|
13
13
|
private final SharedPreferences.Editor editor;
|
|
14
|
+
private static final String DEFAULT_NAME = "StrataStorage";
|
|
15
|
+
|
|
16
|
+
public SharedPreferencesStorage(Context context) {
|
|
17
|
+
this(context, DEFAULT_NAME);
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
public SharedPreferencesStorage(Context context, String name) {
|
|
16
|
-
this.prefs = context.getSharedPreferences(name != null ? name :
|
|
21
|
+
this.prefs = context.getSharedPreferences(name != null ? name : DEFAULT_NAME, Context.MODE_PRIVATE);
|
|
17
22
|
this.editor = prefs.edit();
|
|
18
23
|
}
|
|
19
24
|
|
|
@@ -56,12 +61,47 @@ public class SharedPreferencesStorage {
|
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
public boolean clear() {
|
|
59
|
-
|
|
64
|
+
return clear(null);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public boolean clear(String prefix) {
|
|
68
|
+
if (prefix != null) {
|
|
69
|
+
// Clear only keys with the given prefix
|
|
70
|
+
Set<String> keysToRemove = new HashSet<>();
|
|
71
|
+
for (String key : prefs.getAll().keySet()) {
|
|
72
|
+
if (key.startsWith(prefix) || key.contains(prefix)) {
|
|
73
|
+
keysToRemove.add(key);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (String key : keysToRemove) {
|
|
77
|
+
editor.remove(key);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
// Clear all keys
|
|
81
|
+
editor.clear();
|
|
82
|
+
}
|
|
60
83
|
return editor.commit();
|
|
61
84
|
}
|
|
62
85
|
|
|
63
86
|
public Set<String> keys() {
|
|
64
|
-
return
|
|
87
|
+
return keys(null);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public Set<String> keys(String pattern) {
|
|
91
|
+
Set<String> allKeys = prefs.getAll().keySet();
|
|
92
|
+
|
|
93
|
+
if (pattern == null) {
|
|
94
|
+
return allKeys;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Filter keys by pattern
|
|
98
|
+
Set<String> filteredKeys = new HashSet<>();
|
|
99
|
+
for (String key : allKeys) {
|
|
100
|
+
if (key.startsWith(pattern) || key.contains(pattern)) {
|
|
101
|
+
filteredKeys.add(key);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return filteredKeys;
|
|
65
105
|
}
|
|
66
106
|
|
|
67
107
|
public boolean has(String key) {
|
|
@@ -5,9 +5,13 @@ import com.getcapacitor.Plugin;
|
|
|
5
5
|
import com.getcapacitor.PluginCall;
|
|
6
6
|
import com.getcapacitor.PluginMethod;
|
|
7
7
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
import com.strata.storage.SharedPreferencesStorage;
|
|
9
|
+
import com.strata.storage.EncryptedStorage;
|
|
10
|
+
import com.strata.storage.SQLiteStorage;
|
|
8
11
|
import org.json.JSONArray;
|
|
9
12
|
import org.json.JSONException;
|
|
10
13
|
import java.util.List;
|
|
14
|
+
import java.util.Set;
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Main Capacitor plugin for Strata Storage
|
|
@@ -21,9 +25,14 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
21
25
|
|
|
22
26
|
@Override
|
|
23
27
|
public void load() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
try {
|
|
29
|
+
sharedPrefsStorage = new SharedPreferencesStorage(getContext());
|
|
30
|
+
encryptedStorage = new EncryptedStorage(getContext());
|
|
31
|
+
sqliteStorage = new SQLiteStorage(getContext());
|
|
32
|
+
} catch (Exception e) {
|
|
33
|
+
// Log error but don't crash - some storage types may not be available
|
|
34
|
+
e.printStackTrace();
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
/**
|
|
@@ -6,14 +6,20 @@ import android.os.Build;
|
|
|
6
6
|
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
7
7
|
import androidx.security.crypto.MasterKey;
|
|
8
8
|
import java.util.Set;
|
|
9
|
+
import java.util.HashSet;
|
|
9
10
|
import java.util.Map;
|
|
10
11
|
|
|
11
12
|
public class EncryptedStorage {
|
|
12
13
|
private SharedPreferences encryptedPrefs;
|
|
13
14
|
private SharedPreferences.Editor editor;
|
|
15
|
+
private static final String DEFAULT_NAME = "StrataSecureStorage";
|
|
16
|
+
|
|
17
|
+
public EncryptedStorage(Context context) throws Exception {
|
|
18
|
+
this(context, DEFAULT_NAME);
|
|
19
|
+
}
|
|
14
20
|
|
|
15
21
|
public EncryptedStorage(Context context, String name) throws Exception {
|
|
16
|
-
String fileName = name != null ? name :
|
|
22
|
+
String fileName = name != null ? name : DEFAULT_NAME;
|
|
17
23
|
|
|
18
24
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
19
25
|
MasterKey masterKey = new MasterKey.Builder(context)
|
|
@@ -51,12 +57,47 @@ public class EncryptedStorage {
|
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
public boolean clear() {
|
|
54
|
-
|
|
60
|
+
return clear(null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public boolean clear(String prefix) {
|
|
64
|
+
if (prefix != null) {
|
|
65
|
+
// Clear only keys with the given prefix
|
|
66
|
+
Set<String> keysToRemove = new HashSet<>();
|
|
67
|
+
for (String key : encryptedPrefs.getAll().keySet()) {
|
|
68
|
+
if (key.startsWith(prefix) || key.contains(prefix)) {
|
|
69
|
+
keysToRemove.add(key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (String key : keysToRemove) {
|
|
73
|
+
editor.remove(key);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
// Clear all keys
|
|
77
|
+
editor.clear();
|
|
78
|
+
}
|
|
55
79
|
return editor.commit();
|
|
56
80
|
}
|
|
57
81
|
|
|
58
82
|
public Set<String> keys() {
|
|
59
|
-
return
|
|
83
|
+
return keys(null);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public Set<String> keys(String pattern) {
|
|
87
|
+
Set<String> allKeys = encryptedPrefs.getAll().keySet();
|
|
88
|
+
|
|
89
|
+
if (pattern == null) {
|
|
90
|
+
return allKeys;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Filter keys by pattern
|
|
94
|
+
Set<String> filteredKeys = new HashSet<>();
|
|
95
|
+
for (String key : allKeys) {
|
|
96
|
+
if (key.startsWith(pattern) || key.contains(pattern)) {
|
|
97
|
+
filteredKeys.add(key);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return filteredKeys;
|
|
60
101
|
}
|
|
61
102
|
|
|
62
103
|
public boolean has(String key) {
|
|
@@ -13,6 +13,7 @@ import java.util.Map;
|
|
|
13
13
|
public class SQLiteStorage extends SQLiteOpenHelper {
|
|
14
14
|
private static final int DATABASE_VERSION = 1;
|
|
15
15
|
private static final String TABLE_NAME = "strata_storage";
|
|
16
|
+
private static final String DEFAULT_DB_NAME = "strata.db";
|
|
16
17
|
|
|
17
18
|
private static final String KEY_ID = "key";
|
|
18
19
|
private static final String KEY_VALUE = "value";
|
|
@@ -22,8 +23,12 @@ public class SQLiteStorage extends SQLiteOpenHelper {
|
|
|
22
23
|
private static final String KEY_TAGS = "tags";
|
|
23
24
|
private static final String KEY_METADATA = "metadata";
|
|
24
25
|
|
|
26
|
+
public SQLiteStorage(Context context) {
|
|
27
|
+
this(context, DEFAULT_DB_NAME);
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
public SQLiteStorage(Context context, String dbName) {
|
|
26
|
-
super(context, dbName != null ? dbName :
|
|
31
|
+
super(context, dbName != null ? dbName : DEFAULT_DB_NAME, null, DATABASE_VERSION);
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
@Override
|
|
@@ -112,18 +117,43 @@ public class SQLiteStorage extends SQLiteOpenHelper {
|
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
public boolean clear() {
|
|
120
|
+
return clear(null);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public boolean clear(String prefix) {
|
|
115
124
|
SQLiteDatabase db = this.getWritableDatabase();
|
|
116
|
-
|
|
125
|
+
int result;
|
|
126
|
+
|
|
127
|
+
if (prefix != null) {
|
|
128
|
+
// Clear only keys with the given prefix
|
|
129
|
+
result = db.delete(TABLE_NAME, KEY_ID + " LIKE ?", new String[]{prefix + "%"});
|
|
130
|
+
} else {
|
|
131
|
+
// Clear all keys
|
|
132
|
+
result = db.delete(TABLE_NAME, null, null);
|
|
133
|
+
}
|
|
134
|
+
|
|
117
135
|
db.close();
|
|
118
|
-
return
|
|
136
|
+
return result >= 0;
|
|
119
137
|
}
|
|
120
138
|
|
|
121
139
|
public List<String> keys() {
|
|
140
|
+
return keys(null);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public List<String> keys(String pattern) {
|
|
122
144
|
List<String> keys = new ArrayList<>();
|
|
123
|
-
String selectQuery
|
|
145
|
+
String selectQuery;
|
|
146
|
+
String[] selectionArgs = null;
|
|
147
|
+
|
|
148
|
+
if (pattern != null) {
|
|
149
|
+
selectQuery = "SELECT " + KEY_ID + " FROM " + TABLE_NAME + " WHERE " + KEY_ID + " LIKE ?";
|
|
150
|
+
selectionArgs = new String[]{"% " + pattern + "%"};
|
|
151
|
+
} else {
|
|
152
|
+
selectQuery = "SELECT " + KEY_ID + " FROM " + TABLE_NAME;
|
|
153
|
+
}
|
|
124
154
|
|
|
125
155
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
126
|
-
Cursor cursor = db.rawQuery(selectQuery,
|
|
156
|
+
Cursor cursor = db.rawQuery(selectQuery, selectionArgs);
|
|
127
157
|
|
|
128
158
|
if (cursor.moveToFirst()) {
|
|
129
159
|
do {
|
|
@@ -11,9 +11,14 @@ import org.json.JSONArray;
|
|
|
11
11
|
public class SharedPreferencesStorage {
|
|
12
12
|
private final SharedPreferences prefs;
|
|
13
13
|
private final SharedPreferences.Editor editor;
|
|
14
|
+
private static final String DEFAULT_NAME = "StrataStorage";
|
|
15
|
+
|
|
16
|
+
public SharedPreferencesStorage(Context context) {
|
|
17
|
+
this(context, DEFAULT_NAME);
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
public SharedPreferencesStorage(Context context, String name) {
|
|
16
|
-
this.prefs = context.getSharedPreferences(name != null ? name :
|
|
21
|
+
this.prefs = context.getSharedPreferences(name != null ? name : DEFAULT_NAME, Context.MODE_PRIVATE);
|
|
17
22
|
this.editor = prefs.edit();
|
|
18
23
|
}
|
|
19
24
|
|
|
@@ -56,12 +61,47 @@ public class SharedPreferencesStorage {
|
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
public boolean clear() {
|
|
59
|
-
|
|
64
|
+
return clear(null);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public boolean clear(String prefix) {
|
|
68
|
+
if (prefix != null) {
|
|
69
|
+
// Clear only keys with the given prefix
|
|
70
|
+
Set<String> keysToRemove = new HashSet<>();
|
|
71
|
+
for (String key : prefs.getAll().keySet()) {
|
|
72
|
+
if (key.startsWith(prefix) || key.contains(prefix)) {
|
|
73
|
+
keysToRemove.add(key);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (String key : keysToRemove) {
|
|
77
|
+
editor.remove(key);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
// Clear all keys
|
|
81
|
+
editor.clear();
|
|
82
|
+
}
|
|
60
83
|
return editor.commit();
|
|
61
84
|
}
|
|
62
85
|
|
|
63
86
|
public Set<String> keys() {
|
|
64
|
-
return
|
|
87
|
+
return keys(null);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public Set<String> keys(String pattern) {
|
|
91
|
+
Set<String> allKeys = prefs.getAll().keySet();
|
|
92
|
+
|
|
93
|
+
if (pattern == null) {
|
|
94
|
+
return allKeys;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Filter keys by pattern
|
|
98
|
+
Set<String> filteredKeys = new HashSet<>();
|
|
99
|
+
for (String key : allKeys) {
|
|
100
|
+
if (key.startsWith(pattern) || key.contains(pattern)) {
|
|
101
|
+
filteredKeys.add(key);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return filteredKeys;
|
|
65
105
|
}
|
|
66
106
|
|
|
67
107
|
public boolean has(String key) {
|
|
@@ -5,9 +5,13 @@ import com.getcapacitor.Plugin;
|
|
|
5
5
|
import com.getcapacitor.PluginCall;
|
|
6
6
|
import com.getcapacitor.PluginMethod;
|
|
7
7
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
import com.strata.storage.SharedPreferencesStorage;
|
|
9
|
+
import com.strata.storage.EncryptedStorage;
|
|
10
|
+
import com.strata.storage.SQLiteStorage;
|
|
8
11
|
import org.json.JSONArray;
|
|
9
12
|
import org.json.JSONException;
|
|
10
13
|
import java.util.List;
|
|
14
|
+
import java.util.Set;
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Main Capacitor plugin for Strata Storage
|
|
@@ -21,9 +25,14 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
21
25
|
|
|
22
26
|
@Override
|
|
23
27
|
public void load() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
try {
|
|
29
|
+
sharedPrefsStorage = new SharedPreferencesStorage(getContext());
|
|
30
|
+
encryptedStorage = new EncryptedStorage(getContext());
|
|
31
|
+
sqliteStorage = new SQLiteStorage(getContext());
|
|
32
|
+
} catch (Exception e) {
|
|
33
|
+
// Log error but don't crash - some storage types may not be available
|
|
34
|
+
e.printStackTrace();
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
/**
|
package/dist/capacitor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capacitor.d.ts","sourceRoot":"","sources":["../src/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAO5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"capacitor.d.ts","sourceRoot":"","sources":["../src/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAO5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB9E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAShD;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,CAEnD"}
|
package/dist/capacitor.js
CHANGED
|
@@ -17,7 +17,7 @@ export async function registerCapacitorAdapters(storage) {
|
|
|
17
17
|
// Check if Capacitor is available
|
|
18
18
|
const hasCapacitor = typeof window !== 'undefined' &&
|
|
19
19
|
window.Capacitor &&
|
|
20
|
-
window.Capacitor
|
|
20
|
+
window.Capacitor?.isNativePlatform?.();
|
|
21
21
|
if (!hasCapacitor) {
|
|
22
22
|
console.warn('Capacitor not detected. Capacitor adapters will not be registered.');
|
|
23
23
|
return;
|
|
@@ -36,9 +36,10 @@ export async function registerCapacitorAdapters(storage) {
|
|
|
36
36
|
* Helper to check if running in Capacitor environment
|
|
37
37
|
*/
|
|
38
38
|
export function isCapacitorEnvironment() {
|
|
39
|
-
return (typeof window !== 'undefined' &&
|
|
39
|
+
return ((typeof window !== 'undefined' &&
|
|
40
40
|
window.Capacitor &&
|
|
41
|
-
window.Capacitor
|
|
41
|
+
window.Capacitor?.isNativePlatform?.()) ??
|
|
42
|
+
false);
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* Get Capacitor-specific storage types
|
package/dist/core/Strata.d.ts
CHANGED
|
@@ -33,26 +33,157 @@ export declare class Strata {
|
|
|
33
33
|
initialize(): Promise<void>;
|
|
34
34
|
/**
|
|
35
35
|
* Get a value from storage
|
|
36
|
+
*
|
|
37
|
+
* @param key - The key to retrieve
|
|
38
|
+
* @param options - Storage options
|
|
39
|
+
* @param options.storage - Specific storage type to use (e.g., 'localStorage', 'indexedDB')
|
|
40
|
+
* @param options.decrypt - Whether to decrypt the value (default: auto-detect)
|
|
41
|
+
* @param options.decryptionPassword - Password for decryption (uses config password if not provided)
|
|
42
|
+
* @returns The stored value or null if not found
|
|
43
|
+
* @throws {StorageError} If the storage adapter is not available
|
|
44
|
+
* @throws {EncryptionError} If decryption fails
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Simple get
|
|
49
|
+
* const value = await storage.get('myKey');
|
|
50
|
+
*
|
|
51
|
+
* // Get from specific storage
|
|
52
|
+
* const value = await storage.get('myKey', { storage: 'indexedDB' });
|
|
53
|
+
*
|
|
54
|
+
* // Get encrypted value
|
|
55
|
+
* const value = await storage.get('secure-key', {
|
|
56
|
+
* decryptionPassword: 'myPassword'
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
36
59
|
*/
|
|
37
60
|
get<T = unknown>(key: string, options?: StorageOptions): Promise<T | null>;
|
|
38
61
|
/**
|
|
39
62
|
* Set a value in storage
|
|
63
|
+
*
|
|
64
|
+
* @param key - The key to store under
|
|
65
|
+
* @param value - The value to store (can be any serializable type)
|
|
66
|
+
* @param options - Storage options
|
|
67
|
+
* @param options.storage - Specific storage type to use
|
|
68
|
+
* @param options.encrypt - Whether to encrypt the value
|
|
69
|
+
* @param options.encryptionPassword - Password for encryption
|
|
70
|
+
* @param options.compress - Whether to compress the value
|
|
71
|
+
* @param options.ttl - Time-to-live in milliseconds
|
|
72
|
+
* @param options.tags - Tags for categorization
|
|
73
|
+
* @param options.metadata - Additional metadata to store
|
|
74
|
+
* @throws {StorageError} If the storage adapter is not available
|
|
75
|
+
* @throws {EncryptionError} If encryption fails
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Simple set
|
|
80
|
+
* await storage.set('myKey', 'myValue');
|
|
81
|
+
*
|
|
82
|
+
* // Set with TTL (expires in 1 hour)
|
|
83
|
+
* await storage.set('tempKey', data, { ttl: 3600000 });
|
|
84
|
+
*
|
|
85
|
+
* // Set with encryption and compression
|
|
86
|
+
* await storage.set('secure-key', sensitiveData, {
|
|
87
|
+
* encrypt: true,
|
|
88
|
+
* compress: true,
|
|
89
|
+
* encryptionPassword: 'myPassword'
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // Set with metadata
|
|
93
|
+
* await storage.set('user-123', userData, {
|
|
94
|
+
* tags: ['user', 'active'],
|
|
95
|
+
* metadata: { version: 2, source: 'api' }
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
40
98
|
*/
|
|
41
99
|
set<T = unknown>(key: string, value: T, options?: StorageOptions): Promise<void>;
|
|
42
100
|
/**
|
|
43
101
|
* Remove a value from storage
|
|
102
|
+
*
|
|
103
|
+
* @param key - The key to remove
|
|
104
|
+
* @param options - Storage options
|
|
105
|
+
* @param options.storage - Specific storage type to use
|
|
106
|
+
* @throws {StorageError} If the storage adapter is not available
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* // Remove from default storage
|
|
111
|
+
* await storage.remove('myKey');
|
|
112
|
+
*
|
|
113
|
+
* // Remove from specific storage
|
|
114
|
+
* await storage.remove('myKey', { storage: 'cookies' });
|
|
115
|
+
* ```
|
|
44
116
|
*/
|
|
45
117
|
remove(key: string, options?: StorageOptions): Promise<void>;
|
|
46
118
|
/**
|
|
47
|
-
* Check if a key exists
|
|
119
|
+
* Check if a key exists in storage
|
|
120
|
+
*
|
|
121
|
+
* @param key - The key to check
|
|
122
|
+
* @param options - Storage options
|
|
123
|
+
* @param options.storage - Specific storage type to check
|
|
124
|
+
* @returns True if the key exists, false otherwise
|
|
125
|
+
* @throws {StorageError} If the storage adapter is not available
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Check in default storage
|
|
130
|
+
* const exists = await storage.has('myKey');
|
|
131
|
+
*
|
|
132
|
+
* // Check in specific storage
|
|
133
|
+
* const exists = await storage.has('myKey', { storage: 'sessionStorage' });
|
|
134
|
+
* ```
|
|
48
135
|
*/
|
|
49
136
|
has(key: string, options?: StorageOptions): Promise<boolean>;
|
|
50
137
|
/**
|
|
51
138
|
* Clear storage
|
|
139
|
+
*
|
|
140
|
+
* @param options - Clear options
|
|
141
|
+
* @param options.storage - Specific storage to clear (clears all if not specified)
|
|
142
|
+
* @param options.prefix - Only clear keys with this prefix
|
|
143
|
+
* @param options.tags - Only clear items with these tags
|
|
144
|
+
* @param options.olderThan - Only clear items older than this date
|
|
145
|
+
* @throws {StorageError} If the storage adapter is not available
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Clear all storage
|
|
150
|
+
* await storage.clear();
|
|
151
|
+
*
|
|
152
|
+
* // Clear specific storage
|
|
153
|
+
* await storage.clear({ storage: 'localStorage' });
|
|
154
|
+
*
|
|
155
|
+
* // Clear by prefix
|
|
156
|
+
* await storage.clear({ prefix: 'temp-' });
|
|
157
|
+
*
|
|
158
|
+
* // Clear old items
|
|
159
|
+
* const yesterday = Date.now() - 86400000;
|
|
160
|
+
* await storage.clear({ olderThan: yesterday });
|
|
161
|
+
* ```
|
|
52
162
|
*/
|
|
53
163
|
clear(options?: ClearOptions & StorageOptions): Promise<void>;
|
|
54
164
|
/**
|
|
55
|
-
* Get all keys
|
|
165
|
+
* Get all keys from storage
|
|
166
|
+
*
|
|
167
|
+
* @param pattern - Optional pattern to filter keys (string prefix or RegExp)
|
|
168
|
+
* @param options - Storage options
|
|
169
|
+
* @param options.storage - Specific storage to get keys from (gets from all if not specified)
|
|
170
|
+
* @returns Array of matching keys
|
|
171
|
+
* @throws {StorageError} If the storage adapter is not available
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // Get all keys
|
|
176
|
+
* const keys = await storage.keys();
|
|
177
|
+
*
|
|
178
|
+
* // Get keys with prefix
|
|
179
|
+
* const userKeys = await storage.keys('user-');
|
|
180
|
+
*
|
|
181
|
+
* // Get keys with regex pattern
|
|
182
|
+
* const tempKeys = await storage.keys(/^temp-.*$/);
|
|
183
|
+
*
|
|
184
|
+
* // Get keys from specific storage
|
|
185
|
+
* const localKeys = await storage.keys(null, { storage: 'localStorage' });
|
|
186
|
+
* ```
|
|
56
187
|
*/
|
|
57
188
|
keys(pattern?: string | RegExp, options?: StorageOptions): Promise<string[]>;
|
|
58
189
|
/**
|