@unvired/react-native-unvired-sdk 0.0.33 → 0.0.34
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/dist/database/DatabaseManager.d.ts +1 -1
- package/dist/database/DatabaseManager.js +4 -2
- package/dist/database/services/DatabaseWeb.d.ts +12 -0
- package/dist/database/services/DatabaseWeb.js +237 -0
- package/dist/device-info/BaseDeviceInfo.d.ts +2 -3
- package/dist/device-info/BaseDeviceInfo.js +13 -68
- package/dist/device-info/DeviceInfo.types.d.ts +11 -0
- package/dist/device-info/services/DeviceInfoNative.d.ts +9 -0
- package/dist/device-info/services/DeviceInfoNative.js +83 -0
- package/dist/device-info/services/DeviceInfoWeb.d.ts +12 -0
- package/dist/device-info/services/DeviceInfoWeb.js +54 -0
- package/dist/file-system/services/FileSystemWeb.d.ts +5 -1
- package/dist/file-system/services/FileSystemWeb.js +247 -14
- package/dist/local-storage/services/StorageWeb.js +39 -8
- package/dist/logger/services/LoggerNative.d.ts +1 -1
- package/dist/logger/services/LoggerNative.js +45 -84
- package/dist/logger/services/LoggerWeb.d.ts +5 -2
- package/dist/logger/services/LoggerWeb.js +14 -5
- package/dist/push-notification/BasePushNotification.d.ts +2 -35
- package/dist/push-notification/BasePushNotification.js +18 -150
- package/dist/push-notification/PushNotification.types.d.ts +5 -0
- package/dist/push-notification/services/PushNotificationNative.d.ts +18 -0
- package/dist/push-notification/services/PushNotificationNative.js +130 -0
- package/dist/push-notification/services/PushNotificationWeb.d.ts +21 -0
- package/dist/push-notification/services/PushNotificationWeb.js +69 -0
- package/package.json +7 -5
|
@@ -1,52 +1,19 @@
|
|
|
1
|
-
import { IPushNotificationAdapter } from
|
|
1
|
+
import { IPushNotificationAdapter } from "./PushNotification.types";
|
|
2
2
|
/**
|
|
3
3
|
* Base Push Notification Class
|
|
4
|
-
* Handles push notifications
|
|
4
|
+
* Handles push notifications dynamically across Native (Firebase) & Web (Notification API)
|
|
5
5
|
*/
|
|
6
6
|
export declare class BasePushNotification implements IPushNotificationAdapter {
|
|
7
|
-
private tokenRefreshCallback;
|
|
8
|
-
private messageCallback;
|
|
9
|
-
private backgroundMessageCallback;
|
|
10
|
-
/**
|
|
11
|
-
* Request push notification permission
|
|
12
|
-
*/
|
|
13
7
|
requestPermission(options?: {
|
|
14
8
|
forceShow?: boolean;
|
|
15
9
|
}): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Get FCM token
|
|
18
|
-
*/
|
|
19
10
|
getToken(): Promise<string>;
|
|
20
|
-
/**
|
|
21
|
-
* Listen for token refresh
|
|
22
|
-
*/
|
|
23
11
|
onTokenRefresh(callback: (token: string) => void): void;
|
|
24
|
-
/**
|
|
25
|
-
* Listen for foreground messages
|
|
26
|
-
*/
|
|
27
12
|
onMessage(callback: (message: any) => void): void;
|
|
28
|
-
/**
|
|
29
|
-
* Listen for background messages
|
|
30
|
-
*/
|
|
31
13
|
onBackgroundMessage(callback: (message: any) => void): void;
|
|
32
|
-
/**
|
|
33
|
-
* Check if device supports push notifications
|
|
34
|
-
*/
|
|
35
14
|
static isSupported(): Promise<boolean>;
|
|
36
|
-
/**
|
|
37
|
-
* Delete FCM token
|
|
38
|
-
*/
|
|
39
15
|
deleteToken(): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Get initial notification (app opened from notification)
|
|
42
|
-
*/
|
|
43
16
|
getInitialNotification(): Promise<any | null>;
|
|
44
|
-
/**
|
|
45
|
-
* Subscribe to topic
|
|
46
|
-
*/
|
|
47
17
|
subscribeToTopic(topic: string): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Unsubscribe from topic
|
|
50
|
-
*/
|
|
51
18
|
unsubscribeFromTopic(topic: string): Promise<void>;
|
|
52
19
|
}
|
|
@@ -1,180 +1,48 @@
|
|
|
1
1
|
// BasePushNotification.ts
|
|
2
2
|
// Base push notification implementation
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
}
|
|
3
|
+
import { Platform } from "react-native";
|
|
4
|
+
import { PushNotificationNative } from "./services/PushNotificationNative";
|
|
5
|
+
import { PushNotificationWeb } from "./services/PushNotificationWeb";
|
|
6
|
+
const pushImpl = Platform.OS === "web" ? new PushNotificationWeb() : new PushNotificationNative();
|
|
13
7
|
/**
|
|
14
8
|
* Base Push Notification Class
|
|
15
|
-
* Handles push notifications
|
|
9
|
+
* Handles push notifications dynamically across Native (Firebase) & Web (Notification API)
|
|
16
10
|
*/
|
|
17
11
|
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
12
|
async requestPermission(options = {}) {
|
|
27
|
-
|
|
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
|
-
}
|
|
13
|
+
return await pushImpl.requestPermission(options);
|
|
45
14
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Get FCM token
|
|
48
|
-
*/
|
|
49
15
|
async getToken() {
|
|
50
|
-
|
|
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
|
-
}
|
|
16
|
+
return await pushImpl.getToken();
|
|
62
17
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Listen for token refresh
|
|
65
|
-
*/
|
|
66
18
|
onTokenRefresh(callback) {
|
|
67
|
-
|
|
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
|
-
});
|
|
19
|
+
pushImpl.onTokenRefresh(callback);
|
|
76
20
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Listen for foreground messages
|
|
79
|
-
*/
|
|
80
21
|
onMessage(callback) {
|
|
81
|
-
|
|
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
|
-
});
|
|
22
|
+
pushImpl.onMessage(callback);
|
|
90
23
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Listen for background messages
|
|
93
|
-
*/
|
|
94
24
|
onBackgroundMessage(callback) {
|
|
95
|
-
|
|
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
|
-
});
|
|
25
|
+
pushImpl.onBackgroundMessage(callback);
|
|
104
26
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Check if device supports push notifications
|
|
107
|
-
*/
|
|
108
27
|
static async isSupported() {
|
|
109
|
-
|
|
110
|
-
return false;
|
|
111
|
-
try {
|
|
112
|
-
return await messaging().isDeviceRegisteredForRemoteMessages();
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
28
|
+
return pushImpl.isSupported ? await pushImpl.isSupported() : false;
|
|
117
29
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Delete FCM token
|
|
120
|
-
*/
|
|
121
30
|
async deleteToken() {
|
|
122
|
-
if (
|
|
123
|
-
|
|
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;
|
|
31
|
+
if (pushImpl.deleteToken) {
|
|
32
|
+
await pushImpl.deleteToken();
|
|
132
33
|
}
|
|
133
34
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Get initial notification (app opened from notification)
|
|
136
|
-
*/
|
|
137
35
|
async getInitialNotification() {
|
|
138
|
-
|
|
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
|
-
}
|
|
36
|
+
return pushImpl.getInitialNotification ? await pushImpl.getInitialNotification() : null;
|
|
147
37
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Subscribe to topic
|
|
150
|
-
*/
|
|
151
38
|
async subscribeToTopic(topic) {
|
|
152
|
-
if (
|
|
153
|
-
|
|
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;
|
|
39
|
+
if (pushImpl.subscribeToTopic) {
|
|
40
|
+
await pushImpl.subscribeToTopic(topic);
|
|
162
41
|
}
|
|
163
42
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Unsubscribe from topic
|
|
166
|
-
*/
|
|
167
43
|
async unsubscribeFromTopic(topic) {
|
|
168
|
-
if (
|
|
169
|
-
|
|
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;
|
|
44
|
+
if (pushImpl.unsubscribeFromTopic) {
|
|
45
|
+
await pushImpl.unsubscribeFromTopic(topic);
|
|
178
46
|
}
|
|
179
47
|
}
|
|
180
48
|
}
|
|
@@ -9,4 +9,9 @@ export interface IPushNotificationAdapter {
|
|
|
9
9
|
onTokenRefresh(callback: (token: string) => void): void;
|
|
10
10
|
onMessage(callback: (message: any) => void): void;
|
|
11
11
|
onBackgroundMessage(callback: (message: any) => void): void;
|
|
12
|
+
isSupported?(): Promise<boolean>;
|
|
13
|
+
deleteToken?(): Promise<void>;
|
|
14
|
+
getInitialNotification?(): Promise<any | null>;
|
|
15
|
+
subscribeToTopic?(topic: string): Promise<void>;
|
|
16
|
+
unsubscribeFromTopic?(topic: string): Promise<void>;
|
|
12
17
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IPushNotificationAdapter } from "../PushNotification.types";
|
|
2
|
+
export declare class PushNotificationNative implements IPushNotificationAdapter {
|
|
3
|
+
private tokenRefreshCallback;
|
|
4
|
+
private messageCallback;
|
|
5
|
+
private backgroundMessageCallback;
|
|
6
|
+
requestPermission(options?: {
|
|
7
|
+
forceShow?: boolean;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
getToken(): Promise<string>;
|
|
10
|
+
onTokenRefresh(callback: (token: string) => void): void;
|
|
11
|
+
onMessage(callback: (message: any) => void): void;
|
|
12
|
+
onBackgroundMessage(callback: (message: any) => void): void;
|
|
13
|
+
isSupported(): Promise<boolean>;
|
|
14
|
+
deleteToken(): Promise<void>;
|
|
15
|
+
getInitialNotification(): Promise<any | null>;
|
|
16
|
+
subscribeToTopic(topic: string): Promise<void>;
|
|
17
|
+
unsubscribeFromTopic(topic: string): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
let messaging = null;
|
|
2
|
+
try {
|
|
3
|
+
const firebaseMessaging = require("@react-native-firebase/messaging");
|
|
4
|
+
messaging = firebaseMessaging.default;
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
// Optional if @react-native-firebase/messaging is not installed
|
|
8
|
+
}
|
|
9
|
+
export class PushNotificationNative {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.tokenRefreshCallback = null;
|
|
12
|
+
this.messageCallback = null;
|
|
13
|
+
this.backgroundMessageCallback = null;
|
|
14
|
+
}
|
|
15
|
+
async requestPermission(options = {}) {
|
|
16
|
+
if (!messaging) {
|
|
17
|
+
console.warn("Firebase messaging is not installed");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const authStatus = await messaging().requestPermission();
|
|
22
|
+
const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
|
|
23
|
+
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
|
|
24
|
+
if (enabled) {
|
|
25
|
+
console.log("Push notification permission granted:", authStatus);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.log("Push notification permission denied");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error("Error requesting push notification permission:", error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async getToken() {
|
|
37
|
+
if (!messaging) {
|
|
38
|
+
return "native-mock-token";
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const token = await messaging().getToken();
|
|
42
|
+
return token;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error("Error getting FCM token:", error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
onTokenRefresh(callback) {
|
|
50
|
+
if (!messaging)
|
|
51
|
+
return;
|
|
52
|
+
this.tokenRefreshCallback = callback;
|
|
53
|
+
messaging().onTokenRefresh((token) => {
|
|
54
|
+
if (this.tokenRefreshCallback) {
|
|
55
|
+
this.tokenRefreshCallback(token);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
onMessage(callback) {
|
|
60
|
+
if (!messaging)
|
|
61
|
+
return;
|
|
62
|
+
this.messageCallback = callback;
|
|
63
|
+
messaging().onMessage(async (remoteMessage) => {
|
|
64
|
+
if (this.messageCallback) {
|
|
65
|
+
this.messageCallback(remoteMessage);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
onBackgroundMessage(callback) {
|
|
70
|
+
if (!messaging)
|
|
71
|
+
return;
|
|
72
|
+
this.backgroundMessageCallback = callback;
|
|
73
|
+
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
|
|
74
|
+
if (this.backgroundMessageCallback) {
|
|
75
|
+
this.backgroundMessageCallback(remoteMessage);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async isSupported() {
|
|
80
|
+
if (!messaging)
|
|
81
|
+
return false;
|
|
82
|
+
try {
|
|
83
|
+
return await messaging().isDeviceRegisteredForRemoteMessages();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async deleteToken() {
|
|
90
|
+
if (!messaging)
|
|
91
|
+
return;
|
|
92
|
+
try {
|
|
93
|
+
await messaging().deleteToken();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error("Error deleting FCM token:", error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async getInitialNotification() {
|
|
101
|
+
if (!messaging)
|
|
102
|
+
return null;
|
|
103
|
+
try {
|
|
104
|
+
return await messaging().getInitialNotification();
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async subscribeToTopic(topic) {
|
|
111
|
+
if (!messaging)
|
|
112
|
+
return;
|
|
113
|
+
try {
|
|
114
|
+
await messaging().subscribeToTopic(topic);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error("Error subscribing to topic:", error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async unsubscribeFromTopic(topic) {
|
|
121
|
+
if (!messaging)
|
|
122
|
+
return;
|
|
123
|
+
try {
|
|
124
|
+
await messaging().unsubscribeFromTopic(topic);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error("Error unsubscribing from topic:", error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IPushNotificationAdapter } from "../PushNotification.types";
|
|
2
|
+
/**
|
|
3
|
+
* PushNotificationWeb - Web Notification API implementation
|
|
4
|
+
*/
|
|
5
|
+
export declare class PushNotificationWeb implements IPushNotificationAdapter {
|
|
6
|
+
private tokenRefreshCallback;
|
|
7
|
+
private messageCallback;
|
|
8
|
+
private backgroundMessageCallback;
|
|
9
|
+
requestPermission(options?: {
|
|
10
|
+
forceShow?: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
getToken(): Promise<string>;
|
|
13
|
+
onTokenRefresh(callback: (token: string) => void): void;
|
|
14
|
+
onMessage(callback: (message: any) => void): void;
|
|
15
|
+
onBackgroundMessage(callback: (message: any) => void): void;
|
|
16
|
+
isSupported(): Promise<boolean>;
|
|
17
|
+
deleteToken(): Promise<void>;
|
|
18
|
+
getInitialNotification(): Promise<any | null>;
|
|
19
|
+
subscribeToTopic(topic: string): Promise<void>;
|
|
20
|
+
unsubscribeFromTopic(topic: string): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PushNotificationWeb - Web Notification API implementation
|
|
3
|
+
*/
|
|
4
|
+
export class PushNotificationWeb {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.tokenRefreshCallback = null;
|
|
7
|
+
this.messageCallback = null;
|
|
8
|
+
this.backgroundMessageCallback = null;
|
|
9
|
+
}
|
|
10
|
+
async requestPermission(options = {}) {
|
|
11
|
+
if (typeof window !== "undefined" && "Notification" in window) {
|
|
12
|
+
try {
|
|
13
|
+
const permission = await Notification.requestPermission();
|
|
14
|
+
if (permission === "granted") {
|
|
15
|
+
console.log("[PushNotificationWeb] Notification permission granted");
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.log("[PushNotificationWeb] Notification permission:", permission);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.warn("[PushNotificationWeb] Permission request failed:", e);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async getToken() {
|
|
27
|
+
if (typeof localStorage !== "undefined") {
|
|
28
|
+
try {
|
|
29
|
+
let webToken = localStorage.getItem("__unvired_push_token");
|
|
30
|
+
if (!webToken) {
|
|
31
|
+
webToken = "web-push-" + Math.random().toString(36).substring(2) + "-" + Date.now().toString(36);
|
|
32
|
+
localStorage.setItem("__unvired_push_token", webToken);
|
|
33
|
+
}
|
|
34
|
+
return webToken;
|
|
35
|
+
}
|
|
36
|
+
catch (e) { }
|
|
37
|
+
}
|
|
38
|
+
return "web-push-token-default";
|
|
39
|
+
}
|
|
40
|
+
onTokenRefresh(callback) {
|
|
41
|
+
this.tokenRefreshCallback = callback;
|
|
42
|
+
}
|
|
43
|
+
onMessage(callback) {
|
|
44
|
+
this.messageCallback = callback;
|
|
45
|
+
}
|
|
46
|
+
onBackgroundMessage(callback) {
|
|
47
|
+
this.backgroundMessageCallback = callback;
|
|
48
|
+
}
|
|
49
|
+
async isSupported() {
|
|
50
|
+
return typeof window !== "undefined" && "Notification" in window;
|
|
51
|
+
}
|
|
52
|
+
async deleteToken() {
|
|
53
|
+
if (typeof localStorage !== "undefined") {
|
|
54
|
+
try {
|
|
55
|
+
localStorage.removeItem("__unvired_push_token");
|
|
56
|
+
}
|
|
57
|
+
catch (e) { }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async getInitialNotification() {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
async subscribeToTopic(topic) {
|
|
64
|
+
console.log(`[PushNotificationWeb] Subscribed to topic: ${topic}`);
|
|
65
|
+
}
|
|
66
|
+
async unsubscribeFromTopic(topic) {
|
|
67
|
+
console.log(`[PushNotificationWeb] Unsubscribed from topic: ${topic}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unvired/react-native-unvired-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
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",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@op-engineering/op-sqlite": "^15.2.5",
|
|
16
|
-
"react-native-mmkv": "*",
|
|
17
16
|
"@react-native-firebase/messaging": "^21.8.1",
|
|
18
17
|
"react": ">=18",
|
|
19
18
|
"react-native": ">=0.73",
|
|
20
19
|
"react-native-device-info": "^15.0.1",
|
|
21
20
|
"react-native-fs": "^2.20.0",
|
|
21
|
+
"react-native-mmkv": "*",
|
|
22
22
|
"react-native-zip-archive": "^7.0.2"
|
|
23
23
|
},
|
|
24
24
|
"peerDependenciesMeta": {
|
|
@@ -45,16 +45,17 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"pako": "^2.1.0"
|
|
48
|
+
"pako": "^2.1.0",
|
|
49
|
+
"sql.js": "^1.14.2"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@op-engineering/op-sqlite": "^15.2.5",
|
|
52
53
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
53
|
-
"react-native-mmkv": "^4.3.2",
|
|
54
54
|
"@react-native-firebase/messaging": "^21.8.1",
|
|
55
55
|
"@types/pako": "^2.0.4",
|
|
56
56
|
"@types/react": ">=18",
|
|
57
57
|
"@types/react-native": "^0.73.0",
|
|
58
|
+
"@types/sql.js": "^1.4.11",
|
|
58
59
|
"eslint": "^8.0.0",
|
|
59
60
|
"jest": "^29.0.0",
|
|
60
61
|
"prettier": "^3.0.0",
|
|
@@ -62,6 +63,7 @@
|
|
|
62
63
|
"react-native": "0.83.1",
|
|
63
64
|
"react-native-device-info": "^15.0.1",
|
|
64
65
|
"react-native-fs": "^2.20.0",
|
|
66
|
+
"react-native-mmkv": "^4.3.2",
|
|
65
67
|
"typescript": "^5.0.0"
|
|
66
68
|
},
|
|
67
69
|
"engines": {
|
|
@@ -70,4 +72,4 @@
|
|
|
70
72
|
"publishConfig": {
|
|
71
73
|
"access": "public"
|
|
72
74
|
}
|
|
73
|
-
}
|
|
75
|
+
}
|