@unvired/react-native-unvired-sdk 0.0.13 → 0.0.15

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 (30) hide show
  1. package/BuildNo.txt +1 -1
  2. package/dist/database/DatabaseManager.d.ts +3 -23
  3. package/dist/database/DatabaseManager.js +9 -314
  4. package/dist/database/services/DatabaseNative.d.ts +8 -0
  5. package/dist/database/services/DatabaseNative.js +149 -0
  6. package/dist/database/services/DatabaseWeb.d.ts +13 -0
  7. package/dist/database/services/DatabaseWeb.js +138 -0
  8. package/dist/file-system/FileSystem.d.ts +57 -3
  9. package/dist/file-system/FileSystem.js +158 -5
  10. package/dist/file-system/FileSystem.types.d.ts +31 -1
  11. package/dist/file-system/RNFileEntry.d.ts +26 -0
  12. package/dist/file-system/RNFileEntry.js +114 -0
  13. package/dist/file-system/index.d.ts +1 -1
  14. package/dist/file-system/services/FileSystemNative.d.ts +17 -0
  15. package/dist/file-system/services/FileSystemNative.js +68 -0
  16. package/dist/file-system/services/FileSystemWeb.d.ts +16 -0
  17. package/dist/file-system/services/FileSystemWeb.js +41 -0
  18. package/dist/local-storage/localStorage.d.ts +3 -2
  19. package/dist/local-storage/localStorage.js +16 -11
  20. package/dist/local-storage/services/StorageNative.d.ts +10 -0
  21. package/dist/local-storage/services/StorageNative.js +27 -0
  22. package/dist/local-storage/services/StorageWeb.d.ts +10 -0
  23. package/dist/local-storage/services/StorageWeb.js +26 -0
  24. package/dist/main.d.ts +0 -2
  25. package/dist/main.js +0 -4
  26. package/package.json +4 -2
  27. package/dist/PlatformAdapter.d.ts +0 -57
  28. package/dist/PlatformAdapter.js +0 -116
  29. package/dist/file-system/BaseFileSystem.d.ts +0 -60
  30. package/dist/file-system/BaseFileSystem.js +0 -194
@@ -0,0 +1,27 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ export class StorageNative {
3
+ async getItem(key) {
4
+ return await AsyncStorage.getItem(key);
5
+ }
6
+ async setItem(key, value) {
7
+ await AsyncStorage.setItem(key, value);
8
+ }
9
+ async removeItem(key) {
10
+ await AsyncStorage.removeItem(key);
11
+ }
12
+ async clear() {
13
+ await AsyncStorage.clear();
14
+ }
15
+ async getAllKeys() {
16
+ return await AsyncStorage.getAllKeys();
17
+ }
18
+ async multiGet(keys) {
19
+ return await AsyncStorage.multiGet(keys);
20
+ }
21
+ async multiSet(keyValuePairs) {
22
+ await AsyncStorage.multiSet(keyValuePairs);
23
+ }
24
+ async multiRemove(keys) {
25
+ await AsyncStorage.multiRemove(keys);
26
+ }
27
+ }
@@ -0,0 +1,10 @@
1
+ export declare class StorageWeb {
2
+ getItem(key: string): Promise<string | null>;
3
+ setItem(key: string, value: string): Promise<void>;
4
+ removeItem(key: string): Promise<void>;
5
+ clear(): Promise<void>;
6
+ getAllKeys(): Promise<readonly string[]>;
7
+ multiGet(keys: string[]): Promise<readonly [string, string | null][]>;
8
+ multiSet(keyValuePairs: Array<[string, string]>): Promise<void>;
9
+ multiRemove(keys: string[]): Promise<void>;
10
+ }
@@ -0,0 +1,26 @@
1
+ export class StorageWeb {
2
+ async getItem(key) {
3
+ return localStorage.getItem(key);
4
+ }
5
+ async setItem(key, value) {
6
+ localStorage.setItem(key, value);
7
+ }
8
+ async removeItem(key) {
9
+ localStorage.removeItem(key);
10
+ }
11
+ async clear() {
12
+ localStorage.clear();
13
+ }
14
+ async getAllKeys() {
15
+ return Object.keys(localStorage);
16
+ }
17
+ async multiGet(keys) {
18
+ return keys.map(key => [key, localStorage.getItem(key)]);
19
+ }
20
+ async multiSet(keyValuePairs) {
21
+ keyValuePairs.forEach(([key, value]) => localStorage.setItem(key, value));
22
+ }
23
+ async multiRemove(keys) {
24
+ keys.forEach(key => localStorage.removeItem(key));
25
+ }
26
+ }
package/dist/main.d.ts CHANGED
@@ -9,5 +9,3 @@ export { FileSystem } from './file-system';
9
9
  export type { IFileEntry } from './file-system';
