react-native-unvired-sdk
v1.0.13
Published
Unvired SDK for React Native with logging, database, notifications, and file system support
Maintainers
Readme
React Native Unvired SDK
A comprehensive SDK for React Native applications with support for logging, database operations, notifications, and file system management.
Installation
npm install react-native-unvired-sdk
# or
yarn add react-native-unvired-sdkOptional Dependencies
The logger works out of the box with zero dependencies. For additional features, install the packages you need:
# For file operations
npm install react-native-fs
# For database (choose one)
npm install react-native-sqlite-storage # SQL database
npm install @react-native-async-storage/async-storage # Simple key-value
# For notifications
npm install @notifee/react-nativeSee NPM_PACKAGES.md for detailed package information and implementation guide.
Features
- 📝 Logger - Comprehensive logging with multiple log levels ✅ No dependencies
- 💾 Database - Database operations and data persistence ⚠️ Requires optional package
- 🔔 Notifications - Push and local notification management ⚠️ Requires optional package
- 📁 File System - File read/write and management operations ⚠️ Requires optional package
- 🔌 PlatformInterface - Compatible with PlatformInterface pattern for cross-platform logging
Usage
Basic Initialization
import UnviredSDK, { LogLevel } from 'react-native-unvired-sdk';
// Initialize the SDK with all modules
await UnviredSDK.initialize({
logLevel: LogLevel.DEBUG,
tag: 'MyApp',
database: {
// Database configuration
},
notifications: {
// Notification configuration
},
fileSystem: {
basePath: '/path/to/files'
}
});Using the Logger
import { logger, LogLevel } from 'react-native-unvired-sdk';
// Set log level
logger.setLogLevel(LogLevel.DEBUG);
// Log messages
logger.debug('Debug message');
logger.info('Info message');
logger.warn('Warning message');
logger.error('Error message');
// Create child logger for specific modules
const childLogger = logger.createChild('FeatureModule');
childLogger.info('This is from a child logger');Using PlatformInterface Pattern
import { logger } from 'react-native-unvired-sdk';
// Use with className and methodName (PlatformInterface compatible)
logger.logInfo('UserService', 'login', 'User login attempt');
logger.logError('UserService', 'login', 'Login failed');
logger.logDebug('UserService', 'fetchProfile', 'Fetching user profile');
// Set log level (accepts string)
logger.setLogLevel('DEBUG');
// File-based logging
const logs = await logger.getLogFileContent();
const backupLogs = await logger.getBackupLogFileContent();
await logger.clearLogFile();Database Operations
import { database } from 'react-native-unvired-sdk';
// Initialize database (if not done in SDK initialization)
await database.initialize({ /* config */ });
// Insert or update data
await database.upsert('users', {
id: 1,
name: 'John Doe',
email: '[email protected]'
});
// Query data
const users = await database.query('users', {
where: { active: true }
});
// Delete data
await database.delete('users', { id: 1 });
// Execute transaction
await database.transaction(async (db) => {
await db.upsert('users', userData);
await db.upsert('profiles', profileData);
});
// Clear all data
await database.clear();
// Close database
await database.close();Notifications
import { notificationManager } from 'react-native-unvired-sdk';
// Initialize notifications (if not done in SDK initialization)
await notificationManager.initialize({ /* config */ });
// Request permissions
const granted = await notificationManager.requestPermissions();
// Show a notification
await notificationManager.showNotification({
title: 'Hello',
body: 'This is a notification',
data: { customData: 'value' }
});
// Schedule a notification
const notificationId = await notificationManager.scheduleNotification(
{
title: 'Reminder',
body: 'Don\'t forget!'
},
new Date(Date.now() + 3600000) // 1 hour from now
);
// Cancel a notification
await notificationManager.cancelNotification(notificationId);
// Listen for notification events
const unsubscribe = notificationManager.on('onNotificationReceived', (notification) => {
console.log('Notification received:', notification);
});
// Set badge count
await notificationManager.setBadgeCount(5);
// Get badge count
const count = await notificationManager.getBadgeCount();File System Operations
import { fileManager } from 'react-native-unvired-sdk';
// Initialize file manager (if not done in SDK initialization)
await fileManager.initialize({ basePath: '/path/to/files' });
// Read a file
const content = await fileManager.readFile('data.txt');
// Write to a file
await fileManager.writeFile('data.txt', 'Hello World');
// Append to a file
await fileManager.appendFile('log.txt', 'New log entry\n');
// Check if file exists
const exists = await fileManager.exists('data.txt');
// Delete a file
await fileManager.deleteFile('old-file.txt');
// Create directory
await fileManager.createDirectory('my-folder');
// List files in directory
const files = await fileManager.listFiles('my-folder');
// Copy file
await fileManager.copyFile('source.txt', 'destination.txt');
// Move file
await fileManager.moveFile('old-location.txt', 'new-location.txt');
// Download file
await fileManager.downloadFile(
'https://example.com/file.pdf',
'downloads/file.pdf',
(progress) => console.log(`Downloaded: ${progress}%`)
);
// Upload file
await fileManager.uploadFile(
'local-file.jpg',
'https://example.com/upload',
{ headers: { 'Authorization': 'Bearer token' } },
(progress) => console.log(`Uploaded: ${progress}%`)
);
// Get file info
const info = await fileManager.getFileInfo('data.txt');
console.log(info.size, info.modifiedTime);SDK Shutdown
// Properly shutdown SDK and cleanup resources
await UnviredSDK.shutdown();API Reference
Log Levels
LogLevel.DEBUG- Detailed debugging informationLogLevel.INFO- General informational messagesLogLevel.WARN- Warning messagesLogLevel.ERROR- Error messagesLogLevel.NONE- Disable all logging
Logger Methods
logger.debug(message, ...args)- Log debug messagelogger.info(message, ...args)- Log info messagelogger.warn(message, ...args)- Log warning messagelogger.error(message, ...args)- Log error messagelogger.setLogLevel(level)- Set minimum log levellogger.setTag(tag)- Set custom taglogger.createChild(childTag)- Create child logger with custom tag
Database Methods
database.initialize(config)- Initialize databasedatabase.upsert(table, data)- Insert or update datadatabase.query(table, query)- Query datadatabase.delete(table, query)- Delete datadatabase.transaction(callback)- Execute transactiondatabase.clear()- Clear all datadatabase.close()- Close database connection
Notification Methods
notificationManager.initialize(config)- Initialize notificationsnotificationManager.requestPermissions()- Request notification permissionsnotificationManager.showNotification(notification)- Show notificationnotificationManager.scheduleNotification(notification, time)- Schedule notificationnotificationManager.cancelNotification(id)- Cancel notificationnotificationManager.cancelAllNotifications()- Cancel all notificationsnotificationManager.on(event, handler)- Register event handlernotificationManager.setBadgeCount(count)- Set badge countnotificationManager.getBadgeCount()- Get badge count
File System Methods
fileManager.initialize(config)- Initialize file managerfileManager.readFile(path, encoding)- Read filefileManager.writeFile(path, content, encoding)- Write filefileManager.appendFile(path, content, encoding)- Append to filefileManager.deleteFile(path)- Delete filefileManager.exists(path)- Check if file existsfileManager.createDirectory(path)- Create directoryfileManager.listFiles(path)- List files in directoryfileManager.copyFile(source, dest)- Copy filefileManager.moveFile(source, dest)- Move filefileManager.downloadFile(url, path, onProgress)- Download filefileManager.uploadFile(path, url, options, onProgress)- Upload filefileManager.getFileInfo(path)- Get file information
Development
# Install dependencies
npm install
# Run tests
npm test
# Lint code
npm run lint
# Format code
npm run formatArchitecture
The SDK is organized into modular components:
src/
├── logger/ # Logging utilities
├── database/ # Database operations
├── notifications/ # Notification management
├── fileSystem/ # File system operations
└── index.js # Main SDK entry pointEach module can be initialized independently or as part of the main SDK initialization.
License
MIT
