@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.
Files changed (48) hide show
  1. package/BuildNo.txt +1 -1
  2. package/README.md +884 -255
  3. package/dist/PlatformAdapter.d.ts +57 -0
  4. package/dist/PlatformAdapter.js +116 -0
  5. package/dist/database/Database.d.ts +71 -0
  6. package/dist/database/Database.js +156 -0
  7. package/dist/database/DatabaseManager.d.ts +32 -0
  8. package/dist/database/DatabaseManager.js +323 -0
  9. package/dist/database/index.d.ts +6 -0
  10. package/dist/database/index.js +5 -0
  11. package/dist/database/types.d.ts +94 -0
  12. package/dist/database/types.js +4 -0
  13. package/dist/device-info/BaseDeviceInfo.d.ts +39 -0
  14. package/dist/device-info/BaseDeviceInfo.js +116 -0
  15. package/dist/device-info/DeviceInfo.d.ts +9 -0
  16. package/dist/device-info/DeviceInfo.js +11 -0
  17. package/dist/device-info/DeviceInfo.types.d.ts +11 -0
  18. package/dist/device-info/DeviceInfo.types.js +3 -0
  19. package/dist/device-info/index.d.ts +3 -0
  20. package/dist/device-info/index.js +3 -0
  21. package/dist/file-system/BaseFileSystem.d.ts +60 -0
  22. package/dist/file-system/BaseFileSystem.js +194 -0
  23. package/dist/file-system/FileSystem.d.ts +9 -0
  24. package/dist/file-system/FileSystem.js +11 -0
  25. package/dist/file-system/FileSystem.types.d.ts +11 -0
  26. package/dist/file-system/FileSystem.types.js +3 -0
  27. package/dist/file-system/index.d.ts +3 -0
  28. package/dist/file-system/index.js +3 -0
  29. package/dist/local-storage/index.d.ts +1 -0
  30. package/dist/local-storage/index.js +2 -0
  31. package/dist/local-storage/localStorage.d.ts +48 -0
  32. package/dist/local-storage/localStorage.js +123 -0
  33. package/dist/logger/{Logger.js → index.js} +1 -4
  34. package/dist/main.d.ts +13 -0
  35. package/dist/main.js +28 -0
  36. package/dist/push-notification/BasePushNotification.d.ts +52 -0
  37. package/dist/push-notification/BasePushNotification.js +180 -0
  38. package/dist/push-notification/PushNotification.d.ts +9 -0
  39. package/dist/push-notification/PushNotification.js +11 -0
  40. package/dist/push-notification/PushNotification.types.d.ts +12 -0
  41. package/dist/push-notification/PushNotification.types.js +3 -0
  42. package/dist/push-notification/index.d.ts +3 -0
  43. package/dist/push-notification/index.js +3 -0
  44. package/example/USAGE_EXAMPLE.ts +167 -0
  45. package/package.json +14 -5
  46. package/dist/index.d.ts +0 -3
  47. package/dist/index.js +0 -4
  48. /package/dist/logger/{Logger.d.ts → index.d.ts} +0 -0