10
10
  export { PushNotification } from './push-notification';
11
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 CHANGED
@@ -22,7 +22,3 @@ export { FileSystem } from './file-system';
22
22
  // Push Notification Module
23
23
  // ============================================
24
24
  export { PushNotification } from './push-notification';
25
- // ============================================
26
- // Platform Adapter
27
- // ============================================
28
- export { ReactNativePlatformAdapter, getPlatformAdapter, resetPlatformAdapter, DatabaseType } from './PlatformAdapter';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unvired/react-native-unvired-sdk",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Unvired SDK for React Native with logging, database, notifications, and file system support",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -41,6 +41,7 @@
41
41
  "@types/react": "^18.0.0",
42
42
  "@types/react-native": "^0.72.0",
43
43
  "@types/react-native-sqlite-storage": "^6.0.5",
44
+ "@types/sql.js": "^1.4.9",
44
45
  "eslint": "^8.0.0",
45
46
  "jest": "^29.0.0",
46
47
  "prettier": "^3.0.0",
@@ -49,7 +50,8 @@
49
50
  "dependencies": {
50
51
  "@react-native-async-storage/async-storage": "^2.2.0",
51
52
  "@types/pako": "^2.0.4",
52
- "pako": "^2.1.0"
53
+ "pako": "^2.1.0",
54
+ "sql.js": "^1.10.3"
53
55
  },
54
56
  "repository": {},
55
57
  "bugs": {},
