@unvired/react-native-unvired-sdk
v0.0.14
Published
Unvired SDK for React Native with logging, database, notifications, and file system support
Downloads
972
Readme
Unvired React Native SDK
A comprehensive, production-ready SDK for React Native applications providing logging, database, storage, file system, device info, and push notification capabilities.
📋 Table of Contents
✨ Features
- 📝 Advanced Logging - File persistence, compression, rotation, and multiple log levels
- 💾 SQLite Database - Both low-level and high-level ORM-like APIs
- 🗄️ Local Storage - AsyncStorage wrapper with automatic JSON serialization
- 📁 File System - Comprehensive file and directory operations
- 📱 Device Info - Platform detection and device information
- 🔔 Push Notifications - Firebase Cloud Messaging integration
- 🔌 Platform Adapter - Unified interface for all platform-specific functionality
- 🎯 TypeScript First - Full type safety and IntelliSense support
- 🏗️ Modular Architecture - Use individual modules or the complete platform adapter
- 🚀 Production Ready - Battle-tested and optimized for performance
🏗️ Architecture
Module Structure
The SDK follows a clean, modular architecture where each module is independent and can be used separately or through the unified platform adapter.
src/
├── main.ts # SDK Entry Point
│
├── logger/ # Logger Module
│ ├── index.ts # Module exports
│ ├── BaseLogger.ts # Core logging logic
│ ├── Logger.types.ts # Type definitions
│ └── services/ # Platform-specific implementations
│ ├── LoggerNative.ts
│ ├── LoggerWeb.ts
│ └── LoggerWindows.ts
│
├── database/ # Database Module
│ ├── index.ts # Module exports
│ ├── DatabaseManager.ts # Low-level adapter
│ ├── Database.ts # High-level ORM
│ └── types.ts # Type definitions
│
├── local-storage/ # Local Storage Module
│ ├── index.ts # Module exports
│ └── localStorage.ts # AsyncStorage wrapper
│
├── device-info/ # Device Info Module
│ ├── index.ts # Module exports
│ ├── DeviceInfo.ts # Main class
│ ├── BaseDeviceInfo.ts # Core implementation
│ └── DeviceInfo.types.ts # Type definitions
│
├── file-system/ # File System Module
│ ├── index.ts # Module exports
│ ├── FileSystem.ts # Main class
│ ├── BaseFileSystem.ts # Core implementation
│ └── FileSystem.types.ts # Type definitions
│
├── push-notification/ # Push Notification Module
│ ├── index.ts # Module exports
│ ├── PushNotification.ts # Main class
│ ├── BasePushNotification.ts # Core implementation
│ └── PushNotification.types.ts # Type definitions
│
└── platform/ # Platform Adapter Module
├── index.ts # Module exports
├── Platform.ts # Main adapter
├── BasePlatform.ts # Core implementation
└── Platform.types.ts # Type definitionsConnection Flow
@unvired/react-native-unvired-sdk
↓
src/main.ts (Entry Point)
↓
┌───────┴───────┬───────────┬──────────┬────────────┬─────────────┬──────────┐
↓ ↓ ↓ ↓ ↓ ↓ ↓
logger/ database/ local- device- file- push- platform/
index.ts index.ts storage/ info/ system/ notification/ index.ts
index.ts index.ts index.ts index.ts📦 Installation
Install the SDK
npm install @unvired/react-native-unvired-sdkInstall Peer Dependencies
npm install react-native-device-info @dr.pogodin/react-native-fs react-native-sqlite-storage @react-native-async-storage/async-storageOptional: Push Notifications
npm install @react-native-firebase/app @react-native-firebase/messagingPlatform Setup
iOS
cd ios && pod installAndroid
Ensure your android/build.gradle has the required repositories.
🚀 Quick Start
Option 1: Use Individual Modules (Recommended)
import {
logger,
LocalStorage,
createDatabase,
DeviceInfo,
FileSystem,
PushNotification
} from '@unvired/react-native-unvired-sdk';
// Logger
logger.setLogLevel('DEBUG');
logger.logInfo('App', 'init', 'Application started');
// Local Storage
await LocalStorage.setItem('user', { name: 'John', age: 30 });
const user = await LocalStorage.getItem('user');
// Database
const db = createDatabase('myapp');
await db.createTable('users', {
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
name: 'TEXT NOT NULL',
email: 'TEXT UNIQUE'
});
await db.insert('users', { name: 'John', email: '[email protected]' });
// Device Info
const platform = DeviceInfo.getPlatform(); // 'ios' or 'android'
const deviceInfo = DeviceInfo.getDeviceInfoSync();
// File System
const docDir = FileSystem.getDocumentDirectory();
await FileSystem.writeFile(`${docDir}/test.txt`, 'Hello World');
// Push Notifications
const push = new PushNotification();
await push.requestPermission();
const token = await push.getToken();Option 2: Use Platform Adapter
import { getPlatformAdapter } from '@unvired/react-native-unvired-sdk';
const platform = getPlatformAdapter();
// All modules accessible through platform adapter
const logger = platform.getLoggerAdapter();
const storage = platform.getStorageAdapter();
const dbAdapter = platform.getDatabaseAdapter();
const deviceInfo = platform.getDeviceInfo();📚 Modules
1. Logger Module
Advanced logging with file persistence, compression, and rotation.
import { logger } from '@unvired/react-native-unvired-sdk';
logger.setLogLevel('DEBUG');
logger.logDebug('MyClass', 'myMethod', 'Debug message');
logger.logInfo('MyClass', 'myMethod', 'Info message');
logger.logError('MyClass', 'myMethod', 'Error message');
// Get log file content
const logs = await logger.getLogFileContent();Features:
- Multiple log levels (DEBUG, INFO, ERROR)
- File persistence with automatic rotation
- Compression (gzip)
- Async operations
- Platform-specific implementations
2. Database Module
SQLite database with both low-level and high-level APIs.
import { createDatabase, DatabaseManager } from '@unvired/react-native-unvired-sdk';
// High-level API (recommended)
const db = createDatabase('myapp');
await db.createTable('users', {
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
name: 'TEXT NOT NULL',
email: 'TEXT UNIQUE'
});
await db.insert('users', { name: 'John', email: '[email protected]' });
const users = await db.select('users');
// Low-level API
const adapter = DatabaseManager.getDatabaseAdapter();
adapter.execute({
dbName: 'myapp',
query: 'SELECT * FROM users'
}, successCallback, errorCallback);Features:
- SQLite integration
- ORM-like interface
- Transaction support
- Connection pooling
- Batch operations
- Both callback and promise-based APIs
📚 Database Documentation | Quick Reference
3. Local Storage Module
AsyncStorage wrapper with automatic JSON serialization.
import { LocalStorage } from '@unvired/react-native-unvired-sdk';
// Store data
await LocalStorage.setItem('user', { name: 'John', age: 30 });
// Retrieve data
const user = await LocalStorage.getItem<{ name: string; age: number }>('user');
// Remove item
await LocalStorage.removeItem('user');
// Clear all
await LocalStorage.clear();
// Batch operations
await LocalStorage.multiSet([
['key1', 'value1'],
['key2', 'value2']
]);Features:
- Automatic JSON serialization/deserialization
- TypeScript generics support
- Batch operations
- Error handling
4. Device Info Module
Device information and platform detection.
import { DeviceInfo } from '@unvired/react-native-unvired-sdk';
// Synchronous (returns cached data)
const deviceInfo = DeviceInfo.getDeviceInfoSync();
console.log(deviceInfo.platform); // 'ios' or 'android'
console.log(deviceInfo.model); // 'iPhone 14 Pro'
console.log(deviceInfo.manufacturer); // 'Apple'
// Get platform
const platform = DeviceInfo.getPlatform(); // 'ios' or 'android'
// Get frontend type
const frontendType = DeviceInfo.getFrontendType(); // 'APPLE_PHONE' or 'ANDROID_PHONE'
// Async (populates cache)
await DeviceInfo.getDeviceInfo();Features:
- Platform detection
- Device model and manufacturer
- Unique device ID
- App version information
- Tablet detection
5. File System Module
Comprehensive file system operations.
import { FileSystem } from '@unvired/react-native-unvired-sdk';
// Get document directory
const docDir = FileSystem.getDocumentDirectory();
// Read/Write files
const content = await FileSystem.readFile('/path/to/file.txt');
await FileSystem.writeFile('/path/to/file.txt', 'content');
// File operations
await FileSystem.copyFile(source, destination);
await FileSystem.moveFile(source, destination);
await FileSystem.deleteFile('/path/to/file.txt');
// Directory operations
await FileSystem.createDirectory('/path/to/dir');
const files = await FileSystem.readDir('/path/to/dir');
// Check existence
const exists = await FileSystem.exists('/path/to/file');
// User-specific folders
const userFolder = await FileSystem.getFolderBasedOnUserId('user123');
await FileSystem.deleteUserFolder('user123');Features:
- File read/write operations
- Directory management
- File copy/move operations
- User-specific folder management
- File existence checks
- File stats and metadata
6. Push Notification Module
Firebase Cloud Messaging integration.
import { PushNotification } from '@unvired/react-native-unvired-sdk';
const push = new PushNotification();
// Request permission
await push.requestPermission();
// Get token
const token = await push.getToken();
// Listen for token refresh
push.onTokenRefresh((newToken) => {
console.log('Token refreshed:', newToken);
});
// Listen for messages
push.onMessage((message) => {
console.log('Foreground message:', message);
});
// Listen for background messages
push.onBackgroundMessage((message) => {
console.log('Background message:', message);
});
// Subscribe to topics
await push.subscribeToTopic('news');
await push.unsubscribeFromTopic('news');Features:
- FCM integration
- Permission handling
- Token management
- Foreground/background message handling
- Topic subscription
- Initial notification handling
7. Platform Adapter Module
Unified interface for all platform-specific functionality.
import { getPlatformAdapter } from '@unvired/react-native-unvired-sdk';
const platform = getPlatformAdapter();
// Device info
const deviceInfo = platform.getDeviceInfo();
const platformName = platform.getPlatform();
// File system
const docDir = platform.getDocumentDirectory();
const userFolder = await platform.getFolderBasedOnUserId('user123');
// Database
const dbAdapter = platform.getDatabaseAdapter();
// Storage
const storage = platform.getStorageAdapter();
await storage.setItem('key', 'value');
// Logger
const logger = platform.getLoggerAdapter();
logger.logInfo('Class', 'method', 'message');
// Push notifications
const pushAdapter = platform.getPushNotificationAdapter();Features:
- Unified interface for all modules
- Consistent API across platforms
- Easy integration with ts-core-sdk
- Singleton pattern
📚 Platform Adapter Documentation
📖 Documentation
- Platform Adapter Guide - Complete platform adapter documentation
- Database Guide - Database operations and examples
- Database Quick Reference - Quick reference for database
- LocalStorage Guide - Local storage operations
- Module Connection Map - Architecture and module connections
- How to Use in ts-core-sdk - Integration guide
🎯 TypeScript Support
The SDK is fully typed with TypeScript:
import type {
// Platform types
IPlatformAdapter,
IDeviceInfo,
IFileEntry,
// Database types
IDatabaseAdapter,
DatabaseOptions,
// Logger types
ILoggerAdapter,
LogLevel,
// Storage types
IStorageAdapter,
// Push notification types
IPushNotificationAdapter
} from '@unvired/react-native-unvired-sdk';📋 Requirements
- React Native >= 0.60.0
- React >= 16.8.0
- iOS >= 11.0
- Android >= API 21
- Node.js >= 14.0.0
🤝 Contributing
This is a private SDK. For issues and questions, please contact Unvired support.
📄 License
UNLICENSED - Private SDK for Unvired applications
🆘 Support
For support and questions:
- Check the documentation files in this repository
- Contact Unvired support team
🎉 Summary
The Unvired React Native SDK provides:
- ✅ 7 Major Modules - Logger, Database, LocalStorage, DeviceInfo, FileSystem, PushNotification, Platform
- ✅ Clean Architecture - Modular design with consistent patterns
- ✅ Full TypeScript - Complete type safety throughout
- ✅ Production Ready - Battle-tested and optimized
- ✅ Comprehensive Docs - Detailed guides and examples
- ✅ Easy Integration - Works seamlessly with ts-core-sdk
Build powerful React Native applications with confidence! 🚀
Comprehensive SDK for React Native applications providing logging, database, storage, file system, device info, and push notification capabilities.
Features
- 📝 Logger - Advanced logging with file persistence and compression
- 💾 Database - SQLite database with ORM-like interface
- 🗄️ Local Storage - AsyncStorage wrapper with JSON serialization
- 📁 File System - Comprehensive file system operations
- 📱 Device Info - Device information and platform detection
- 🔔 Push Notifications - Firebase Cloud Messaging integration
- 🔌 Platform Adapter - Unified interface for all platform-specific functionality
Installation
npm install @unvired/react-native-unvired-sdkPeer Dependencies
Install required peer dependencies:
npm install react-native-device-info @dr.pogodin/react-native-fs react-native-sqlite-storage @react-native-async-storage/async-storageOptional Dependencies
For push notifications:
npm install @react-native-firebase/app @react-native-firebase/messagingPlatform Setup
iOS
cd ios && pod installAndroid
Ensure your android/build.gradle has the required repositories.
Quick Start
import {
getPlatformAdapter,
logger,
LocalStorage,
createDatabase
} from '@unvired/react-native-unvired-sdk';
// Get platform adapter (recommended)
const platform = getPlatformAdapter();
// Or use individual modules
logger.logInfo('App', 'init', 'Application started');
await LocalStorage.setItem('user', { name: 'John' });
const db = createDatabase('myapp');Modules
1. Platform Adapter (Recommended)
Unified interface for all SDK functionality.
import { getPlatformAdapter } from '@unvired/react-native-unvired-sdk';
const platform = getPlatformAdapter();
// Device info
const deviceInfo = platform.getDeviceInfo();
// Logger
const logger = platform.getLoggerAdapter();
logger.logInfo('MyClass', 'myMethod', 'Message');
// Database
const dbAdapter = platform.getDatabaseAdapter();
// Storage
const storage = platform.getStorageAdapter();
await storage.setItem('key', 'value');
// File system
const userFolder = await platform.getFolderBasedOnUserId('user123');
// Push notifications
const pushAdapter = platform.getPushNotificationAdapter();📚 Platform Adapter Documentation
2. Logger
Advanced logging with file persistence, compression, and rotation.
import { logger } from '@unvired/react-native-unvired-sdk';
logger.setLogLevel('DEBUG');
logger.logDebug('MyClass', 'myMethod', 'Debug message');
logger.logInfo('MyClass', 'myMethod', 'Info message');
logger.logError('MyClass', 'myMethod', 'Error message');
// Get log file content
const logs = await logger.getLogFileContent();Features:
- Multiple log levels (DEBUG, INFO, ERROR)
- File persistence with rotation
- Compression (gzip)
- Async operations
3. Database
SQLite database with both low-level and high-level APIs.
import { createDatabase, DatabaseManager } from '@unvired/react-native-unvired-sdk';
// High-level API (recommended)
const db = createDatabase('myapp');
await db.createTable('users', {
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
name: 'TEXT NOT NULL',
email: 'TEXT UNIQUE'
});
await db.insert('users', { name: 'John', email: '[email protected]' });
const users = await db.select('users');
// Low-level API
const adapter = DatabaseManager.getDatabaseAdapter();
adapter.execute({
dbName: 'myapp',
query: 'SELECT * FROM users'
}, successCallback, errorCallback);Features:
- SQLite integration
- ORM-like interface
- Transaction support
- Connection pooling
- Batch operations
📚 Database Documentation | Quick Reference
4. Local Storage
AsyncStorage wrapper with automatic JSON serialization.
import { LocalStorage } from '@unvired/react-native-unvired-sdk';
// Store data
await LocalStorage.setItem('user', { name: 'John', age: 30 });
// Retrieve data
const user = await LocalStorage.getItem<{ name: string; age: number }>('user');
// Remove item
await LocalStorage.removeItem('user');
// Clear all
await LocalStorage.clear();
// Batch operations
await LocalStorage.multiSet([
['key1', 'value1'],
['key2', 'value2']
]);Features:
- Automatic JSON serialization/deserialization
- TypeScript generics support
- Batch operations
- Error handling
5. File System
Comprehensive file system operations.
import { FileSystemManager } from '@unvired/react-native-unvired-sdk';
// Create directory
await FileSystemManager.createDirectory('/path/to/dir');
// Read/Write files
const content = await FileSystemManager.readFile('/path/to/file.txt');
await FileSystemManager.writeFile('/path/to/file.txt', 'content');
// File operations
await FileSystemManager.copyFile(source, destination);
await FileSystemManager.moveFile(source, destination);
await FileSystemManager.deleteFile('/path/to/file.txt');
// Check existence
const exists = await FileSystemManager.exists('/path/to/file.txt');
// List directory
const files = await FileSystemManager.readDir('/path/to/dir');6. Device Info
Device information and platform detection.
import { DeviceInfoManager } from '@unvired/react-native-unvired-sdk';
const deviceInfo = await DeviceInfoManager.getDeviceInfo();
console.log(deviceInfo.platform); // 'ios' or 'android'
console.log(deviceInfo.model); // 'iPhone 14 Pro'
console.log(deviceInfo.manufacturer); // 'Apple'
console.log(deviceInfo.uuid); // Unique device ID
const isTablet = await DeviceInfoManager.isTablet();
const appVersion = await DeviceInfoManager.getAppVersion();7. Push Notifications
Firebase Cloud Messaging integration.
import { PushNotificationManager } from '@unvired/react-native-unvired-sdk';
const pushManager = new PushNotificationManager();
// Request permission
await pushManager.requestPermission();
// Get token
const token = await pushManager.getToken();
// Listen for messages
pushManager.onMessage((message) => {
console.log('Foreground message:', message);
});
pushManager.onBackgroundMessage((message) => {
console.log('Background message:', message);
});
// Subscribe to topics
await pushManager.subscribeToTopic('news');TypeScript Support
The SDK is fully typed with TypeScript:
import type {
PlatformInterface,
IDeviceInfo,
IFileEntry,
IDatabaseAdapter,
IPushNotificationAdapter,
ILoggerAdapter,
IStorageAdapter,
LogLevel
} from '@unvired/react-native-unvired-sdk';Complete Example
import React, { useEffect } from 'react';
import { View, Text } from 'react-native';
import {
getPlatformAdapter,
createDatabase,
LocalStorage,
logger
} from '@unvired/react-native-unvired-sdk';
const App = () => {
useEffect(() => {
initializeSDK();
}, []);
const initializeSDK = async () => {
// Initialize logger
logger.setLogLevel('DEBUG');
logger.logInfo('App', 'init', 'Initializing SDK');
// Get platform adapter
const platform = getPlatformAdapter();
const deviceInfo = platform.getDeviceInfo();
logger.logInfo('App', 'init', `Platform: ${deviceInfo.platform}`);
// Initialize database
const db = createDatabase('myapp');
await db.createTable('users', {
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
name: 'TEXT NOT NULL',
email: 'TEXT UNIQUE'
});
// Store user preferences
await LocalStorage.setItem('preferences', {
theme: 'dark',
notifications: true
});
// Get user folder
const userFolder = await platform.getFolderBasedOnUserId('user123');
logger.logInfo('App', 'init', `User folder: ${userFolder}`);
// Initialize push notifications
const pushAdapter = platform.getPushNotificationAdapter();
if (pushAdapter) {
await pushAdapter.requestPermission();
const token = await pushAdapter.getToken();
logger.logInfo('App', 'init', `FCM Token: ${token}`);
}
};
return (
<View>
<Text>Unvired SDK Initialized</Text>
</View>
);
};
export default App;Documentation
- Platform Adapter Guide - Complete platform adapter documentation
- Database Guide - Database operations and examples
- Database Quick Reference - Quick reference for database
- LocalStorage Guide - Local storage operations
API Reference
Exports
// Platform
export { ReactNativePlatformAdapter, getPlatformAdapter, resetPlatformAdapter }
export { DeviceInfoManager, FileSystemManager, PushNotificationManager }
// Logger
export { Logger, logger }
// Database
export { DatabaseManager, Database, createDatabase }
// Storage
export { LocalStorage }
// Types
export type {
PlatformInterface,
IDeviceInfo,
IFileEntry,
IDatabaseAdapter,
IPushNotificationAdapter,
ILoggerAdapter,
IStorageAdapter,
LogLevel,
DatabaseOptions,
// ... and more
}Best Practices
- Use Platform Adapter - Recommended for accessing all SDK functionality
- Initialize Early - Initialize SDK in your app's entry point
- Handle Errors - Always use try-catch for async operations
- TypeScript - Leverage TypeScript for type safety
- Logging - Use the logger for consistent logging across your app
- Clean Up - Properly close database connections and clean up resources
Requirements
- React Native >= 0.60.0
- React >= 16.8.0
- iOS >= 11.0
- Android >= API 21
License
UNLICENSED
Support
For issues and questions, please refer to the documentation files or contact Unvired support.
