@unvired/react-native-unvired-sdk 0.0.11 → 0.0.13
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/BuildNo.txt +1 -1
- package/README.md +884 -255
- package/dist/PlatformAdapter.d.ts +57 -0
- package/dist/PlatformAdapter.js +116 -0
- package/dist/database/Database.d.ts +71 -0
- package/dist/database/Database.js +156 -0
- package/dist/database/DatabaseManager.d.ts +32 -0
- package/dist/database/DatabaseManager.js +323 -0
- package/dist/database/index.d.ts +6 -0
- package/dist/database/index.js +5 -0
- package/dist/database/types.d.ts +94 -0
- package/dist/database/types.js +4 -0
- package/dist/device-info/BaseDeviceInfo.d.ts +39 -0
- package/dist/device-info/BaseDeviceInfo.js +116 -0
- package/dist/device-info/DeviceInfo.d.ts +9 -0
- package/dist/device-info/DeviceInfo.js +11 -0
- package/dist/device-info/DeviceInfo.types.d.ts +11 -0
- package/dist/device-info/DeviceInfo.types.js +3 -0
- package/dist/device-info/index.d.ts +3 -0
- package/dist/device-info/index.js +3 -0
- package/dist/file-system/BaseFileSystem.d.ts +60 -0
- package/dist/file-system/BaseFileSystem.js +194 -0
- package/dist/file-system/FileSystem.d.ts +9 -0
- package/dist/file-system/FileSystem.js +11 -0
- package/dist/file-system/FileSystem.types.d.ts +11 -0
- package/dist/file-system/FileSystem.types.js +3 -0
- package/dist/file-system/index.d.ts +3 -0
- package/dist/file-system/index.js +3 -0
- package/dist/local-storage/index.d.ts +1 -0
- package/dist/local-storage/index.js +2 -0
- package/dist/local-storage/localStorage.d.ts +48 -0
- package/dist/local-storage/localStorage.js +123 -0
- package/dist/logger/BaseLogger.js +8 -13
- package/dist/logger/{Logger.js → index.js} +1 -4
- package/dist/logger/services/LoggerNative.js +5 -5
- package/dist/logger/services/LoggerWindows.d.ts +20 -0
- package/dist/logger/services/LoggerWindows.js +225 -0
- package/dist/main.d.ts +13 -0
- package/dist/main.js +28 -0
- package/dist/push-notification/BasePushNotification.d.ts +52 -0
- package/dist/push-notification/BasePushNotification.js +180 -0
- package/dist/push-notification/PushNotification.d.ts +9 -0
- package/dist/push-notification/PushNotification.js +11 -0
- package/dist/push-notification/PushNotification.types.d.ts +12 -0
- package/dist/push-notification/PushNotification.types.js +3 -0
- package/dist/push-notification/index.d.ts +3 -0
- package/dist/push-notification/index.js +3 -0
- package/example/USAGE_EXAMPLE.ts +167 -0
- package/package.json +17 -5
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -4
- /package/dist/logger/{Logger.d.ts → index.d.ts} +0 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import SQLite from 'react-native-sqlite-storage';
|
|
2
|
+
// Enable promise-based API and debug mode
|
|
3
|
+
SQLite.enablePromise(true);
|
|
4
|
+
SQLite.DEBUG(false); // Set to true for debugging
|
|
5
|
+
/**
|
|
6
|
+
* DatabaseManager - Manages SQLite database operations for React Native
|
|
7
|
+
*/
|
|
8
|
+
export class DatabaseManager {
|
|
9
|
+
/**
|
|
10
|
+
* Get or create a database connection
|
|
11
|
+
*/
|
|
12
|
+
static async getDatabase(name, location) {
|
|
13
|
+
const dbKey = `${name}_${location || this.defaultLocation}`;
|
|
14
|
+
if (this.databases.has(dbKey)) {
|
|
15
|
+
return this.databases.get(dbKey);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const dbLocation = (location || this.defaultLocation);
|
|
19
|
+
const db = await SQLite.openDatabase({
|
|
20
|
+
name: name,
|
|
21
|
+
location: dbLocation,
|
|
22
|
+
});
|
|
23
|
+
this.databases.set(dbKey, db);
|
|
24
|
+
return db;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error(`Error opening database ${name}:`, error);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Close a database connection
|
|
33
|
+
*/
|
|
34
|
+
static async closeDatabase(name, location) {
|
|
35
|
+
const dbKey = `${name}_${location || this.defaultLocation}`;
|
|
36
|
+
const db = this.databases.get(dbKey);
|
|
37
|
+
if (db) {
|
|
38
|
+
await db.close();
|
|
39
|
+
this.databases.delete(dbKey);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convert SQLResultSet to array of objects
|
|
44
|
+
*/
|
|
45
|
+
static resultSetToArray(resultSet) {
|
|
46
|
+
const results = [];
|
|
47
|
+
for (let i = 0; i < resultSet.rows.length; i++) {
|
|
48
|
+
results.push(resultSet.rows.item(i));
|
|
49
|
+
}
|
|
50
|
+
return results;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the database adapter implementation
|
|
54
|
+
*/
|
|
55
|
+
static getDatabaseAdapter() {
|
|
56
|
+
return {
|
|
57
|
+
/**
|
|
58
|
+
* Create a new database
|
|
59
|
+
*/
|
|
60
|
+
create: async (options, successCallback, errorCallback) => {
|
|
61
|
+
try {
|
|
62
|
+
const db = await DatabaseManager.getDatabase(options.name, options.location);
|
|
63
|
+
successCallback({ success: true, database: options.name });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
67
|
+
console.error('Error creating database:', errorMsg);
|
|
68
|
+
errorCallback(errorMsg);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Execute a SQL statement
|
|
73
|
+
*/
|
|
74
|
+
execute: async (options, successCallback, errorCallback) => {
|
|
75
|
+
try {
|
|
76
|
+
const db = await DatabaseManager.getDatabase(options.dbName);
|
|
77
|
+
const results = await new Promise((resolve, reject) => {
|
|
78
|
+
db.transaction((tx) => {
|
|
79
|
+
tx.executeSql(options.query, options.params || [], (_, resultSet) => {
|
|
80
|
+
const data = DatabaseManager.resultSetToArray(resultSet);
|
|
81
|
+
resolve(data);
|
|
82
|
+
}, (_, error) => {
|
|
83
|
+
reject(error);
|
|
84
|
+
return false;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
successCallback(results);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
92
|
+
console.error('Error executing SQL:', errorMsg);
|
|
93
|
+
errorCallback(errorMsg);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Execute a SQL statement on a specific database path
|
|
98
|
+
*/
|
|
99
|
+
executeStatementOnPath: async (dbPath, sqlQuery, callback) => {
|
|
100
|
+
var _a;
|
|
101
|
+
try {
|
|
102
|
+
// Extract database name from path
|
|
103
|
+
const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
|
|
104
|
+
const db = await DatabaseManager.getDatabase(dbName);
|
|
105
|
+
const results = await new Promise((resolve, reject) => {
|
|
106
|
+
db.transaction((tx) => {
|
|
107
|
+
tx.executeSql(sqlQuery, [], (_, resultSet) => {
|
|
108
|
+
const data = DatabaseManager.resultSetToArray(resultSet);
|
|
109
|
+
resolve(data);
|
|
110
|
+
}, (_, error) => {
|
|
111
|
+
console.error('Error in executeStatementOnPath:', error);
|
|
112
|
+
resolve([]);
|
|
113
|
+
return false;
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
callback(results);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error('Error executing statement on path:', error);
|
|
121
|
+
callback([]);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* Execute a SELECT query on a specific database path
|
|
126
|
+
*/
|
|
127
|
+
selectFromPath: async (dbPath, sqlQuery, callback) => {
|
|
128
|
+
var _a;
|
|
129
|
+
try {
|
|
130
|
+
const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
|
|
131
|
+
const db = await DatabaseManager.getDatabase(dbName);
|
|
132
|
+
const results = await new Promise((resolve, reject) => {
|
|
133
|
+
db.readTransaction((tx) => {
|
|
134
|
+
tx.executeSql(sqlQuery, [], (_, resultSet) => {
|
|
135
|
+
const data = DatabaseManager.resultSetToArray(resultSet);
|
|
136
|
+
resolve(data);
|
|
137
|
+
}, (_, error) => {
|
|
138
|
+
console.error('Error in selectFromPath:', error);
|
|
139
|
+
resolve([]);
|
|
140
|
+
return false;
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
callback(results);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error('Error selecting from path:', error);
|
|
148
|
+
callback([]);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Create a database at a specific path
|
|
153
|
+
*/
|
|
154
|
+
createDatabase: async (dbPath, callback) => {
|
|
155
|
+
var _a;
|
|
156
|
+
try {
|
|
157
|
+
const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
|
|
158
|
+
await DatabaseManager.getDatabase(dbName);
|
|
159
|
+
callback();
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.error('Error creating database:', error);
|
|
163
|
+
callback();
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Get the file path of a database
|
|
168
|
+
*/
|
|
169
|
+
getDBFilePath: async (options, callback) => {
|
|
170
|
+
try {
|
|
171
|
+
// Return the database name with .db extension
|
|
172
|
+
// The actual path is managed by react-native-sqlite-storage based on the location
|
|
173
|
+
const dbPath = `${options.name}.db`;
|
|
174
|
+
callback(dbPath);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error('Error getting database file path:', error);
|
|
178
|
+
callback('');
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* Save web database data
|
|
183
|
+
*/
|
|
184
|
+
saveWebDB: async (options, callback, errorCallback) => {
|
|
185
|
+
try {
|
|
186
|
+
const db = await DatabaseManager.getDatabase(options.dbName);
|
|
187
|
+
// Convert web DB data to SQLite
|
|
188
|
+
// This is a simplified implementation - adjust based on your data structure
|
|
189
|
+
const data = options.data;
|
|
190
|
+
if (Array.isArray(data)) {
|
|
191
|
+
for (const item of data) {
|
|
192
|
+
if (item.query && item.params) {
|
|
193
|
+
await new Promise((resolve, reject) => {
|
|
194
|
+
db.transaction((tx) => {
|
|
195
|
+
tx.executeSql(item.query, item.params, () => resolve(), (_, error) => {
|
|
196
|
+
reject(error);
|
|
197
|
+
return false;
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
callback({ success: true, message: 'Web DB saved successfully' });
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
208
|
+
console.error('Error saving web DB:', errorMsg);
|
|
209
|
+
errorCallback(errorMsg);
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Export web database
|
|
214
|
+
*/
|
|
215
|
+
exportWebDB: async (options, callback, errorCallback) => {
|
|
216
|
+
try {
|
|
217
|
+
const db = await DatabaseManager.getDatabase(options.dbName);
|
|
218
|
+
// Get all tables
|
|
219
|
+
const tables = await new Promise((resolve, reject) => {
|
|
220
|
+
db.readTransaction((tx) => {
|
|
221
|
+
tx.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'", [], (_, resultSet) => {
|
|
222
|
+
const data = DatabaseManager.resultSetToArray(resultSet);
|
|
223
|
+
resolve(data);
|
|
224
|
+
}, (_, error) => {
|
|
225
|
+
reject(error);
|
|
226
|
+
return false;
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
const exportData = {};
|
|
231
|
+
// Export data from each table
|
|
232
|
+
for (const table of tables) {
|
|
233
|
+
const tableName = table.name;
|
|
234
|
+
const tableData = await new Promise((resolve, reject) => {
|
|
235
|
+
db.readTransaction((tx) => {
|
|
236
|
+
tx.executeSql(`SELECT * FROM ${tableName}`, [], (_, resultSet) => {
|
|
237
|
+
const data = DatabaseManager.resultSetToArray(resultSet);
|
|
238
|
+
resolve(data);
|
|
239
|
+
}, (_, error) => {
|
|
240
|
+
reject(error);
|
|
241
|
+
return false;
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
exportData[tableName] = tableData;
|
|
246
|
+
}
|
|
247
|
+
callback({
|
|
248
|
+
success: true,
|
|
249
|
+
data: exportData,
|
|
250
|
+
tables: tables.map(t => t.name)
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
255
|
+
console.error('Error exporting web DB:', errorMsg);
|
|
256
|
+
errorCallback(errorMsg);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* Delete user data from database
|
|
261
|
+
*/
|
|
262
|
+
deleteUserData: async (options, callback, errorCallback) => {
|
|
263
|
+
try {
|
|
264
|
+
const db = await DatabaseManager.getDatabase(options.dbName);
|
|
265
|
+
if (options.userId) {
|
|
266
|
+
// Delete specific user data
|
|
267
|
+
await new Promise((resolve, reject) => {
|
|
268
|
+
db.transaction((tx) => {
|
|
269
|
+
tx.executeSql('DELETE FROM user_data WHERE user_id = ?', [options.userId], () => resolve(), (_, error) => {
|
|
270
|
+
reject(error);
|
|
271
|
+
return false;
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
// Delete all user data
|
|
278
|
+
await new Promise((resolve, reject) => {
|
|
279
|
+
db.transaction((tx) => {
|
|
280
|
+
tx.executeSql('DELETE FROM user_data', [], () => resolve(), (_, error) => {
|
|
281
|
+
reject(error);
|
|
282
|
+
return false;
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
callback();
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
291
|
+
console.error('Error deleting user data:', errorMsg);
|
|
292
|
+
errorCallback(errorMsg);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Close all database connections
|
|
299
|
+
*/
|
|
300
|
+
static async closeAllDatabases() {
|
|
301
|
+
const closePromises = Array.from(this.databases.values()).map(db => new Promise((resolve) => {
|
|
302
|
+
db.close(() => resolve(), () => resolve());
|
|
303
|
+
}));
|
|
304
|
+
await Promise.all(closePromises);
|
|
305
|
+
this.databases.clear();
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Delete a database
|
|
309
|
+
*/
|
|
310
|
+
static async deleteDatabase(name, location) {
|
|
311
|
+
try {
|
|
312
|
+
await this.closeDatabase(name, location);
|
|
313
|
+
const dbLocation = (location || this.defaultLocation);
|
|
314
|
+
await SQLite.deleteDatabase({ name, location: dbLocation });
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
console.error(`Error deleting database ${name}:`, error);
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
DatabaseManager.databases = new Map();
|
|
323
|
+
DatabaseManager.defaultLocation = 'default';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database module exports
|
|
3
|
+
*/
|
|
4
|
+
export { DatabaseManager } from './DatabaseManager';
|
|
5
|
+
export { Database, createDatabase } from './Database';
|
|
6
|
+
export type { IDatabaseAdapter, DatabaseOptions, ExecuteOptions, SaveWebDBOptions, ExportWebDBOptions, DeleteUserDataOptions, SuccessCallback, ErrorCallback, ResultCallback, SQLResultSet, SQLTransaction, SQLiteDatabase } from './types';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database types and interfaces for the Unvired SDK
|
|
3
|
+
*/
|
|
4
|
+
export interface DatabaseOptions {
|
|
5
|
+
name: string;
|
|
6
|
+
location?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ExecuteOptions {
|
|
9
|
+
dbName: string;
|
|
10
|
+
query: string;
|
|
11
|
+
params?: any[];
|
|
12
|
+
}
|
|
13
|
+
export interface SaveWebDBOptions {
|
|
14
|
+
dbName: string;
|
|
15
|
+
data: any;
|
|
16
|
+
}
|
|
17
|
+
export interface ExportWebDBOptions {
|
|
18
|
+
dbName: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DeleteUserDataOptions {
|
|
21
|
+
dbName: string;
|
|
22
|
+
userId?: string;
|
|
23
|
+
}
|
|
24
|
+
export type SuccessCallback<T = any> = (result: T) => void;
|
|
25
|
+
export type ErrorCallback = (error: Error | string) => void;
|
|
26
|
+
export type ResultCallback<T = any> = (result: T) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Database adapter interface
|
|
29
|
+
*/
|
|
30
|
+
export interface IDatabaseAdapter {
|
|
31
|
+
/**
|
|
32
|
+
* Create a new database
|
|
33
|
+
*/
|
|
34
|
+
create(options: DatabaseOptions, successCallback: SuccessCallback, errorCallback: ErrorCallback): void;
|
|
35
|
+
/**
|
|
36
|
+
* Execute a SQL statement
|
|
37
|
+
*/
|
|
38
|
+
execute(options: ExecuteOptions, successCallback: SuccessCallback<any[]>, errorCallback: ErrorCallback): void;
|
|
39
|
+
/**
|
|
40
|
+
* Execute a SQL statement on a specific database path
|
|
41
|
+
*/
|
|
42
|
+
executeStatementOnPath(dbPath: string, sqlQuery: string, callback: ResultCallback<any[]>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Execute a SELECT query on a specific database path
|
|
45
|
+
*/
|
|
46
|
+
selectFromPath(dbPath: string, sqlQuery: string, callback: ResultCallback<any[]>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Create a database at a specific path
|
|
49
|
+
*/
|
|
50
|
+
createDatabase(dbPath: string, callback: ResultCallback<void>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get the file path of a database
|
|
53
|
+
*/
|
|
54
|
+
getDBFilePath(options: DatabaseOptions, callback: ResultCallback<string>): void;
|
|
55
|
+
/**
|
|
56
|
+
* Save web database data
|
|
57
|
+
*/
|
|
58
|
+
saveWebDB(options: SaveWebDBOptions, callback: ResultCallback<any>, errorCallback: ErrorCallback): void;
|
|
59
|
+
/**
|
|
60
|
+
* Export web database
|
|
61
|
+
*/
|
|
62
|
+
exportWebDB(options: ExportWebDBOptions, callback: ResultCallback<any>, errorCallback: ErrorCallback): void;
|
|
63
|
+
/**
|
|
64
|
+
* Delete user data from database
|
|
65
|
+
*/
|
|
66
|
+
deleteUserData(options: DeleteUserDataOptions, callback: ResultCallback<void>, errorCallback: ErrorCallback): void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* SQL result set interface
|
|
70
|
+
*/
|
|
71
|
+
export interface SQLResultSet {
|
|
72
|
+
insertId?: number;
|
|
73
|
+
rowsAffected: number;
|
|
74
|
+
rows: {
|
|
75
|
+
length: number;
|
|
76
|
+
item: (index: number) => any;
|
|
77
|
+
raw: () => any[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Transaction interface
|
|
82
|
+
*/
|
|
83
|
+
export interface SQLTransaction {
|
|
84
|
+
executeSql(sqlStatement: string, args?: any[], callback?: (transaction: SQLTransaction, resultSet: SQLResultSet) => void, errorCallback?: (transaction: SQLTransaction, error: Error) => boolean): void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Database connection interface
|
|
88
|
+
*/
|
|
89
|
+
export interface SQLiteDatabase {
|
|
90
|
+
transaction(callback: (transaction: SQLTransaction) => void, errorCallback?: (error: Error) => void, successCallback?: () => void): void;
|
|
91
|
+
readTransaction(callback: (transaction: SQLTransaction) => void, errorCallback?: (error: Error) => void, successCallback?: () => void): void;
|
|
92
|
+
executeSql(statement: string, params?: any[], success?: (results: any) => void, error?: (error: Error) => void): void;
|
|
93
|
+
close(success?: () => void, error?: (error: Error) => void): void;
|
|
94
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IDeviceInfo } from './DeviceInfo.types';
|
|
2
|
+
/**
|
|
3
|
+
* Base Device Information Class
|
|
4
|
+
* Handles device information retrieval for React Native
|
|
5
|
+
*/
|
|
6
|
+
export declare class BaseDeviceInfo {
|
|
7
|
+
private static cachedDeviceInfo;
|
|
8
|
+
/**
|
|
9
|
+
* Get comprehensive device information (async)
|
|
10
|
+
* Call this once during app initialization to populate cache
|
|
11
|
+
*/
|
|
12
|
+
static getDeviceInfo(): Promise<IDeviceInfo>;
|
|
13
|
+
/**
|
|
14
|
+
* Get device information synchronously (returns cached data)
|
|
15
|
+
* Returns loading state if not yet initialized
|
|
16
|
+
* Call getDeviceInfo() first to populate cache
|
|
17
|
+
*/
|
|
18
|
+
static getDeviceInfoSync(): IDeviceInfo;
|
|
19
|
+
/**
|
|
20
|
+
* Get platform name
|
|
21
|
+
*/
|
|
22
|
+
static getPlatform(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get frontend type
|
|
25
|
+
*/
|
|
26
|
+
static getFrontendType(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Check if device is a tablet
|
|
29
|
+
*/
|
|
30
|
+
static isTablet(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Get app version
|
|
33
|
+
*/
|
|
34
|
+
static getAppVersion(): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Get build number
|
|
37
|
+
*/
|
|
38
|
+
static getBuildNumber(): Promise<string>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// BaseDeviceInfo.ts
|
|
2
|
+
// Base device information implementation
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import DeviceInfo from 'react-native-device-info';
|
|
5
|
+
/**
|
|
6
|
+
* Base Device Information Class
|
|
7
|
+
* Handles device information retrieval for React Native
|
|
8
|
+
*/
|
|
9
|
+
export class BaseDeviceInfo {
|
|
10
|
+
/**
|
|
11
|
+
* Get comprehensive device information (async)
|
|
12
|
+
* Call this once during app initialization to populate cache
|
|
13
|
+
*/
|
|
14
|
+
static async getDeviceInfo() {
|
|
15
|
+
if (this.cachedDeviceInfo) {
|
|
16
|
+
return this.cachedDeviceInfo;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const deviceInfo = {
|
|
20
|
+
platform: Platform.OS,
|
|
21
|
+
model: await DeviceInfo.getModel(),
|
|
22
|
+
version: Platform.Version.toString(),
|
|
23
|
+
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
24
|
+
manufacturer: await DeviceInfo.getManufacturer(),
|
|
25
|
+
uuid: await DeviceInfo.getUniqueId(),
|
|
26
|
+
};
|
|
27
|
+
this.cachedDeviceInfo = deviceInfo;
|
|
28
|
+
return deviceInfo;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error('Error getting device info:', error);
|
|
32
|
+
const fallback = {
|
|
33
|
+
platform: Platform.OS,
|
|
34
|
+
model: 'Unknown',
|
|
35
|
+
version: Platform.Version.toString(),
|
|
36
|
+
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
37
|
+
};
|
|
38
|
+
this.cachedDeviceInfo = fallback;
|
|
39
|
+
return fallback;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get device information synchronously (returns cached data)
|
|
44
|
+
* Returns loading state if not yet initialized
|
|
45
|
+
* Call getDeviceInfo() first to populate cache
|
|
46
|
+
*/
|
|
47
|
+
static getDeviceInfoSync() {
|
|
48
|
+
if (this.cachedDeviceInfo) {
|
|
49
|
+
return this.cachedDeviceInfo;
|
|
50
|
+
}
|
|
51
|
+
// Return immediate fallback while async initialization happens
|
|
52
|
+
return {
|
|
53
|
+
platform: Platform.OS,
|
|
54
|
+
model: 'Loading...',
|
|
55
|
+
version: Platform.Version.toString(),
|
|
56
|
+
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get platform name
|
|
61
|
+
*/
|
|
62
|
+
static getPlatform() {
|
|
63
|
+
return Platform.OS;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get frontend type
|
|
67
|
+
*/
|
|
68
|
+
static getFrontendType() {
|
|
69
|
+
if (Platform.OS === 'ios') {
|
|
70
|
+
return 'APPLE_PHONE';
|
|
71
|
+
}
|
|
72
|
+
else if (Platform.OS === 'android') {
|
|
73
|
+
return 'ANDROID_PHONE';
|
|
74
|
+
}
|
|
75
|
+
else if (Platform.OS === 'windows') {
|
|
76
|
+
return 'WINDOWS_PHONE';
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return 'UNKNOWN';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if device is a tablet
|
|
84
|
+
*/
|
|
85
|
+
static async isTablet() {
|
|
86
|
+
try {
|
|
87
|
+
return await DeviceInfo.isTablet();
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get app version
|
|
95
|
+
*/
|
|
96
|
+
static async getAppVersion() {
|
|
97
|
+
try {
|
|
98
|
+
return await DeviceInfo.getVersion();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return '1.0.0';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get build number
|
|
106
|
+
*/
|
|
107
|
+
static async getBuildNumber() {
|
|
108
|
+
try {
|
|
109
|
+
return await DeviceInfo.getBuildNumber();
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return '1';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
BaseDeviceInfo.cachedDeviceInfo = null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// DeviceInfo.ts
|
|
2
|
+
// Main device info export
|
|
3
|
+
import { BaseDeviceInfo } from './BaseDeviceInfo';
|
|
4
|
+
/**
|
|
5
|
+
* DeviceInfo class
|
|
6
|
+
* Extends BaseDeviceInfo
|
|
7
|
+
*/
|
|
8
|
+
export class DeviceInfo extends BaseDeviceInfo {
|
|
9
|
+
}
|
|
10
|
+
// Default export
|
|
11
|
+
export default DeviceInfo;
|