@@ -0,0 +1,60 @@
1
+ import * as RNFS from '@dr.pogodin/react-native-fs';
2
+ import { IFileEntry } from './FileSystem.types';
3
+ /**
4
+ * Base File System Class
5
+ * Handles file system operations for React Native
6
+ */
7
+ export declare class BaseFileSystem {
8
+ /**
9
+ * Get document directory path
10
+ */
11
+ static getDocumentDirectory(): string;
12
+ /**
13
+ * Resolve local file system URL
14
+ */
15
+ static resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
16
+ /**
17
+ * Get folder based on user ID
18
+ */
19
+ static getFolderBasedOnUserId(userId: string): Promise<string>;
20
+ /**
21
+ * Delete user folder
22
+ */
23
+ static deleteUserFolder(userId: string): Promise<void>;
24
+ /**
25
+ * Create directory
26
+ */
27
+ static createDirectory(path: string): Promise<void>;
28
+ /**
29
+ * Read file content
30
+ */
31
+ static readFile(path: string, encoding?: RNFS.EncodingT): Promise<string>;
32
+ /**
33
+ * Write file content
34
+ */
35
+ static writeFile(path: string, content: string, encoding?: RNFS.EncodingT): Promise<void>;
36
+ /**
37
+ * Delete file
38
+ */
39
+ static deleteFile(path: string): Promise<void>;
40
+ /**
41
+ * Check if file exists
42
+ */
43
+ static exists(path: string): Promise<boolean>;
44
+ /**
45
+ * Get file info
46
+ */
47
+ static stat(path: string): Promise<RNFS.StatResultT>;
48
+ /**
49
+ * List directory contents
50
+ */
51
+ static readDir(path: string): Promise<RNFS.ReadDirResItemT[]>;
52
+ /**
53
+ * Copy file
54
+ */
55
+ static copyFile(source: string, destination: string): Promise<void>;
56
+ /**
57
+ * Move file
58
+ */
59
+ static moveFile(source: string, destination: string): Promise<void>;
60
+ }
@@ -0,0 +1,194 @@
1
+ // BaseFileSystem.ts
2
+ // Base file system implementation
3
+ import * as RNFS from '@dr.pogodin/react-native-fs';
4
+ /**
5
+ * Base File System Class
6
+ * Handles file system operations for React Native
7
+ */
8
+ export class BaseFileSystem {
9
+ /**
10
+ * Get document directory path
11
+ */
12
+ static getDocumentDirectory() {
13
+ return RNFS.DocumentDirectoryPath;
14
+ }
15
+ /**
16
+ * Resolve local file system URL
17
+ */
18
+ static async resolveLocalFileSystemURL(url) {
19
+ try {
20
+ let normalizedPath = url;
21
+ if (normalizedPath.startsWith('file://')) {
22
+ normalizedPath = normalizedPath.substring(7);
23
+ }
24
+ const exists = await RNFS.exists(normalizedPath);
25
+ if (!exists) {
26
+ throw new Error(`File or directory does not exist: ${normalizedPath}`);
27
+ }
28
+ const stat = await RNFS.stat(normalizedPath);
29
+ // Extract filename from path if stat.name is undefined
30
+ const fileName = stat.name || normalizedPath.split('/').pop() || 'unknown';
31
+ const fileEntry = {
32
+ isFile: stat.isFile(),
33
+ isDirectory: stat.isDirectory(),
34
+ name: fileName,
35
+ fullPath: stat.path,
36
+ nativeURL: `file://${stat.path}`,
37
+ };
38
+ return fileEntry;
39
+ }
40
+ catch (error) {
41
+ console.error('Error resolving file system URL:', error);
42
+ throw error;
43
+ }
44
+ }
45
+ /**
46
+ * Get folder based on user ID
47
+ */
48
+ static async getFolderBasedOnUserId(userId) {
49
+ try {
50
+ const userFolder = `${RNFS.DocumentDirectoryPath}/users/${userId}`;
51
+ const exists = await RNFS.exists(userFolder);
52
+ if (!exists) {
53
+ await RNFS.mkdir(userFolder, {
54
+ NSURLIsExcludedFromBackupKey: true,
55
+ });
56
+ }
57
+ return userFolder;
58
+ }
59
+ catch (error) {
60
+ console.error('Error getting user folder:', error);
61
+ throw error;
62
+ }
63
+ }
64
+ /**
65
+ * Delete user folder
66
+ */
67
+ static async deleteUserFolder(userId) {
68
+ try {
69
+ const userFolder = `${RNFS.DocumentDirectoryPath}/users/${userId}`;
70
+ const exists = await RNFS.exists(userFolder);
71
+ if (exists) {
72
+ await RNFS.unlink(userFolder);
73
+ console.log(`User folder deleted: ${userFolder}`);
74
+ }
75
+ }
76
+ catch (error) {
77
+ console.error('Error deleting user folder:', error);
78
+ throw error;
79
+ }
80
+ }
81
+ /**
82
+ * Create directory
83
+ */
84
+ static async createDirectory(path) {
85
+ try {
86
+ const exists = await RNFS.exists(path);
87
+ if (!exists) {
88
+ await RNFS.mkdir(path);
89
+ }
90
+ }
91
+ catch (error) {
92
+ console.error('Error creating directory:', error);
93
+ throw error;
94
+ }
95
+ }
96
+ /**
97
+ * Read file content
98
+ */
99
+ static async readFile(path, encoding = 'utf8') {
100
+ try {
101
+ return await RNFS.readFile(path, encoding);
102
+ }
103
+ catch (error) {
104
+ console.error('Error reading file:', error);
105
+ throw error;
106
+ }
107
+ }
108
+ /**
109
+ * Write file content
110
+ */
111
+ static async writeFile(path, content, encoding = 'utf8') {
112
+ try {
113
+ await RNFS.writeFile(path, content, encoding);
114
+ }
115
+ catch (error) {
116
+ console.error('Error writing file:', error);
117
+ throw error;
118
+ }
119
+ }
120
+ /**
121
+ * Delete file
122
+ */
123
+ static async deleteFile(path) {
124
+ try {
125
+ const exists = await RNFS.exists(path);
126
+ if (exists) {
127
+ await RNFS.unlink(path);
128
+ }
129
+ }
130
+ catch (error) {
131
+ console.error('Error deleting file:', error);
132
+ throw error;
133
+ }
134
+ }
135
+ /**
136
+ * Check if file exists
137
+ */
138
+ static async exists(path) {
139
+ try {
140
+ return await RNFS.exists(path);
141
+ }
142
+ catch (error) {
143
+ return false;
144
+ }
145
+ }
146
+ /**
147
+ * Get file info
148
+ */
149
+ static async stat(path) {
150
+ try {
151
+ return await RNFS.stat(path);
152
+ }
153
+ catch (error) {
154
+ console.error('Error getting file stats:', error);
155
+ throw error;
156
+ }
157
+ }
158
+ /**
159
+ * List directory contents
160
+ */
161
+ static async readDir(path) {
162
+ try {
163
+ return await RNFS.readDir(path);
164
+ }
165
+ catch (error) {
166
+ console.error('Error reading directory:', error);
167
+ throw error;
168
+ }
169
+ }
170
+ /**
171
+ * Copy file
172
+ */
173
+ static async copyFile(source, destination) {
174
+ try {
175
+ await RNFS.copyFile(source, destination);
176
+ }
177
+ catch (error) {
178
+ console.error('Error copying file:', error);
179
+ throw error;
180
+ }
181
+ }
182
+ /**
183
+ * Move file
184
+ */
185
+ static async moveFile(source, destination) {
186
+ try {
187
+ await RNFS.moveFile(source, destination);
188
+ }
189
+ catch (error) {
190
+ console.error('Error moving file:', error);
191
+ throw error;
192
+ }
193
+ }
194
+ }
@@ -0,0 +1,9 @@
1
+ import { BaseFileSystem } from './BaseFileSystem';
2
+ /**
3
+ * FileSystem class
4
+ * Extends BaseFileSystem
5
+ */
6
+ export declare class FileSystem extends BaseFileSystem {
7
+ }
8
+ export type { IFileEntry } from './FileSystem.types';
9
+ export default FileSystem;
@@ -0,0 +1,11 @@
1
+ // FileSystem.ts
2
+ // Main file system export
3
+ import { BaseFileSystem } from './BaseFileSystem';
4
+ /**
5
+ * FileSystem class
6
+ * Extends BaseFileSystem
7
+ */
8
+ export class FileSystem extends BaseFileSystem {
9
+ }
10
+ // Default export
11
+ export default FileSystem;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * File entry interface
3
+ */
4
+ export interface IFileEntry {
5
+ isFile: boolean;
6
+ isDirectory: boolean;
7
+ name: string;
8
+ fullPath: string;
9
+ filesystem?: any;
10
+ nativeURL?: string;
11
+ }
@@ -0,0 +1,3 @@
1
+ // FileSystem.types.ts
2
+ // Type definitions for file system module
3
+ export {};
@@ -0,0 +1,3 @@
1
+ export { FileSystem } from './FileSystem';
2
+ export type { IFileEntry } from './FileSystem.types';
3
+ export { default } from './FileSystem';
@@ -0,0 +1,3 @@
1
+ // File System module exports
2
+ export { FileSystem } from './FileSystem';
3
+ export { default } from './FileSystem';
@@ -0,0 +1 @@
1
+ export { LocalStorage } from './localStorage';
@@ -0,0 +1,2 @@
1
+ // Local Storage module exports
2
+ export { LocalStorage } from './localStorage';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * LocalStorage class provides a wrapper around React Native AsyncStorage
3
+ * with convenient methods for storing and retrieving data.
4
+ */
5
+ export declare class LocalStorage {
6
+ /**
7
+ * Get an item from storage
8
+ * @param key - The key to retrieve
9
+ * @returns The parsed value or null if not found
10
+ */
11
+ static getItem<T = any>(key: string): Promise<T | null>;
12
+ /**
13
+ * Set an item in storage
14
+ * @param key - The key to store the value under
15
+ * @param value - The value to store (will be JSON stringified)
16
+ */
17
+ static setItem(key: string, value: any): Promise<void>;
18
+ /**
19
+ * Remove an item from storage
20
+ * @param key - The key to remove
21
+ */
22
+ static removeItem(key: string): Promise<void>;
23
+ /**
24
+ * Clear all items from storage
25
+ */
26
+ static clear(): Promise<void>;
27
+ /**
28
+ * Get all keys from storage
29
+ * @returns Array of all keys
30
+ */
31
+ static getAllKeys(): Promise<readonly string[]>;
32
+ /**
33
+ * Get multiple items from storage
34
+ * @param keys - Array of keys to retrieve
35
+ * @returns Array of [key, value] pairs
36
+ */
37
+ static multiGet(keys: string[]): Promise<Array<[string, any]>>;
38
+ /**
39
+ * Set multiple items in storage
40
+ * @param keyValuePairs - Array of [key, value] pairs to store
41
+ */
42
+ static multiSet(keyValuePairs: Array<[string, any]>): Promise<void>;
43
+ /**
44
+ * Remove multiple items from storage
45
+ * @param keys - Array of keys to remove
46
+ */
47
+ static multiRemove(keys: string[]): Promise<void>;
48
+ }
@@ -0,0 +1,123 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ /**
3
+ * LocalStorage class provides a wrapper around React Native AsyncStorage
4
+ * with convenient methods for storing and retrieving data.
5
+ */
6
+ export class LocalStorage {
7
+ /**
8
+ * Get an item from storage
9
+ * @param key - The key to retrieve
10
+ * @returns The parsed value or null if not found
11
+ */
12
+ static async getItem(key) {
13
+ try {
14
+ const value = await AsyncStorage.getItem(key);
15
+ return value ? JSON.parse(value) : null;
16
+ }
17
+ catch (error) {
18
+ console.error(`Error getting item with key "${key}":`, error);
19
+ return null;
20
+ }
21
+ }
22
+ /**
23
+ * Set an item in storage
24
+ * @param key - The key to store the value under
25
+ * @param value - The value to store (will be JSON stringified)
26
+ */
27
+ static async setItem(key, value) {
28
+ try {
29
+ const jsonValue = JSON.stringify(value);
30
+ await AsyncStorage.setItem(key, jsonValue);
31
+ }
32
+ catch (error) {
33
+ console.error(`Error setting item with key "${key}":`, error);
34
+ throw error;
35
+ }
36
+ }
37
+ /**
38
+ * Remove an item from storage
39
+ * @param key - The key to remove
40
+ */
41
+ static async removeItem(key) {
42
+ try {
43
+ await AsyncStorage.removeItem(key);
44
+ }
45
+ catch (error) {
46
+ console.error(`Error removing item with key "${key}":`, error);
47
+ throw error;
48
+ }
49
+ }
50
+ /**
51
+ * Clear all items from storage
52
+ */
53
+ static async clear() {
54
+ try {
55
+ await AsyncStorage.clear();
56
+ }
57
+ catch (error) {
58
+ console.error('Error clearing storage:', error);
59
+ throw error;
60
+ }
61
+ }
62
+ /**
63
+ * Get all keys from storage
64
+ * @returns Array of all keys
65
+ */
66
+ static async getAllKeys() {
67
+ try {
68
+ return await AsyncStorage.getAllKeys();
69
+ }
70
+ catch (error) {
71
+ console.error('Error getting all keys:', error);
72
+ return [];
73
+ }
74
+ }
75
+ /**
76
+ * Get multiple items from storage
77
+ * @param keys - Array of keys to retrieve
78
+ * @returns Array of [key, value] pairs
79
+ */
80
+ static async multiGet(keys) {
81
+ try {
82
+ const results = await AsyncStorage.multiGet(keys);
83
+ return results.map(([key, value]) => [
84
+ key,
85
+ value ? JSON.parse(value) : null
86
+ ]);
87
+ }
88
+ catch (error) {
89
+ console.error('Error getting multiple items:', error);
90
+ return [];
91
+ }
92
+ }
93
+ /**
94
+ * Set multiple items in storage
95
+ * @param keyValuePairs - Array of [key, value] pairs to store
96
+ */
97
+ static async multiSet(keyValuePairs) {
98
+ try {
99
+ const jsonPairs = keyValuePairs.map(([key, value]) => [
100
+ key,
101
+ JSON.stringify(value)
102
+ ]);
103
+ await AsyncStorage.multiSet(jsonPairs);
104
+ }
105
+ catch (error) {
106
+ console.error('Error setting multiple items:', error);
107
+ throw error;
108
+ }
109
+ }
110
+ /**
111
+ * Remove multiple items from storage
112
+ * @param keys - Array of keys to remove
113
+ */
114
+ static async multiRemove(keys) {
115
+ try {
116
+ await AsyncStorage.multiRemove(keys);
117
+ }
118
+ catch (error) {
119
+ console.error('Error removing multiple items:', error);
120
+ throw error;
121
+ }
122
+ }
123
+ }
@@ -1,4 +1,4 @@
1
- // Logger.ts
1
+ // Logger module main file
2
2
  import { BaseLogger } from './BaseLogger';
