@unvired/react-native-unvired-sdk 0.0.32 → 0.0.34
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/dist/database/DatabaseManager.d.ts +1 -1
- package/dist/database/DatabaseManager.js +4 -2
- package/dist/database/services/DatabaseWeb.d.ts +12 -0
- package/dist/database/services/DatabaseWeb.js +237 -0
- package/dist/device-info/BaseDeviceInfo.d.ts +2 -3
- package/dist/device-info/BaseDeviceInfo.js +13 -68
- package/dist/device-info/DeviceInfo.types.d.ts +11 -0
- package/dist/device-info/services/DeviceInfoNative.d.ts +9 -0
- package/dist/device-info/services/DeviceInfoNative.js +83 -0
- package/dist/device-info/services/DeviceInfoWeb.d.ts +12 -0
- package/dist/device-info/services/DeviceInfoWeb.js +54 -0
- package/dist/file-system/services/FileSystemWeb.d.ts +5 -1
- package/dist/file-system/services/FileSystemWeb.js +247 -14
- package/dist/local-storage/services/StorageWeb.js +39 -8
- package/dist/logger/services/LoggerNative.d.ts +1 -1
- package/dist/logger/services/LoggerNative.js +45 -84
- package/dist/logger/services/LoggerWeb.d.ts +5 -2
- package/dist/logger/services/LoggerWeb.js +14 -5
- package/dist/main.js +12 -0
- package/dist/push-notification/BasePushNotification.d.ts +2 -35
- package/dist/push-notification/BasePushNotification.js +18 -150
- package/dist/push-notification/PushNotification.types.d.ts +5 -0
- package/dist/push-notification/services/PushNotificationNative.d.ts +18 -0
- package/dist/push-notification/services/PushNotificationNative.js +130 -0
- package/dist/push-notification/services/PushNotificationWeb.d.ts +21 -0
- package/dist/push-notification/services/PushNotificationWeb.js +69 -0
- package/package.json +7 -5
package/BuildNo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
R-0.000.
|
|
1
|
+
R-0.000.0034
|
|
@@ -2,7 +2,7 @@ import { IDatabaseAdapter } from "./types";
|
|
|
2
2
|
/**
|
|
3
3
|
* DatabaseManager - Manages database operations across platforms
|
|
4
4
|
* - iOS/Android/Windows: Uses @op-engineering/op-sqlite
|
|
5
|
-
* - Web: Uses WebSQL
|
|
5
|
+
* - Web: Uses Browser/WebSQL/IndexedDB/UnviredDB
|
|
6
6
|
*/
|
|
7
7
|
export declare class DatabaseManager {
|
|
8
8
|
/**
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
1
2
|
import { DatabaseNative } from "./services/DatabaseNative";
|
|
3
|
+
import { DatabaseWeb } from "./services/DatabaseWeb";
|
|
2
4
|
// Select database implementation based on platform
|
|
3
|
-
const dbImpl = new DatabaseNative();
|
|
5
|
+
const dbImpl = Platform.OS === "web" ? new DatabaseWeb() : new DatabaseNative();
|
|
4
6
|
/**
|
|
5
7
|
* DatabaseManager - Manages database operations across platforms
|
|
6
8
|
* - iOS/Android/Windows: Uses @op-engineering/op-sqlite
|
|
7
|
-
* - Web: Uses WebSQL
|
|
9
|
+
* - Web: Uses Browser/WebSQL/IndexedDB/UnviredDB
|
|
8
10
|
*/
|
|
9
11
|
export class DatabaseManager {
|
|
10
12
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IDatabaseAdapter } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* DatabaseWeb - SQLite WebAssembly adapter for React Native Web using sql.js
|
|
4
|
+
* Persists SQLite databases to localStorage
|
|
5
|
+
*/
|
|
6
|
+
export declare class DatabaseWeb {
|
|
7
|
+
private databases;
|
|
8
|
+
private defaultLocation;
|
|
9
|
+
private getDatabase;
|
|
10
|
+
private persistDatabase;
|
|
11
|
+
getAdapter(): IDatabaseAdapter;
|
|
12
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import initSqlJs from "sql.js";
|
|
2
|
+
let SQL = null;
|
|
3
|
+
let initPromise = null;
|
|
4
|
+
function getSqlJs() {
|
|
5
|
+
if (!initPromise) {
|
|
6
|
+
initPromise = initSqlJs({
|
|
7
|
+
locateFile: (file) => `https://sql.js.org/dist/${file}`,
|
|
8
|
+
}).then((sql) => {
|
|
9
|
+
SQL = sql;
|
|
10
|
+
return sql;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return initPromise;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* DatabaseWeb - SQLite WebAssembly adapter for React Native Web using sql.js
|
|
17
|
+
* Persists SQLite databases to localStorage
|
|
18
|
+
*/
|
|
19
|
+
export class DatabaseWeb {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.databases = new Map();
|
|
22
|
+
this.defaultLocation = "default";
|
|
23
|
+
}
|
|
24
|
+
async getDatabase(name, location) {
|
|
25
|
+
const dbKey = `${name}_${location || this.defaultLocation}`;
|
|
26
|
+
if (this.databases.has(dbKey)) {
|
|
27
|
+
return this.databases.get(dbKey);
|
|
28
|
+
}
|
|
29
|
+
if (!name) {
|
|
30
|
+
throw new Error("Database name is required");
|
|
31
|
+
}
|
|
32
|
+
const sql = await getSqlJs();
|
|
33
|
+
let db;
|
|
34
|
+
if (typeof localStorage !== "undefined") {
|
|
35
|
+
try {
|
|
36
|
+
const savedData = localStorage.getItem(`__sqlite_${name}`);
|
|
37
|
+
if (savedData) {
|
|
38
|
+
const u8 = new Uint8Array(JSON.parse(savedData));
|
|
39
|
+
db = new sql.Database(u8);
|
|
40
|
+
this.databases.set(dbKey, db);
|
|
41
|
+
return db;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.warn("[DatabaseWeb] Failed to load database from localStorage:", e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
db = new sql.Database();
|
|
49
|
+
this.databases.set(dbKey, db);
|
|
50
|
+
return db;
|
|
51
|
+
}
|
|
52
|
+
persistDatabase(name, location) {
|
|
53
|
+
const dbKey = `${name}_${location || this.defaultLocation}`;
|
|
54
|
+
const db = this.databases.get(dbKey);
|
|
55
|
+
if (db && typeof localStorage !== "undefined") {
|
|
56
|
+
try {
|
|
57
|
+
const data = db.export();
|
|
58
|
+
localStorage.setItem(`__sqlite_${name}`, JSON.stringify(Array.from(data)));
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.warn("[DatabaseWeb] Failed to persist database to localStorage:", e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
getAdapter() {
|
|
66
|
+
return {
|
|
67
|
+
create: async (options, successCallback, errorCallback) => {
|
|
68
|
+
try {
|
|
69
|
+
const dbName = (options.name || options.userId || "default");
|
|
70
|
+
await this.getDatabase(dbName, options.location);
|
|
71
|
+
successCallback({ success: true, database: dbName });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
errorCallback(error instanceof Error ? error.message : String(error));
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
execute: async (options, successCallback, errorCallback) => {
|
|
78
|
+
try {
|
|
79
|
+
const dbName = (options.dbName || options.userId || "default");
|
|
80
|
+
const params = options.params || options.args || [];
|
|
81
|
+
const db = await this.getDatabase(dbName);
|
|
82
|
+
const trimmedQuery = options.query.trim();
|
|
83
|
+
const isSelect = /^SELECT\b/i.test(trimmedQuery);
|
|
84
|
+
let resultToReturn = [];
|
|
85
|
+
if (isSelect) {
|
|
86
|
+
const stmt = db.prepare(options.query);
|
|
87
|
+
if (params && params.length > 0) {
|
|
88
|
+
stmt.bind(params);
|
|
89
|
+
}
|
|
90
|
+
while (stmt.step()) {
|
|
91
|
+
resultToReturn.push(stmt.getAsObject());
|
|
92
|
+
}
|
|
93
|
+
stmt.free();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const stmt = db.prepare(options.query);
|
|
97
|
+
if (params && params.length > 0) {
|
|
98
|
+
stmt.bind(params);
|
|
99
|
+
}
|
|
100
|
+
stmt.step();
|
|
101
|
+
stmt.free();
|
|
102
|
+
let insertId = 0;
|
|
103
|
+
let rowsAffected = 0;
|
|
104
|
+
try {
|
|
105
|
+
const res = db.exec("SELECT last_insert_rowid() as id, changes() as changes;");
|
|
106
|
+
if (res.length > 0 && res[0].values && res[0].values.length > 0) {
|
|
107
|
+
insertId = res[0].values[0][0];
|
|
108
|
+
rowsAffected = res[0].values[0][1];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (e) { }
|
|
112
|
+
resultToReturn.insertId = insertId;
|
|
113
|
+
resultToReturn.rowsAffected = rowsAffected;
|
|
114
|
+
this.persistDatabase(dbName);
|
|
115
|
+
}
|
|
116
|
+
successCallback(resultToReturn);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
errorCallback(error instanceof Error ? error.message : String(error));
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
executeStatementOnPath: async (dbPath, sqlQuery, callback) => {
|
|
123
|
+
var _a;
|
|
124
|
+
try {
|
|
125
|
+
const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
|
|
126
|
+
const db = await this.getDatabase(dbName);
|
|
127
|
+
const stmt = db.prepare(sqlQuery);
|
|
128
|
+
const resultToReturn = [];
|
|
129
|
+
while (stmt.step()) {
|
|
130
|
+
resultToReturn.push(stmt.getAsObject());
|
|
131
|
+
}
|
|
132
|
+
stmt.free();
|
|
133
|
+
let insertId = 0;
|
|
134
|
+
let rowsAffected = 0;
|
|
135
|
+
try {
|
|
136
|
+
const res = db.exec("SELECT last_insert_rowid() as id, changes() as changes;");
|
|
137
|
+
if (res.length > 0 && res[0].values && res[0].values.length > 0) {
|
|
138
|
+
insertId = res[0].values[0][0];
|
|
139
|
+
rowsAffected = res[0].values[0][1];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (e) { }
|
|
143
|
+
resultToReturn.insertId = insertId;
|
|
144
|
+
resultToReturn.rowsAffected = rowsAffected;
|
|
145
|
+
this.persistDatabase(dbName);
|
|
146
|
+
callback(resultToReturn);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
callback([]);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
selectFromPath: async (dbPath, sqlQuery, callback) => {
|
|
153
|
+
var _a;
|
|
154
|
+
try {
|
|
155
|
+
const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
|
|
156
|
+
const db = await this.getDatabase(dbName);
|
|
157
|
+
const stmt = db.prepare(sqlQuery);
|
|
158
|
+
const resultToReturn = [];
|
|
159
|
+
while (stmt.step()) {
|
|
160
|
+
resultToReturn.push(stmt.getAsObject());
|
|
161
|
+
}
|
|
162
|
+
stmt.free();
|
|
163
|
+
callback(resultToReturn);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
callback([]);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
createDatabase: async (dbPath, callback) => {
|
|
170
|
+
var _a;
|
|
171
|
+
try {
|
|
172
|
+
const dbName = ((_a = dbPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.replace(".db", "")) || "default";
|
|
173
|
+
await this.getDatabase(dbName);
|
|
174
|
+
callback();
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
callback();
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
getDBFilePath: async (options, callback) => {
|
|
181
|
+
callback(`${options.name || options.userId || "default"}.db`);
|
|
182
|
+
},
|
|
183
|
+
saveWebDB: async (options, callback, errorCallback) => {
|
|
184
|
+
try {
|
|
185
|
+
const dbName = options.dbName || options.userId || "default";
|
|
186
|
+
const db = await this.getDatabase(dbName);
|
|
187
|
+
const data = db.export();
|
|
188
|
+
if (typeof localStorage !== "undefined") {
|
|
189
|
+
localStorage.setItem(`__sqlite_${dbName}`, JSON.stringify(Array.from(data)));
|
|
190
|
+
}
|
|
191
|
+
callback({ success: true });
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
errorCallback(error instanceof Error ? error.message : String(error));
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
exportWebDB: async (options, callback, errorCallback) => {
|
|
198
|
+
try {
|
|
199
|
+
const dbName = options.dbName || options.userId || "default";
|
|
200
|
+
const db = await this.getDatabase(dbName);
|
|
201
|
+
const data = db.export();
|
|
202
|
+
callback({ success: true, data: Array.from(data) });
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
errorCallback(error instanceof Error ? error.message : String(error));
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
deleteUserData: async (options, callback, errorCallback) => {
|
|
209
|
+
try {
|
|
210
|
+
const dbName = options.dbName || options.userId;
|
|
211
|
+
if (dbName) {
|
|
212
|
+
const dbKey = `${dbName}_${this.defaultLocation}`;
|
|
213
|
+
if (this.databases.has(dbKey)) {
|
|
214
|
+
const db = this.databases.get(dbKey);
|
|
215
|
+
try {
|
|
216
|
+
db === null || db === void 0 ? void 0 : db.close();
|
|
217
|
+
}
|
|
218
|
+
catch (e) { }
|
|
219
|
+
this.databases.delete(dbKey);
|
|
220
|
+
}
|
|
221
|
+
if (typeof localStorage !== "undefined") {
|
|
222
|
+
localStorage.removeItem(`__sqlite_${dbName}`);
|
|
223
|
+
localStorage.removeItem(`__unvired_db_${dbName}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
callback();
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
errorCallback(error instanceof Error ? error.message : String(error));
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
getEncryptionKey: (options, successCallback, errorCallback) => {
|
|
233
|
+
successCallback("");
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { IDeviceInfo } from
|
|
1
|
+
import { IDeviceInfo } from "./DeviceInfo.types";
|
|
2
2
|
/**
|
|
3
3
|
* Base Device Information Class
|
|
4
|
-
* Handles device information retrieval
|
|
4
|
+
* Handles device information retrieval across Native & Web
|
|
5
5
|
*/
|
|
6
6
|
export declare class BaseDeviceInfo {
|
|
7
7
|
private static cachedDeviceInfo;
|
|
8
8
|
/**
|
|
9
9
|
* Get comprehensive device information synchronously
|
|
10
|
-
* Uses synchronous methods from react-native-device-info
|
|
11
10
|
*/
|
|
12
11
|
static getDeviceInfo(): IDeviceInfo;
|
|
13
12
|
/**
|
|
@@ -1,109 +1,54 @@
|
|
|
1
1
|
// BaseDeviceInfo.ts
|
|
2
2
|
// Base device information implementation
|
|
3
|
-
import { Platform } from
|
|
4
|
-
import
|
|
3
|
+
import { Platform } from "react-native";
|
|
4
|
+
import { DeviceInfoNative } from "./services/DeviceInfoNative";
|
|
5
|
+
import { DeviceInfoWeb } from "./services/DeviceInfoWeb";
|
|
6
|
+
const deviceInfoImpl = Platform.OS === "web" ? new DeviceInfoWeb() : new DeviceInfoNative();
|
|
5
7
|
/**
|
|
6
8
|
* Base Device Information Class
|
|
7
|
-
* Handles device information retrieval
|
|
9
|
+
* Handles device information retrieval across Native & Web
|
|
8
10
|
*/
|
|
9
11
|
export class BaseDeviceInfo {
|
|
10
12
|
/**
|
|
11
13
|
* Get comprehensive device information synchronously
|
|
12
|
-
* Uses synchronous methods from react-native-device-info
|
|
13
14
|
*/
|
|
14
15
|
static getDeviceInfo() {
|
|
15
16
|
if (this.cachedDeviceInfo) {
|
|
16
17
|
return this.cachedDeviceInfo;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
platform: Platform.OS,
|
|
22
|
-
model: DeviceInfo.getModel(),
|
|
23
|
-
version: Platform.Version.toString(),
|
|
24
|
-
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
25
|
-
manufacturer: DeviceInfo.getManufacturerSync(),
|
|
26
|
-
uuid: DeviceInfo.getUniqueIdSync(),
|
|
27
|
-
deviceId: DeviceInfo.getUniqueIdSync(),
|
|
28
|
-
deviceName: DeviceInfo.getDeviceNameSync(),
|
|
29
|
-
brand: DeviceInfo.getBrand(),
|
|
30
|
-
deviceType: DeviceInfo.getDeviceType(),
|
|
31
|
-
};
|
|
32
|
-
this.cachedDeviceInfo = deviceInfo;
|
|
33
|
-
return deviceInfo;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error('Error getting device info:', error);
|
|
37
|
-
// Return fallback with synchronous Platform data
|
|
38
|
-
const fallback = {
|
|
39
|
-
platform: Platform.OS,
|
|
40
|
-
model: 'Unknown',
|
|
41
|
-
version: Platform.Version.toString(),
|
|
42
|
-
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
43
|
-
deviceId: 'N/A',
|
|
44
|
-
deviceName: 'N/A',
|
|
45
|
-
brand: 'N/A',
|
|
46
|
-
deviceType: 'N/A',
|
|
47
|
-
};
|
|
48
|
-
this.cachedDeviceInfo = fallback;
|
|
49
|
-
return fallback;
|
|
50
|
-
}
|
|
19
|
+
const info = deviceInfoImpl.getDeviceInfo();
|
|
20
|
+
this.cachedDeviceInfo = info;
|
|
21
|
+
return info;
|
|
51
22
|
}
|
|
52
23
|
/**
|
|
53
24
|
* Get platform name
|
|
54
25
|
*/
|
|
55
26
|
static getPlatform() {
|
|
56
|
-
return
|
|
27
|
+
return deviceInfoImpl.getPlatform();
|
|
57
28
|
}
|
|
58
29
|
/**
|
|
59
30
|
* Get frontend type
|
|
60
31
|
*/
|
|
61
32
|
static getFrontendType() {
|
|
62
|
-
|
|
63
|
-
return 'APPLE_PHONE';
|
|
64
|
-
}
|
|
65
|
-
else if (Platform.OS === 'android') {
|
|
66
|
-
return 'ANDROID_PHONE';
|
|
67
|
-
}
|
|
68
|
-
else if (Platform.OS === 'windows') {
|
|
69
|
-
return 'WINDOWS_PHONE';
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return 'UNKNOWN';
|
|
73
|
-
}
|
|
33
|
+
return deviceInfoImpl.getFrontendType();
|
|
74
34
|
}
|
|
75
35
|
/**
|
|
76
36
|
* Check if device is a tablet
|
|
77
37
|
*/
|
|
78
38
|
static async isTablet() {
|
|
79
|
-
|
|
80
|
-
return await DeviceInfo.isTablet();
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
39
|
+
return await deviceInfoImpl.isTablet();
|
|
85
40
|
}
|
|
86
41
|
/**
|
|
87
42
|
* Get app version
|
|
88
43
|
*/
|
|
89
44
|
static async getAppVersion() {
|
|
90
|
-
|
|
91
|
-
return await DeviceInfo.getVersion();
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
return '1.0.0';
|
|
95
|
-
}
|
|
45
|
+
return await deviceInfoImpl.getAppVersion();
|
|
96
46
|
}
|
|
97
47
|
/**
|
|
98
48
|
* Get build number
|
|
99
49
|
*/
|
|
100
50
|
static async getBuildNumber() {
|
|
101
|
-
|
|
102
|
-
return await DeviceInfo.getBuildNumber();
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
return '1';
|
|
106
|
-
}
|
|
51
|
+
return await deviceInfoImpl.getBuildNumber();
|
|
107
52
|
}
|
|
108
53
|
}
|
|
109
54
|
BaseDeviceInfo.cachedDeviceInfo = null;
|
|
@@ -13,3 +13,14 @@ export interface IDeviceInfo {
|
|
|
13
13
|
brand?: string;
|
|
14
14
|
deviceType?: string;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Device info implementation interface
|
|
18
|
+
*/
|
|
19
|
+
export interface IDeviceInfoImplementation {
|
|
20
|
+
getDeviceInfo(): IDeviceInfo;
|
|
21
|
+
getPlatform(): string;
|
|
22
|
+
getFrontendType(): string;
|
|
23
|
+
isTablet(): Promise<boolean>;
|
|
24
|
+
getAppVersion(): Promise<string>;
|
|
25
|
+
getBuildNumber(): Promise<string>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IDeviceInfo, IDeviceInfoImplementation } from "../DeviceInfo.types";
|
|
2
|
+
export declare class DeviceInfoNative implements IDeviceInfoImplementation {
|
|
3
|
+
getDeviceInfo(): IDeviceInfo;
|
|
4
|
+
getPlatform(): string;
|
|
5
|
+
getFrontendType(): string;
|
|
6
|
+
isTablet(): Promise<boolean>;
|
|
7
|
+
getAppVersion(): Promise<string>;
|
|
8
|
+
getBuildNumber(): Promise<string>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// DeviceInfoNative.ts
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
let RNDeviceInfo = null;
|
|
4
|
+
try {
|
|
5
|
+
RNDeviceInfo = require("react-native-device-info").default || require("react-native-device-info");
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
RNDeviceInfo = null;
|
|
9
|
+
}
|
|
10
|
+
export class DeviceInfoNative {
|
|
11
|
+
getDeviceInfo() {
|
|
12
|
+
try {
|
|
13
|
+
if (RNDeviceInfo) {
|
|
14
|
+
return {
|
|
15
|
+
platform: Platform.OS,
|
|
16
|
+
model: RNDeviceInfo.getModel ? RNDeviceInfo.getModel() : "Unknown",
|
|
17
|
+
version: Platform.Version ? Platform.Version.toString() : "1.0",
|
|
18
|
+
isMobile: Platform.OS === "ios" || Platform.OS === "android",
|
|
19
|
+
manufacturer: RNDeviceInfo.getManufacturerSync ? RNDeviceInfo.getManufacturerSync() : "Unknown",
|
|
20
|
+
uuid: RNDeviceInfo.getUniqueIdSync ? RNDeviceInfo.getUniqueIdSync() : "default-uuid",
|
|
21
|
+
deviceId: RNDeviceInfo.getUniqueIdSync ? RNDeviceInfo.getUniqueIdSync() : "default-id",
|
|
22
|
+
deviceName: RNDeviceInfo.getDeviceNameSync ? RNDeviceInfo.getDeviceNameSync() : "Device",
|
|
23
|
+
brand: RNDeviceInfo.getBrand ? RNDeviceInfo.getBrand() : "Unknown",
|
|
24
|
+
deviceType: RNDeviceInfo.getDeviceType ? RNDeviceInfo.getDeviceType() : "Handset",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.warn("Error getting native device info:", error);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
platform: Platform.OS,
|
|
33
|
+
model: "Unknown",
|
|
34
|
+
version: Platform.Version ? Platform.Version.toString() : "1.0",
|
|
35
|
+
isMobile: Platform.OS === "ios" || Platform.OS === "android",
|
|
36
|
+
deviceId: "N/A",
|
|
37
|
+
deviceName: "N/A",
|
|
38
|
+
brand: "N/A",
|
|
39
|
+
deviceType: "N/A",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
getPlatform() {
|
|
43
|
+
return Platform.OS;
|
|
44
|
+
}
|
|
45
|
+
getFrontendType() {
|
|
46
|
+
if (Platform.OS === "ios") {
|
|
47
|
+
return "APPLE_PHONE";
|
|
48
|
+
}
|
|
49
|
+
else if (Platform.OS === "android") {
|
|
50
|
+
return "ANDROID_PHONE";
|
|
51
|
+
}
|
|
52
|
+
else if (Platform.OS === "windows") {
|
|
53
|
+
return "WINDOWS_PHONE";
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return "UNKNOWN";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async isTablet() {
|
|
60
|
+
try {
|
|
61
|
+
return RNDeviceInfo && RNDeviceInfo.isTablet ? await RNDeviceInfo.isTablet() : false;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async getAppVersion() {
|
|
68
|
+
try {
|
|
69
|
+
return RNDeviceInfo && RNDeviceInfo.getVersion ? await RNDeviceInfo.getVersion() : "1.0.0";
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return "1.0.0";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async getBuildNumber() {
|
|
76
|
+
try {
|
|
77
|
+
return RNDeviceInfo && RNDeviceInfo.getBuildNumber ? await RNDeviceInfo.getBuildNumber() : "1";
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return "1";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IDeviceInfo, IDeviceInfoImplementation } from "../DeviceInfo.types";
|
|
2
|
+
/**
|
|
3
|
+
* DeviceInfoWeb - Browser-native implementation using Navigator & LocalStorage
|
|
4
|
+
*/
|
|
5
|
+
export declare class DeviceInfoWeb implements IDeviceInfoImplementation {
|
|
6
|
+
getDeviceInfo(): IDeviceInfo;
|
|
7
|
+
getPlatform(): string;
|
|
8
|
+
getFrontendType(): string;
|
|
9
|
+
isTablet(): Promise<boolean>;
|
|
10
|
+
getAppVersion(): Promise<string>;
|
|
11
|
+
getBuildNumber(): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function getWebDeviceId() {
|
|
2
|
+
if (typeof localStorage !== "undefined") {
|
|
3
|
+
try {
|
|
4
|
+
let id = localStorage.getItem("__unvired_device_id");
|
|
5
|
+
if (!id) {
|
|
6
|
+
id = "web-" + Math.random().toString(36).substring(2, 15) + "-" + Date.now().toString(36);
|
|
7
|
+
localStorage.setItem("__unvired_device_id", id);
|
|
8
|
+
}
|
|
9
|
+
return id;
|
|
10
|
+
}
|
|
11
|
+
catch (e) { }
|
|
12
|
+
}
|
|
13
|
+
return "web-device-default";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* DeviceInfoWeb - Browser-native implementation using Navigator & LocalStorage
|
|
17
|
+
*/
|
|
18
|
+
export class DeviceInfoWeb {
|
|
19
|
+
getDeviceInfo() {
|
|
20
|
+
const nav = typeof navigator !== "undefined" ? navigator : null;
|
|
21
|
+
const ua = (nav === null || nav === void 0 ? void 0 : nav.userAgent) || "Browser";
|
|
22
|
+
const isMobile = /Mobi|Android|iPhone|iPad|iPod/i.test(ua);
|
|
23
|
+
const isTablet = /iPad|Tablet/i.test(ua);
|
|
24
|
+
const deviceId = getWebDeviceId();
|
|
25
|
+
return {
|
|
26
|
+
platform: "web",
|
|
27
|
+
model: (nav === null || nav === void 0 ? void 0 : nav.userAgent) || "Web Browser",
|
|
28
|
+
version: (nav === null || nav === void 0 ? void 0 : nav.appVersion) || "1.0.0",
|
|
29
|
+
isMobile,
|
|
30
|
+
manufacturer: (nav === null || nav === void 0 ? void 0 : nav.vendor) || "Browser Vendor",
|
|
31
|
+
uuid: deviceId,
|
|
32
|
+
deviceId: deviceId,
|
|
33
|
+
deviceName: (nav === null || nav === void 0 ? void 0 : nav.appName) || "Web Client",
|
|
34
|
+
brand: (nav === null || nav === void 0 ? void 0 : nav.vendor) || "Web",
|
|
35
|
+
deviceType: isTablet ? "Tablet" : isMobile ? "Handset" : "Desktop",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
getPlatform() {
|
|
39
|
+
return "web";
|
|
40
|
+
}
|
|
41
|
+
getFrontendType() {
|
|
42
|
+
return "BROWSER";
|
|
43
|
+
}
|
|
44
|
+
async isTablet() {
|
|
45
|
+
const ua = typeof navigator !== "undefined" ? navigator.userAgent : "";
|
|
46
|
+
return /iPad|Tablet/i.test(ua);
|
|
47
|
+
}
|
|
48
|
+
async getAppVersion() {
|
|
49
|
+
return "1.0.0";
|
|
50
|
+
}
|
|
51
|
+
async getBuildNumber() {
|
|
52
|
+
return "1";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type { IFileEntry, IFileSystem, FileSystemEncoding } from
|
|
1
|
+
import type { IFileEntry, IFileSystem, FileSystemEncoding } from "../FileSystem";
|
|
2
|
+
/**
|
|
3
|
+
* FileSystemWeb - Virtual browser-backed file system with localStorage persistence
|
|
4
|
+
*/
|
|
2
5
|
export declare class FileSystemWeb implements IFileSystem {
|
|
6
|
+
private baseDir;
|
|
3
7
|
getDocumentDirectory(): string;
|
|
4
8
|
resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
|
|
5
9
|
getFolderBasedOnUserId(userId: string): Promise<string>;
|