From 63b7f8cc5188c8bfe3895a566177462754a46e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B2=9D=E6=96=AF=E9=84=A7=E4=B8=8D=E5=88=A9=E5=A4=9A?= Date: Thu, 26 Dec 2019 20:11:18 +0800 Subject: [PATCH] update dist js --- lib/android/app/.gitignore | 2 - lib/dist/DTO/Notification.d.ts | 12 ++ lib/dist/DTO/Notification.js | 30 ++++ lib/dist/DTO/Notification.test.d.ts | 1 + lib/dist/DTO/Notification.test.js | 45 +++++ lib/dist/Notifications.d.ts | 45 +++++ lib/dist/Notifications.js | 68 ++++++++ lib/dist/NotificationsAndroid.d.ts | 9 + lib/dist/NotificationsAndroid.js | 25 +++ lib/dist/NotificationsIOS.d.ts | 54 ++++++ lib/dist/NotificationsIOS.js | 88 ++++++++++ .../adapters/CompletionCallbackWrapper.d.ts | 8 + .../adapters/CompletionCallbackWrapper.js | 29 ++++ lib/dist/adapters/NativeCommandsSender.d.ts | 26 +++ lib/dist/adapters/NativeCommandsSender.js | 63 +++++++ .../adapters/NativeCommandsSender.mock.d.ts | 1 + .../adapters/NativeCommandsSender.mock.js | 3 + lib/dist/adapters/NativeEventsReceiver.d.ts | 14 ++ lib/dist/adapters/NativeEventsReceiver.js | 34 ++++ .../adapters/NativeEventsReceiver.mock.d.ts | 1 + .../adapters/NativeEventsReceiver.mock.js | 3 + lib/dist/adapters/UniqueIdProvider.d.ts | 3 + lib/dist/adapters/UniqueIdProvider.js | 9 + lib/dist/commands/Commands.d.ts | 26 +++ lib/dist/commands/Commands.js | 67 ++++++++ lib/dist/commands/Commands.test.d.ts | 1 + lib/dist/commands/Commands.test.js | 157 ++++++++++++++++++ lib/dist/events/EventsRegistry.d.ts | 15 ++ lib/dist/events/EventsRegistry.js | 21 +++ lib/dist/events/EventsRegistry.test.d.ts | 1 + lib/dist/events/EventsRegistry.test.js | 124 ++++++++++++++ lib/dist/events/EventsRegistryIOS.d.ts | 9 + lib/dist/events/EventsRegistryIOS.js | 14 ++ lib/dist/events/EventsRegistryIOS.test.d.ts | 1 + lib/dist/events/EventsRegistryIOS.test.js | 23 +++ lib/dist/index.d.ts | 6 + lib/dist/index.js | 8 + lib/dist/interfaces/EventSubscription.d.ts | 3 + lib/dist/interfaces/EventSubscription.js | 2 + .../NotificationActionResponse.d.ts | 5 + .../interfaces/NotificationActionResponse.js | 9 + lib/dist/interfaces/NotificationCategory.d.ts | 17 ++ lib/dist/interfaces/NotificationCategory.js | 19 +++ .../interfaces/NotificationCompletion.d.ts | 5 + lib/dist/interfaces/NotificationCompletion.js | 2 + lib/dist/interfaces/NotificationEvents.d.ts | 18 ++ lib/dist/interfaces/NotificationEvents.js | 2 + .../interfaces/NotificationPermissions.d.ts | 5 + .../interfaces/NotificationPermissions.js | 2 + package.json | 2 +- 50 files changed, 1134 insertions(+), 3 deletions(-) delete mode 100644 lib/android/app/.gitignore create mode 100644 lib/dist/DTO/Notification.d.ts create mode 100644 lib/dist/DTO/Notification.js create mode 100644 lib/dist/DTO/Notification.test.d.ts create mode 100644 lib/dist/DTO/Notification.test.js create mode 100644 lib/dist/Notifications.d.ts create mode 100644 lib/dist/Notifications.js create mode 100644 lib/dist/NotificationsAndroid.d.ts create mode 100644 lib/dist/NotificationsAndroid.js create mode 100644 lib/dist/NotificationsIOS.d.ts create mode 100644 lib/dist/NotificationsIOS.js create mode 100644 lib/dist/adapters/CompletionCallbackWrapper.d.ts create mode 100644 lib/dist/adapters/CompletionCallbackWrapper.js create mode 100644 lib/dist/adapters/NativeCommandsSender.d.ts create mode 100644 lib/dist/adapters/NativeCommandsSender.js create mode 100644 lib/dist/adapters/NativeCommandsSender.mock.d.ts create mode 100644 lib/dist/adapters/NativeCommandsSender.mock.js create mode 100644 lib/dist/adapters/NativeEventsReceiver.d.ts create mode 100644 lib/dist/adapters/NativeEventsReceiver.js create mode 100644 lib/dist/adapters/NativeEventsReceiver.mock.d.ts create mode 100644 lib/dist/adapters/NativeEventsReceiver.mock.js create mode 100644 lib/dist/adapters/UniqueIdProvider.d.ts create mode 100644 lib/dist/adapters/UniqueIdProvider.js create mode 100644 lib/dist/commands/Commands.d.ts create mode 100644 lib/dist/commands/Commands.js create mode 100644 lib/dist/commands/Commands.test.d.ts create mode 100644 lib/dist/commands/Commands.test.js create mode 100644 lib/dist/events/EventsRegistry.d.ts create mode 100644 lib/dist/events/EventsRegistry.js create mode 100644 lib/dist/events/EventsRegistry.test.d.ts create mode 100644 lib/dist/events/EventsRegistry.test.js create mode 100644 lib/dist/events/EventsRegistryIOS.d.ts create mode 100644 lib/dist/events/EventsRegistryIOS.js create mode 100644 lib/dist/events/EventsRegistryIOS.test.d.ts create mode 100644 lib/dist/events/EventsRegistryIOS.test.js create mode 100644 lib/dist/index.d.ts create mode 100644 lib/dist/index.js create mode 100644 lib/dist/interfaces/EventSubscription.d.ts create mode 100644 lib/dist/interfaces/EventSubscription.js create mode 100644 lib/dist/interfaces/NotificationActionResponse.d.ts create mode 100644 lib/dist/interfaces/NotificationActionResponse.js create mode 100644 lib/dist/interfaces/NotificationCategory.d.ts create mode 100644 lib/dist/interfaces/NotificationCategory.js create mode 100644 lib/dist/interfaces/NotificationCompletion.d.ts create mode 100644 lib/dist/interfaces/NotificationCompletion.js create mode 100644 lib/dist/interfaces/NotificationEvents.d.ts create mode 100644 lib/dist/interfaces/NotificationEvents.js create mode 100644 lib/dist/interfaces/NotificationPermissions.d.ts create mode 100644 lib/dist/interfaces/NotificationPermissions.js diff --git a/lib/android/app/.gitignore b/lib/android/app/.gitignore deleted file mode 100644 index 65d12b9..0000000 --- a/lib/android/app/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/build -google-services.json \ No newline at end of file diff --git a/lib/dist/DTO/Notification.d.ts b/lib/dist/DTO/Notification.d.ts new file mode 100644 index 0000000..0e55940 --- /dev/null +++ b/lib/dist/DTO/Notification.d.ts @@ -0,0 +1,12 @@ +export declare class Notification { + identifier: string; + private _data?; + constructor(payload: object); + readonly data: any; + readonly title: string; + readonly body: string; + readonly sound: string; + readonly badge: number; + readonly type: string; + readonly thread: string; +} diff --git a/lib/dist/DTO/Notification.js b/lib/dist/DTO/Notification.js new file mode 100644 index 0000000..d37f610 --- /dev/null +++ b/lib/dist/DTO/Notification.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class Notification { + constructor(payload) { + this._data = payload; + this.identifier = this._data.identifier; + } + get data() { + return this._data; + } + get title() { + return this._data.title; + } + get body() { + return this._data.body; + } + get sound() { + return this._data.sound; + } + get badge() { + return this._data.badge; + } + get type() { + return this._data.type; + } + get thread() { + return this._data.thread; + } +} +exports.Notification = Notification; diff --git a/lib/dist/DTO/Notification.test.d.ts b/lib/dist/DTO/Notification.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/dist/DTO/Notification.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/dist/DTO/Notification.test.js b/lib/dist/DTO/Notification.test.js new file mode 100644 index 0000000..2cf234f --- /dev/null +++ b/lib/dist/DTO/Notification.test.js @@ -0,0 +1,45 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Notification_1 = require("./Notification"); +describe('Notification', () => { + it('Should create notification with payload', () => { + const payload = { p: 'p' }; + const notification = new Notification_1.Notification(payload); + expect(notification.data).toEqual(payload); + }); + it('Should create notification with identifier', () => { + const payload = { identifier: 'identifier' }; + const notification = new Notification_1.Notification(payload); + expect(notification.identifier).toEqual(payload.identifier); + }); + it('Should return title from payload', () => { + const payload = { title: 'title' }; + const notification = new Notification_1.Notification(payload); + expect(notification.title).toEqual(payload.title); + }); + it('Should return body from payload', () => { + const payload = { body: 'body' }; + const notification = new Notification_1.Notification(payload); + expect(notification.body).toEqual(payload.body); + }); + it('Should return sound from payload', () => { + const payload = { sound: 'sound.mp4' }; + const notification = new Notification_1.Notification(payload); + expect(notification.sound).toEqual(payload.sound); + }); + it('Should return badge from payload', () => { + const payload = { badge: 1 }; + const notification = new Notification_1.Notification(payload); + expect(notification.badge).toEqual(payload.badge); + }); + it('Should return type from payload', () => { + const payload = { type: 'type' }; + const notification = new Notification_1.Notification(payload); + expect(notification.type).toEqual(payload.type); + }); + it('Should return thread from payload', () => { + const payload = { thread: 'thread' }; + const notification = new Notification_1.Notification(payload); + expect(notification.thread).toEqual(payload.thread); + }); +}); diff --git a/lib/dist/Notifications.d.ts b/lib/dist/Notifications.d.ts new file mode 100644 index 0000000..3d8d418 --- /dev/null +++ b/lib/dist/Notifications.d.ts @@ -0,0 +1,45 @@ +import { EventsRegistry } from './events/EventsRegistry'; +import { Notification } from './DTO/Notification'; +import { NotificationCategory } from './interfaces/NotificationCategory'; +import { NotificationsIOS } from './NotificationsIOS'; +import { NotificationsAndroid } from './NotificationsAndroid'; +export declare class NotificationsRoot { + readonly ios: NotificationsIOS; + readonly android: NotificationsAndroid; + private readonly nativeEventsReceiver; + private readonly nativeCommandsSender; + private readonly commands; + private readonly eventsRegistry; + private readonly eventsRegistryIOS; + private readonly uniqueIdProvider; + private readonly completionCallbackWrapper; + constructor(); + /** + * registerRemoteNotifications + */ + registerRemoteNotifications(): void; + /** + * postLocalNotification + */ + postLocalNotification(notification: Notification, id: number): void; + /** + * getInitialNotification + */ + getInitialNotification(): Promise; + /** + * setCategories + */ + setCategories(categories: [NotificationCategory?]): void; + /** + * cancelLocalNotification + */ + cancelLocalNotification(notificationId: string): void; + /** + * isRegisteredForRemoteNotifications + */ + isRegisteredForRemoteNotifications(): Promise; + /** + * Obtain the events registry instance + */ + events(): EventsRegistry; +} diff --git a/lib/dist/Notifications.js b/lib/dist/Notifications.js new file mode 100644 index 0000000..a706b5b --- /dev/null +++ b/lib/dist/Notifications.js @@ -0,0 +1,68 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const NativeCommandsSender_1 = require("./adapters/NativeCommandsSender"); +const NativeEventsReceiver_1 = require("./adapters/NativeEventsReceiver"); +const Commands_1 = require("./commands/Commands"); +const EventsRegistry_1 = require("./events/EventsRegistry"); +const EventsRegistryIOS_1 = require("./events/EventsRegistryIOS"); +const UniqueIdProvider_1 = require("./adapters/UniqueIdProvider"); +const CompletionCallbackWrapper_1 = require("./adapters/CompletionCallbackWrapper"); +const NotificationsIOS_1 = require("./NotificationsIOS"); +const NotificationsAndroid_1 = require("./NotificationsAndroid"); +class NotificationsRoot { + constructor() { + this.nativeEventsReceiver = new NativeEventsReceiver_1.NativeEventsReceiver(); + this.nativeCommandsSender = new NativeCommandsSender_1.NativeCommandsSender(); + this.completionCallbackWrapper = new CompletionCallbackWrapper_1.CompletionCallbackWrapper(this.nativeCommandsSender); + this.uniqueIdProvider = new UniqueIdProvider_1.UniqueIdProvider(); + this.commands = new Commands_1.Commands(this.nativeCommandsSender, this.uniqueIdProvider); + this.eventsRegistry = new EventsRegistry_1.EventsRegistry(this.nativeEventsReceiver, this.completionCallbackWrapper); + this.eventsRegistryIOS = new EventsRegistryIOS_1.EventsRegistryIOS(this.nativeEventsReceiver); + this.ios = new NotificationsIOS_1.NotificationsIOS(this.commands, this.eventsRegistryIOS); + this.android = new NotificationsAndroid_1.NotificationsAndroid(this.commands); + } + /** + * registerRemoteNotifications + */ + registerRemoteNotifications() { + this.ios.registerRemoteNotifications(); + this.android.registerRemoteNotifications(); + } + /** + * postLocalNotification + */ + postLocalNotification(notification, id) { + return this.commands.postLocalNotification(notification, id); + } + /** + * getInitialNotification + */ + getInitialNotification() { + return this.commands.getInitialNotification(); + } + /** + * setCategories + */ + setCategories(categories) { + this.commands.setCategories(categories); + } + /** + * cancelLocalNotification + */ + cancelLocalNotification(notificationId) { + return this.commands.cancelLocalNotification(notificationId); + } + /** + * isRegisteredForRemoteNotifications + */ + isRegisteredForRemoteNotifications() { + return this.commands.isRegisteredForRemoteNotifications(); + } + /** + * Obtain the events registry instance + */ + events() { + return this.eventsRegistry; + } +} +exports.NotificationsRoot = NotificationsRoot; diff --git a/lib/dist/NotificationsAndroid.d.ts b/lib/dist/NotificationsAndroid.d.ts new file mode 100644 index 0000000..4383d9a --- /dev/null +++ b/lib/dist/NotificationsAndroid.d.ts @@ -0,0 +1,9 @@ +import { Commands } from './commands/Commands'; +export declare class NotificationsAndroid { + private readonly commands; + constructor(commands: Commands); + /** + * Refresh FCM token + */ + registerRemoteNotifications(): void; +} diff --git a/lib/dist/NotificationsAndroid.js b/lib/dist/NotificationsAndroid.js new file mode 100644 index 0000000..5b6f817 --- /dev/null +++ b/lib/dist/NotificationsAndroid.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_native_1 = require("react-native"); +class NotificationsAndroid { + constructor(commands) { + this.commands = commands; + return new Proxy(this, { + get(target, name) { + if (react_native_1.Platform.OS === 'android') { + return target[name]; + } + else { + return () => { }; + } + } + }); + } + /** + * Refresh FCM token + */ + registerRemoteNotifications() { + this.commands.refreshToken(); + } +} +exports.NotificationsAndroid = NotificationsAndroid; diff --git a/lib/dist/NotificationsIOS.d.ts b/lib/dist/NotificationsIOS.d.ts new file mode 100644 index 0000000..0a8fc24 --- /dev/null +++ b/lib/dist/NotificationsIOS.d.ts @@ -0,0 +1,54 @@ +import { Notification } from './DTO/Notification'; +import { Commands } from './commands/Commands'; +import { EventsRegistryIOS } from './events/EventsRegistryIOS'; +export declare class NotificationsIOS { + private readonly commands; + private readonly eventsRegistry; + constructor(commands: Commands, eventsRegistry: EventsRegistryIOS); + /** + * Request permissions to send remote notifications + */ + registerRemoteNotifications(): void; + /** + * Unregister for all remote notifications received via Apple Push Notification service + */ + abandonPermissions(): void; + /** + * registerPushKit + */ + registerPushKit(): void; + /** + * getBadgesCount + */ + getBadgeCount(): Promise; + /** + * setBadgeCount + * @param count number of the new badge count + */ + setBadgeCount(count: number): void; + /** + * cancelAllLocalNotifications + */ + cancelAllLocalNotifications(): void; + /** + * checkPermissions + */ + checkPermissions(): Promise; + /** + * removeAllDeliveredNotifications + */ + removeAllDeliveredNotifications(): void; + /** + * removeDeliveredNotifications + * @param identifiers Array of notification identifiers + */ + removeDeliveredNotifications(identifiers: Array): void; + /** + * getDeliveredNotifications + */ + getDeliveredNotifications(): Array; + /** + * Obtain the events registry instance + */ + events(): EventsRegistryIOS; +} diff --git a/lib/dist/NotificationsIOS.js b/lib/dist/NotificationsIOS.js new file mode 100644 index 0000000..5c9fca7 --- /dev/null +++ b/lib/dist/NotificationsIOS.js @@ -0,0 +1,88 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_native_1 = require("react-native"); +class NotificationsIOS { + constructor(commands, eventsRegistry) { + this.commands = commands; + this.eventsRegistry = eventsRegistry; + return new Proxy(this, { + get(target, name) { + if (react_native_1.Platform.OS === 'ios') { + return target[name]; + } + else { + return () => { }; + } + } + }); + } + /** + * Request permissions to send remote notifications + */ + registerRemoteNotifications() { + return this.commands.requestPermissions(); + } + /** + * Unregister for all remote notifications received via Apple Push Notification service + */ + abandonPermissions() { + return this.commands.abandonPermissions(); + } + /** + * registerPushKit + */ + registerPushKit() { + return this.commands.registerPushKit(); + } + /** + * getBadgesCount + */ + getBadgeCount() { + return this.commands.getBadgeCount(); + } + /** + * setBadgeCount + * @param count number of the new badge count + */ + setBadgeCount(count) { + return this.commands.setBadgeCount(count); + } + /** + * cancelAllLocalNotifications + */ + cancelAllLocalNotifications() { + this.commands.cancelAllLocalNotifications(); + } + /** + * checkPermissions + */ + checkPermissions() { + return this.commands.checkPermissions(); + } + /** + * removeAllDeliveredNotifications + */ + removeAllDeliveredNotifications() { + return this.commands.removeAllDeliveredNotifications(); + } + /** + * removeDeliveredNotifications + * @param identifiers Array of notification identifiers + */ + removeDeliveredNotifications(identifiers) { + return this.commands.removeDeliveredNotifications(identifiers); + } + /** + * getDeliveredNotifications + */ + getDeliveredNotifications() { + return this.commands.getDeliveredNotifications(); + } + /** + * Obtain the events registry instance + */ + events() { + return this.eventsRegistry; + } +} +exports.NotificationsIOS = NotificationsIOS; diff --git a/lib/dist/adapters/CompletionCallbackWrapper.d.ts b/lib/dist/adapters/CompletionCallbackWrapper.d.ts new file mode 100644 index 0000000..0e5fc4d --- /dev/null +++ b/lib/dist/adapters/CompletionCallbackWrapper.d.ts @@ -0,0 +1,8 @@ +import { NativeCommandsSender } from './NativeCommandsSender'; +import { Notification } from '../DTO/Notification'; +export declare class CompletionCallbackWrapper { + private readonly nativeCommandsSender; + constructor(nativeCommandsSender: NativeCommandsSender); + wrapReceivedCallback(callback: Function): (notification: Notification) => void; + wrapOpenedCallback(callback: Function): (notification: Notification) => void; +} diff --git a/lib/dist/adapters/CompletionCallbackWrapper.js b/lib/dist/adapters/CompletionCallbackWrapper.js new file mode 100644 index 0000000..6455e51 --- /dev/null +++ b/lib/dist/adapters/CompletionCallbackWrapper.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_native_1 = require("react-native"); +class CompletionCallbackWrapper { + constructor(nativeCommandsSender) { + this.nativeCommandsSender = nativeCommandsSender; + } + wrapReceivedCallback(callback) { + return (notification) => { + const completion = (response) => { + if (react_native_1.Platform.OS === 'ios') { + this.nativeCommandsSender.finishPresentingNotification(notification.identifier, response); + } + }; + callback(notification, completion); + }; + } + wrapOpenedCallback(callback) { + return (notification) => { + const completion = () => { + if (react_native_1.Platform.OS === 'ios') { + this.nativeCommandsSender.finishHandlingAction(notification.identifier); + } + }; + callback(notification, completion); + }; + } +} +exports.CompletionCallbackWrapper = CompletionCallbackWrapper; diff --git a/lib/dist/adapters/NativeCommandsSender.d.ts b/lib/dist/adapters/NativeCommandsSender.d.ts new file mode 100644 index 0000000..a0a4bc1 --- /dev/null +++ b/lib/dist/adapters/NativeCommandsSender.d.ts @@ -0,0 +1,26 @@ +import { Notification } from '../DTO/Notification'; +import { NotificationCompletion } from '../interfaces/NotificationCompletion'; +import { NotificationPermissions } from '../interfaces/NotificationPermissions'; +import { NotificationCategory } from '../interfaces/NotificationCategory'; +export declare class NativeCommandsSender { + private readonly nativeCommandsModule; + constructor(); + postLocalNotification(notification: Notification, id: number): void; + getInitialNotification(): Promise; + requestPermissions(): void; + abandonPermissions(): void; + refreshToken(): void; + registerPushKit(): void; + setCategories(categories: [NotificationCategory?]): void; + getBadgeCount(): Promise; + setBadgeCount(count: number): void; + cancelLocalNotification(notificationId: string): void; + cancelAllLocalNotifications(): void; + isRegisteredForRemoteNotifications(): Promise; + checkPermissions(): Promise; + removeAllDeliveredNotifications(): void; + removeDeliveredNotifications(identifiers: Array): void; + getDeliveredNotifications(): Array; + finishPresentingNotification(notificationId: string, notificationCompletion: NotificationCompletion): void; + finishHandlingAction(notificationId: string): void; +} diff --git a/lib/dist/adapters/NativeCommandsSender.js b/lib/dist/adapters/NativeCommandsSender.js new file mode 100644 index 0000000..0cc4b58 --- /dev/null +++ b/lib/dist/adapters/NativeCommandsSender.js @@ -0,0 +1,63 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_native_1 = require("react-native"); +class NativeCommandsSender { + constructor() { + this.nativeCommandsModule = react_native_1.NativeModules.RNBridgeModule; + } + postLocalNotification(notification, id) { + return this.nativeCommandsModule.postLocalNotification(notification, id); + } + getInitialNotification() { + return this.nativeCommandsModule.getInitialNotification(); + } + requestPermissions() { + return this.nativeCommandsModule.requestPermissions(); + } + abandonPermissions() { + return this.nativeCommandsModule.abandonPermissions(); + } + refreshToken() { + this.nativeCommandsModule.refreshToken(); + } + registerPushKit() { + return this.nativeCommandsModule.registerPushKit(); + } + setCategories(categories) { + this.nativeCommandsModule.setCategories(categories); + } + getBadgeCount() { + return this.nativeCommandsModule.getBadgeCount(); + } + setBadgeCount(count) { + this.nativeCommandsModule.setBadgeCount(count); + } + cancelLocalNotification(notificationId) { + this.nativeCommandsModule.cancelLocalNotification(notificationId); + } + cancelAllLocalNotifications() { + this.nativeCommandsModule.cancelAllLocalNotifications(); + } + isRegisteredForRemoteNotifications() { + return this.nativeCommandsModule.isRegisteredForRemoteNotifications(); + } + checkPermissions() { + return this.nativeCommandsModule.checkPermissions(); + } + removeAllDeliveredNotifications() { + return this.nativeCommandsModule.removeAllDeliveredNotifications(); + } + removeDeliveredNotifications(identifiers) { + return this.nativeCommandsModule.removeDeliveredNotifications(identifiers); + } + getDeliveredNotifications() { + return this.nativeCommandsModule.getDeliveredNotifications(); + } + finishPresentingNotification(notificationId, notificationCompletion) { + this.nativeCommandsModule.finishPresentingNotification(notificationId, notificationCompletion); + } + finishHandlingAction(notificationId) { + this.nativeCommandsModule.finishHandlingAction(notificationId); + } +} +exports.NativeCommandsSender = NativeCommandsSender; diff --git a/lib/dist/adapters/NativeCommandsSender.mock.d.ts b/lib/dist/adapters/NativeCommandsSender.mock.d.ts new file mode 100644 index 0000000..1c82182 --- /dev/null +++ b/lib/dist/adapters/NativeCommandsSender.mock.d.ts @@ -0,0 +1 @@ +export declare const NativeCommandsSender: any; diff --git a/lib/dist/adapters/NativeCommandsSender.mock.js b/lib/dist/adapters/NativeCommandsSender.mock.js new file mode 100644 index 0000000..0d9cc78 --- /dev/null +++ b/lib/dist/adapters/NativeCommandsSender.mock.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.NativeCommandsSender = jest.genMockFromModule('./NativeCommandsSender').NativeCommandsSender; diff --git a/lib/dist/adapters/NativeEventsReceiver.d.ts b/lib/dist/adapters/NativeEventsReceiver.d.ts new file mode 100644 index 0000000..45dec95 --- /dev/null +++ b/lib/dist/adapters/NativeEventsReceiver.d.ts @@ -0,0 +1,14 @@ +import { EmitterSubscription } from 'react-native'; +import { Registered, RegistrationError, RegisteredPushKit } from '../interfaces/NotificationEvents'; +import { Notification } from '../DTO/Notification'; +import { NotificationActionResponse } from '../interfaces/NotificationActionResponse'; +export declare class NativeEventsReceiver { + private emitter; + constructor(); + registerRemoteNotificationsRegistered(callback: (event: Registered) => void): EmitterSubscription; + registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription; + registerRemoteNotificationReceived(callback: (notification: Notification) => void): EmitterSubscription; + registerPushKitNotificationReceived(callback: (event: object) => void): EmitterSubscription; + registerRemoteNotificationOpened(callback: (notification: Notification, completion: () => void, actionResponse?: NotificationActionResponse) => void): EmitterSubscription; + registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription; +} diff --git a/lib/dist/adapters/NativeEventsReceiver.js b/lib/dist/adapters/NativeEventsReceiver.js new file mode 100644 index 0000000..602241a --- /dev/null +++ b/lib/dist/adapters/NativeEventsReceiver.js @@ -0,0 +1,34 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_native_1 = require("react-native"); +const Notification_1 = require("../DTO/Notification"); +const NotificationActionResponse_1 = require("../interfaces/NotificationActionResponse"); +class NativeEventsReceiver { + constructor() { + this.emitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNEventEmitter); + } + registerRemoteNotificationsRegistered(callback) { + return this.emitter.addListener('remoteNotificationsRegistered', callback); + } + registerPushKitRegistered(callback) { + return this.emitter.addListener('pushKitRegistered', callback); + } + registerRemoteNotificationReceived(callback) { + return this.emitter.addListener('notificationReceived', (payload) => { + callback(new Notification_1.Notification(payload)); + }); + } + registerPushKitNotificationReceived(callback) { + return this.emitter.addListener('pushKitNotificationReceived', callback); + } + registerRemoteNotificationOpened(callback) { + return this.emitter.addListener('notificationOpened', (response, completion) => { + const action = response.action ? new NotificationActionResponse_1.NotificationActionResponse(response.action) : undefined; + callback(new Notification_1.Notification(response.notification), completion, action); + }); + } + registerRemoteNotificationsRegistrationFailed(callback) { + return this.emitter.addListener('remoteNotificationsRegistrationFailed', callback); + } +} +exports.NativeEventsReceiver = NativeEventsReceiver; diff --git a/lib/dist/adapters/NativeEventsReceiver.mock.d.ts b/lib/dist/adapters/NativeEventsReceiver.mock.d.ts new file mode 100644 index 0000000..bcdf0ed --- /dev/null +++ b/lib/dist/adapters/NativeEventsReceiver.mock.d.ts @@ -0,0 +1 @@ +export declare const NativeEventsReceiver: any; diff --git a/lib/dist/adapters/NativeEventsReceiver.mock.js b/lib/dist/adapters/NativeEventsReceiver.mock.js new file mode 100644 index 0000000..1f634fa --- /dev/null +++ b/lib/dist/adapters/NativeEventsReceiver.mock.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.NativeEventsReceiver = jest.genMockFromModule('./NativeEventsReceiver').NativeEventsReceiver; diff --git a/lib/dist/adapters/UniqueIdProvider.d.ts b/lib/dist/adapters/UniqueIdProvider.d.ts new file mode 100644 index 0000000..8d5ee38 --- /dev/null +++ b/lib/dist/adapters/UniqueIdProvider.d.ts @@ -0,0 +1,3 @@ +export declare class UniqueIdProvider { + generate(): number; +} diff --git a/lib/dist/adapters/UniqueIdProvider.js b/lib/dist/adapters/UniqueIdProvider.js new file mode 100644 index 0000000..069faf6 --- /dev/null +++ b/lib/dist/adapters/UniqueIdProvider.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const _ = require("lodash"); +class UniqueIdProvider { + generate() { + return parseInt(_.uniqueId()); + } +} +exports.UniqueIdProvider = UniqueIdProvider; diff --git a/lib/dist/commands/Commands.d.ts b/lib/dist/commands/Commands.d.ts new file mode 100644 index 0000000..0d69d9f --- /dev/null +++ b/lib/dist/commands/Commands.d.ts @@ -0,0 +1,26 @@ +import { NativeCommandsSender } from '../adapters/NativeCommandsSender'; +import { Notification } from '../DTO/Notification'; +import { NotificationCategory } from '../interfaces/NotificationCategory'; +import { NotificationPermissions } from '../interfaces/NotificationPermissions'; +import { UniqueIdProvider } from '../adapters/UniqueIdProvider'; +export declare class Commands { + private readonly nativeCommandsSender; + private readonly uniqueIdProvider; + constructor(nativeCommandsSender: NativeCommandsSender, uniqueIdProvider: UniqueIdProvider); + postLocalNotification(notification: Notification, id?: number): void; + getInitialNotification(): Promise; + requestPermissions(): void; + abandonPermissions(): void; + registerPushKit(): void; + setCategories(categories: [NotificationCategory?]): void; + getBadgeCount(): Promise; + setBadgeCount(count: number): void; + cancelLocalNotification(notificationId: string): void; + cancelAllLocalNotifications(): void; + isRegisteredForRemoteNotifications(): Promise; + checkPermissions(): Promise; + removeAllDeliveredNotifications(): void; + removeDeliveredNotifications(identifiers: Array): void; + getDeliveredNotifications(): Array; + refreshToken(): void; +} diff --git a/lib/dist/commands/Commands.js b/lib/dist/commands/Commands.js new file mode 100644 index 0000000..6c1479c --- /dev/null +++ b/lib/dist/commands/Commands.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Notification_1 = require("../DTO/Notification"); +class Commands { + constructor(nativeCommandsSender, uniqueIdProvider) { + this.nativeCommandsSender = nativeCommandsSender; + this.uniqueIdProvider = uniqueIdProvider; + } + postLocalNotification(notification, id) { + const notificationId = id ? id : this.uniqueIdProvider.generate(); + const result = this.nativeCommandsSender.postLocalNotification(notification, notificationId); + return result; + } + async getInitialNotification() { + return this.nativeCommandsSender.getInitialNotification().then((payload) => { + if (payload) { + return new Notification_1.Notification(payload); + } + return undefined; + }); + } + requestPermissions() { + const result = this.nativeCommandsSender.requestPermissions(); + return result; + } + abandonPermissions() { + const result = this.nativeCommandsSender.abandonPermissions(); + return result; + } + registerPushKit() { + this.nativeCommandsSender.registerPushKit(); + } + setCategories(categories) { + this.nativeCommandsSender.setCategories(categories); + } + getBadgeCount() { + return this.nativeCommandsSender.getBadgeCount(); + } + setBadgeCount(count) { + this.nativeCommandsSender.setBadgeCount(count); + } + cancelLocalNotification(notificationId) { + this.nativeCommandsSender.cancelLocalNotification(notificationId); + } + cancelAllLocalNotifications() { + this.nativeCommandsSender.cancelAllLocalNotifications(); + } + isRegisteredForRemoteNotifications() { + return this.nativeCommandsSender.isRegisteredForRemoteNotifications(); + } + checkPermissions() { + return this.nativeCommandsSender.checkPermissions(); + } + removeAllDeliveredNotifications() { + this.nativeCommandsSender.removeAllDeliveredNotifications(); + } + removeDeliveredNotifications(identifiers) { + return this.nativeCommandsSender.removeDeliveredNotifications(identifiers); + } + getDeliveredNotifications() { + return this.nativeCommandsSender.getDeliveredNotifications(); + } + refreshToken() { + this.nativeCommandsSender.refreshToken(); + } +} +exports.Commands = Commands; diff --git a/lib/dist/commands/Commands.test.d.ts b/lib/dist/commands/Commands.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/dist/commands/Commands.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/dist/commands/Commands.test.js b/lib/dist/commands/Commands.test.js new file mode 100644 index 0000000..8fd8ff8 --- /dev/null +++ b/lib/dist/commands/Commands.test.js @@ -0,0 +1,157 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ts_mockito_1 = require("ts-mockito"); +const Commands_1 = require("./Commands"); +const NativeCommandsSender_1 = require("../adapters/NativeCommandsSender"); +const Notification_1 = require("../DTO/Notification"); +const UniqueIdProvider_1 = require("../adapters/UniqueIdProvider"); +describe('Commands', () => { + let uut; + let mockedNativeCommandsSender; + let mockedUniqueIdProvider; + beforeEach(() => { + mockedNativeCommandsSender = ts_mockito_1.mock(NativeCommandsSender_1.NativeCommandsSender); + mockedUniqueIdProvider = ts_mockito_1.mock(UniqueIdProvider_1.UniqueIdProvider); + ts_mockito_1.when(mockedUniqueIdProvider.generate()).thenCall(() => 12); + uut = new Commands_1.Commands(ts_mockito_1.instance(mockedNativeCommandsSender), ts_mockito_1.instance(mockedUniqueIdProvider)); + }); + describe('getInitialNotification', () => { + it('sends to native', () => { + uut.getInitialNotification(); + ts_mockito_1.verify(mockedNativeCommandsSender.getInitialNotification()).called(); + }); + it('returns a promise with the initial notification', async () => { + const expectedNotification = new Notification_1.Notification({ identifier: 'id' }); + ts_mockito_1.when(mockedNativeCommandsSender.getInitialNotification()).thenResolve({ identifier: 'id' }); + const result = await uut.getInitialNotification(); + expect(result).toEqual(expectedNotification); + }); + }); + describe('requestPermissions', () => { + it('sends to native', () => { + uut.requestPermissions(); + ts_mockito_1.verify(mockedNativeCommandsSender.requestPermissions()).called(); + }); + }); + describe('registerPushKit', () => { + it('sends to native', () => { + uut.registerPushKit(); + ts_mockito_1.verify(mockedNativeCommandsSender.registerPushKit()).called(); + }); + }); + describe('setCategories', () => { + it('sends to native', () => { + const emptyCategoriesArray = []; + uut.setCategories(emptyCategoriesArray); + ts_mockito_1.verify(mockedNativeCommandsSender.setCategories(emptyCategoriesArray)).called(); + }); + it('sends to native with categories', () => { + const category = { identifier: 'id', actions: [] }; + const categoriesArray = [category]; + uut.setCategories(categoriesArray); + ts_mockito_1.verify(mockedNativeCommandsSender.setCategories(categoriesArray)).called(); + }); + }); + describe('abandonPermissions', () => { + it('sends to native', () => { + uut.abandonPermissions(); + ts_mockito_1.verify(mockedNativeCommandsSender.abandonPermissions()).called(); + }); + }); + describe('postLocalNotification', () => { + it('sends to native', () => { + const notification = new Notification_1.Notification({ identifier: 'id' }); + uut.postLocalNotification(notification); + ts_mockito_1.verify(mockedNativeCommandsSender.postLocalNotification(notification, ts_mockito_1.anyNumber())).called(); + }); + it('generates unique identifier', () => { + const notification = new Notification_1.Notification({ identifier: 'id' }); + uut.postLocalNotification(notification); + ts_mockito_1.verify(mockedNativeCommandsSender.postLocalNotification(notification, ts_mockito_1.anyNumber())).called(); + }); + it('use passed notification id', () => { + const notification = new Notification_1.Notification({ identifier: 'id' }); + const passedId = 2; + uut.postLocalNotification(notification, passedId); + ts_mockito_1.verify(mockedNativeCommandsSender.postLocalNotification(notification, passedId)).called(); + }); + }); + describe('getBadgeCount', () => { + it('sends to native', () => { + uut.getBadgeCount(); + ts_mockito_1.verify(mockedNativeCommandsSender.getBadgeCount()).called(); + }); + }); + describe('setBadgeCount', () => { + it('sends to native', () => { + uut.setBadgeCount(10); + ts_mockito_1.verify(mockedNativeCommandsSender.setBadgeCount(10)).called(); + }); + }); + describe('cancelLocalNotification', () => { + it('sends to native', () => { + uut.cancelLocalNotification("notificationId"); + ts_mockito_1.verify(mockedNativeCommandsSender.cancelLocalNotification("notificationId")).called(); + }); + }); + describe('cancelAllLocalNotifications', () => { + it('sends to native', () => { + uut.cancelAllLocalNotifications(); + ts_mockito_1.verify(mockedNativeCommandsSender.cancelAllLocalNotifications()).called(); + }); + }); + describe('isRegisteredForRemoteNotifications', () => { + it('sends to native', () => { + uut.isRegisteredForRemoteNotifications(); + ts_mockito_1.verify(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called(); + }); + it('return positive response from native', async () => { + ts_mockito_1.when(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(true); + const isRegistered = await uut.isRegisteredForRemoteNotifications(); + ts_mockito_1.verify(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called(); + expect(isRegistered).toEqual(true); + }); + it('return negative response from native', async () => { + ts_mockito_1.when(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(false); + const isRegistered = await uut.isRegisteredForRemoteNotifications(); + expect(isRegistered).toEqual(false); + }); + }); + describe('checkPermissions', () => { + it('sends to native', () => { + uut.checkPermissions(); + ts_mockito_1.verify(mockedNativeCommandsSender.checkPermissions()).called(); + }); + it('return negative response from native', async () => { + const expectedPermissions = { badge: false, alert: true, sound: false }; + ts_mockito_1.when(mockedNativeCommandsSender.checkPermissions()).thenResolve(expectedPermissions); + const permissions = await uut.checkPermissions(); + expect(permissions).toEqual(expectedPermissions); + }); + }); + describe('removeAllDeliveredNotifications', () => { + it('sends to native', () => { + uut.removeAllDeliveredNotifications(); + ts_mockito_1.verify(mockedNativeCommandsSender.removeAllDeliveredNotifications()).called(); + }); + }); + describe('removeDeliveredNotifications', async () => { + it('sends to native', () => { + const identifiers = ["id1", "id2"]; + uut.removeDeliveredNotifications(identifiers); + ts_mockito_1.verify(mockedNativeCommandsSender.removeDeliveredNotifications(identifiers)).called(); + }); + }); + describe('getDeliveredNotifications', () => { + it('sends to native', () => { + uut.getDeliveredNotifications(); + ts_mockito_1.verify(mockedNativeCommandsSender.getDeliveredNotifications()).called(); + }); + }); + describe('refreshToken', () => { + it('sends to native', () => { + uut.refreshToken(); + ts_mockito_1.verify(mockedNativeCommandsSender.refreshToken()).called(); + }); + }); +}); diff --git a/lib/dist/events/EventsRegistry.d.ts b/lib/dist/events/EventsRegistry.d.ts new file mode 100644 index 0000000..28109a4 --- /dev/null +++ b/lib/dist/events/EventsRegistry.d.ts @@ -0,0 +1,15 @@ +import { EmitterSubscription } from 'react-native'; +import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver'; +import { Registered, RegistrationError, NotificationResponse } from '../interfaces/NotificationEvents'; +import { CompletionCallbackWrapper } from '../adapters/CompletionCallbackWrapper'; +import { Notification } from '../DTO/Notification'; +import { NotificationCompletion } from '../interfaces/NotificationCompletion'; +export declare class EventsRegistry { + private nativeEventsReceiver; + private completionCallbackWrapper; + constructor(nativeEventsReceiver: NativeEventsReceiver, completionCallbackWrapper: CompletionCallbackWrapper); + registerRemoteNotificationsRegistered(callback: (event: Registered) => void): EmitterSubscription; + registerNotificationReceived(callback: (notification: Notification, completion: (response: NotificationCompletion) => void) => void): EmitterSubscription; + registerRemoteNotificationOpened(callback: (response: NotificationResponse, completion: () => void) => void): EmitterSubscription; + registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription; +} diff --git a/lib/dist/events/EventsRegistry.js b/lib/dist/events/EventsRegistry.js new file mode 100644 index 0000000..9a6d2f9 --- /dev/null +++ b/lib/dist/events/EventsRegistry.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class EventsRegistry { + constructor(nativeEventsReceiver, completionCallbackWrapper) { + this.nativeEventsReceiver = nativeEventsReceiver; + this.completionCallbackWrapper = completionCallbackWrapper; + } + registerRemoteNotificationsRegistered(callback) { + return this.nativeEventsReceiver.registerRemoteNotificationsRegistered(callback); + } + registerNotificationReceived(callback) { + return this.nativeEventsReceiver.registerRemoteNotificationReceived(this.completionCallbackWrapper.wrapReceivedCallback(callback)); + } + registerRemoteNotificationOpened(callback) { + return this.nativeEventsReceiver.registerRemoteNotificationOpened(this.completionCallbackWrapper.wrapOpenedCallback(callback)); + } + registerRemoteNotificationsRegistrationFailed(callback) { + return this.nativeEventsReceiver.registerRemoteNotificationsRegistrationFailed(callback); + } +} +exports.EventsRegistry = EventsRegistry; diff --git a/lib/dist/events/EventsRegistry.test.d.ts b/lib/dist/events/EventsRegistry.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/dist/events/EventsRegistry.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/dist/events/EventsRegistry.test.js b/lib/dist/events/EventsRegistry.test.js new file mode 100644 index 0000000..34d9943 --- /dev/null +++ b/lib/dist/events/EventsRegistry.test.js @@ -0,0 +1,124 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const EventsRegistry_1 = require("./EventsRegistry"); +const NativeEventsReceiver_mock_1 = require("../adapters/NativeEventsReceiver.mock"); +const Notification_1 = require("../DTO/Notification"); +const CompletionCallbackWrapper_1 = require("../adapters/CompletionCallbackWrapper"); +const NativeCommandsSender_mock_1 = require("../adapters/NativeCommandsSender.mock"); +const react_native_1 = require("react-native"); +describe('EventsRegistry', () => { + let uut; + const mockNativeEventsReceiver = new NativeEventsReceiver_mock_1.NativeEventsReceiver(); + const mockNativeCommandsSender = new NativeCommandsSender_mock_1.NativeCommandsSender(); + const completionCallbackWrapper = new CompletionCallbackWrapper_1.CompletionCallbackWrapper(mockNativeCommandsSender); + beforeEach(() => { + uut = new EventsRegistry_1.EventsRegistry(mockNativeEventsReceiver, completionCallbackWrapper); + }); + describe('registerRemoteNotificationsReceived', () => { + it('delegates to nativeEventsReceiver', () => { + const cb = jest.fn(); + uut.registerNotificationReceived(cb); + expect(mockNativeEventsReceiver.registerRemoteNotificationReceived).toHaveBeenCalledTimes(1); + expect(mockNativeEventsReceiver.registerRemoteNotificationReceived).toHaveBeenCalledWith(expect.any(Function)); + }); + it('should wrap callback with completion block', () => { + const wrappedCallback = jest.fn(); + const notification = new Notification_1.Notification({ identifier: 'identifier' }); + uut.registerNotificationReceived(wrappedCallback); + const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0]; + call(notification); + expect(wrappedCallback).toBeCalledWith(notification, expect.any(Function)); + expect(wrappedCallback).toBeCalledTimes(1); + }); + it('should wrap callback with completion block', () => { + const expectedNotification = new Notification_1.Notification({ identifier: 'identifier' }); + uut.registerNotificationReceived((notification) => { + expect(notification).toEqual(expectedNotification); + }); + const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0]; + call(expectedNotification); + }); + it('should invoke finishPresentingNotification', () => { + const notification = new Notification_1.Notification({ identifier: 'notificationId' }); + const response = { alert: true }; + uut.registerNotificationReceived((notification, completion) => { + completion(response); + expect(mockNativeCommandsSender.finishPresentingNotification).toBeCalledWith(notification.identifier, response); + }); + const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0]; + call(notification); + }); + it('should not invoke finishPresentingNotification on Android', () => { + react_native_1.Platform.OS = 'android'; + const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' }); + const response = { alert: true }; + uut.registerNotificationReceived((notification, completion) => { + completion(response); + expect(expectedNotification).toEqual(notification); + expect(mockNativeCommandsSender.finishPresentingNotification).toBeCalledTimes(0); + }); + const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0]; + call(expectedNotification); + }); + }); + describe('', () => { + it('delegates to nativeEventsReceiver', () => { + const cb = jest.fn(); + uut.registerRemoteNotificationOpened(cb); + expect(mockNativeEventsReceiver.registerRemoteNotificationOpened).toHaveBeenCalledTimes(1); + expect(mockNativeEventsReceiver.registerRemoteNotificationOpened).toHaveBeenCalledWith(expect.any(Function)); + }); + it('should wrap callback with completion block', () => { + const wrappedCallback = jest.fn(); + const notification = new Notification_1.Notification({ identifier: 'identifier' }); + const response = { notification, identifier: 'responseId' }; + uut.registerRemoteNotificationOpened(wrappedCallback); + const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0]; + call(response); + expect(wrappedCallback).toBeCalledWith(response, expect.any(Function)); + expect(wrappedCallback).toBeCalledTimes(1); + }); + it('should wrap callback with completion block', () => { + const notification = new Notification_1.Notification({ identifier: 'identifier' }); + const expectedResponse = { notification, identifier: 'responseId' }; + uut.registerRemoteNotificationOpened((response) => { + expect(response).toEqual(expectedResponse); + }); + const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0]; + call(expectedResponse); + }); + it('calling completion should invoke finishHandlingAction', () => { + const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' }); + uut.registerRemoteNotificationOpened((notification, completion) => { + completion(); + expect(expectedNotification).toEqual(notification); + expect(mockNativeCommandsSender.finishHandlingAction).toBeCalledWith(notification.identifier); + }); + const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0]; + call(expectedNotification); + }); + it('should not invoke finishHandlingAction on Android', () => { + react_native_1.Platform.OS = 'android'; + const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' }); + uut.registerRemoteNotificationOpened((notification, completion) => { + completion(); + expect(expectedNotification).toEqual(notification); + expect(mockNativeCommandsSender.finishHandlingAction).toBeCalledTimes(0); + }); + const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0]; + call(expectedNotification); + }); + }); + it('delegates registerRemoteNotificationsRegistered to nativeEventsReceiver', () => { + const cb = jest.fn(); + uut.registerRemoteNotificationsRegistered(cb); + expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistered).toHaveBeenCalledTimes(1); + expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistered).toHaveBeenCalledWith(cb); + }); + it('delegates registerRemoteNotificationsRegistrationFailed to nativeEventsReceiver', () => { + const cb = jest.fn(); + uut.registerRemoteNotificationsRegistrationFailed(cb); + expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistrationFailed).toHaveBeenCalledTimes(1); + expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistrationFailed).toHaveBeenCalledWith(cb); + }); +}); diff --git a/lib/dist/events/EventsRegistryIOS.d.ts b/lib/dist/events/EventsRegistryIOS.d.ts new file mode 100644 index 0000000..0c05155 --- /dev/null +++ b/lib/dist/events/EventsRegistryIOS.d.ts @@ -0,0 +1,9 @@ +import { EmitterSubscription } from 'react-native'; +import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver'; +import { RegisteredPushKit } from '../interfaces/NotificationEvents'; +export declare class EventsRegistryIOS { + private nativeEventsReceiver; + constructor(nativeEventsReceiver: NativeEventsReceiver); + registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription; + registerPushKitNotificationReceived(callback: (event: object) => void): EmitterSubscription; +} diff --git a/lib/dist/events/EventsRegistryIOS.js b/lib/dist/events/EventsRegistryIOS.js new file mode 100644 index 0000000..bd69563 --- /dev/null +++ b/lib/dist/events/EventsRegistryIOS.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class EventsRegistryIOS { + constructor(nativeEventsReceiver) { + this.nativeEventsReceiver = nativeEventsReceiver; + } + registerPushKitRegistered(callback) { + return this.nativeEventsReceiver.registerPushKitRegistered(callback); + } + registerPushKitNotificationReceived(callback) { + return this.nativeEventsReceiver.registerPushKitNotificationReceived(callback); + } +} +exports.EventsRegistryIOS = EventsRegistryIOS; diff --git a/lib/dist/events/EventsRegistryIOS.test.d.ts b/lib/dist/events/EventsRegistryIOS.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/dist/events/EventsRegistryIOS.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/dist/events/EventsRegistryIOS.test.js b/lib/dist/events/EventsRegistryIOS.test.js new file mode 100644 index 0000000..2e2b58b --- /dev/null +++ b/lib/dist/events/EventsRegistryIOS.test.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const EventsRegistryIOS_1 = require("./EventsRegistryIOS"); +const NativeEventsReceiver_mock_1 = require("../adapters/NativeEventsReceiver.mock"); +describe('EventsRegistryIOS', () => { + let uut; + const mockNativeEventsReceiver = new NativeEventsReceiver_mock_1.NativeEventsReceiver(); + beforeEach(() => { + uut = new EventsRegistryIOS_1.EventsRegistryIOS(mockNativeEventsReceiver); + }); + it('delegates registerPushKitRegistered to nativeEventsReceiver', () => { + const cb = jest.fn(); + uut.registerPushKitRegistered(cb); + expect(mockNativeEventsReceiver.registerPushKitRegistered).toHaveBeenCalledTimes(1); + expect(mockNativeEventsReceiver.registerPushKitRegistered).toHaveBeenCalledWith(cb); + }); + it('delegates registerPushKitNotificationReceived to nativeEventsReceiver', () => { + const cb = jest.fn(); + uut.registerPushKitNotificationReceived(cb); + expect(mockNativeEventsReceiver.registerPushKitNotificationReceived).toHaveBeenCalledTimes(1); + expect(mockNativeEventsReceiver.registerPushKitNotificationReceived).toHaveBeenCalledWith(cb); + }); +}); diff --git a/lib/dist/index.d.ts b/lib/dist/index.d.ts new file mode 100644 index 0000000..7e8925c --- /dev/null +++ b/lib/dist/index.d.ts @@ -0,0 +1,6 @@ +import { NotificationsRoot } from './Notifications'; +export declare const Notifications: NotificationsRoot; +export * from './interfaces/EventSubscription'; +export * from './DTO/Notification'; +export * from './interfaces/NotificationEvents'; +export * from './interfaces/NotificationCategory'; diff --git a/lib/dist/index.js b/lib/dist/index.js new file mode 100644 index 0000000..15fee9b --- /dev/null +++ b/lib/dist/index.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tslib_1 = require("tslib"); +const Notifications_1 = require("./Notifications"); +const notificationsSingleton = new Notifications_1.NotificationsRoot(); +exports.Notifications = notificationsSingleton; +tslib_1.__exportStar(require("./DTO/Notification"), exports); +tslib_1.__exportStar(require("./interfaces/NotificationCategory"), exports); diff --git a/lib/dist/interfaces/EventSubscription.d.ts b/lib/dist/interfaces/EventSubscription.d.ts new file mode 100644 index 0000000..3cd09f5 --- /dev/null +++ b/lib/dist/interfaces/EventSubscription.d.ts @@ -0,0 +1,3 @@ +export interface EventSubscription { + remove(): void; +} diff --git a/lib/dist/interfaces/EventSubscription.js b/lib/dist/interfaces/EventSubscription.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/lib/dist/interfaces/EventSubscription.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/dist/interfaces/NotificationActionResponse.d.ts b/lib/dist/interfaces/NotificationActionResponse.d.ts new file mode 100644 index 0000000..ee174df --- /dev/null +++ b/lib/dist/interfaces/NotificationActionResponse.d.ts @@ -0,0 +1,5 @@ +export declare class NotificationActionResponse { + identifier: string; + text?: string; + constructor(response: any); +} diff --git a/lib/dist/interfaces/NotificationActionResponse.js b/lib/dist/interfaces/NotificationActionResponse.js new file mode 100644 index 0000000..9945720 --- /dev/null +++ b/lib/dist/interfaces/NotificationActionResponse.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class NotificationActionResponse { + constructor(response) { + this.identifier = response.identifier; + this.text = response.text; + } +} +exports.NotificationActionResponse = NotificationActionResponse; diff --git a/lib/dist/interfaces/NotificationCategory.d.ts b/lib/dist/interfaces/NotificationCategory.d.ts new file mode 100644 index 0000000..04bee82 --- /dev/null +++ b/lib/dist/interfaces/NotificationCategory.d.ts @@ -0,0 +1,17 @@ +export declare class NotificationCategory { + identifier: string; + actions: [NotificationAction?]; + constructor(identifier: string, actions: [NotificationAction?]); +} +export interface NotificationTextInput { + buttonTitle: string; + placeholder: string; +} +export declare class NotificationAction { + identifier: string; + activationMode: 'foreground' | 'authenticationRequired' | 'destructive'; + title: string; + authenticationRequired: boolean; + textInput: NotificationTextInput; + constructor(identifier: string, activationMode: 'foreground' | 'authenticationRequired' | 'destructive', title: string, authenticationRequired: boolean, textInput: NotificationTextInput); +} diff --git a/lib/dist/interfaces/NotificationCategory.js b/lib/dist/interfaces/NotificationCategory.js new file mode 100644 index 0000000..ed67a56 --- /dev/null +++ b/lib/dist/interfaces/NotificationCategory.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class NotificationCategory { + constructor(identifier, actions) { + this.identifier = identifier; + this.actions = actions; + } +} +exports.NotificationCategory = NotificationCategory; +class NotificationAction { + constructor(identifier, activationMode, title, authenticationRequired, textInput) { + this.identifier = identifier; + this.activationMode = activationMode; + this.title = title; + this.authenticationRequired = authenticationRequired; + this.textInput = textInput; + } +} +exports.NotificationAction = NotificationAction; diff --git a/lib/dist/interfaces/NotificationCompletion.d.ts b/lib/dist/interfaces/NotificationCompletion.d.ts new file mode 100644 index 0000000..8256e3d --- /dev/null +++ b/lib/dist/interfaces/NotificationCompletion.d.ts @@ -0,0 +1,5 @@ +export interface NotificationCompletion { + badge?: boolean; + alert?: boolean; + sound?: boolean; +} diff --git a/lib/dist/interfaces/NotificationCompletion.js b/lib/dist/interfaces/NotificationCompletion.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/lib/dist/interfaces/NotificationCompletion.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/dist/interfaces/NotificationEvents.d.ts b/lib/dist/interfaces/NotificationEvents.d.ts new file mode 100644 index 0000000..d21e232 --- /dev/null +++ b/lib/dist/interfaces/NotificationEvents.d.ts @@ -0,0 +1,18 @@ +import { Notification } from '../DTO/Notification'; +import { NotificationActionResponse } from './NotificationActionResponse'; +export interface Registered { + deviceToken: string; +} +export interface RegistrationError { + code: string; + domain: string; + localizedDescription: string; +} +export interface RegisteredPushKit { + pushKitToken: string; +} +export interface NotificationResponse { + identifier: string; + notification: Notification; + action?: NotificationActionResponse; +} diff --git a/lib/dist/interfaces/NotificationEvents.js b/lib/dist/interfaces/NotificationEvents.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/lib/dist/interfaces/NotificationEvents.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/dist/interfaces/NotificationPermissions.d.ts b/lib/dist/interfaces/NotificationPermissions.d.ts new file mode 100644 index 0000000..0ea2925 --- /dev/null +++ b/lib/dist/interfaces/NotificationPermissions.d.ts @@ -0,0 +1,5 @@ +export interface NotificationPermissions { + badge: boolean; + alert: boolean; + sound: boolean; +} diff --git a/lib/dist/interfaces/NotificationPermissions.js b/lib/dist/interfaces/NotificationPermissions.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/lib/dist/interfaces/NotificationPermissions.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/package.json b/package.json index cb08673..f5d34b3 100644 --- a/package.json +++ b/package.json @@ -140,4 +140,4 @@ "html" ] } -} \ No newline at end of file +} -- 2.26.2