3
3
  // Export the Logger class
4
4
  export class Logger extends BaseLogger {
@@ -7,6 +7,3 @@ export class Logger extends BaseLogger {
7
7
  export const logger = new Logger();
8
8
  // Default export (logger instance)
9
9
  export default logger;
10
- // adb shell
11
- // run-as com.rnturboapp
12
- // ls -lh files/localLogs
package/dist/main.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export { Logger, logger } from './logger';
2
+ export type { LogLevel, ILogger, ILoggerImplementation } from './logger';
3
+ export { LocalStorage } from './local-storage';
4
+ export { DatabaseManager, Database, createDatabase } from './database';
5
+ export type { IDatabaseAdapter, DatabaseOptions, ExecuteOptions, SaveWebDBOptions, ExportWebDBOptions, DeleteUserDataOptions, SuccessCallback, ErrorCallback, ResultCallback, SQLResultSet, SQLTransaction, SQLiteDatabase } from './database';
6
+ export { DeviceInfo } from './device-info';
7
+ export type { IDeviceInfo } from './device-info';
8
+ export { FileSystem } from './file-system';
9
+ export type { IFileEntry } from './file-system';
10
+ export { PushNotification } from './push-notification';
11
+ export type { IPushNotificationAdapter } from './push-notification';
12
+ export { ReactNativePlatformAdapter, getPlatformAdapter, resetPlatformAdapter, DatabaseType } from './PlatformAdapter';
13
+ export type { IPlatformAdapter, ILoggerAdapter, IStorageAdapter } from './PlatformAdapter';
package/dist/main.js ADDED
@@ -0,0 +1,28 @@
1
+ // ============================================
2
+ // Logger Module
3
+ // ============================================
4
+ export { Logger, logger } from './logger';
5
+ // ============================================
6
+ // Local Storage Module
7
+ // ============================================
8
+ export { LocalStorage } from './local-storage';
9
+ // ============================================
10
+ // Database Module
11
+ // ============================================
12
+ export { DatabaseManager, Database, createDatabase } from './database';
13
+ // ============================================
14
+ // Device Info Module
15
+ // ============================================
16
+ export { DeviceInfo } from './device-info';
17
+ // ============================================
18
+ // File System Module
19
+ // ============================================
20
+ export { FileSystem } from './file-system';
21
+ // ============================================
22
+ // Push Notification Module
23
+ // ============================================
24
+ export { PushNotification } from './push-notification';
25
+ // ============================================
26
+ // Platform Adapter
27
+ // ============================================
28
+ export { ReactNativePlatformAdapter, getPlatformAdapter, resetPlatformAdapter, DatabaseType } from './PlatformAdapter';
@@ -0,0 +1,52 @@
1
+ import { IPushNotificationAdapter } from './PushNotification.types';
2
+ /**
3
+ * Base Push Notification Class
4
+ * Handles push notifications using Firebase Cloud Messaging
5
+ */
6
+ export declare class BasePushNotification implements IPushNotificationAdapter {
7
+ private tokenRefreshCallback;
8
+ private messageCallback;
9
+ private backgroundMessageCallback;
10
+ /**
11
+ * Request push notification permission
12
+ */
13
+ requestPermission(options?: {
14
+ forceShow?: boolean;
15
+ }): Promise<void>;
16
+ /**
17
+ * Get FCM token
18
+ */
19
+ getToken(): Promise<string>;
20
+ /**
21
+ * Listen for token refresh
22
+ */
23
+ onTokenRefresh(callback: (token: string) => void): void;
24
+ /**
25
+ * Listen for foreground messages
26
+ */
27
+ onMessage(callback: (message: any) => void): void;
28
+ /**
29
+ * Listen for background messages
30
+ */
31
+ onBackgroundMessage(callback: (message: any) => void): void;
32
+ /**
33
+ * Check if device supports push notifications
34
+ */
35
+ static isSupported(): Promise<boolean>;
36
+ /**
37
+ * Delete FCM token
38
+ */
39
+ deleteToken(): Promise<void>;
40
+ /**
41
+ * Get initial notification (app opened from notification)
42
+ */
43
+ getInitialNotification(): Promise<any | null>;
44
+ /**
45
+ * Subscribe to topic
46
+ */
47
+ subscribeToTopic(topic: string): Promise<void>;
48
+ /**
49
+ * Unsubscribe from topic
50
+ */
51
+ unsubscribeFromTopic(topic: string): Promise<void>;
52
+ }