@unvired/react-native-unvired-sdk 0.0.11 → 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/BaseLogger.js +8 -13
- package/dist/logger/{Logger.js → index.js} +1 -4
- package/dist/logger/services/LoggerNative.js +5 -5
- package/dist/logger/services/LoggerWindows.d.ts +20 -0
- package/dist/logger/services/LoggerWindows.js +225 -0
- 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 +17 -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
|
@@ -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,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 @@
|
|
|
1
|
+
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
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
3
|
import { LoggerNative } from './services/LoggerNative';
|
|
4
4
|
import { LoggerWeb } from './services/LoggerWeb';
|
|
5
|
+
import { LoggerWindows } from './services/LoggerWindows';
|
|
5
6
|
export const MAX_LOG_SIZE = 100 * 1024 * 1024;
|
|
6
7
|
export class BaseLogger {
|
|
7
8
|
constructor() {
|
|
@@ -10,9 +11,7 @@ export class BaseLogger {
|
|
|
10
11
|
this.impl = new LoggerWeb();
|
|
11
12
|
}
|
|
12
13
|
else if (Platform.OS === 'windows') {
|
|
13
|
-
|
|
14
|
-
console.warn('Windows logger not implemented yet, using web logger');
|
|
15
|
-
this.impl = new LoggerWeb();
|
|
14
|
+
this.impl = new LoggerWindows();
|
|
16
15
|
}
|
|
17
16
|
else {
|
|
18
17
|
this.impl = new LoggerNative();
|
|
@@ -24,7 +23,7 @@ export class BaseLogger {
|
|
|
24
23
|
// -------------------------
|
|
25
24
|
format(className, methodName, message, level) {
|
|
26
25
|
const ts = new Date().toISOString();
|
|
27
|
-
return
|
|
26
|
+
return `[${ts}] [${level.toUpperCase()}] [${className}] [${methodName}] ${message}`;
|
|
28
27
|
}
|
|
29
28
|
setLogLevel(level) {
|
|
30
29
|
this.logLevel = level;
|
|
@@ -46,17 +45,13 @@ export class BaseLogger {
|
|
|
46
45
|
return;
|
|
47
46
|
const line = this.format(className, methodName, message, level);
|
|
48
47
|
// console always
|
|
48
|
+
/*
|
|
49
49
|
switch (level) {
|
|
50
|
-
case 'debug':
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
case 'info':
|
|
54
|
-
console.info(line);
|
|
55
|
-
break;
|
|
56
|
-
case 'error':
|
|
57
|
-
console.error(line);
|
|
58
|
-
break;
|
|
50
|
+
case 'debug': console.debug(line); break;
|
|
51
|
+
case 'info': console.info(line); break;
|
|
52
|
+
case 'error': console.error(line); break;
|
|
59
53
|
}
|
|
54
|
+
*/
|
|
60
55
|
await this.impl.writeLine(line, MAX_LOG_SIZE);
|
|
61
56
|
}
|
|
62
57
|
// -------------------------
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Logger
|
|
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
|
|
@@ -27,8 +27,8 @@ export class LoggerNative {
|
|
|
27
27
|
constructor() {
|
|
28
28
|
this.isRotating = false; // Rotation lock to prevent concurrent rotations
|
|
29
29
|
this.isAvailable = false;
|
|
30
|
-
const dir = '
|
|
31
|
-
const file = '
|
|
30
|
+
const dir = 'unvired_logs';
|
|
31
|
+
const file = 'applog.txt'; // main log file
|
|
32
32
|
if (!RNFS) {
|
|
33
33
|
console.warn('⚠️ LoggerNative: RNFS not available, logging to file system disabled');
|
|
34
34
|
this.logDir = '';
|
|
@@ -47,7 +47,7 @@ export class LoggerNative {
|
|
|
47
47
|
this.logDir = '';
|
|
48
48
|
}
|
|
49
49
|
this.logFile = `${this.logDir}/${file}`;
|
|
50
|
-
this.backupZip = `${this.logDir}/
|
|
50
|
+
this.backupZip = `${this.logDir}/backuplog.zip`;
|
|
51
51
|
}
|
|
52
52
|
async init() {
|
|
53
53
|
if (!this.isAvailable || !this.logDir || !RNFS)
|
|
@@ -188,8 +188,8 @@ export class LoggerNative {
|
|
|
188
188
|
if (!this.isAvailable || !RNFS)
|
|
189
189
|
return null;
|
|
190
190
|
try {
|
|
191
|
-
//
|
|
192
|
-
await this.rotateLog();
|
|
191
|
+
// Do NOT force rotation. Only return existing backup if present.
|
|
192
|
+
// await this.rotateLog();
|
|
193
193
|
if (await RNFS.exists(this.backupZip)) {
|
|
194
194
|
// Return base64 content for download/upload
|
|
195
195
|
return await RNFS.readFile(this.backupZip, 'base64');
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ILoggerImplementation } from '../Logger.types';
|
|
2
|
+
export declare class LoggerWindows implements ILoggerImplementation {
|
|
3
|
+
logDir: string;
|
|
4
|
+
logFile: string;
|
|
5
|
+
backupZip: string;
|
|
6
|
+
private isRotating;
|
|
7
|
+
private isAvailable;
|
|
8
|
+
constructor();
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
private writeQueue;
|
|
11
|
+
private isWriting;
|
|
12
|
+
writeLine(line: string, maxSize: number): Promise<void>;
|
|
13
|
+
private processWriteQueue;
|
|
14
|
+
private ensureDir;
|
|
15
|
+
private rotateLog;
|
|
16
|
+
getLogFileURL(): Promise<string>;
|
|
17
|
+
getLogFileContent(): Promise<any>;
|
|
18
|
+
getBackupLogFileContent(): Promise<any>;
|
|
19
|
+
clear(): Promise<void>;
|
|
20
|
+
}
|