@@ -1,57 +0,0 @@
1
- import { LogLevel } from './logger';
2
- import { IDeviceInfo } from './device-info';
3
- import { IFileEntry } from './file-system';
4
- import { IDatabaseAdapter } from './database';
5
- import { IPushNotificationAdapter } from './push-notification';
6
- export interface ILoggerAdapter {
7
- logDebug(sourceClass: string, method: string, message: string): void;
8
- logError(sourceClass: string, method: string, message: string): void;
9
- logInfo(sourceClass: string, method: string, message: string): void;
10
- setLogLevel(logLevel: LogLevel): void;
11
- getLogFileURL(): Promise<string>;
12
- getLogFileContent(): Promise<string>;
13
- getBackupLogFileContent(): Promise<string | null>;
14
- clearLogFile(): Promise<void>;
15
- }
16
- export interface IStorageAdapter {
17
- getItem<T = any>(key: string): Promise<T | null>;
18
- setItem(key: string, value: any): Promise<void>;
19
- removeItem(key: string): Promise<void>;
20
- clear(): Promise<void>;
21
- }
22
- export declare enum DatabaseType {
23
- SQLITE = "sqlite",
24
- WEBSQL = "websql"
25
- }
26
- export interface IPlatformAdapter {
27
- getDeviceInfo(): IDeviceInfo;
28
- getPlatform(): string;
29
- getFrontendType(): string;
30
- getDocumentDirectory(): string;
31
- resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
32
- getFolderBasedOnUserId(userId: string): Promise<string>;
33
- deleteUserFolder(userId: string): Promise<void>;
34
- getDatabaseAdapter(): IDatabaseAdapter;
35
- getPushNotificationAdapter(): IPushNotificationAdapter | null;
36
- getLoggerAdapter(): ILoggerAdapter;
37
- getStorageAdapter(): IStorageAdapter;
38
- }
39
- export declare class ReactNativePlatformAdapter implements IPlatformAdapter {
40
- private deviceInfo;
41
- private pushNotification;
42
- constructor();
43
- private initializeDeviceInfo;
44
- getDeviceInfo(): IDeviceInfo;
45
- getPlatform(): string;
46
- getFrontendType(): string;
47
- getDocumentDirectory(): string;
48
- resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
49
- getFolderBasedOnUserId(userId: string): Promise<string>;
50
- deleteUserFolder(userId: string): Promise<void>;
51
- getDatabaseAdapter(): IDatabaseAdapter;
52
- getPushNotificationAdapter(): IPushNotificationAdapter | null;
53
- getLoggerAdapter(): ILoggerAdapter;
54
- getStorageAdapter(): IStorageAdapter;
55
- }
56
- export declare function getPlatformAdapter(): ReactNativePlatformAdapter;
57
- export declare function resetPlatformAdapter(): void;
@@ -1,116 +0,0 @@
1
- import { logger } from './logger';
2
- import { DatabaseManager } from './database';
3
- import { LocalStorage } from './local-storage';
4
- import { DeviceInfo } from './device-info';
5
- import { FileSystem } from './file-system';
6
- import { PushNotification } from './push-notification';
7
- export var DatabaseType;
8
- (function (DatabaseType) {
9
- DatabaseType["SQLITE"] = "sqlite";
10
- DatabaseType["WEBSQL"] = "websql";
11
- })(DatabaseType || (DatabaseType = {}));
12
- export class ReactNativePlatformAdapter {
13
- constructor() {
14
- this.deviceInfo = null;
15
- this.pushNotification = null;
16
- this.initializeDeviceInfo();
17
- }
18
- async initializeDeviceInfo() {
19
- try {
20
- this.deviceInfo = await DeviceInfo.getDeviceInfo();
21
- }
22
- catch (error) {
23
- console.error('Error initializing device info:', error);
24
- }
25
- }
26
- getDeviceInfo() {
27
- return this.deviceInfo || DeviceInfo.getDeviceInfoSync();
28
- }
29
- getPlatform() {
30
- return DeviceInfo.getPlatform();
31
- }
32
- getFrontendType() {
33
- return DeviceInfo.getFrontendType();
34
- }
35
- getDocumentDirectory() {
36
- return FileSystem.getDocumentDirectory();
37
- }
38
- async resolveLocalFileSystemURL(url) {
39
- return FileSystem.resolveLocalFileSystemURL(url);
40
- }
41
- async getFolderBasedOnUserId(userId) {
42
- return FileSystem.getFolderBasedOnUserId(userId);
43
- }
44
- async deleteUserFolder(userId) {
45
- return FileSystem.deleteUserFolder(userId);
46
- }
47
- getDatabaseAdapter() {
48
- return DatabaseManager.getDatabaseAdapter();
49
- }
50
- getPushNotificationAdapter() {
51
- try {
52
- if (!this.pushNotification) {
53
- this.pushNotification = new PushNotification();
54
- }
55
- return this.pushNotification;
56
- }
57
- catch (error) {
58
- console.error('Error initializing push notification adapter:', error);
59
- return null;
60
- }
61
- }
62
- getLoggerAdapter() {
63
- return {
64
- logDebug: (sourceClass, method, message) => {
65
- logger.logDebug(sourceClass, method, message);
66
- },
67
- logError: (sourceClass, method, message) => {
68
- logger.logError(sourceClass, method, message);
69
- },
70
- logInfo: (sourceClass, method, message) => {
71
- logger.logInfo(sourceClass, method, message);
72
- },
73
- setLogLevel: (logLevel) => {
74
- logger.setLogLevel(logLevel);
75
- },
76
- getLogFileURL: async () => {
77
- return logger.getLogFileURL();
78
- },
79
- getLogFileContent: async () => {
80
- return logger.getLogFileContent() || '';
81
- },
82
- getBackupLogFileContent: async () => {
83
- return logger.getBackupLogFileContent();
84
- },
85
- clearLogFile: async () => {
86
- await logger.clearLogFile();
87
- }
88
- };
89
- }
90
- getStorageAdapter() {
91
- return {
92
- getItem: async (key) => {
93
- return LocalStorage.getItem(key);
94
- },
95
- setItem: async (key, value) => {
96
- return LocalStorage.setItem(key, value);
97
- },
98
- removeItem: async (key) => {
99
- return LocalStorage.removeItem(key);
100
- },
101
- clear: async () => {
102
- return LocalStorage.clear();
103
- }
104
- };
105
- }
106
- }
107
- let platformInstance = null;
108
- export function getPlatformAdapter() {
109
- if (!platformInstance) {
110
- platformInstance = new ReactNativePlatformAdapter();
111
- }
112
- return platformInstance;
113
- }
114
- export function resetPlatformAdapter() {
115
- platformInstance = null;
116
- }
@@ -1,60 +0,0 @@
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
- }
@@ -1,194 +0,0 @@
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
- }