@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,57 @@
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;
@@ -0,0 +1,116 @@
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
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Database helper class with common database operations
3
+ */
4
+ export declare class Database {
5
+ private dbName;
6
+ private location?;
7
+ constructor(dbName: string, location?: string);
8
+ /**
9
+ * Execute a raw SQL query
10
+ */
11
+ executeSql(query: string, params?: any[]): Promise<any[]>;
12
+ /**
13
+ * Create a table
14
+ */
15
+ createTable(tableName: string, columns: Record<string, string>): Promise<void>;
16
+ /**
17
+ * Drop a table
18
+ */
19
+ dropTable(tableName: string): Promise<void>;
20
+ /**
21
+ * Insert a record
22
+ */
23
+ insert(tableName: string, data: Record<string, any>): Promise<number>;
24
+ /**
25
+ * Insert multiple records in a transaction
26
+ */
27
+ insertBatch(tableName: string, records: Record<string, any>[]): Promise<void>;
28
+ /**
29
+ * Update records
30
+ */
31
+ update(tableName: string, data: Record<string, any>, where: string, whereParams?: any[]): Promise<number>;
32
+ /**
33
+ * Delete records
34
+ */
35
+ delete(tableName: string, where: string, whereParams?: any[]): Promise<number>;
36
+ /**
37
+ * Select records
38
+ */
39
+ select(tableName: string, columns?: string[], where?: string, whereParams?: any[], orderBy?: string, limit?: number): Promise<any[]>;
40
+ /**
41
+ * Select a single record
42
+ */
43
+ selectOne(tableName: string, columns?: string[], where?: string, whereParams?: any[]): Promise<any | null>;
44
+ /**
45
+ * Count records
46
+ */
47
+ count(tableName: string, where?: string, whereParams?: any[]): Promise<number>;
48
+ /**
49
+ * Check if a table exists
50
+ */
51
+ tableExists(tableName: string): Promise<boolean>;
52
+ /**
53
+ * Get all table names
54
+ */
55
+ getAllTables(): Promise<string[]>;
56
+ /**
57
+ * Clear all data from a table
58
+ */
59
+ truncate(tableName: string): Promise<void>;
60
+ /**
61
+ * Execute multiple SQL statements in a transaction
62
+ */
63
+ transaction(queries: Array<{
64
+ query: string;
65
+ params?: any[];
66
+ }>): Promise<void>;
67
+ }
68
+ /**
69
+ * Create a new database instance
70
+ */
71
+ export declare function createDatabase(dbName: string, location?: string): Database;
@@ -0,0 +1,156 @@
1
+ import { DatabaseManager } from './DatabaseManager';
2
+ /**
3
+ * Database helper class with common database operations
4
+ */
5
+ export class Database {
6
+ constructor(dbName, location) {
7
+ this.dbName = dbName;
8
+ this.location = location;
9
+ }
10
+ /**
11
+ * Execute a raw SQL query
12
+ */
13
+ async executeSql(query, params = []) {
14
+ return new Promise((resolve, reject) => {
15
+ const adapter = DatabaseManager.getDatabaseAdapter();
16
+ adapter.execute({ dbName: this.dbName, query, params }, (results) => resolve(results), (error) => reject(new Error(String(error))));
17
+ });
18
+ }
19
+ /**
20
+ * Create a table
21
+ */
22
+ async createTable(tableName, columns) {
23
+ const columnDefs = Object.entries(columns)
24
+ .map(([name, type]) => `${name} ${type}`)
25
+ .join(', ');
26
+ const query = `CREATE TABLE IF NOT EXISTS ${tableName} (${columnDefs})`;
27
+ await this.executeSql(query);
28
+ }
29
+ /**
30
+ * Drop a table
31
+ */
32
+ async dropTable(tableName) {
33
+ const query = `DROP TABLE IF EXISTS ${tableName}`;
34
+ await this.executeSql(query);
35
+ }
36
+ /**
37
+ * Insert a record
38
+ */
39
+ async insert(tableName, data) {
40
+ var _a;
41
+ const columns = Object.keys(data).join(', ');
42
+ const placeholders = Object.keys(data).map(() => '?').join(', ');
43
+ const values = Object.values(data);
44
+ const query = `INSERT INTO ${tableName} (${columns}) VALUES (${placeholders})`;
45
+ const result = await this.executeSql(query, values);
46
+ // Return the insert ID if available
47
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.insertId) || 0;
48
+ }
49
+ /**
50
+ * Insert multiple records in a transaction
51
+ */
52
+ async insertBatch(tableName, records) {
53
+ if (records.length === 0)
54
+ return;
55
+ const columns = Object.keys(records[0]).join(', ');
56
+ const placeholders = Object.keys(records[0]).map(() => '?').join(', ');
57
+ const query = `INSERT INTO ${tableName} (${columns}) VALUES (${placeholders})`;
58
+ for (const record of records) {
59
+ const values = Object.values(record);
60
+ await this.executeSql(query, values);
61
+ }
62
+ }
63
+ /**
64
+ * Update records
65
+ */
66
+ async update(tableName, data, where, whereParams = []) {
67
+ var _a;
68
+ const setClause = Object.keys(data)
69
+ .map(key => `${key} = ?`)
70
+ .join(', ');
71
+ const values = [...Object.values(data), ...whereParams];
72
+ const query = `UPDATE ${tableName} SET ${setClause} WHERE ${where}`;
73
+ const result = await this.executeSql(query, values);
74
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.rowsAffected) || 0;
75
+ }
76
+ /**
77
+ * Delete records
78
+ */
79
+ async delete(tableName, where, whereParams = []) {
80
+ var _a;
81
+ const query = `DELETE FROM ${tableName} WHERE ${where}`;
82
+ const result = await this.executeSql(query, whereParams);
83
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.rowsAffected) || 0;
84
+ }
85
+ /**
86
+ * Select records
87
+ */
88
+ async select(tableName, columns = ['*'], where, whereParams = [], orderBy, limit) {
89
+ let query = `SELECT ${columns.join(', ')} FROM ${tableName}`;
90
+ if (where) {
91
+ query += ` WHERE ${where}`;
92
+ }
93
+ if (orderBy) {
94
+ query += ` ORDER BY ${orderBy}`;
95
+ }
96
+ if (limit) {
97
+ query += ` LIMIT ${limit}`;
98
+ }
99
+ return this.executeSql(query, whereParams);
100
+ }
101
+ /**
102
+ * Select a single record
103
+ */
104
+ async selectOne(tableName, columns = ['*'], where, whereParams = []) {
105
+ const results = await this.select(tableName, columns, where, whereParams, undefined, 1);
106
+ return results.length > 0 ? results[0] : null;
107
+ }
108
+ /**
109
+ * Count records
110
+ */
111
+ async count(tableName, where, whereParams = []) {
112
+ var _a;
113
+ let query = `SELECT COUNT(*) as count FROM ${tableName}`;
114
+ if (where) {
115
+ query += ` WHERE ${where}`;
116
+ }
117
+ const result = await this.executeSql(query, whereParams);
118
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.count) || 0;
119
+ }
120
+ /**
121
+ * Check if a table exists
122
+ */
123
+ async tableExists(tableName) {
124
+ const query = `SELECT name FROM sqlite_master WHERE type='table' AND name=?`;
125
+ const result = await this.executeSql(query, [tableName]);
126
+ return result.length > 0;
127
+ }
128
+ /**
129
+ * Get all table names
130
+ */
131
+ async getAllTables() {
132
+ const query = `SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`;
133
+ const result = await this.executeSql(query);
134
+ return result.map(row => row.name);
135
+ }
136
+ /**
137
+ * Clear all data from a table
138
+ */
139
+ async truncate(tableName) {
140
+ await this.executeSql(`DELETE FROM ${tableName}`);
141
+ }
142
+ /**
143
+ * Execute multiple SQL statements in a transaction
144
+ */
145
+ async transaction(queries) {
146
+ for (const { query, params } of queries) {
147
+ await this.executeSql(query, params || []);
148
+ }
149
+ }
150
+ }
151
+ /**
152
+ * Create a new database instance
153
+ */
154
+ export function createDatabase(dbName, location) {
155
+ return new Database(dbName, location);
156
+ }
@@ -0,0 +1,32 @@
1
+ import { IDatabaseAdapter } from './types';
2
+ /**
3
+ * DatabaseManager - Manages SQLite database operations for React Native
4
+ */
5
+ export declare class DatabaseManager {
6
+ private static databases;
7
+ private static defaultLocation;
8
+ /**
9
+ * Get or create a database connection
10
+ */
11
+ private static getDatabase;
12
+ /**
13
+ * Close a database connection
14
+ */
15
+ private static closeDatabase;
16
+ /**
17
+ * Convert SQLResultSet to array of objects
18
+ */
19
+ private static resultSetToArray;
20
+ /**
21
+ * Get the database adapter implementation
22
+ */
23
+ static getDatabaseAdapter(): IDatabaseAdapter;
24
+ /**
25
+ * Close all database connections
26
+ */
27
+ static closeAllDatabases(): Promise<void>;
28
+ /**
29
+ * Delete a database
30
+ */
31
+ static deleteDatabase(name: string, location?: string): Promise<void>;
32
+ }