@unvired/react-native-unvired-sdk 0.0.21 → 0.0.22

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 CHANGED
@@ -1 +1 @@
1
- R-0.000.0021
1
+ R-0.000.0022
@@ -1,4 +1,4 @@
1
- import { IDatabaseAdapter } from './types';
1
+ import { IDatabaseAdapter } from "./types";
2
2
  /**
3
3
  * DatabaseManager - Manages database operations across platforms
4
4
  * - iOS/Android/Windows: Uses @op-engineering/op-sqlite
@@ -1,8 +1,6 @@
1
- import { Platform } from 'react-native';
2
- import { DatabaseNative } from './services/DatabaseNative';
3
- import { DatabaseWeb } from './services/DatabaseWeb';
1
+ import { DatabaseNative } from "./services/DatabaseNative";
4
2
  // Select database implementation based on platform
5
- const dbImpl = Platform.OS === 'web' ? new DatabaseWeb() : new DatabaseNative();
3
+ const dbImpl = new DatabaseNative();
6
4
  /**
7
5
  * DatabaseManager - Manages database operations across platforms
8
6
  * - iOS/Android/Windows: Uses @op-engineering/op-sqlite
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unvired/react-native-unvired-sdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Unvired SDK for React Native with logging, database, notifications, and file system support",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -12,14 +12,14 @@
12
12
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
13
13
  },
14
14
  "peerDependencies": {
15
+ "@op-engineering/op-sqlite": "^15.2.5",
16
+ "@react-native-async-storage/async-storage": "^2.2.0",
17
+ "@react-native-firebase/messaging": "^21.8.1",
15
18
  "react": ">=18",
16
19
  "react-native": ">=0.73",
17
- "react-native-fs": "^2.20.0",
18
20
  "react-native-device-info": "^15.0.1",
19
- "@op-engineering/op-sqlite": "^15.2.5",
20
- "react-native-zip-archive": "^7.0.2",
21
- "@react-native-firebase/messaging": "^21.8.1",
22
- "@react-native-async-storage/async-storage": "^2.2.0"
21
+ "react-native-fs": "^2.20.0",
22
+ "react-native-zip-archive": "^7.0.2"
23
23
  },
24
24
  "peerDependenciesMeta": {
25
25
  "@react-native-firebase/messaging": {
@@ -42,25 +42,23 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "pako": "^2.1.0",
46
- "sql.js": "^1.10.3"
45
+ "pako": "^2.1.0"
47
46
  },
48
47
  "devDependencies": {
49
- "typescript": "^5.0.0",
48
+ "@op-engineering/op-sqlite": "^15.2.5",
49
+ "@react-native-async-storage/async-storage": "^2.2.0",
50
+ "@react-native-firebase/messaging": "^21.8.1",
51
+ "@types/pako": "^2.0.4",
52
+ "@types/react": ">=18",
53
+ "@types/react-native": "^0.73.0",
50
54
  "eslint": "^8.0.0",
51
55
  "jest": "^29.0.0",
52
56
  "prettier": "^3.0.0",
53
- "@types/react": ">=18",
54
- "@types/react-native": "^0.73.0",
55
57
  "react": "19.2.0",
56
58
  "react-native": "0.83.1",
57
- "react-native-fs": "^2.20.0",
58
59
  "react-native-device-info": "^15.0.1",
59
- "@op-engineering/op-sqlite": "^15.2.5",
60
- "@react-native-firebase/messaging": "^21.8.1",
61
- "@react-native-async-storage/async-storage": "^2.2.0",
62
- "@types/pako": "^2.0.4",
63
- "@types/sql.js": "^1.4.9"
60
+ "react-native-fs": "^2.20.0",
61
+ "typescript": "^5.0.0"
64
62
  },
65
63
  "engines": {
66
64
  "node": ">=18"
@@ -68,4 +66,4 @@
68
66
  "publishConfig": {
69
67
  "access": "public"
70
68
  }
71
- }
69
+ }
@@ -1,32 +1,21 @@
1
- import { PlatformInterface, IDeviceInfo, IFileEntry, IDatabaseAdapter, IPushNotificationAdapter, ILoggerAdapter, DatabaseType } from './PlatformInterface';
2
- import { logger, LogLevel } from '../src/logger';
3
- import { RNFileEntry } from '../src/file-system/RNFileEntry';
4
- import { FileSystem } from '../src/file-system/FileSystem';
1
+ import { DeviceInfo, DatabaseManager, LocalStorage, logger, LogLevel, PushNotification, FileSystem } from '@unvired/react-native-unvired-sdk';
2
+ import { PlatformInterface, IDeviceInfo, IFileEntry, IDatabaseAdapter, IPushNotificationAdapter, ILoggerAdapter, IStorageAdapter } from './PlatformInterface';
3
+
5
4
  export class ReactNativePlatformAdapter implements PlatformInterface {
6
5
 
7
- getDeviceInfo(): IDeviceInfo {
8
- // TODO: Implement device info retrieval
9
- return {
10
- platform: 'unknown',
11
- model: '',
12
- version: '',
13
- isMobile: true
14
- };
6
+ async getDeviceInfo(): Promise<IDeviceInfo> {
7
+ return await DeviceInfo.getDeviceInfo();
15
8
  }
16
9
 
17
10
  getPlatform(): string {
18
- // TODO: Implement platform retrieval
19
- return "";
11
+ return DeviceInfo.getPlatform();
20
12
  }
21
13
 
22
14
  getFrontendType(): string {
23
- // TODO: Implement frontend type retrieval
24
- // Refer CordovaPlatformAdapter.ts for reference to return values
25
- return "";
15
+ return DeviceInfo.getFrontendType();
26
16
  }
27
17
 
28
18
  getDocumentDirectory(): string {
29
- // Return the document directory path for React Native
30
19
  return FileSystem.getDocumentDirectory();
31
20
  }
32
21
 
@@ -35,71 +24,66 @@ export class ReactNativePlatformAdapter implements PlatformInterface {
35
24
  }
36
25
 
37
26
  async getFolderBasedOnUserId(userId: string): Promise<string> {
38
- return FileSystem.getFolderBasedOnUserId(userId);
27
+ return await FileSystem.getFolderBasedOnUserId(userId);
39
28
  }
40
29
 
41
30
  async deleteUserFolder(userId: string): Promise<void> {
42
- return FileSystem.deleteUserFolder(userId);
31
+ await FileSystem.deleteUserFolder(userId);
43
32
  }
44
33
 
45
34
  getDatabaseAdapter(): IDatabaseAdapter {
46
- // TODO: Implement database adapter
47
35
  return {
48
- create: (options, successCallback, errorCallback) => {
49
- // TODO: Implement database creation
36
+ create: (options: { userId: string }, successCallback, errorCallback) => {
37
+ // Map userId to dbName or pass appropriate options
38
+ DatabaseManager.getDatabaseAdapter().create({ name: options.userId }, successCallback, errorCallback);
50
39
  },
51
- execute: (options, successCallback, errorCallback) => {
52
- // TODO: Implement SQL execution
40
+ execute: (options: any, successCallback, errorCallback) => {
41
+ DatabaseManager.getDatabaseAdapter().execute(options, successCallback, errorCallback);
53
42
  },
54
43
  executeStatementOnPath: (dbPath, sqlQuery, callback) => {
55
- // TODO: Implement SQL execution on specific path
56
- callback([]);
44
+ DatabaseManager.getDatabaseAdapter().executeStatementOnPath(dbPath, sqlQuery, callback);
57
45
  },
58
46
  selectFromPath: (dbPath, sqlQuery, callback) => {
59
- // TODO: Implement SELECT query
60
- callback([]);
47
+ DatabaseManager.getDatabaseAdapter().selectFromPath(dbPath, sqlQuery, callback);
61
48
  },
62
49
  createDatabase: (dbPath, callback) => {
63
- // TODO: Implement database creation
64
- callback();
50
+ DatabaseManager.getDatabaseAdapter().createDatabase(dbPath, callback);
65
51
  },
66
- getDBFilePath: (options, callback) => {
67
- // TODO: Implement database file path retrieval
68
- callback("");
52
+ getDBFilePath: (options: { dbType: string }, callback) => {
53
+ DatabaseManager.getDatabaseAdapter().getDBFilePath({ name: options.dbType }, callback);
69
54
  },
70
- saveWebDB: (options, callback, errorCallback) => {
71
- // TODO: Implement web database save
72
- callback({});
55
+ saveWebDB: (options: { userId: string }, callback, errorCallback) => {
56
+ const dbName = options.userId;
57
+ const data = (options as any).data || {};
58
+ DatabaseManager.getDatabaseAdapter().saveWebDB({ dbName, data }, callback, errorCallback);
73
59
  },
74
- exportWebDB: (options, callback, errorCallback) => {
75
- // TODO: Implement web database export
76
- callback({});
60
+ exportWebDB: (options: { userId: string }, callback, errorCallback) => {
61
+ DatabaseManager.getDatabaseAdapter().exportWebDB({ dbName: options.userId }, callback, errorCallback);
77
62
  },
78
- deleteUserData: (options, callback, errorCallback) => {
79
- // TODO: Implement user data deletion
80
- callback();
63
+ deleteUserData: (options: { userId: string }, callback, errorCallback) => {
64
+ DatabaseManager.getDatabaseAdapter().deleteUserData({ dbName: options.userId, userId: options.userId }, callback, errorCallback);
81
65
  }
82
66
  };
83
67
  }
84
68
 
85
69
  getPushNotificationAdapter(): IPushNotificationAdapter | null {
86
70
  try {
71
+ const pushNotification = new PushNotification();
87
72
  return {
88
73
  requestPermission: async (options = { forceShow: false }) => {
89
- //TODO: Implement push notification permission request
74
+ await pushNotification.requestPermission(options);
90
75
  },
91
76
  getToken: async () => {
92
- //TODO: Implement push notification token retrieval
93
- return "";
77
+ return await pushNotification.getToken();
94
78
  },
95
79
  onTokenRefresh: (callback) => {
96
- //TODO: Implement push notification token refresh
80
+ pushNotification.onTokenRefresh(callback);
97
81
  },
98
82
  onMessage: (callback) => {
99
- //TODO: Implement push notification message handling
83
+ pushNotification.onMessage(callback);
100
84
  },
101
85
  onBackgroundMessage: (callback) => {
102
- //TODO: Implement push notification background message handling
86
+ pushNotification.onBackgroundMessage(callback);
103
87
  }
104
88
  };
105
89
  } catch (error) {
@@ -110,58 +94,45 @@ export class ReactNativePlatformAdapter implements PlatformInterface {
110
94
  getLoggerAdapter(): ILoggerAdapter {
111
95
  return {
112
96
  logDebug: (sourceClass, method, message) => {
113
- console.log(`[DEBUG] ${sourceClass}.${method}: ${message}`);
114
97
  logger.logDebug(sourceClass, method, message);
115
- // TODO: Implement log file writing
116
98
  },
117
99
  logError: (sourceClass, method, message) => {
118
- console.error(`[ERROR] ${sourceClass}.${method}: ${message}`);
119
100
  logger.logError(sourceClass, method, message);
120
- // TODO: Implement log file writing
121
101
  },
122
102
  logInfo: (sourceClass, method, message) => {
123
- console.info(`[INFO] ${sourceClass}.${method}: ${message}`);
124
103
  logger.logInfo(sourceClass, method, message);
125
- // TODO: Implement log file writing
126
104
  },
127
105
  setLogLevel: (logLevel: LogLevel) => {
128
- // TODO: Implement log level setting
129
- console.log(`Setting log level to: ${logLevel}`);
130
106
  logger.setLogLevel(logLevel);
131
107
  },
132
108
  getLogFileURL: async () => {
133
- // TODO: Implement log file URL retrieval
134
109
  return logger.getLogFileURL();
135
110
  },
136
111
  getLogFileContent: async () => {
137
- // TODO: Implement log file content retrieval
138
112
  return logger.getLogFileContent();
139
113
  },
140
114
  getBackupLogFileContent: async () => {
141
- // TODO: Implement backup log file content retrieval
142
- const content = await logger.getBackupLogFileContent();
143
- return content || '';
115
+ return logger.getBackupLogFileContent();
144
116
  },
145
117
  clearLogFile: async () => {
146
- // TODO: Implement log file clearing
147
118
  logger.clearLogFile();
148
119
  }
149
120
  };
150
121
  }
151
122
 
152
- getStorageAdapter() {
123
+ getStorageAdapter(): IStorageAdapter {
153
124
  return {
154
125
  getItem: (key: string) => {
155
- return null;
126
+ return LocalStorage.getItem(key);
156
127
  },
157
128
  setItem: (key: string, value: string) => {
158
- // Dummy implementation
129
+ return LocalStorage.setItem(key, value);
159
130
  },
160
131
  removeItem: (key: string) => {
161
- // Dummy implementation
132
+ return LocalStorage.removeItem(key);
162
133
  },
163
134
  clear: () => {
164
- // Dummy implementation
135
+ return LocalStorage.clear();
165
136
  }
166
137
  };
167
138
  }
@@ -1,13 +0,0 @@
1
- import { IDatabaseAdapter } from '../types';
2
- /**
3
- * DatabaseWeb - Web database implementation using sql.js
4
- * Uses SQLite compiled to WebAssembly for full SQLite compatibility in browsers
5
- */
6
- export declare class DatabaseWeb {
7
- private databases;
8
- private SQL;
9
- private initSQL;
10
- private getDatabase;
11
- private executeQuery;
12
- getAdapter(): IDatabaseAdapter;
13
- }
@@ -1,138 +0,0 @@
1
- import initSqlJs from 'sql.js';
2
- /**
3
- * DatabaseWeb - Web database implementation using sql.js
4
- * Uses SQLite compiled to WebAssembly for full SQLite compatibility in browsers
5
- */
6
- export class DatabaseWeb {
7
- constructor() {
8
- this.databases = new Map();
9
- this.SQL = null;
10
- }
11
- async initSQL() {
12
- if (!this.SQL) {
13
- this.SQL = await initSqlJs({
14
- locateFile: (file) => `https://sql.js.org/dist/${file}`
15
- });
16
- }
17
- return this.SQL;
18
- }
19
- async getDatabase(name) {
20
- if (this.databases.has(name)) {
21
- return this.databases.get(name);
22
- }
23
- const SQL = await this.initSQL();
24
- const db = new SQL.Database();
25
- this.databases.set(name, db);
26
- return db;
27
- }
28
- executeQuery(db, query, params = []) {
29
- const results = [];
30
- const stmt = db.prepare(query);
31
- stmt.bind(params);
32
- while (stmt.step()) {
33
- const row = stmt.getAsObject();
34
- results.push(row);
35
- }
36
- stmt.free();
37
- return results;
38
- }
39
- getAdapter() {
40
- return {
41
- create: async (options, successCallback, errorCallback) => {
42
- try {
43
- await this.getDatabase(options.name);
44
- successCallback({ success: true, database: options.name });
45
- }
46
- catch (error) {
47
- errorCallback(error instanceof Error ? error.message : String(error));
48
- }
49
- },
50
- execute: async (options, successCallback, errorCallback) => {
51
- try {
52
- const db = await this.getDatabase(options.dbName);
53
- const results = this.executeQuery(db, options.query, options.params);
54
- successCallback(results);
55
- }
56
- catch (error) {
57
- errorCallback(error instanceof Error ? error.message : String(error));
58
- }
59
- },
60
- executeStatementOnPath: async (dbPath, sqlQuery, callback) => {
61
- var _a;
62
- try {
63
- const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
64
- const db = await this.getDatabase(dbName);
65
- const results = this.executeQuery(db, sqlQuery);
66
- callback(results);
67
- }
68
- catch (error) {
69
- callback([]);
70
- }
71
- },
72
- selectFromPath: async (dbPath, sqlQuery, callback) => {
73
- var _a;
74
- try {
75
- const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
76
- const db = await this.getDatabase(dbName);
77
- const results = this.executeQuery(db, sqlQuery);
78
- callback(results);
79
- }
80
- catch (error) {
81
- callback([]);
82
- }
83
- },
84
- createDatabase: async (dbPath, callback) => {
85
- var _a;
86
- try {
87
- const dbName = ((_a = dbPath.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace('.db', '')) || 'default';
88
- await this.getDatabase(dbName);
89
- callback();
90
- }
91
- catch (error) {
92
- callback();
93
- }
94
- },
95
- getDBFilePath: async (options, callback) => {
96
- callback(`sqljs://${options.name}`);
97
- },
98
- saveWebDB: async (options, callback, errorCallback) => {
99
- try {
100
- const db = await this.getDatabase(options.dbName);
101
- if (Array.isArray(options.data)) {
102
- for (const item of options.data) {
103
- if (item.query && item.params) {
104
- db.run(item.query, item.params);
105
- }
106
- }
107
- }
108
- callback({ success: true });
109
- }
110
- catch (error) {
111
- errorCallback(error instanceof Error ? error.message : String(error));
112
- }
113
- },
114
- exportWebDB: async (options, callback, errorCallback) => {
115
- try {
116
- const db = await this.getDatabase(options.dbName);
117
- const tables = this.executeQuery(db, "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'");
118
- callback({ success: true, tables: tables.map(t => t.name) });
119
- }
120
- catch (error) {
121
- errorCallback(error instanceof Error ? error.message : String(error));
122
- }
123
- },
124
- deleteUserData: async (options, callback, errorCallback) => {
125
- try {
126
- const db = await this.getDatabase(options.dbName);
127
- const query = options.userId ? 'DELETE FROM user_data WHERE user_id = ?' : 'DELETE FROM user_data';
128
- const params = options.userId ? [options.userId] : [];
129
- db.run(query, params);
130
- callback();
131
- }
132
- catch (error) {
133
- errorCallback(error instanceof Error ? error.message : String(error));
134
- }
135
- }
136
- };
137
- }
138
- }