@unvired/react-native-unvired-sdk 0.0.12 → 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/{Logger.js → index.js} +1 -4
- 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 +14 -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
package/README.md
CHANGED
|
@@ -1,348 +1,977 @@
|
|
|
1
|
-
# React Native
|
|
1
|
+
# Unvired React Native SDK
|
|
2
2
|
|
|
3
|
-
A comprehensive SDK for React Native applications
|
|
3
|
+
A comprehensive, production-ready SDK for React Native applications providing logging, database, storage, file system, device info, and push notification capabilities.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@unvired/react-native-unvired-sdk)
|
|
6
|
+
[](LICENSE)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 📋 Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Architecture](#architecture)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick Start](#quick-start)
|
|
16
|
+
- [Modules](#modules)
|
|
17
|
+
- [Documentation](#documentation)
|
|
18
|
+
- [Requirements](#requirements)
|
|
19
|
+
- [License](#license)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ✨ Features
|
|
24
|
+
|
|
25
|
+
- 📝 **Advanced Logging** - File persistence, compression, rotation, and multiple log levels
|
|
26
|
+
- 💾 **SQLite Database** - Both low-level and high-level ORM-like APIs
|
|
27
|
+
- 🗄️ **Local Storage** - AsyncStorage wrapper with automatic JSON serialization
|
|
28
|
+
- 📁 **File System** - Comprehensive file and directory operations
|
|
29
|
+
- 📱 **Device Info** - Platform detection and device information
|
|
30
|
+
- 🔔 **Push Notifications** - Firebase Cloud Messaging integration
|
|
31
|
+
- 🔌 **Platform Adapter** - Unified interface for all platform-specific functionality
|
|
32
|
+
- 🎯 **TypeScript First** - Full type safety and IntelliSense support
|
|
33
|
+
- 🏗️ **Modular Architecture** - Use individual modules or the complete platform adapter
|
|
34
|
+
- 🚀 **Production Ready** - Battle-tested and optimized for performance
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🏗️ Architecture
|
|
39
|
+
|
|
40
|
+
### Module Structure
|
|
41
|
+
|
|
42
|
+
The SDK follows a clean, modular architecture where each module is independent and can be used separately or through the unified platform adapter.
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
src/
|
|
46
|
+
├── main.ts # SDK Entry Point
|
|
47
|
+
│
|
|
48
|
+
├── logger/ # Logger Module
|
|
49
|
+
│ ├── index.ts # Module exports
|
|
50
|
+
│ ├── BaseLogger.ts # Core logging logic
|
|
51
|
+
│ ├── Logger.types.ts # Type definitions
|
|
52
|
+
│ └── services/ # Platform-specific implementations
|
|
53
|
+
│ ├── LoggerNative.ts
|
|
54
|
+
│ ├── LoggerWeb.ts
|
|
55
|
+
│ └── LoggerWindows.ts
|
|
56
|
+
│
|
|
57
|
+
├── database/ # Database Module
|
|
58
|
+
│ ├── index.ts # Module exports
|
|
59
|
+
│ ├── DatabaseManager.ts # Low-level adapter
|
|
60
|
+
│ ├── Database.ts # High-level ORM
|
|
61
|
+
│ └── types.ts # Type definitions
|
|
62
|
+
│
|
|
63
|
+
├── local-storage/ # Local Storage Module
|
|
64
|
+
│ ├── index.ts # Module exports
|
|
65
|
+
│ └── localStorage.ts # AsyncStorage wrapper
|
|
66
|
+
│
|
|
67
|
+
├── device-info/ # Device Info Module
|
|
68
|
+
│ ├── index.ts # Module exports
|
|
69
|
+
│ ├── DeviceInfo.ts # Main class
|
|
70
|
+
│ ├── BaseDeviceInfo.ts # Core implementation
|
|
71
|
+
│ └── DeviceInfo.types.ts # Type definitions
|
|
72
|
+
│
|
|
73
|
+
├── file-system/ # File System Module
|
|
74
|
+
│ ├── index.ts # Module exports
|
|
75
|
+
│ ├── FileSystem.ts # Main class
|
|
76
|
+
│ ├── BaseFileSystem.ts # Core implementation
|
|
77
|
+
│ └── FileSystem.types.ts # Type definitions
|
|
78
|
+
│
|
|
79
|
+
├── push-notification/ # Push Notification Module
|
|
80
|
+
│ ├── index.ts # Module exports
|
|
81
|
+
│ ├── PushNotification.ts # Main class
|
|
82
|
+
│ ├── BasePushNotification.ts # Core implementation
|
|
83
|
+
│ └── PushNotification.types.ts # Type definitions
|
|
84
|
+
│
|
|
85
|
+
└── platform/ # Platform Adapter Module
|
|
86
|
+
├── index.ts # Module exports
|
|
87
|
+
├── Platform.ts # Main adapter
|
|
88
|
+
├── BasePlatform.ts # Core implementation
|
|
89
|
+
└── Platform.types.ts # Type definitions
|
|
11
90
|
```
|
|
12
91
|
|
|
13
|
-
###
|
|
92
|
+
### Connection Flow
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
@unvired/react-native-unvired-sdk
|
|
96
|
+
↓
|
|
97
|
+
src/main.ts (Entry Point)
|
|
98
|
+
↓
|
|
99
|
+
┌───────┴───────┬───────────┬──────────┬────────────┬─────────────┬──────────┐
|
|
100
|
+
↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
101
|
+
logger/ database/ local- device- file- push- platform/
|
|
102
|
+
index.ts index.ts storage/ info/ system/ notification/ index.ts
|
|
103
|
+
index.ts index.ts index.ts index.ts
|
|
104
|
+
```
|
|
14
105
|
|
|
15
|
-
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 📦 Installation
|
|
109
|
+
|
|
110
|
+
### Install the SDK
|
|
16
111
|
|
|
17
112
|
```bash
|
|
18
|
-
|
|
19
|
-
|
|
113
|
+
npm install @unvired/react-native-unvired-sdk
|
|
114
|
+
```
|
|
20
115
|
|
|
21
|
-
|
|
22
|
-
npm install react-native-sqlite-storage # SQL database
|
|
23
|
-
npm install @react-native-async-storage/async-storage # Simple key-value
|
|
116
|
+
### Install Peer Dependencies
|
|
24
117
|
|
|
25
|
-
|
|
26
|
-
npm install @
|
|
118
|
+
```bash
|
|
119
|
+
npm install react-native-device-info @dr.pogodin/react-native-fs react-native-sqlite-storage @react-native-async-storage/async-storage
|
|
27
120
|
```
|
|
28
121
|
|
|
29
|
-
|
|
122
|
+
### Optional: Push Notifications
|
|
30
123
|
|
|
31
|
-
|
|
124
|
+
```bash
|
|
125
|
+
npm install @react-native-firebase/app @react-native-firebase/messaging
|
|
126
|
+
```
|
|
32
127
|
|
|
33
|
-
|
|
34
|
-
- `Cannot read property 'RNFSFileTypeRegular' of null`
|
|
35
|
-
- `Cannot read property 'PlatformManager' of undefined`
|
|
36
|
-
- Native module linking issues
|
|
128
|
+
### Platform Setup
|
|
37
129
|
|
|
38
|
-
|
|
130
|
+
#### iOS
|
|
131
|
+
```bash
|
|
132
|
+
cd ios && pod install
|
|
133
|
+
```
|
|
39
134
|
|
|
40
|
-
|
|
135
|
+
#### Android
|
|
136
|
+
Ensure your `android/build.gradle` has the required repositories.
|
|
41
137
|
|
|
42
|
-
|
|
138
|
+
---
|
|
43
139
|
|
|
44
|
-
|
|
45
|
-
>
|
|
46
|
-
> If you're upgrading from an older version, see [MIGRATION_GUIDE.md](./MIGRATION_GUIDE.md) for step-by-step instructions.
|
|
140
|
+
## 🚀 Quick Start
|
|
47
141
|
|
|
48
|
-
|
|
142
|
+
### Option 1: Use Individual Modules (Recommended)
|
|
49
143
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
basePath: '/path/to/files'
|
|
75
|
-
}
|
|
144
|
+
```typescript
|
|
145
|
+
import {
|
|
146
|
+
logger,
|
|
147
|
+
LocalStorage,
|
|
148
|
+
createDatabase,
|
|
149
|
+
DeviceInfo,
|
|
150
|
+
FileSystem,
|
|
151
|
+
PushNotification
|
|
152
|
+
} from '@unvired/react-native-unvired-sdk';
|
|
153
|
+
|
|
154
|
+
// Logger
|
|
155
|
+
logger.setLogLevel('DEBUG');
|
|
156
|
+
logger.logInfo('App', 'init', 'Application started');
|
|
157
|
+
|
|
158
|
+
// Local Storage
|
|
159
|
+
await LocalStorage.setItem('user', { name: 'John', age: 30 });
|
|
160
|
+
const user = await LocalStorage.getItem('user');
|
|
161
|
+
|
|
162
|
+
// Database
|
|
163
|
+
const db = createDatabase('myapp');
|
|
164
|
+
await db.createTable('users', {
|
|
165
|
+
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
|
|
166
|
+
name: 'TEXT NOT NULL',
|
|
167
|
+
email: 'TEXT UNIQUE'
|
|
76
168
|
});
|
|
77
|
-
|
|
169
|
+
await db.insert('users', { name: 'John', email: 'john@example.com' });
|
|
78
170
|
|
|
79
|
-
|
|
171
|
+
// Device Info
|
|
172
|
+
const platform = DeviceInfo.getPlatform(); // 'ios' or 'android'
|
|
173
|
+
const deviceInfo = DeviceInfo.getDeviceInfoSync();
|
|
80
174
|
|
|
81
|
-
|
|
82
|
-
|
|
175
|
+
// File System
|
|
176
|
+
const docDir = FileSystem.getDocumentDirectory();
|
|
177
|
+
await FileSystem.writeFile(`${docDir}/test.txt`, 'Hello World');
|
|
83
178
|
|
|
84
|
-
//
|
|
85
|
-
|
|
179
|
+
// Push Notifications
|
|
180
|
+
const push = new PushNotification();
|
|
181
|
+
await push.requestPermission();
|
|
182
|
+
const token = await push.getToken();
|
|
183
|
+
```
|
|
86
184
|
|
|
87
|
-
|
|
88
|
-
logger.debug('Debug message');
|
|
89
|
-
logger.info('Info message');
|
|
90
|
-
logger.warn('Warning message');
|
|
91
|
-
logger.error('Error message');
|
|
185
|
+
### Option 2: Use Platform Adapter
|
|
92
186
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
187
|
+
```typescript
|
|
188
|
+
import { getPlatformAdapter } from '@unvired/react-native-unvired-sdk';
|
|
189
|
+
|
|
190
|
+
const platform = getPlatformAdapter();
|
|
191
|
+
|
|
192
|
+
// All modules accessible through platform adapter
|
|
193
|
+
const logger = platform.getLoggerAdapter();
|
|
194
|
+
const storage = platform.getStorageAdapter();
|
|
195
|
+
const dbAdapter = platform.getDatabaseAdapter();
|
|
196
|
+
const deviceInfo = platform.getDeviceInfo();
|
|
96
197
|
```
|
|
97
198
|
|
|
98
|
-
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 📚 Modules
|
|
99
202
|
|
|
100
|
-
|
|
101
|
-
import { logger } from 'react-native-unvired-sdk';
|
|
203
|
+
### 1. Logger Module
|
|
102
204
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
logger
|
|
205
|
+
Advanced logging with file persistence, compression, and rotation.
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { logger } from '@unvired/react-native-unvired-sdk';
|
|
107
209
|
|
|
108
|
-
// Set log level (accepts string)
|
|
109
210
|
logger.setLogLevel('DEBUG');
|
|
211
|
+
logger.logDebug('MyClass', 'myMethod', 'Debug message');
|
|
212
|
+
logger.logInfo('MyClass', 'myMethod', 'Info message');
|
|
213
|
+
logger.logError('MyClass', 'myMethod', 'Error message');
|
|
110
214
|
|
|
111
|
-
//
|
|
215
|
+
// Get log file content
|
|
112
216
|
const logs = await logger.getLogFileContent();
|
|
113
|
-
const backupLogs = await logger.getBackupLogFileContent();
|
|
114
|
-
await logger.clearLogFile();
|
|
115
217
|
```
|
|
116
218
|
|
|
117
|
-
|
|
219
|
+
**Features:**
|
|
220
|
+
- Multiple log levels (DEBUG, INFO, ERROR)
|
|
221
|
+
- File persistence with automatic rotation
|
|
222
|
+
- Compression (gzip)
|
|
223
|
+
- Async operations
|
|
224
|
+
- Platform-specific implementations
|
|
118
225
|
|
|
119
|
-
|
|
120
|
-
import { database } from 'react-native-unvired-sdk';
|
|
226
|
+
---
|
|
121
227
|
|
|
122
|
-
|
|
123
|
-
await database.initialize({ /* config */ });
|
|
228
|
+
### 2. Database Module
|
|
124
229
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
email: 'john@example.com'
|
|
130
|
-
});
|
|
230
|
+
SQLite database with both low-level and high-level APIs.
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { createDatabase, DatabaseManager } from '@unvired/react-native-unvired-sdk';
|
|
131
234
|
|
|
132
|
-
//
|
|
133
|
-
const
|
|
134
|
-
|
|
235
|
+
// High-level API (recommended)
|
|
236
|
+
const db = createDatabase('myapp');
|
|
237
|
+
await db.createTable('users', {
|
|
238
|
+
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
|
|
239
|
+
name: 'TEXT NOT NULL',
|
|
240
|
+
email: 'TEXT UNIQUE'
|
|
135
241
|
});
|
|
242
|
+
await db.insert('users', { name: 'John', email: 'john@example.com' });
|
|
243
|
+
const users = await db.select('users');
|
|
244
|
+
|
|
245
|
+
// Low-level API
|
|
246
|
+
const adapter = DatabaseManager.getDatabaseAdapter();
|
|
247
|
+
adapter.execute({
|
|
248
|
+
dbName: 'myapp',
|
|
249
|
+
query: 'SELECT * FROM users'
|
|
250
|
+
}, successCallback, errorCallback);
|
|
251
|
+
```
|
|
136
252
|
|
|
137
|
-
|
|
138
|
-
|
|
253
|
+
**Features:**
|
|
254
|
+
- SQLite integration
|
|
255
|
+
- ORM-like interface
|
|
256
|
+
- Transaction support
|
|
257
|
+
- Connection pooling
|
|
258
|
+
- Batch operations
|
|
259
|
+
- Both callback and promise-based APIs
|
|
139
260
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
261
|
+
📚 **[Database Documentation](./DATABASE_USAGE.md)** | **[Quick Reference](./DATABASE_QUICK_REF.md)**
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
### 3. Local Storage Module
|
|
266
|
+
|
|
267
|
+
AsyncStorage wrapper with automatic JSON serialization.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { LocalStorage } from '@unvired/react-native-unvired-sdk';
|
|
271
|
+
|
|
272
|
+
// Store data
|
|
273
|
+
await LocalStorage.setItem('user', { name: 'John', age: 30 });
|
|
274
|
+
|
|
275
|
+
// Retrieve data
|
|
276
|
+
const user = await LocalStorage.getItem<{ name: string; age: number }>('user');
|
|
277
|
+
|
|
278
|
+
// Remove item
|
|
279
|
+
await LocalStorage.removeItem('user');
|
|
280
|
+
|
|
281
|
+
// Clear all
|
|
282
|
+
await LocalStorage.clear();
|
|
283
|
+
|
|
284
|
+
// Batch operations
|
|
285
|
+
await LocalStorage.multiSet([
|
|
286
|
+
['key1', 'value1'],
|
|
287
|
+
['key2', 'value2']
|
|
288
|
+
]);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Features:**
|
|
292
|
+
- Automatic JSON serialization/deserialization
|
|
293
|
+
- TypeScript generics support
|
|
294
|
+
- Batch operations
|
|
295
|
+
- Error handling
|
|
296
|
+
|
|
297
|
+
📚 **[LocalStorage Documentation](./LOCALSTORAGE_USAGE.md)**
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
### 4. Device Info Module
|
|
145
302
|
|
|
146
|
-
|
|
147
|
-
await database.clear();
|
|
303
|
+
Device information and platform detection.
|
|
148
304
|
|
|
149
|
-
|
|
150
|
-
|
|
305
|
+
```typescript
|
|
306
|
+
import { DeviceInfo } from '@unvired/react-native-unvired-sdk';
|
|
307
|
+
|
|
308
|
+
// Synchronous (returns cached data)
|
|
309
|
+
const deviceInfo = DeviceInfo.getDeviceInfoSync();
|
|
310
|
+
console.log(deviceInfo.platform); // 'ios' or 'android'
|
|
311
|
+
console.log(deviceInfo.model); // 'iPhone 14 Pro'
|
|
312
|
+
console.log(deviceInfo.manufacturer); // 'Apple'
|
|
313
|
+
|
|
314
|
+
// Get platform
|
|
315
|
+
const platform = DeviceInfo.getPlatform(); // 'ios' or 'android'
|
|
316
|
+
|
|
317
|
+
// Get frontend type
|
|
318
|
+
const frontendType = DeviceInfo.getFrontendType(); // 'APPLE_PHONE' or 'ANDROID_PHONE'
|
|
319
|
+
|
|
320
|
+
// Async (populates cache)
|
|
321
|
+
await DeviceInfo.getDeviceInfo();
|
|
151
322
|
```
|
|
152
323
|
|
|
153
|
-
|
|
324
|
+
**Features:**
|
|
325
|
+
- Platform detection
|
|
326
|
+
- Device model and manufacturer
|
|
327
|
+
- Unique device ID
|
|
328
|
+
- App version information
|
|
329
|
+
- Tablet detection
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
### 5. File System Module
|
|
334
|
+
|
|
335
|
+
Comprehensive file system operations.
|
|
154
336
|
|
|
155
|
-
```
|
|
156
|
-
import {
|
|
337
|
+
```typescript
|
|
338
|
+
import { FileSystem } from '@unvired/react-native-unvired-sdk';
|
|
339
|
+
|
|
340
|
+
// Get document directory
|
|
341
|
+
const docDir = FileSystem.getDocumentDirectory();
|
|
342
|
+
|
|
343
|
+
// Read/Write files
|
|
344
|
+
const content = await FileSystem.readFile('/path/to/file.txt');
|
|
345
|
+
await FileSystem.writeFile('/path/to/file.txt', 'content');
|
|
346
|
+
|
|
347
|
+
// File operations
|
|
348
|
+
await FileSystem.copyFile(source, destination);
|
|
349
|
+
await FileSystem.moveFile(source, destination);
|
|
350
|
+
await FileSystem.deleteFile('/path/to/file.txt');
|
|
351
|
+
|
|
352
|
+
// Directory operations
|
|
353
|
+
await FileSystem.createDirectory('/path/to/dir');
|
|
354
|
+
const files = await FileSystem.readDir('/path/to/dir');
|
|
355
|
+
|
|
356
|
+
// Check existence
|
|
357
|
+
const exists = await FileSystem.exists('/path/to/file');
|
|
358
|
+
|
|
359
|
+
// User-specific folders
|
|
360
|
+
const userFolder = await FileSystem.getFolderBasedOnUserId('user123');
|
|
361
|
+
await FileSystem.deleteUserFolder('user123');
|
|
362
|
+
```
|
|
157
363
|
|
|
158
|
-
|
|
159
|
-
|
|
364
|
+
**Features:**
|
|
365
|
+
- File read/write operations
|
|
366
|
+
- Directory management
|
|
367
|
+
- File copy/move operations
|
|
368
|
+
- User-specific folder management
|
|
369
|
+
- File existence checks
|
|
370
|
+
- File stats and metadata
|
|
160
371
|
|
|
161
|
-
|
|
162
|
-
const granted = await notificationManager.requestPermissions();
|
|
372
|
+
---
|
|
163
373
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
374
|
+
### 6. Push Notification Module
|
|
375
|
+
|
|
376
|
+
Firebase Cloud Messaging integration.
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import { PushNotification } from '@unvired/react-native-unvired-sdk';
|
|
380
|
+
|
|
381
|
+
const push = new PushNotification();
|
|
382
|
+
|
|
383
|
+
// Request permission
|
|
384
|
+
await push.requestPermission();
|
|
385
|
+
|
|
386
|
+
// Get token
|
|
387
|
+
const token = await push.getToken();
|
|
388
|
+
|
|
389
|
+
// Listen for token refresh
|
|
390
|
+
push.onTokenRefresh((newToken) => {
|
|
391
|
+
console.log('Token refreshed:', newToken);
|
|
169
392
|
});
|
|
170
393
|
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
title: 'Reminder',
|
|
175
|
-
body: 'Don\'t forget!'
|
|
176
|
-
},
|
|
177
|
-
new Date(Date.now() + 3600000) // 1 hour from now
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
// Cancel a notification
|
|
181
|
-
await notificationManager.cancelNotification(notificationId);
|
|
182
|
-
|
|
183
|
-
// Listen for notification events
|
|
184
|
-
const unsubscribe = notificationManager.on('onNotificationReceived', (notification) => {
|
|
185
|
-
console.log('Notification received:', notification);
|
|
394
|
+
// Listen for messages
|
|
395
|
+
push.onMessage((message) => {
|
|
396
|
+
console.log('Foreground message:', message);
|
|
186
397
|
});
|
|
187
398
|
|
|
188
|
-
//
|
|
189
|
-
|
|
399
|
+
// Listen for background messages
|
|
400
|
+
push.onBackgroundMessage((message) => {
|
|
401
|
+
console.log('Background message:', message);
|
|
402
|
+
});
|
|
190
403
|
|
|
191
|
-
//
|
|
192
|
-
|
|
404
|
+
// Subscribe to topics
|
|
405
|
+
await push.subscribeToTopic('news');
|
|
406
|
+
await push.unsubscribeFromTopic('news');
|
|
193
407
|
```
|
|
194
408
|
|
|
195
|
-
|
|
409
|
+
**Features:**
|
|
410
|
+
- FCM integration
|
|
411
|
+
- Permission handling
|
|
412
|
+
- Token management
|
|
413
|
+
- Foreground/background message handling
|
|
414
|
+
- Topic subscription
|
|
415
|
+
- Initial notification handling
|
|
196
416
|
|
|
197
|
-
|
|
198
|
-
import { fileManager } from 'react-native-unvired-sdk';
|
|
417
|
+
---
|
|
199
418
|
|
|
200
|
-
|
|
201
|
-
await fileManager.initialize({ basePath: '/path/to/files' });
|
|
419
|
+
### 7. Platform Adapter Module
|
|
202
420
|
|
|
203
|
-
|
|
204
|
-
const content = await fileManager.readFile('data.txt');
|
|
421
|
+
Unified interface for all platform-specific functionality.
|
|
205
422
|
|
|
206
|
-
|
|
207
|
-
|
|
423
|
+
```typescript
|
|
424
|
+
import { getPlatformAdapter } from '@unvired/react-native-unvired-sdk';
|
|
208
425
|
|
|
209
|
-
|
|
210
|
-
await fileManager.appendFile('log.txt', 'New log entry\n');
|
|
426
|
+
const platform = getPlatformAdapter();
|
|
211
427
|
|
|
212
|
-
//
|
|
213
|
-
const
|
|
428
|
+
// Device info
|
|
429
|
+
const deviceInfo = platform.getDeviceInfo();
|
|
430
|
+
const platformName = platform.getPlatform();
|
|
214
431
|
|
|
215
|
-
//
|
|
216
|
-
|
|
432
|
+
// File system
|
|
433
|
+
const docDir = platform.getDocumentDirectory();
|
|
434
|
+
const userFolder = await platform.getFolderBasedOnUserId('user123');
|
|
217
435
|
|
|
218
|
-
//
|
|
219
|
-
|
|
436
|
+
// Database
|
|
437
|
+
const dbAdapter = platform.getDatabaseAdapter();
|
|
438
|
+
|
|
439
|
+
// Storage
|
|
440
|
+
const storage = platform.getStorageAdapter();
|
|
441
|
+
await storage.setItem('key', 'value');
|
|
442
|
+
|
|
443
|
+
// Logger
|
|
444
|
+
const logger = platform.getLoggerAdapter();
|
|
445
|
+
logger.logInfo('Class', 'method', 'message');
|
|
220
446
|
|
|
221
|
-
//
|
|
222
|
-
const
|
|
447
|
+
// Push notifications
|
|
448
|
+
const pushAdapter = platform.getPushNotificationAdapter();
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**Features:**
|
|
452
|
+
- Unified interface for all modules
|
|
453
|
+
- Consistent API across platforms
|
|
454
|
+
- Easy integration with ts-core-sdk
|
|
455
|
+
- Singleton pattern
|
|
456
|
+
|
|
457
|
+
📚 **[Platform Adapter Documentation](./PLATFORM_USAGE.md)**
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
## 📖 Documentation
|
|
462
|
+
|
|
463
|
+
- **[Platform Adapter Guide](./PLATFORM_USAGE.md)** - Complete platform adapter documentation
|
|
464
|
+
- **[Database Guide](./DATABASE_USAGE.md)** - Database operations and examples
|
|
465
|
+
- **[Database Quick Reference](./DATABASE_QUICK_REF.md)** - Quick reference for database
|
|
466
|
+
- **[LocalStorage Guide](./LOCALSTORAGE_USAGE.md)** - Local storage operations
|
|
467
|
+
- **[Module Connection Map](./MODULE_CONNECTION_MAP.md)** - Architecture and module connections
|
|
468
|
+
- **[How to Use in ts-core-sdk](./HOW_TO_USE_IN_TS_CORE_SDK.md)** - Integration guide
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
## 🎯 TypeScript Support
|
|
473
|
+
|
|
474
|
+
The SDK is fully typed with TypeScript:
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
import type {
|
|
478
|
+
// Platform types
|
|
479
|
+
IPlatformAdapter,
|
|
480
|
+
IDeviceInfo,
|
|
481
|
+
IFileEntry,
|
|
482
|
+
|
|
483
|
+
// Database types
|
|
484
|
+
IDatabaseAdapter,
|
|
485
|
+
DatabaseOptions,
|
|
486
|
+
|
|
487
|
+
// Logger types
|
|
488
|
+
ILoggerAdapter,
|
|
489
|
+
LogLevel,
|
|
490
|
+
|
|
491
|
+
// Storage types
|
|
492
|
+
IStorageAdapter,
|
|
493
|
+
|
|
494
|
+
// Push notification types
|
|
495
|
+
IPushNotificationAdapter
|
|
496
|
+
} from '@unvired/react-native-unvired-sdk';
|
|
497
|
+
```
|
|
223
498
|
|
|
224
|
-
|
|
225
|
-
await fileManager.copyFile('source.txt', 'destination.txt');
|
|
499
|
+
---
|
|
226
500
|
|
|
227
|
-
|
|
228
|
-
await fileManager.moveFile('old-location.txt', 'new-location.txt');
|
|
501
|
+
## 📋 Requirements
|
|
229
502
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
);
|
|
503
|
+
- **React Native** >= 0.60.0
|
|
504
|
+
- **React** >= 16.8.0
|
|
505
|
+
- **iOS** >= 11.0
|
|
506
|
+
- **Android** >= API 21
|
|
507
|
+
- **Node.js** >= 14.0.0
|
|
236
508
|
|
|
237
|
-
|
|
238
|
-
await fileManager.uploadFile(
|
|
239
|
-
'local-file.jpg',
|
|
240
|
-
'https://example.com/upload',
|
|
241
|
-
{ headers: { 'Authorization': 'Bearer token' } },
|
|
242
|
-
(progress) => console.log(`Uploaded: ${progress}%`)
|
|
243
|
-
);
|
|
509
|
+
---
|
|
244
510
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
511
|
+
## 🤝 Contributing
|
|
512
|
+
|
|
513
|
+
This is a private SDK. For issues and questions, please contact Unvired support.
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
## 📄 License
|
|
518
|
+
|
|
519
|
+
UNLICENSED - Private SDK for Unvired applications
|
|
520
|
+
|
|
521
|
+
---
|
|
522
|
+
|
|
523
|
+
## 🆘 Support
|
|
524
|
+
|
|
525
|
+
For support and questions:
|
|
526
|
+
- Check the documentation files in this repository
|
|
527
|
+
- Contact Unvired support team
|
|
528
|
+
|
|
529
|
+
---
|
|
530
|
+
|
|
531
|
+
## 🎉 Summary
|
|
532
|
+
|
|
533
|
+
The Unvired React Native SDK provides:
|
|
534
|
+
|
|
535
|
+
- ✅ **7 Major Modules** - Logger, Database, LocalStorage, DeviceInfo, FileSystem, PushNotification, Platform
|
|
536
|
+
- ✅ **Clean Architecture** - Modular design with consistent patterns
|
|
537
|
+
- ✅ **Full TypeScript** - Complete type safety throughout
|
|
538
|
+
- ✅ **Production Ready** - Battle-tested and optimized
|
|
539
|
+
- ✅ **Comprehensive Docs** - Detailed guides and examples
|
|
540
|
+
- ✅ **Easy Integration** - Works seamlessly with ts-core-sdk
|
|
541
|
+
|
|
542
|
+
**Build powerful React Native applications with confidence!** 🚀
|
|
543
|
+
|
|
544
|
+
Comprehensive SDK for React Native applications providing logging, database, storage, file system, device info, and push notification capabilities.
|
|
545
|
+
|
|
546
|
+
## Features
|
|
547
|
+
|
|
548
|
+
- 📝 **Logger** - Advanced logging with file persistence and compression
|
|
549
|
+
- 💾 **Database** - SQLite database with ORM-like interface
|
|
550
|
+
- 🗄️ **Local Storage** - AsyncStorage wrapper with JSON serialization
|
|
551
|
+
- 📁 **File System** - Comprehensive file system operations
|
|
552
|
+
- 📱 **Device Info** - Device information and platform detection
|
|
553
|
+
- 🔔 **Push Notifications** - Firebase Cloud Messaging integration
|
|
554
|
+
- 🔌 **Platform Adapter** - Unified interface for all platform-specific functionality
|
|
555
|
+
|
|
556
|
+
## Installation
|
|
557
|
+
|
|
558
|
+
```bash
|
|
559
|
+
npm install @unvired/react-native-unvired-sdk
|
|
248
560
|
```
|
|
249
561
|
|
|
250
|
-
###
|
|
562
|
+
### Peer Dependencies
|
|
251
563
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
564
|
+
Install required peer dependencies:
|
|
565
|
+
|
|
566
|
+
```bash
|
|
567
|
+
npm install react-native-device-info @dr.pogodin/react-native-fs react-native-sqlite-storage @react-native-async-storage/async-storage
|
|
255
568
|
```
|
|
256
569
|
|
|
257
|
-
|
|
570
|
+
### Optional Dependencies
|
|
258
571
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
- `LogLevel.DEBUG` - Detailed debugging information
|
|
262
|
-
- `LogLevel.INFO` - General informational messages
|
|
263
|
-
- `LogLevel.WARN` - Warning messages
|
|
264
|
-
- `LogLevel.ERROR` - Error messages
|
|
265
|
-
- `LogLevel.NONE` - Disable all logging
|
|
266
|
-
|
|
267
|
-
### Logger Methods
|
|
268
|
-
|
|
269
|
-
- `logger.debug(message, ...args)` - Log debug message
|
|
270
|
-
- `logger.info(message, ...args)` - Log info message
|
|
271
|
-
- `logger.warn(message, ...args)` - Log warning message
|
|
272
|
-
- `logger.error(message, ...args)` - Log error message
|
|
273
|
-
- `logger.setLogLevel(level)` - Set minimum log level
|
|
274
|
-
- `logger.setTag(tag)` - Set custom tag
|
|
275
|
-
- `logger.createChild(childTag)` - Create child logger with custom tag
|
|
276
|
-
|
|
277
|
-
### Database Methods
|
|
278
|
-
|
|
279
|
-
- `database.initialize(config)` - Initialize database
|
|
280
|
-
- `database.upsert(table, data)` - Insert or update data
|
|
281
|
-
- `database.query(table, query)` - Query data
|
|
282
|
-
- `database.delete(table, query)` - Delete data
|
|
283
|
-
- `database.transaction(callback)` - Execute transaction
|
|
284
|
-
- `database.clear()` - Clear all data
|
|
285
|
-
- `database.close()` - Close database connection
|
|
286
|
-
|
|
287
|
-
### Notification Methods
|
|
288
|
-
|
|
289
|
-
- `notificationManager.initialize(config)` - Initialize notifications
|
|
290
|
-
- `notificationManager.requestPermissions()` - Request notification permissions
|
|
291
|
-
- `notificationManager.showNotification(notification)` - Show notification
|
|
292
|
-
- `notificationManager.scheduleNotification(notification, time)` - Schedule notification
|
|
293
|
-
- `notificationManager.cancelNotification(id)` - Cancel notification
|
|
294
|
-
- `notificationManager.cancelAllNotifications()` - Cancel all notifications
|
|
295
|
-
- `notificationManager.on(event, handler)` - Register event handler
|
|
296
|
-
- `notificationManager.setBadgeCount(count)` - Set badge count
|
|
297
|
-
- `notificationManager.getBadgeCount()` - Get badge count
|
|
298
|
-
|
|
299
|
-
### File System Methods
|
|
300
|
-
|
|
301
|
-
- `fileManager.initialize(config)` - Initialize file manager
|
|
302
|
-
- `fileManager.readFile(path, encoding)` - Read file
|
|
303
|
-
- `fileManager.writeFile(path, content, encoding)` - Write file
|
|
304
|
-
- `fileManager.appendFile(path, content, encoding)` - Append to file
|
|
305
|
-
- `fileManager.deleteFile(path)` - Delete file
|
|
306
|
-
- `fileManager.exists(path)` - Check if file exists
|
|
307
|
-
- `fileManager.createDirectory(path)` - Create directory
|
|
308
|
-
- `fileManager.listFiles(path)` - List files in directory
|
|
309
|
-
- `fileManager.copyFile(source, dest)` - Copy file
|
|
310
|
-
- `fileManager.moveFile(source, dest)` - Move file
|
|
311
|
-
- `fileManager.downloadFile(url, path, onProgress)` - Download file
|
|
312
|
-
- `fileManager.uploadFile(path, url, options, onProgress)` - Upload file
|
|
313
|
-
- `fileManager.getFileInfo(path)` - Get file information
|
|
314
|
-
|
|
315
|
-
## Development
|
|
572
|
+
For push notifications:
|
|
316
573
|
|
|
317
574
|
```bash
|
|
318
|
-
|
|
319
|
-
|
|
575
|
+
npm install @react-native-firebase/app @react-native-firebase/messaging
|
|
576
|
+
```
|
|
320
577
|
|
|
321
|
-
|
|
322
|
-
npm test
|
|
578
|
+
### Platform Setup
|
|
323
579
|
|
|
324
|
-
|
|
325
|
-
npm run lint
|
|
580
|
+
#### iOS
|
|
326
581
|
|
|
327
|
-
|
|
328
|
-
|
|
582
|
+
```bash
|
|
583
|
+
cd ios && pod install
|
|
329
584
|
```
|
|
330
585
|
|
|
331
|
-
|
|
586
|
+
#### Android
|
|
332
587
|
|
|
333
|
-
|
|
588
|
+
Ensure your `android/build.gradle` has the required repositories.
|
|
334
589
|
|
|
590
|
+
## Quick Start
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
import {
|
|
594
|
+
getPlatformAdapter,
|
|
595
|
+
logger,
|
|
596
|
+
LocalStorage,
|
|
597
|
+
createDatabase
|
|
598
|
+
} from '@unvired/react-native-unvired-sdk';
|
|
599
|
+
|
|
600
|
+
// Get platform adapter (recommended)
|
|
601
|
+
const platform = getPlatformAdapter();
|
|
602
|
+
|
|
603
|
+
// Or use individual modules
|
|
604
|
+
logger.logInfo('App', 'init', 'Application started');
|
|
605
|
+
await LocalStorage.setItem('user', { name: 'John' });
|
|
606
|
+
const db = createDatabase('myapp');
|
|
335
607
|
```
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
608
|
+
|
|
609
|
+
## Modules
|
|
610
|
+
|
|
611
|
+
### 1. Platform Adapter (Recommended)
|
|
612
|
+
|
|
613
|
+
Unified interface for all SDK functionality.
|
|
614
|
+
|
|
615
|
+
```typescript
|
|
616
|
+
import { getPlatformAdapter } from '@unvired/react-native-unvired-sdk';
|
|
617
|
+
|
|
618
|
+
const platform = getPlatformAdapter();
|
|
619
|
+
|
|
620
|
+
// Device info
|
|
621
|
+
const deviceInfo = platform.getDeviceInfo();
|
|
622
|
+
|
|
623
|
+
// Logger
|
|
624
|
+
const logger = platform.getLoggerAdapter();
|
|
625
|
+
logger.logInfo('MyClass', 'myMethod', 'Message');
|
|
626
|
+
|
|
627
|
+
// Database
|
|
628
|
+
const dbAdapter = platform.getDatabaseAdapter();
|
|
629
|
+
|
|
630
|
+
// Storage
|
|
631
|
+
const storage = platform.getStorageAdapter();
|
|
632
|
+
await storage.setItem('key', 'value');
|
|
633
|
+
|
|
634
|
+
// File system
|
|
635
|
+
const userFolder = await platform.getFolderBasedOnUserId('user123');
|
|
636
|
+
|
|
637
|
+
// Push notifications
|
|
638
|
+
const pushAdapter = platform.getPushNotificationAdapter();
|
|
342
639
|
```
|
|
343
640
|
|
|
344
|
-
|
|
641
|
+
📚 **[Platform Adapter Documentation](./PLATFORM_USAGE.md)**
|
|
642
|
+
|
|
643
|
+
---
|
|
644
|
+
|
|
645
|
+
### 2. Logger
|
|
646
|
+
|
|
647
|
+
Advanced logging with file persistence, compression, and rotation.
|
|
648
|
+
|
|
649
|
+
```typescript
|
|
650
|
+
import { logger } from '@unvired/react-native-unvired-sdk';
|
|
651
|
+
|
|
652
|
+
logger.setLogLevel('DEBUG');
|
|
653
|
+
logger.logDebug('MyClass', 'myMethod', 'Debug message');
|
|
654
|
+
logger.logInfo('MyClass', 'myMethod', 'Info message');
|
|
655
|
+
logger.logError('MyClass', 'myMethod', 'Error message');
|
|
656
|
+
|
|
657
|
+
// Get log file content
|
|
658
|
+
const logs = await logger.getLogFileContent();
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
**Features:**
|
|
662
|
+
- Multiple log levels (DEBUG, INFO, ERROR)
|
|
663
|
+
- File persistence with rotation
|
|
664
|
+
- Compression (gzip)
|
|
665
|
+
- Async operations
|
|
666
|
+
|
|
667
|
+
---
|
|
668
|
+
|
|
669
|
+
### 3. Database
|
|
670
|
+
|
|
671
|
+
SQLite database with both low-level and high-level APIs.
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
import { createDatabase, DatabaseManager } from '@unvired/react-native-unvired-sdk';
|
|
675
|
+
|
|
676
|
+
// High-level API (recommended)
|
|
677
|
+
const db = createDatabase('myapp');
|
|
678
|
+
|
|
679
|
+
await db.createTable('users', {
|
|
680
|
+
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
|
|
681
|
+
name: 'TEXT NOT NULL',
|
|
682
|
+
email: 'TEXT UNIQUE'
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
await db.insert('users', { name: 'John', email: 'john@example.com' });
|
|
686
|
+
const users = await db.select('users');
|
|
687
|
+
|
|
688
|
+
// Low-level API
|
|
689
|
+
const adapter = DatabaseManager.getDatabaseAdapter();
|
|
690
|
+
adapter.execute({
|
|
691
|
+
dbName: 'myapp',
|
|
692
|
+
query: 'SELECT * FROM users'
|
|
693
|
+
}, successCallback, errorCallback);
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
**Features:**
|
|
697
|
+
- SQLite integration
|
|
698
|
+
- ORM-like interface
|
|
699
|
+
- Transaction support
|
|
700
|
+
- Connection pooling
|
|
701
|
+
- Batch operations
|
|
702
|
+
|
|
703
|
+
📚 **[Database Documentation](./DATABASE_USAGE.md)** | **[Quick Reference](./DATABASE_QUICK_REF.md)**
|
|
704
|
+
|
|
705
|
+
---
|
|
706
|
+
|
|
707
|
+
### 4. Local Storage
|
|
708
|
+
|
|
709
|
+
AsyncStorage wrapper with automatic JSON serialization.
|
|
710
|
+
|
|
711
|
+
```typescript
|
|
712
|
+
import { LocalStorage } from '@unvired/react-native-unvired-sdk';
|
|
713
|
+
|
|
714
|
+
// Store data
|
|
715
|
+
await LocalStorage.setItem('user', { name: 'John', age: 30 });
|
|
716
|
+
|
|
717
|
+
// Retrieve data
|
|
718
|
+
const user = await LocalStorage.getItem<{ name: string; age: number }>('user');
|
|
719
|
+
|
|
720
|
+
// Remove item
|
|
721
|
+
await LocalStorage.removeItem('user');
|
|
722
|
+
|
|
723
|
+
// Clear all
|
|
724
|
+
await LocalStorage.clear();
|
|
725
|
+
|
|
726
|
+
// Batch operations
|
|
727
|
+
await LocalStorage.multiSet([
|
|
728
|
+
['key1', 'value1'],
|
|
729
|
+
['key2', 'value2']
|
|
730
|
+
]);
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**Features:**
|
|
734
|
+
- Automatic JSON serialization/deserialization
|
|
735
|
+
- TypeScript generics support
|
|
736
|
+
- Batch operations
|
|
737
|
+
- Error handling
|
|
738
|
+
|
|
739
|
+
📚 **[LocalStorage Documentation](./LOCALSTORAGE_USAGE.md)**
|
|
740
|
+
|
|
741
|
+
---
|
|
742
|
+
|
|
743
|
+
### 5. File System
|
|
744
|
+
|
|
745
|
+
Comprehensive file system operations.
|
|
746
|
+
|
|
747
|
+
```typescript
|
|
748
|
+
import { FileSystemManager } from '@unvired/react-native-unvired-sdk';
|
|
749
|
+
|
|
750
|
+
// Create directory
|
|
751
|
+
await FileSystemManager.createDirectory('/path/to/dir');
|
|
752
|
+
|
|
753
|
+
// Read/Write files
|
|
754
|
+
const content = await FileSystemManager.readFile('/path/to/file.txt');
|
|
755
|
+
await FileSystemManager.writeFile('/path/to/file.txt', 'content');
|
|
756
|
+
|
|
757
|
+
// File operations
|
|
758
|
+
await FileSystemManager.copyFile(source, destination);
|
|
759
|
+
await FileSystemManager.moveFile(source, destination);
|
|
760
|
+
await FileSystemManager.deleteFile('/path/to/file.txt');
|
|
761
|
+
|
|
762
|
+
// Check existence
|
|
763
|
+
const exists = await FileSystemManager.exists('/path/to/file.txt');
|
|
764
|
+
|
|
765
|
+
// List directory
|
|
766
|
+
const files = await FileSystemManager.readDir('/path/to/dir');
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
---
|
|
770
|
+
|
|
771
|
+
### 6. Device Info
|
|
772
|
+
|
|
773
|
+
Device information and platform detection.
|
|
774
|
+
|
|
775
|
+
```typescript
|
|
776
|
+
import { DeviceInfoManager } from '@unvired/react-native-unvired-sdk';
|
|
777
|
+
|
|
778
|
+
const deviceInfo = await DeviceInfoManager.getDeviceInfo();
|
|
779
|
+
console.log(deviceInfo.platform); // 'ios' or 'android'
|
|
780
|
+
console.log(deviceInfo.model); // 'iPhone 14 Pro'
|
|
781
|
+
console.log(deviceInfo.manufacturer); // 'Apple'
|
|
782
|
+
console.log(deviceInfo.uuid); // Unique device ID
|
|
783
|
+
|
|
784
|
+
const isTablet = await DeviceInfoManager.isTablet();
|
|
785
|
+
const appVersion = await DeviceInfoManager.getAppVersion();
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
---
|
|
789
|
+
|
|
790
|
+
### 7. Push Notifications
|
|
791
|
+
|
|
792
|
+
Firebase Cloud Messaging integration.
|
|
793
|
+
|
|
794
|
+
```typescript
|
|
795
|
+
import { PushNotificationManager } from '@unvired/react-native-unvired-sdk';
|
|
796
|
+
|
|
797
|
+
const pushManager = new PushNotificationManager();
|
|
798
|
+
|
|
799
|
+
// Request permission
|
|
800
|
+
await pushManager.requestPermission();
|
|
801
|
+
|
|
802
|
+
// Get token
|
|
803
|
+
const token = await pushManager.getToken();
|
|
804
|
+
|
|
805
|
+
// Listen for messages
|
|
806
|
+
pushManager.onMessage((message) => {
|
|
807
|
+
console.log('Foreground message:', message);
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
pushManager.onBackgroundMessage((message) => {
|
|
811
|
+
console.log('Background message:', message);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// Subscribe to topics
|
|
815
|
+
await pushManager.subscribeToTopic('news');
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
---
|
|
819
|
+
|
|
820
|
+
## TypeScript Support
|
|
821
|
+
|
|
822
|
+
The SDK is fully typed with TypeScript:
|
|
823
|
+
|
|
824
|
+
```typescript
|
|
825
|
+
import type {
|
|
826
|
+
PlatformInterface,
|
|
827
|
+
IDeviceInfo,
|
|
828
|
+
IFileEntry,
|
|
829
|
+
IDatabaseAdapter,
|
|
830
|
+
IPushNotificationAdapter,
|
|
831
|
+
ILoggerAdapter,
|
|
832
|
+
IStorageAdapter,
|
|
833
|
+
LogLevel
|
|
834
|
+
} from '@unvired/react-native-unvired-sdk';
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
---
|
|
838
|
+
|
|
839
|
+
## Complete Example
|
|
840
|
+
|
|
841
|
+
```typescript
|
|
842
|
+
import React, { useEffect } from 'react';
|
|
843
|
+
import { View, Text } from 'react-native';
|
|
844
|
+
import {
|
|
845
|
+
getPlatformAdapter,
|
|
846
|
+
createDatabase,
|
|
847
|
+
LocalStorage,
|
|
848
|
+
logger
|
|
849
|
+
} from '@unvired/react-native-unvired-sdk';
|
|
850
|
+
|
|
851
|
+
const App = () => {
|
|
852
|
+
useEffect(() => {
|
|
853
|
+
initializeSDK();
|
|
854
|
+
}, []);
|
|
855
|
+
|
|
856
|
+
const initializeSDK = async () => {
|
|
857
|
+
// Initialize logger
|
|
858
|
+
logger.setLogLevel('DEBUG');
|
|
859
|
+
logger.logInfo('App', 'init', 'Initializing SDK');
|
|
860
|
+
|
|
861
|
+
// Get platform adapter
|
|
862
|
+
const platform = getPlatformAdapter();
|
|
863
|
+
const deviceInfo = platform.getDeviceInfo();
|
|
864
|
+
logger.logInfo('App', 'init', `Platform: ${deviceInfo.platform}`);
|
|
865
|
+
|
|
866
|
+
// Initialize database
|
|
867
|
+
const db = createDatabase('myapp');
|
|
868
|
+
await db.createTable('users', {
|
|
869
|
+
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
|
|
870
|
+
name: 'TEXT NOT NULL',
|
|
871
|
+
email: 'TEXT UNIQUE'
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
// Store user preferences
|
|
875
|
+
await LocalStorage.setItem('preferences', {
|
|
876
|
+
theme: 'dark',
|
|
877
|
+
notifications: true
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
// Get user folder
|
|
881
|
+
const userFolder = await platform.getFolderBasedOnUserId('user123');
|
|
882
|
+
logger.logInfo('App', 'init', `User folder: ${userFolder}`);
|
|
883
|
+
|
|
884
|
+
// Initialize push notifications
|
|
885
|
+
const pushAdapter = platform.getPushNotificationAdapter();
|
|
886
|
+
if (pushAdapter) {
|
|
887
|
+
await pushAdapter.requestPermission();
|
|
888
|
+
const token = await pushAdapter.getToken();
|
|
889
|
+
logger.logInfo('App', 'init', `FCM Token: ${token}`);
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
return (
|
|
894
|
+
<View>
|
|
895
|
+
<Text>Unvired SDK Initialized</Text>
|
|
896
|
+
</View>
|
|
897
|
+
);
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
export default App;
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
---
|
|
904
|
+
|
|
905
|
+
## Documentation
|
|
906
|
+
|
|
907
|
+
- **[Platform Adapter Guide](./PLATFORM_USAGE.md)** - Complete platform adapter documentation
|
|
908
|
+
- **[Database Guide](./DATABASE_USAGE.md)** - Database operations and examples
|
|
909
|
+
- **[Database Quick Reference](./DATABASE_QUICK_REF.md)** - Quick reference for database
|
|
910
|
+
- **[LocalStorage Guide](./LOCALSTORAGE_USAGE.md)** - Local storage operations
|
|
911
|
+
|
|
912
|
+
---
|
|
913
|
+
|
|
914
|
+
## API Reference
|
|
915
|
+
|
|
916
|
+
### Exports
|
|
917
|
+
|
|
918
|
+
```typescript
|
|
919
|
+
// Platform
|
|
920
|
+
export { ReactNativePlatformAdapter, getPlatformAdapter, resetPlatformAdapter }
|
|
921
|
+
export { DeviceInfoManager, FileSystemManager, PushNotificationManager }
|
|
922
|
+
|
|
923
|
+
// Logger
|
|
924
|
+
export { Logger, logger }
|
|
925
|
+
|
|
926
|
+
// Database
|
|
927
|
+
export { DatabaseManager, Database, createDatabase }
|
|
928
|
+
|
|
929
|
+
// Storage
|
|
930
|
+
export { LocalStorage }
|
|
931
|
+
|
|
932
|
+
// Types
|
|
933
|
+
export type {
|
|
934
|
+
PlatformInterface,
|
|
935
|
+
IDeviceInfo,
|
|
936
|
+
IFileEntry,
|
|
937
|
+
IDatabaseAdapter,
|
|
938
|
+
IPushNotificationAdapter,
|
|
939
|
+
ILoggerAdapter,
|
|
940
|
+
IStorageAdapter,
|
|
941
|
+
LogLevel,
|
|
942
|
+
DatabaseOptions,
|
|
943
|
+
// ... and more
|
|
944
|
+
}
|
|
945
|
+
```
|
|
946
|
+
|
|
947
|
+
---
|
|
948
|
+
|
|
949
|
+
## Best Practices
|
|
950
|
+
|
|
951
|
+
1. **Use Platform Adapter** - Recommended for accessing all SDK functionality
|
|
952
|
+
2. **Initialize Early** - Initialize SDK in your app's entry point
|
|
953
|
+
3. **Handle Errors** - Always use try-catch for async operations
|
|
954
|
+
4. **TypeScript** - Leverage TypeScript for type safety
|
|
955
|
+
5. **Logging** - Use the logger for consistent logging across your app
|
|
956
|
+
6. **Clean Up** - Properly close database connections and clean up resources
|
|
957
|
+
|
|
958
|
+
---
|
|
959
|
+
|
|
960
|
+
## Requirements
|
|
961
|
+
|
|
962
|
+
- React Native >= 0.60.0
|
|
963
|
+
- React >= 16.8.0
|
|
964
|
+
- iOS >= 11.0
|
|
965
|
+
- Android >= API 21
|
|
966
|
+
|
|
967
|
+
---
|
|
345
968
|
|
|
346
969
|
## License
|
|
347
970
|
|
|
348
|
-
|
|
971
|
+
UNLICENSED
|
|
972
|
+
|
|
973
|
+
---
|
|
974
|
+
|
|
975
|
+
## Support
|
|
976
|
+
|
|
977
|
+
For issues and questions, please refer to the documentation files or contact Unvired support.
|