@imatis/react-native-notifications 4.3.3-imatis.11 → 4.3.3-imatis.12
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/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +1 -1
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java +8 -3
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java +3 -11
- package/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java +2 -2
- package/lib/dist/DTO/Notification.d.ts +11 -0
- package/lib/dist/DTO/Notification.js +30 -0
- package/lib/dist/DTO/Notification.test.d.ts +1 -0
- package/lib/dist/DTO/Notification.test.js +52 -0
- package/lib/dist/DTO/NotificationAndroid.d.ts +7 -0
- package/lib/dist/DTO/NotificationAndroid.js +20 -0
- package/lib/dist/DTO/NotificationAndroid.test.d.ts +1 -0
- package/lib/dist/DTO/NotificationAndroid.test.js +25 -0
- package/lib/dist/DTO/NotificationFactory.d.ts +4 -0
- package/lib/dist/DTO/NotificationFactory.js +18 -0
- package/lib/dist/DTO/NotificationIOS.d.ts +12 -0
- package/lib/dist/DTO/NotificationIOS.js +41 -0
- package/lib/dist/DTO/NotificationIOS.test.d.ts +1 -0
- package/lib/dist/DTO/NotificationIOS.test.js +58 -0
- package/lib/dist/Notifications.d.ts +65 -0
- package/lib/dist/Notifications.js +108 -0
- package/lib/dist/NotificationsAndroid.d.ts +14 -0
- package/lib/dist/NotificationsAndroid.js +33 -0
- package/lib/dist/NotificationsIOS.d.ts +51 -0
- package/lib/dist/NotificationsIOS.js +85 -0
- package/lib/dist/adapters/CompletionCallbackWrapper.d.ts +11 -0
- package/lib/dist/adapters/CompletionCallbackWrapper.js +45 -0
- package/lib/dist/adapters/NativeCommandsSender.d.ts +31 -0
- package/lib/dist/adapters/NativeCommandsSender.js +74 -0
- package/lib/dist/adapters/NativeEventsReceiver.d.ts +19 -0
- package/lib/dist/adapters/NativeEventsReceiver.js +49 -0
- package/lib/dist/adapters/UniqueIdProvider.d.ts +3 -0
- package/lib/dist/adapters/UniqueIdProvider.js +10 -0
- package/lib/dist/commands/Commands.d.ts +32 -0
- package/lib/dist/commands/Commands.js +82 -0
- package/lib/dist/commands/Commands.test.d.ts +1 -0
- package/lib/dist/commands/Commands.test.js +201 -0
- package/lib/dist/events/EventsRegistry.d.ts +18 -0
- package/lib/dist/events/EventsRegistry.js +30 -0
- package/lib/dist/events/EventsRegistry.test.d.ts +1 -0
- package/lib/dist/events/EventsRegistry.test.js +183 -0
- package/lib/dist/events/EventsRegistryIOS.d.ts +12 -0
- package/lib/dist/events/EventsRegistryIOS.js +21 -0
- package/lib/dist/events/EventsRegistryIOS.test.d.ts +1 -0
- package/lib/dist/events/EventsRegistryIOS.test.js +53 -0
- package/lib/dist/index.d.ts +7 -0
- package/lib/dist/index.js +12 -0
- package/lib/dist/interfaces/EventSubscription.d.ts +3 -0
- package/lib/dist/interfaces/EventSubscription.js +2 -0
- package/lib/dist/interfaces/NotificationActionResponse.d.ts +5 -0
- package/lib/dist/interfaces/NotificationActionResponse.js +12 -0
- package/lib/dist/interfaces/NotificationCategory.d.ts +18 -0
- package/lib/dist/interfaces/NotificationCategory.js +27 -0
- package/lib/dist/interfaces/NotificationChannel.d.ts +14 -0
- package/lib/dist/interfaces/NotificationChannel.js +2 -0
- package/lib/dist/interfaces/NotificationCompletion.d.ts +10 -0
- package/lib/dist/interfaces/NotificationCompletion.js +9 -0
- package/lib/dist/interfaces/NotificationEvents.d.ts +18 -0
- package/lib/dist/interfaces/NotificationEvents.js +2 -0
- package/lib/dist/interfaces/NotificationPermissions.d.ts +14 -0
- package/lib/dist/interfaces/NotificationPermissions.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationsIOS = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
class NotificationsIOS {
|
|
6
|
+
commands;
|
|
7
|
+
eventsRegistry;
|
|
8
|
+
constructor(commands, eventsRegistry) {
|
|
9
|
+
this.commands = commands;
|
|
10
|
+
this.eventsRegistry = eventsRegistry;
|
|
11
|
+
return new Proxy(this, {
|
|
12
|
+
get(target, name) {
|
|
13
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
14
|
+
return target[name];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return () => { };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Request permissions to send remote notifications
|
|
24
|
+
*/
|
|
25
|
+
registerRemoteNotifications(options) {
|
|
26
|
+
return this.commands.requestPermissions(options);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Unregister for all remote notifications received via Apple Push Notification service
|
|
30
|
+
*/
|
|
31
|
+
abandonPermissions() {
|
|
32
|
+
return this.commands.abandonPermissions();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* registerPushKit
|
|
36
|
+
*/
|
|
37
|
+
registerPushKit() {
|
|
38
|
+
return this.commands.registerPushKit();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* getBadgeCount
|
|
42
|
+
*/
|
|
43
|
+
getBadgeCount() {
|
|
44
|
+
return this.commands.getBadgeCount();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* setBadgeCount
|
|
48
|
+
* @param count number of the new badge count
|
|
49
|
+
*/
|
|
50
|
+
setBadgeCount(count) {
|
|
51
|
+
return this.commands.setBadgeCount(count);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* cancelAllLocalNotifications
|
|
55
|
+
*/
|
|
56
|
+
cancelAllLocalNotifications() {
|
|
57
|
+
this.commands.cancelAllLocalNotifications();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* checkPermissions
|
|
61
|
+
*/
|
|
62
|
+
checkPermissions() {
|
|
63
|
+
return this.commands.checkPermissions();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* removeDeliveredNotifications
|
|
67
|
+
* @param identifiers Array of notification identifiers
|
|
68
|
+
*/
|
|
69
|
+
removeDeliveredNotifications(identifiers) {
|
|
70
|
+
return this.commands.removeDeliveredNotifications(identifiers);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* getDeliveredNotifications
|
|
74
|
+
*/
|
|
75
|
+
getDeliveredNotifications() {
|
|
76
|
+
return this.commands.getDeliveredNotifications();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Obtain the events registry instance
|
|
80
|
+
*/
|
|
81
|
+
events() {
|
|
82
|
+
return this.eventsRegistry;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.NotificationsIOS = NotificationsIOS;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NativeCommandsSender } from './NativeCommandsSender';
|
|
2
|
+
import { Notification } from "..";
|
|
3
|
+
import { NotificationActionResponse } from '../interfaces/NotificationActionResponse';
|
|
4
|
+
export declare class CompletionCallbackWrapper {
|
|
5
|
+
private readonly nativeCommandsSender;
|
|
6
|
+
constructor(nativeCommandsSender: NativeCommandsSender);
|
|
7
|
+
wrapReceivedBackgroundCallback(callback: Function): (notification: Notification) => void;
|
|
8
|
+
wrapReceivedForegroundCallback(callback: Function): (notification: Notification) => void;
|
|
9
|
+
private wrapReceivedAndInvoke;
|
|
10
|
+
wrapOpenedCallback(callback: Function): (notification: object, actionResponse?: NotificationActionResponse) => void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompletionCallbackWrapper = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
class CompletionCallbackWrapper {
|
|
6
|
+
nativeCommandsSender;
|
|
7
|
+
constructor(nativeCommandsSender) {
|
|
8
|
+
this.nativeCommandsSender = nativeCommandsSender;
|
|
9
|
+
}
|
|
10
|
+
wrapReceivedBackgroundCallback(callback) {
|
|
11
|
+
return (notification) => {
|
|
12
|
+
this.wrapReceivedAndInvoke(callback, notification, true);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
wrapReceivedForegroundCallback(callback) {
|
|
16
|
+
return (notification) => {
|
|
17
|
+
this.wrapReceivedAndInvoke(callback, notification, false);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
wrapReceivedAndInvoke(callback, notification, background) {
|
|
21
|
+
const completion = (response) => {
|
|
22
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
23
|
+
const identifier = notification.identifier;
|
|
24
|
+
if (background) {
|
|
25
|
+
this.nativeCommandsSender.finishHandlingBackgroundAction(identifier, response);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.nativeCommandsSender.finishPresentingNotification(identifier, response);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
callback(notification, completion);
|
|
33
|
+
}
|
|
34
|
+
wrapOpenedCallback(callback) {
|
|
35
|
+
return (notification, actionResponse) => {
|
|
36
|
+
const completion = () => {
|
|
37
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
38
|
+
this.nativeCommandsSender.finishHandlingAction(notification.identifier);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
callback(notification, completion, actionResponse);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.CompletionCallbackWrapper = CompletionCallbackWrapper;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Notification } from '../DTO/Notification';
|
|
2
|
+
import { NotificationCompletion } from '../interfaces/NotificationCompletion';
|
|
3
|
+
import { NotificationPermissions } from '../interfaces/NotificationPermissions';
|
|
4
|
+
import { NotificationCategory } from '../interfaces/NotificationCategory';
|
|
5
|
+
import { NotificationChannel } from '../interfaces/NotificationChannel';
|
|
6
|
+
import { NotificationPermissionOptions } from '../interfaces/NotificationPermissions';
|
|
7
|
+
export declare class NativeCommandsSender {
|
|
8
|
+
private readonly nativeCommandsModule;
|
|
9
|
+
constructor();
|
|
10
|
+
postLocalNotification(notification: Notification, id: number): void;
|
|
11
|
+
getInitialNotification(): Promise<Object>;
|
|
12
|
+
getLastAction(): Promise<Object>;
|
|
13
|
+
requestPermissions(options?: NotificationPermissionOptions): void;
|
|
14
|
+
abandonPermissions(): void;
|
|
15
|
+
refreshToken(): void;
|
|
16
|
+
registerPushKit(): void;
|
|
17
|
+
setCategories(categories: [NotificationCategory?]): void;
|
|
18
|
+
getBadgeCount(): Promise<number>;
|
|
19
|
+
setBadgeCount(count: number): void;
|
|
20
|
+
cancelLocalNotification(notificationId: number): void;
|
|
21
|
+
cancelAllLocalNotifications(): void;
|
|
22
|
+
isRegisteredForRemoteNotifications(): Promise<any>;
|
|
23
|
+
checkPermissions(): Promise<NotificationPermissions>;
|
|
24
|
+
removeAllDeliveredNotifications(): void;
|
|
25
|
+
removeDeliveredNotifications(identifiers: Array<string>): void;
|
|
26
|
+
getDeliveredNotifications(): Promise<Notification[]>;
|
|
27
|
+
finishPresentingNotification(notificationId: string, notificationCompletion: NotificationCompletion): void;
|
|
28
|
+
finishHandlingAction(notificationId: string): void;
|
|
29
|
+
setNotificationChannel(notificationChannel: NotificationChannel): void;
|
|
30
|
+
finishHandlingBackgroundAction(notificationId: string, backgroundFetchResult: string): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeCommandsSender = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
class NativeCommandsSender {
|
|
6
|
+
nativeCommandsModule;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.nativeCommandsModule = react_native_1.NativeModules.RNBridgeModule;
|
|
9
|
+
}
|
|
10
|
+
postLocalNotification(notification, id) {
|
|
11
|
+
return this.nativeCommandsModule.postLocalNotification(notification, id);
|
|
12
|
+
}
|
|
13
|
+
getInitialNotification() {
|
|
14
|
+
return this.nativeCommandsModule.getInitialNotification();
|
|
15
|
+
}
|
|
16
|
+
getLastAction() {
|
|
17
|
+
return this.nativeCommandsModule.getLastAction();
|
|
18
|
+
}
|
|
19
|
+
requestPermissions(options) {
|
|
20
|
+
return this.nativeCommandsModule.requestPermissions(options || {});
|
|
21
|
+
}
|
|
22
|
+
abandonPermissions() {
|
|
23
|
+
return this.nativeCommandsModule.abandonPermissions();
|
|
24
|
+
}
|
|
25
|
+
refreshToken() {
|
|
26
|
+
this.nativeCommandsModule.refreshToken();
|
|
27
|
+
}
|
|
28
|
+
registerPushKit() {
|
|
29
|
+
return this.nativeCommandsModule.registerPushKit();
|
|
30
|
+
}
|
|
31
|
+
setCategories(categories) {
|
|
32
|
+
this.nativeCommandsModule.setCategories(categories);
|
|
33
|
+
}
|
|
34
|
+
getBadgeCount() {
|
|
35
|
+
return this.nativeCommandsModule.getBadgeCount();
|
|
36
|
+
}
|
|
37
|
+
setBadgeCount(count) {
|
|
38
|
+
this.nativeCommandsModule.setBadgeCount(count);
|
|
39
|
+
}
|
|
40
|
+
cancelLocalNotification(notificationId) {
|
|
41
|
+
this.nativeCommandsModule.cancelLocalNotification(notificationId);
|
|
42
|
+
}
|
|
43
|
+
cancelAllLocalNotifications() {
|
|
44
|
+
this.nativeCommandsModule.cancelAllLocalNotifications();
|
|
45
|
+
}
|
|
46
|
+
isRegisteredForRemoteNotifications() {
|
|
47
|
+
return this.nativeCommandsModule.isRegisteredForRemoteNotifications();
|
|
48
|
+
}
|
|
49
|
+
checkPermissions() {
|
|
50
|
+
return this.nativeCommandsModule.checkPermissions();
|
|
51
|
+
}
|
|
52
|
+
removeAllDeliveredNotifications() {
|
|
53
|
+
return this.nativeCommandsModule.removeAllDeliveredNotifications();
|
|
54
|
+
}
|
|
55
|
+
removeDeliveredNotifications(identifiers) {
|
|
56
|
+
return this.nativeCommandsModule.removeDeliveredNotifications(identifiers);
|
|
57
|
+
}
|
|
58
|
+
getDeliveredNotifications() {
|
|
59
|
+
return this.nativeCommandsModule.getDeliveredNotifications();
|
|
60
|
+
}
|
|
61
|
+
finishPresentingNotification(notificationId, notificationCompletion) {
|
|
62
|
+
this.nativeCommandsModule.finishPresentingNotification(notificationId, notificationCompletion);
|
|
63
|
+
}
|
|
64
|
+
finishHandlingAction(notificationId) {
|
|
65
|
+
this.nativeCommandsModule.finishHandlingAction(notificationId);
|
|
66
|
+
}
|
|
67
|
+
setNotificationChannel(notificationChannel) {
|
|
68
|
+
this.nativeCommandsModule.setNotificationChannel(notificationChannel);
|
|
69
|
+
}
|
|
70
|
+
finishHandlingBackgroundAction(notificationId, backgroundFetchResult) {
|
|
71
|
+
this.nativeCommandsModule.finishHandlingBackgroundAction(notificationId, backgroundFetchResult);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.NativeCommandsSender = NativeCommandsSender;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EmitterSubscription } from 'react-native';
|
|
2
|
+
import { Registered, RegistrationError, RegisteredPushKit } from '../interfaces/NotificationEvents';
|
|
3
|
+
import { Notification } from '../DTO/Notification';
|
|
4
|
+
import { NotificationActionResponse } from '../interfaces/NotificationActionResponse';
|
|
5
|
+
import { NotificationFactory } from '../DTO/NotificationFactory';
|
|
6
|
+
export declare class NativeEventsReceiver {
|
|
7
|
+
private readonly notificationFactory;
|
|
8
|
+
private emitter;
|
|
9
|
+
constructor(notificationFactory?: NotificationFactory);
|
|
10
|
+
registerRemoteNotificationsRegistered(callback: (event: Registered) => void): EmitterSubscription;
|
|
11
|
+
appNotificationSettingsLinked(callback: () => void): EmitterSubscription;
|
|
12
|
+
registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription;
|
|
13
|
+
registerNotificationReceived(callback: (notification: Notification) => void): EmitterSubscription;
|
|
14
|
+
registerNotificationReceivedBackground(callback: (notification: Notification) => void): EmitterSubscription;
|
|
15
|
+
registerPushKitNotificationReceived(callback: (event: object) => void): EmitterSubscription;
|
|
16
|
+
registerNotificationOpened(callback: (notification: Notification, actionResponse?: NotificationActionResponse) => void): EmitterSubscription;
|
|
17
|
+
registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription;
|
|
18
|
+
registerRemoteNotificationsRegistrationDenied(callback: () => void): EmitterSubscription;
|
|
19
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeEventsReceiver = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const NotificationActionResponse_1 = require("../interfaces/NotificationActionResponse");
|
|
6
|
+
const NotificationFactory_1 = require("../DTO/NotificationFactory");
|
|
7
|
+
class NativeEventsReceiver {
|
|
8
|
+
notificationFactory;
|
|
9
|
+
emitter;
|
|
10
|
+
constructor(notificationFactory = new NotificationFactory_1.NotificationFactory()) {
|
|
11
|
+
this.notificationFactory = notificationFactory;
|
|
12
|
+
this.emitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNEventEmitter);
|
|
13
|
+
}
|
|
14
|
+
registerRemoteNotificationsRegistered(callback) {
|
|
15
|
+
return this.emitter.addListener('remoteNotificationsRegistered', callback);
|
|
16
|
+
}
|
|
17
|
+
appNotificationSettingsLinked(callback) {
|
|
18
|
+
return this.emitter.addListener('appNotificationSettingsLinked', callback);
|
|
19
|
+
}
|
|
20
|
+
registerPushKitRegistered(callback) {
|
|
21
|
+
return this.emitter.addListener('pushKitRegistered', callback);
|
|
22
|
+
}
|
|
23
|
+
registerNotificationReceived(callback) {
|
|
24
|
+
return this.emitter.addListener('notificationReceived', (payload) => {
|
|
25
|
+
callback(this.notificationFactory.fromPayload(payload));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
registerNotificationReceivedBackground(callback) {
|
|
29
|
+
return this.emitter.addListener('notificationReceivedBackground', (payload) => {
|
|
30
|
+
callback(this.notificationFactory.fromPayload(payload));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
registerPushKitNotificationReceived(callback) {
|
|
34
|
+
return this.emitter.addListener('pushKitNotificationReceived', callback);
|
|
35
|
+
}
|
|
36
|
+
registerNotificationOpened(callback) {
|
|
37
|
+
return this.emitter.addListener('notificationOpened', (response) => {
|
|
38
|
+
const action = response.action ? new NotificationActionResponse_1.NotificationActionResponse(response.action) : undefined;
|
|
39
|
+
callback(this.notificationFactory.fromPayload(response.notification), action);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
registerRemoteNotificationsRegistrationFailed(callback) {
|
|
43
|
+
return this.emitter.addListener('remoteNotificationsRegistrationFailed', callback);
|
|
44
|
+
}
|
|
45
|
+
registerRemoteNotificationsRegistrationDenied(callback) {
|
|
46
|
+
return this.emitter.addListener('remoteNotificationsRegistrationDenied', callback);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.NativeEventsReceiver = NativeEventsReceiver;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueIdProvider = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
class UniqueIdProvider {
|
|
6
|
+
generate() {
|
|
7
|
+
return parseInt(_.uniqueId());
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.UniqueIdProvider = UniqueIdProvider;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NativeCommandsSender } from '../adapters/NativeCommandsSender';
|
|
2
|
+
import { Notification } from '../DTO/Notification';
|
|
3
|
+
import { NotificationCategory } from '../interfaces/NotificationCategory';
|
|
4
|
+
import { NotificationChannel } from '../interfaces/NotificationChannel';
|
|
5
|
+
import { NotificationPermissions } from '../interfaces/NotificationPermissions';
|
|
6
|
+
import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
|
|
7
|
+
import { NotificationFactory } from '../DTO/NotificationFactory';
|
|
8
|
+
import { NotificationPermissionOptions } from '../interfaces/NotificationPermissions';
|
|
9
|
+
export declare class Commands {
|
|
10
|
+
private readonly nativeCommandsSender;
|
|
11
|
+
private readonly uniqueIdProvider;
|
|
12
|
+
private readonly notificationFactory;
|
|
13
|
+
constructor(nativeCommandsSender: NativeCommandsSender, uniqueIdProvider: UniqueIdProvider, notificationFactory: NotificationFactory);
|
|
14
|
+
postLocalNotification(notification: Notification, id?: number): number;
|
|
15
|
+
getInitialNotification(): Promise<Notification | undefined>;
|
|
16
|
+
getLastAction(): Promise<Notification | undefined>;
|
|
17
|
+
requestPermissions(options?: NotificationPermissionOptions): void;
|
|
18
|
+
abandonPermissions(): void;
|
|
19
|
+
registerPushKit(): void;
|
|
20
|
+
setCategories(categories: [NotificationCategory?]): void;
|
|
21
|
+
getBadgeCount(): Promise<number>;
|
|
22
|
+
setBadgeCount(count: number): void;
|
|
23
|
+
cancelLocalNotification(notificationId: number): void;
|
|
24
|
+
cancelAllLocalNotifications(): void;
|
|
25
|
+
isRegisteredForRemoteNotifications(): Promise<boolean>;
|
|
26
|
+
checkPermissions(): Promise<NotificationPermissions>;
|
|
27
|
+
removeAllDeliveredNotifications(): void;
|
|
28
|
+
removeDeliveredNotifications(identifiers: Array<string>): void;
|
|
29
|
+
getDeliveredNotifications(): Promise<Notification[]>;
|
|
30
|
+
refreshToken(): void;
|
|
31
|
+
setNotificationChannel(notificationChannel: NotificationChannel): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Commands = void 0;
|
|
4
|
+
class Commands {
|
|
5
|
+
nativeCommandsSender;
|
|
6
|
+
uniqueIdProvider;
|
|
7
|
+
notificationFactory;
|
|
8
|
+
constructor(nativeCommandsSender, uniqueIdProvider, notificationFactory) {
|
|
9
|
+
this.nativeCommandsSender = nativeCommandsSender;
|
|
10
|
+
this.uniqueIdProvider = uniqueIdProvider;
|
|
11
|
+
this.notificationFactory = notificationFactory;
|
|
12
|
+
}
|
|
13
|
+
postLocalNotification(notification, id) {
|
|
14
|
+
const notificationId = id ? id : this.uniqueIdProvider.generate();
|
|
15
|
+
this.nativeCommandsSender.postLocalNotification(notification, notificationId);
|
|
16
|
+
return notificationId;
|
|
17
|
+
}
|
|
18
|
+
async getInitialNotification() {
|
|
19
|
+
return this.nativeCommandsSender.getInitialNotification().then((payload) => {
|
|
20
|
+
if (payload) {
|
|
21
|
+
return this.notificationFactory.fromPayload(payload);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async getLastAction() {
|
|
27
|
+
return this.nativeCommandsSender.getLastAction().then((payload) => {
|
|
28
|
+
if (payload) {
|
|
29
|
+
return this.notificationFactory.fromPayload(payload);
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
requestPermissions(options) {
|
|
35
|
+
const result = this.nativeCommandsSender.requestPermissions(options);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
abandonPermissions() {
|
|
39
|
+
const result = this.nativeCommandsSender.abandonPermissions();
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
registerPushKit() {
|
|
43
|
+
this.nativeCommandsSender.registerPushKit();
|
|
44
|
+
}
|
|
45
|
+
setCategories(categories) {
|
|
46
|
+
this.nativeCommandsSender.setCategories(categories);
|
|
47
|
+
}
|
|
48
|
+
getBadgeCount() {
|
|
49
|
+
return this.nativeCommandsSender.getBadgeCount();
|
|
50
|
+
}
|
|
51
|
+
setBadgeCount(count) {
|
|
52
|
+
this.nativeCommandsSender.setBadgeCount(count);
|
|
53
|
+
}
|
|
54
|
+
cancelLocalNotification(notificationId) {
|
|
55
|
+
this.nativeCommandsSender.cancelLocalNotification(notificationId);
|
|
56
|
+
}
|
|
57
|
+
cancelAllLocalNotifications() {
|
|
58
|
+
this.nativeCommandsSender.cancelAllLocalNotifications();
|
|
59
|
+
}
|
|
60
|
+
isRegisteredForRemoteNotifications() {
|
|
61
|
+
return this.nativeCommandsSender.isRegisteredForRemoteNotifications();
|
|
62
|
+
}
|
|
63
|
+
checkPermissions() {
|
|
64
|
+
return this.nativeCommandsSender.checkPermissions();
|
|
65
|
+
}
|
|
66
|
+
removeAllDeliveredNotifications() {
|
|
67
|
+
this.nativeCommandsSender.removeAllDeliveredNotifications();
|
|
68
|
+
}
|
|
69
|
+
removeDeliveredNotifications(identifiers) {
|
|
70
|
+
return this.nativeCommandsSender.removeDeliveredNotifications(identifiers);
|
|
71
|
+
}
|
|
72
|
+
getDeliveredNotifications() {
|
|
73
|
+
return this.nativeCommandsSender.getDeliveredNotifications();
|
|
74
|
+
}
|
|
75
|
+
refreshToken() {
|
|
76
|
+
this.nativeCommandsSender.refreshToken();
|
|
77
|
+
}
|
|
78
|
+
setNotificationChannel(notificationChannel) {
|
|
79
|
+
this.nativeCommandsSender.setNotificationChannel(notificationChannel);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.Commands = Commands;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ts_mockito_1 = require("ts-mockito");
|
|
4
|
+
const Commands_1 = require("./Commands");
|
|
5
|
+
const NativeCommandsSender_1 = require("../adapters/NativeCommandsSender");
|
|
6
|
+
const Notification_1 = require("../DTO/Notification");
|
|
7
|
+
const UniqueIdProvider_1 = require("../adapters/UniqueIdProvider");
|
|
8
|
+
const NotificationFactory_1 = require("../DTO/NotificationFactory");
|
|
9
|
+
const NotificationAndroid_1 = require("../DTO/NotificationAndroid");
|
|
10
|
+
const react_native_1 = require("react-native");
|
|
11
|
+
const NotificationIOS_1 = require("../DTO/NotificationIOS");
|
|
12
|
+
describe('Commands', () => {
|
|
13
|
+
let uut;
|
|
14
|
+
let mockedNativeCommandsSender;
|
|
15
|
+
let mockedUniqueIdProvider;
|
|
16
|
+
let notificationFactory;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
notificationFactory = new NotificationFactory_1.NotificationFactory();
|
|
19
|
+
mockedNativeCommandsSender = (0, ts_mockito_1.mock)(NativeCommandsSender_1.NativeCommandsSender);
|
|
20
|
+
mockedUniqueIdProvider = (0, ts_mockito_1.mock)(UniqueIdProvider_1.UniqueIdProvider);
|
|
21
|
+
(0, ts_mockito_1.when)(mockedUniqueIdProvider.generate()).thenCall(() => 12);
|
|
22
|
+
uut = new Commands_1.Commands((0, ts_mockito_1.instance)(mockedNativeCommandsSender), (0, ts_mockito_1.instance)(mockedUniqueIdProvider), notificationFactory);
|
|
23
|
+
});
|
|
24
|
+
describe('getInitialNotification', () => {
|
|
25
|
+
it('sends to native', () => {
|
|
26
|
+
uut.getInitialNotification();
|
|
27
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.getInitialNotification()).called();
|
|
28
|
+
});
|
|
29
|
+
it('Android - returns a promise with the initial notification', async () => {
|
|
30
|
+
react_native_1.Platform.OS = 'android';
|
|
31
|
+
const expectedNotification = new NotificationAndroid_1.NotificationAndroid({ 'google.message_id': 'id' });
|
|
32
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.getInitialNotification()).thenResolve({ 'google.message_id': 'id' });
|
|
33
|
+
const result = await uut.getInitialNotification();
|
|
34
|
+
expect(result).toEqual(expectedNotification);
|
|
35
|
+
});
|
|
36
|
+
it('Should return undefined initial notification', async () => {
|
|
37
|
+
react_native_1.Platform.OS = 'android';
|
|
38
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.getInitialNotification()).thenResolve();
|
|
39
|
+
const result = await uut.getInitialNotification();
|
|
40
|
+
expect(result).toEqual(undefined);
|
|
41
|
+
});
|
|
42
|
+
it('iOS - returns a promise with the initial notification', async () => {
|
|
43
|
+
react_native_1.Platform.OS = 'ios';
|
|
44
|
+
const expectedNotification = new NotificationIOS_1.NotificationIOS({ identifier: 'id' });
|
|
45
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.getInitialNotification()).thenResolve({ identifier: 'id' });
|
|
46
|
+
const result = await uut.getInitialNotification();
|
|
47
|
+
expect(result).toEqual(expectedNotification);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('requestPermissions', () => {
|
|
51
|
+
it('sends to native', () => {
|
|
52
|
+
const opts = {};
|
|
53
|
+
uut.requestPermissions(opts);
|
|
54
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.requestPermissions(opts)).called();
|
|
55
|
+
});
|
|
56
|
+
it('sends to native with options', () => {
|
|
57
|
+
const opts = { criticalAlert: true };
|
|
58
|
+
uut.requestPermissions(opts);
|
|
59
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.requestPermissions(opts)).called();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('registerPushKit', () => {
|
|
63
|
+
it('sends to native', () => {
|
|
64
|
+
uut.registerPushKit();
|
|
65
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.registerPushKit()).called();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('setCategories', () => {
|
|
69
|
+
it('sends to native', () => {
|
|
70
|
+
const emptyCategoriesArray = [];
|
|
71
|
+
uut.setCategories(emptyCategoriesArray);
|
|
72
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.setCategories(emptyCategoriesArray)).called();
|
|
73
|
+
});
|
|
74
|
+
it('sends to native with categories', () => {
|
|
75
|
+
const category = { identifier: 'id', actions: [] };
|
|
76
|
+
const categoriesArray = [category];
|
|
77
|
+
uut.setCategories(categoriesArray);
|
|
78
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.setCategories(categoriesArray)).called();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('abandonPermissions', () => {
|
|
82
|
+
it('sends to native', () => {
|
|
83
|
+
uut.abandonPermissions();
|
|
84
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.abandonPermissions()).called();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('postLocalNotification', () => {
|
|
88
|
+
it('sends to native', () => {
|
|
89
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
90
|
+
uut.postLocalNotification(notification);
|
|
91
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.postLocalNotification(notification, (0, ts_mockito_1.anyNumber)())).called();
|
|
92
|
+
});
|
|
93
|
+
it('generates unique identifier', () => {
|
|
94
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
95
|
+
uut.postLocalNotification(notification);
|
|
96
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.postLocalNotification(notification, (0, ts_mockito_1.anyNumber)())).called();
|
|
97
|
+
});
|
|
98
|
+
it('use passed notification id', () => {
|
|
99
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
100
|
+
const passedId = 2;
|
|
101
|
+
uut.postLocalNotification(notification, passedId);
|
|
102
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.postLocalNotification(notification, passedId)).called();
|
|
103
|
+
});
|
|
104
|
+
it('return notification id', () => {
|
|
105
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
106
|
+
const notificationId = 2;
|
|
107
|
+
const response = uut.postLocalNotification(notification, notificationId);
|
|
108
|
+
expect(response).toEqual(notificationId);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe('getBadgeCount', () => {
|
|
112
|
+
it('sends to native', () => {
|
|
113
|
+
uut.getBadgeCount();
|
|
114
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.getBadgeCount()).called();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe('setBadgeCount', () => {
|
|
118
|
+
it('sends to native', () => {
|
|
119
|
+
uut.setBadgeCount(10);
|
|
120
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.setBadgeCount(10)).called();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe('cancelLocalNotification', () => {
|
|
124
|
+
it('sends to native', () => {
|
|
125
|
+
const notificationId = 1;
|
|
126
|
+
uut.cancelLocalNotification(notificationId);
|
|
127
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.cancelLocalNotification(notificationId)).called();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('cancelAllLocalNotifications', () => {
|
|
131
|
+
it('sends to native', () => {
|
|
132
|
+
uut.cancelAllLocalNotifications();
|
|
133
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.cancelAllLocalNotifications()).called();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe('isRegisteredForRemoteNotifications', () => {
|
|
137
|
+
it('sends to native', () => {
|
|
138
|
+
uut.isRegisteredForRemoteNotifications();
|
|
139
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called();
|
|
140
|
+
});
|
|
141
|
+
it('return positive response from native', async () => {
|
|
142
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(true);
|
|
143
|
+
const isRegistered = await uut.isRegisteredForRemoteNotifications();
|
|
144
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called();
|
|
145
|
+
expect(isRegistered).toEqual(true);
|
|
146
|
+
});
|
|
147
|
+
it('return negative response from native', async () => {
|
|
148
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(false);
|
|
149
|
+
const isRegistered = await uut.isRegisteredForRemoteNotifications();
|
|
150
|
+
expect(isRegistered).toEqual(false);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('checkPermissions', () => {
|
|
154
|
+
it('sends to native', () => {
|
|
155
|
+
uut.checkPermissions();
|
|
156
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.checkPermissions()).called();
|
|
157
|
+
});
|
|
158
|
+
it('return negative response from native', async () => {
|
|
159
|
+
const expectedPermissions = {
|
|
160
|
+
badge: false,
|
|
161
|
+
alert: true,
|
|
162
|
+
sound: false,
|
|
163
|
+
carPlay: false,
|
|
164
|
+
criticalAlert: false,
|
|
165
|
+
providesAppNotificationSettings: false,
|
|
166
|
+
provisional: false,
|
|
167
|
+
announcement: false,
|
|
168
|
+
notificationCenter: true,
|
|
169
|
+
lockScreen: false,
|
|
170
|
+
};
|
|
171
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.checkPermissions()).thenResolve(expectedPermissions);
|
|
172
|
+
const permissions = await uut.checkPermissions();
|
|
173
|
+
expect(permissions).toEqual(expectedPermissions);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe('removeAllDeliveredNotifications', () => {
|
|
177
|
+
it('sends to native', () => {
|
|
178
|
+
uut.removeAllDeliveredNotifications();
|
|
179
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.removeAllDeliveredNotifications()).called();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('removeDeliveredNotifications', () => {
|
|
183
|
+
it('sends to native', () => {
|
|
184
|
+
const identifiers = ["id1", "id2"];
|
|
185
|
+
uut.removeDeliveredNotifications(identifiers);
|
|
186
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.removeDeliveredNotifications(identifiers)).called();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
describe('getDeliveredNotifications', () => {
|
|
190
|
+
it('sends to native', () => {
|
|
191
|
+
uut.getDeliveredNotifications();
|
|
192
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.getDeliveredNotifications()).called();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
describe('refreshToken', () => {
|
|
196
|
+
it('sends to native', () => {
|
|
197
|
+
uut.refreshToken();
|
|
198
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.refreshToken()).called();
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|