@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.
- 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/{Logger.js → index.js} +1 -4
- 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 +14 -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,180 @@
|
|
|
1
|
+
// BasePushNotification.ts
|
|
2
|
+
// Base push notification implementation
|
|
3
|
+
let messaging;
|
|
4
|
+
let FirebaseMessagingTypes;
|
|
5
|
+
try {
|
|
6
|
+
const firebaseMessaging = require('@react-native-firebase/messaging');
|
|
7
|
+
messaging = firebaseMessaging.default;
|
|
8
|
+
FirebaseMessagingTypes = firebaseMessaging.FirebaseMessagingTypes;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
console.warn('Firebase messaging not installed. Push notifications will not work.');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Base Push Notification Class
|
|
15
|
+
* Handles push notifications using Firebase Cloud Messaging
|
|
16
|
+
*/
|
|
17
|
+
export class BasePushNotification {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.tokenRefreshCallback = null;
|
|
20
|
+
this.messageCallback = null;
|
|
21
|
+
this.backgroundMessageCallback = null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Request push notification permission
|
|
25
|
+
*/
|
|
26
|
+
async requestPermission(options = {}) {
|
|
27
|
+
if (!messaging) {
|
|
28
|
+
throw new Error('Firebase messaging is not installed');
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const authStatus = await messaging().requestPermission();
|
|
32
|
+
const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
|
|
33
|
+
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
|
|
34
|
+
if (enabled) {
|
|
35
|
+
console.log('Push notification permission granted:', authStatus);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.log('Push notification permission denied');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('Error requesting push notification permission:', error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get FCM token
|
|
48
|
+
*/
|
|
49
|
+
async getToken() {
|
|
50
|
+
if (!messaging) {
|
|
51
|
+
throw new Error('Firebase messaging is not installed');
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const token = await messaging().getToken();
|
|
55
|
+
console.log('FCM Token:', token);
|
|
56
|
+
return token;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Error getting FCM token:', error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Listen for token refresh
|
|
65
|
+
*/
|
|
66
|
+
onTokenRefresh(callback) {
|
|
67
|
+
if (!messaging)
|
|
68
|
+
return;
|
|
69
|
+
this.tokenRefreshCallback = callback;
|
|
70
|
+
messaging().onTokenRefresh((token) => {
|
|
71
|
+
console.log('FCM Token refreshed:', token);
|
|
72
|
+
if (this.tokenRefreshCallback) {
|
|
73
|
+
this.tokenRefreshCallback(token);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Listen for foreground messages
|
|
79
|
+
*/
|
|
80
|
+
onMessage(callback) {
|
|
81
|
+
if (!messaging)
|
|
82
|
+
return;
|
|
83
|
+
this.messageCallback = callback;
|
|
84
|
+
messaging().onMessage(async (remoteMessage) => {
|
|
85
|
+
console.log('Foreground message received:', remoteMessage);
|
|
86
|
+
if (this.messageCallback) {
|
|
87
|
+
this.messageCallback(remoteMessage);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Listen for background messages
|
|
93
|
+
*/
|
|
94
|
+
onBackgroundMessage(callback) {
|
|
95
|
+
if (!messaging)
|
|
96
|
+
return;
|
|
97
|
+
this.backgroundMessageCallback = callback;
|
|
98
|
+
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
|
|
99
|
+
console.log('Background message received:', remoteMessage);
|
|
100
|
+
if (this.backgroundMessageCallback) {
|
|
101
|
+
this.backgroundMessageCallback(remoteMessage);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if device supports push notifications
|
|
107
|
+
*/
|
|
108
|
+
static async isSupported() {
|
|
109
|
+
if (!messaging)
|
|
110
|
+
return false;
|
|
111
|
+
try {
|
|
112
|
+
return await messaging().isDeviceRegisteredForRemoteMessages();
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Delete FCM token
|
|
120
|
+
*/
|
|
121
|
+
async deleteToken() {
|
|
122
|
+
if (!messaging) {
|
|
123
|
+
throw new Error('Firebase messaging is not installed');
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
await messaging().deleteToken();
|
|
127
|
+
console.log('FCM token deleted');
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error('Error deleting FCM token:', error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get initial notification (app opened from notification)
|
|
136
|
+
*/
|
|
137
|
+
async getInitialNotification() {
|
|
138
|
+
if (!messaging)
|
|
139
|
+
return null;
|
|
140
|
+
try {
|
|
141
|
+
return await messaging().getInitialNotification();
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error('Error getting initial notification:', error);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Subscribe to topic
|
|
150
|
+
*/
|
|
151
|
+
async subscribeToTopic(topic) {
|
|
152
|
+
if (!messaging) {
|
|
153
|
+
throw new Error('Firebase messaging is not installed');
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
await messaging().subscribeToTopic(topic);
|
|
157
|
+
console.log(`Subscribed to topic: ${topic}`);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.error('Error subscribing to topic:', error);
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Unsubscribe from topic
|
|
166
|
+
*/
|
|
167
|
+
async unsubscribeFromTopic(topic) {
|
|
168
|
+
if (!messaging) {
|
|
169
|
+
throw new Error('Firebase messaging is not installed');
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
await messaging().unsubscribeFromTopic(topic);
|
|
173
|
+
console.log(`Unsubscribed from topic: ${topic}`);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
console.error('Error unsubscribing from topic:', error);
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasePushNotification } from './BasePushNotification';
|
|
2
|
+
/**
|
|
3
|
+
* PushNotification class
|
|
4
|
+
* Extends BasePushNotification
|
|
5
|
+
*/
|
|
6
|
+
export declare class PushNotification extends BasePushNotification {
|
|
7
|
+
}
|
|
8
|
+
export type { IPushNotificationAdapter } from './PushNotification.types';
|
|
9
|
+
export default PushNotification;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// PushNotification.ts
|
|
2
|
+
// Main push notification export
|
|
3
|
+
import { BasePushNotification } from './BasePushNotification';
|
|
4
|
+
/**
|
|
5
|
+
* PushNotification class
|
|
6
|
+
* Extends BasePushNotification
|
|
7
|
+
*/
|
|
8
|
+
export class PushNotification extends BasePushNotification {
|
|
9
|
+
}
|
|
10
|
+
// Default export
|
|
11
|
+
export default PushNotification;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push notification adapter interface
|
|
3
|
+
*/
|
|
4
|
+
export interface IPushNotificationAdapter {
|
|
5
|
+
requestPermission(options?: {
|
|
6
|
+
forceShow?: boolean;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
getToken(): Promise<string>;
|
|
9
|
+
onTokenRefresh(callback: (token: string) => void): void;
|
|
10
|
+
onMessage(callback: (message: any) => void): void;
|
|
11
|
+
onBackgroundMessage(callback: (message: any) => void): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { PlatformInterface, IDeviceInfo, IFileEntry, IDatabaseAdapter, IPushNotificationAdapter, ILoggerAdapter, DatabaseType } from './PlatformInterface';
|
|
2
|
+
import { logger, LogLevel } from '@unvired/react-native-unvired-sdk';
|
|
3
|
+
export class ReactNativePlatformAdapter implements PlatformInterface {
|
|
4
|
+
|
|
5
|
+
getDeviceInfo(): IDeviceInfo {
|
|
6
|
+
// TODO: Implement device info retrieval
|
|
7
|
+
return {
|
|
8
|
+
platform: 'unknown',
|
|
9
|
+
model: '',
|
|
10
|
+
version: '',
|
|
11
|
+
isMobile: true
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getPlatform(): string {
|
|
16
|
+
// TODO: Implement platform retrieval
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getFrontendType(): string {
|
|
21
|
+
// TODO: Implement frontend type retrieval
|
|
22
|
+
// Refer CordovaPlatformAdapter.ts for reference to return values
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getDocumentDirectory(): string {
|
|
27
|
+
// TODO: Implement document directory retrieval
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
resolveLocalFileSystemURL(url: string): Promise<IFileEntry> {
|
|
32
|
+
// TODO: Implement local file system URL resolution
|
|
33
|
+
return Promise.resolve({} as IFileEntry);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getFolderBasedOnUserId(userId: string): Promise<string> {
|
|
37
|
+
// TODO: Implement folder retrieval based on user ID
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async deleteUserFolder(userId: string): Promise<void> {
|
|
42
|
+
// TODO: Implement user folder deletion
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getDatabaseAdapter(): IDatabaseAdapter {
|
|
46
|
+
// TODO: Implement database adapter
|
|
47
|
+
return {
|
|
48
|
+
create: (options, successCallback, errorCallback) => {
|
|
49
|
+
// TODO: Implement database creation
|
|
50
|
+
},
|
|
51
|
+
execute: (options, successCallback, errorCallback) => {
|
|
52
|
+
// TODO: Implement SQL execution
|
|
53
|
+
},
|
|
54
|
+
executeStatementOnPath: (dbPath, sqlQuery, callback) => {
|
|
55
|
+
// TODO: Implement SQL execution on specific path
|
|
56
|
+
callback([]);
|
|
57
|
+
},
|
|
58
|
+
selectFromPath: (dbPath, sqlQuery, callback) => {
|
|
59
|
+
// TODO: Implement SELECT query
|
|
60
|
+
callback([]);
|
|
61
|
+
},
|
|
62
|
+
createDatabase: (dbPath, callback) => {
|
|
63
|
+
// TODO: Implement database creation
|
|
64
|
+
callback();
|
|
65
|
+
},
|
|
66
|
+
getDBFilePath: (options, callback) => {
|
|
67
|
+
// TODO: Implement database file path retrieval
|
|
68
|
+
callback("");
|
|
69
|
+
},
|
|
70
|
+
saveWebDB: (options, callback, errorCallback) => {
|
|
71
|
+
// TODO: Implement web database save
|
|
72
|
+
callback({});
|
|
73
|
+
},
|
|
74
|
+
exportWebDB: (options, callback, errorCallback) => {
|
|
75
|
+
// TODO: Implement web database export
|
|
76
|
+
callback({});
|
|
77
|
+
},
|
|
78
|
+
deleteUserData: (options, callback, errorCallback) => {
|
|
79
|
+
// TODO: Implement user data deletion
|
|
80
|
+
callback();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getPushNotificationAdapter(): IPushNotificationAdapter | null {
|
|
86
|
+
try {
|
|
87
|
+
return {
|
|
88
|
+
requestPermission: async (options = { forceShow: false }) => {
|
|
89
|
+
//TODO: Implement push notification permission request
|
|
90
|
+
},
|
|
91
|
+
getToken: async () => {
|
|
92
|
+
//TODO: Implement push notification token retrieval
|
|
93
|
+
return "";
|
|
94
|
+
},
|
|
95
|
+
onTokenRefresh: (callback) => {
|
|
96
|
+
//TODO: Implement push notification token refresh
|
|
97
|
+
},
|
|
98
|
+
onMessage: (callback) => {
|
|
99
|
+
//TODO: Implement push notification message handling
|
|
100
|
+
},
|
|
101
|
+
onBackgroundMessage: (callback) => {
|
|
102
|
+
//TODO: Implement push notification background message handling
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
} catch (error) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getLoggerAdapter(): ILoggerAdapter {
|
|
111
|
+
return {
|
|
112
|
+
logDebug: (sourceClass, method, message) => {
|
|
113
|
+
console.log(`[DEBUG] ${sourceClass}.${method}: ${message}`);
|
|
114
|
+
logger.logDebug(sourceClass, method, message);
|
|
115
|
+
// TODO: Implement log file writing
|
|
116
|
+
},
|
|
117
|
+
logError: (sourceClass, method, message) => {
|
|
118
|
+
console.error(`[ERROR] ${sourceClass}.${method}: ${message}`);
|
|
119
|
+
logger.logError(sourceClass, method, message);
|
|
120
|
+
// TODO: Implement log file writing
|
|
121
|
+
},
|
|
122
|
+
logInfo: (sourceClass, method, message) => {
|
|
123
|
+
console.info(`[INFO] ${sourceClass}.${method}: ${message}`);
|
|
124
|
+
logger.logInfo(sourceClass, method, message);
|
|
125
|
+
// TODO: Implement log file writing
|
|
126
|
+
},
|
|
127
|
+
setLogLevel: (logLevel: LogLevel) => {
|
|
128
|
+
// TODO: Implement log level setting
|
|
129
|
+
console.log(`Setting log level to: ${logLevel}`);
|
|
130
|
+
logger.setLogLevel(logLevel);
|
|
131
|
+
},
|
|
132
|
+
getLogFileURL: async () => {
|
|
133
|
+
// TODO: Implement log file URL retrieval
|
|
134
|
+
return logger.getLogFileURL();
|
|
135
|
+
},
|
|
136
|
+
getLogFileContent: async () => {
|
|
137
|
+
// TODO: Implement log file content retrieval
|
|
138
|
+
return logger.getLogFileContent();
|
|
139
|
+
},
|
|
140
|
+
getBackupLogFileContent: async () => {
|
|
141
|
+
// TODO: Implement backup log file content retrieval
|
|
142
|
+
return logger.getBackupLogFileContent();
|
|
143
|
+
},
|
|
144
|
+
clearLogFile: async () => {
|
|
145
|
+
// TODO: Implement log file clearing
|
|
146
|
+
logger.clearLogFile();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getStorageAdapter() {
|
|
152
|
+
return {
|
|
153
|
+
getItem: (key: string) => {
|
|
154
|
+
return null;
|
|
155
|
+
},
|
|
156
|
+
setItem: (key: string, value: string) => {
|
|
157
|
+
// Dummy implementation
|
|
158
|
+
},
|
|
159
|
+
removeItem: (key: string) => {
|
|
160
|
+
// Dummy implementation
|
|
161
|
+
},
|
|
162
|
+
clear: () => {
|
|
163
|
+
// Dummy implementation
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unvired/react-native-unvired-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Unvired SDK for React Native with logging, database, notifications, and file system support",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"types": "dist/
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"types": "dist/main.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc --project tsconfig.json",
|
|
9
9
|
"prepare": "npm run build",
|
|
@@ -25,20 +25,29 @@
|
|
|
25
25
|
"license": "UNLICENSED",
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@dr.pogodin/react-native-fs": "^2.36.2",
|
|
28
|
+
"@react-native-firebase/messaging": "^21.8.1",
|
|
28
29
|
"react": ">=16.8.0",
|
|
29
30
|
"react-native": ">=0.60.0",
|
|
31
|
+
"react-native-device-info": "^14.1.1",
|
|
32
|
+
"react-native-sqlite-storage": "^6.0.1",
|
|
30
33
|
"react-native-zip-archive": "^7.0.2"
|
|
31
34
|
},
|
|
32
|
-
"peerDependenciesMeta": {
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@react-native-firebase/messaging": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
33
40
|
"devDependencies": {
|
|
34
41
|
"@types/react": "^18.0.0",
|
|
35
42
|
"@types/react-native": "^0.72.0",
|
|
43
|
+
"@types/react-native-sqlite-storage": "^6.0.5",
|
|
36
44
|
"eslint": "^8.0.0",
|
|
37
45
|
"jest": "^29.0.0",
|
|
38
46
|
"prettier": "^3.0.0",
|
|
39
47
|
"typescript": "^5.0.0"
|
|
40
48
|
},
|
|
41
49
|
"dependencies": {
|
|
50
|
+
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
42
51
|
"@types/pako": "^2.0.4",
|
|
43
52
|
"pako": "^2.1.0"
|
|
44
53
|
},
|
|
@@ -50,4 +59,4 @@
|
|
|
50
59
|
"publishConfig": {
|
|
51
60
|
"access": "public"
|
|
52
61
|
}
|
|
53
|
-
}
|
|
62
|
+
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
File without changes
|