diff --git a/lib/android/app/.gitignore b/lib/android/app/.gitignore deleted file mode 100644 index 65d12b95469b46008614734d430ea36c91c3f1d9..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..0e559401ecb7373db75fe3bce169563a6153ee3b --- /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 0000000000000000000000000000000000000000..d37f610fb7ff52227ecd3cdc42edb64e83c7553a --- /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 0000000000000000000000000000000000000000..cb0ff5c3b541f646105198ee23ac0fc3d805023e --- /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 0000000000000000000000000000000000000000..2cf234f73cb06b8aea58705dbca7bd7cfb2be202 --- /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 0000000000000000000000000000000000000000..3d8d418be2aa5b71ee14f4c26823e419c82ea8e8 --- /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 0000000000000000000000000000000000000000..a706b5b2249a2f166d6d9d6b113b19b06efd3655 --- /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 0000000000000000000000000000000000000000..4383d9a4afc945e0184e52dc2835b1ee763a336d --- /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 0000000000000000000000000000000000000000..5b6f817c5155bcf03e14729f4bcd0af51e6f72ac --- /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 0000000000000000000000000000000000000000..0a8fc24c71132a82770d853a93664acdfbced9f4 --- /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 0000000000000000000000000000000000000000..5c9fca7192f60d1a8fb13467b163fc821037bee7 --- /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 0000000000000000000000000000000000000000..0e5fc4d0aeb4869e76c28dbd7b63a68a09119256 --- /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 0000000000000000000000000000000000000000..6455e51b730b0ff8cd54458bdac906dd360f73e3 --- /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 0000000000000000000000000000000000000000..a0a4bc18650c0484dd53168c3eb8020dfca8dcab --- /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 0000000000000000000000000000000000000000..0cc4b588f09092595de2572157e8970fc96a613c --- /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 0000000000000000000000000000000000000000..1c821829c65194944d4f31aeefb66c56cd999680 --- /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 0000000000000000000000000000000000000000..0d9cc78d0dc8b591f40c21e063870686f3df6fdc --- /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 0000000000000000000000000000000000000000..45dec953a10f037f896e8051445031b46bda8e2f --- /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 0000000000000000000000000000000000000000..602241a0df2af4b84fef3da21376ac2a26745828 --- /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 0000000000000000000000000000000000000000..bcdf0eda60b52fd344765b008b8f65c297018038 --- /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 0000000000000000000000000000000000000000..1f634fa7f846396d6e34e8375efc6221e9d5c035 --- /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 0000000000000000000000000000000000000000..8d5ee38ba977a54bbaf846fd3d031fcc01244e3c --- /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 0000000000000000000000000000000000000000..069faf63c5f7ba374b562db06989022b917220e9 --- /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 0000000000000000000000000000000000000000..0d69d9fd32300cce5c4f8f11561b598557cb2d9f --- /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 0000000000000000000000000000000000000000..6c1479cd94571e74b19c553bc9fe500d17d85c95 --- /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 0000000000000000000000000000000000000000..cb0ff5c3b541f646105198ee23ac0fc3d805023e --- /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 0000000000000000000000000000000000000000..8fd8ff87a30ef56ff25ba63501c053a0760caabc --- /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 0000000000000000000000000000000000000000..28109a42186b929a65cf1e80cbf83a4f5db9077b --- /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 0000000000000000000000000000000000000000..9a6d2f958e2dcdd3d6ab098301ed42a0d8713754 --- /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 0000000000000000000000000000000000000000..cb0ff5c3b541f646105198ee23ac0fc3d805023e --- /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 0000000000000000000000000000000000000000..34d9943f0fddce3d384ad32d92fa925947e5b46c --- /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 0000000000000000000000000000000000000000..0c051555d68e98e866d61cc3b9707c91e86bcd88 --- /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 0000000000000000000000000000000000000000..bd69563262d0bc2213347ad5c19e59f263d2a5f1 --- /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 0000000000000000000000000000000000000000..cb0ff5c3b541f646105198ee23ac0fc3d805023e --- /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 0000000000000000000000000000000000000000..2e2b58b21caa05886be7c695c17bb1f62f4f4fbb --- /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 0000000000000000000000000000000000000000..7e8925cc1190cf555347c30b2375e9425d59faf9 --- /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 0000000000000000000000000000000000000000..15fee9b9604eaaeb7822f7ee4ecf89597fd3bd03 --- /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 0000000000000000000000000000000000000000..3cd09f5982a51e8679fcdf8f91ec4f08595a8403 --- /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 0000000000000000000000000000000000000000..c8ad2e549bdc6801e0d1c80b0308d4b9bd4985ce --- /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 0000000000000000000000000000000000000000..ee174df2fd511aa9e178db9eabee9be9cdd9c9b1 --- /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 0000000000000000000000000000000000000000..9945720ef08a980e329f40a422fd7295d9dde825 --- /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 0000000000000000000000000000000000000000..04bee821bba5fac9f20a1714885e1ccfcbfa2356 --- /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 0000000000000000000000000000000000000000..ed67a56232c0597c53a419cdb51d033b7cda7f95 --- /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 0000000000000000000000000000000000000000..8256e3dd2e23c932fa0248691d5127fd63b0bf74 --- /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 0000000000000000000000000000000000000000..c8ad2e549bdc6801e0d1c80b0308d4b9bd4985ce --- /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 0000000000000000000000000000000000000000..d21e2326ddf2f9ddd97d24c8e9b048bec4bc6d2b --- /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 0000000000000000000000000000000000000000..c8ad2e549bdc6801e0d1c80b0308d4b9bd4985ce --- /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 0000000000000000000000000000000000000000..0ea2925018e93939b7e5df6bf60e00df91f10103 --- /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 0000000000000000000000000000000000000000..c8ad2e549bdc6801e0d1c80b0308d4b9bd4985ce --- /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 cb086730a62a3946e4b6754120634d863926b5fa..f5d34b38e16c1a121f2a59eaa0258a3826c1b6ca 100644 --- a/package.json +++ b/package.json @@ -140,4 +140,4 @@ "html" ] } -} \ No newline at end of file +}