@psync/notifee 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/LICENSE +44 -0
  2. package/README.md +142 -0
  3. package/RNNotifee.podspec +39 -0
  4. package/RNNotifeeCore.podspec +33 -0
  5. package/android/.editorconfig +10 -0
  6. package/android/build.gradle +116 -0
  7. package/android/gradle.properties +1 -0
  8. package/android/lint.xml +5 -0
  9. package/android/proguard-rules.pro +82 -0
  10. package/android/settings.gradle +1 -0
  11. package/android/src/main/AndroidManifest.xml +12 -0
  12. package/android/src/main/java/io/invertase/notifee/HeadlessTask.java +431 -0
  13. package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +365 -0
  14. package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
  15. package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
  16. package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
  17. package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +135 -0
  18. package/dist/NotifeeApiModule.d.ts +53 -0
  19. package/dist/NotifeeApiModule.js +609 -0
  20. package/dist/NotifeeApiModule.js.map +1 -0
  21. package/dist/NotifeeJSEventEmitter.d.ts +3 -0
  22. package/dist/NotifeeJSEventEmitter.js +14 -0
  23. package/dist/NotifeeJSEventEmitter.js.map +1 -0
  24. package/dist/NotifeeNativeError.d.ts +15 -0
  25. package/dist/NotifeeNativeError.js +59 -0
  26. package/dist/NotifeeNativeError.js.map +1 -0
  27. package/dist/NotifeeNativeModule.d.ts +14 -0
  28. package/dist/NotifeeNativeModule.js +42 -0
  29. package/dist/NotifeeNativeModule.js.map +1 -0
  30. package/dist/NotifeeNativeModule.web.d.ts +12 -0
  31. package/dist/NotifeeNativeModule.web.js +18 -0
  32. package/dist/NotifeeNativeModule.web.js.map +1 -0
  33. package/dist/index.d.ts +8 -0
  34. package/dist/index.js +43 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/types/Library.d.ts +21 -0
  37. package/dist/types/Library.js +6 -0
  38. package/dist/types/Library.js.map +1 -0
  39. package/dist/types/Module.d.ts +576 -0
  40. package/dist/types/Module.js +6 -0
  41. package/dist/types/Module.js.map +1 -0
  42. package/dist/types/Notification.d.ts +462 -0
  43. package/dist/types/Notification.js +111 -0
  44. package/dist/types/Notification.js.map +1 -0
  45. package/dist/types/NotificationAndroid.d.ts +1311 -0
  46. package/dist/types/NotificationAndroid.js +409 -0
  47. package/dist/types/NotificationAndroid.js.map +1 -0
  48. package/dist/types/NotificationIOS.d.ts +539 -0
  49. package/dist/types/NotificationIOS.js +92 -0
  50. package/dist/types/NotificationIOS.js.map +1 -0
  51. package/dist/types/NotificationWeb.d.ts +5 -0
  52. package/dist/types/NotificationWeb.js +6 -0
  53. package/dist/types/NotificationWeb.js.map +1 -0
  54. package/dist/types/PowerManagerInfo.d.ts +36 -0
  55. package/dist/types/PowerManagerInfo.js +6 -0
  56. package/dist/types/PowerManagerInfo.js.map +1 -0
  57. package/dist/types/Trigger.d.ts +124 -0
  58. package/dist/types/Trigger.js +51 -0
  59. package/dist/types/Trigger.js.map +1 -0
  60. package/dist/utils/id.d.ts +1 -0
  61. package/dist/utils/id.js +15 -0
  62. package/dist/utils/id.js.map +1 -0
  63. package/dist/utils/index.d.ts +16 -0
  64. package/dist/utils/index.js +51 -0
  65. package/dist/utils/index.js.map +1 -0
  66. package/dist/utils/validate.d.ts +15 -0
  67. package/dist/utils/validate.js +90 -0
  68. package/dist/utils/validate.js.map +1 -0
  69. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
  70. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +51 -0
  71. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
  72. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
  73. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
  74. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
  75. package/dist/validators/validate.d.ts +25 -0
  76. package/dist/validators/validate.js +74 -0
  77. package/dist/validators/validate.js.map +1 -0
  78. package/dist/validators/validateAndroidAction.d.ts +2 -0
  79. package/dist/validators/validateAndroidAction.js +52 -0
  80. package/dist/validators/validateAndroidAction.js.map +1 -0
  81. package/dist/validators/validateAndroidChannel.d.ts +2 -0
  82. package/dist/validators/validateAndroidChannel.js +155 -0
  83. package/dist/validators/validateAndroidChannel.js.map +1 -0
  84. package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
  85. package/dist/validators/validateAndroidChannelGroup.js +42 -0
  86. package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
  87. package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
  88. package/dist/validators/validateAndroidFullScreenAction.js +50 -0
  89. package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
  90. package/dist/validators/validateAndroidInput.d.ts +2 -0
  91. package/dist/validators/validateAndroidInput.js +54 -0
  92. package/dist/validators/validateAndroidInput.js.map +1 -0
  93. package/dist/validators/validateAndroidNotification.d.ts +2 -0
  94. package/dist/validators/validateAndroidNotification.js +547 -0
  95. package/dist/validators/validateAndroidNotification.js.map +1 -0
  96. package/dist/validators/validateAndroidPressAction.d.ts +2 -0
  97. package/dist/validators/validateAndroidPressAction.js +50 -0
  98. package/dist/validators/validateAndroidPressAction.js.map +1 -0
  99. package/dist/validators/validateAndroidStyle.d.ts +22 -0
  100. package/dist/validators/validateAndroidStyle.js +230 -0
  101. package/dist/validators/validateAndroidStyle.js.map +1 -0
  102. package/dist/validators/validateIOSAttachment.d.ts +6 -0
  103. package/dist/validators/validateIOSAttachment.js +100 -0
  104. package/dist/validators/validateIOSAttachment.js.map +1 -0
  105. package/dist/validators/validateIOSCategory.d.ts +2 -0
  106. package/dist/validators/validateIOSCategory.js +124 -0
  107. package/dist/validators/validateIOSCategory.js.map +1 -0
  108. package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
  109. package/dist/validators/validateIOSCategoryAction.js +59 -0
  110. package/dist/validators/validateIOSCategoryAction.js.map +1 -0
  111. package/dist/validators/validateIOSInput.d.ts +2 -0
  112. package/dist/validators/validateIOSInput.js +32 -0
  113. package/dist/validators/validateIOSInput.js.map +1 -0
  114. package/dist/validators/validateIOSNotification.d.ts +2 -0
  115. package/dist/validators/validateIOSNotification.js +211 -0
  116. package/dist/validators/validateIOSNotification.js.map +1 -0
  117. package/dist/validators/validateIOSPermissions.d.ts +2 -0
  118. package/dist/validators/validateIOSPermissions.js +62 -0
  119. package/dist/validators/validateIOSPermissions.js.map +1 -0
  120. package/dist/validators/validateNotification.d.ts +11 -0
  121. package/dist/validators/validateNotification.js +129 -0
  122. package/dist/validators/validateNotification.js.map +1 -0
  123. package/dist/validators/validateTrigger.d.ts +2 -0
  124. package/dist/validators/validateTrigger.js +110 -0
  125. package/dist/validators/validateTrigger.js.map +1 -0
  126. package/dist/version.d.ts +1 -0
  127. package/dist/version.js +6 -0
  128. package/dist/version.js.map +1 -0
  129. package/ios/NotifeeCore/Info.plist +22 -0
  130. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
  131. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +76 -0
  132. package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
  133. package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
  134. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +44 -0
  135. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +270 -0
  136. package/ios/NotifeeCore/NotifeeCore.h +118 -0
  137. package/ios/NotifeeCore/NotifeeCore.m +843 -0
  138. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
  139. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
  140. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
  141. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
  142. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
  143. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
  144. package/ios/NotifeeCore/NotifeeCoreUtil.h +81 -0
  145. package/ios/NotifeeCore/NotifeeCoreUtil.m +834 -0
  146. package/ios/RNNotifee/NotifeeApiModule.h +25 -0
  147. package/ios/RNNotifee/NotifeeApiModule.m +371 -0
  148. package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
  149. package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
  150. package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
  151. package/ios/RNNotifee.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  152. package/ios/RNNotifee.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  153. package/jest-mock.js +161 -0
  154. package/package.json +74 -0
  155. package/react-native.config.js +11 -0
  156. package/src/NotifeeApiModule.ts +827 -0
  157. package/src/NotifeeJSEventEmitter.ts +10 -0
  158. package/src/NotifeeNativeError.ts +68 -0
  159. package/src/NotifeeNativeModule.ts +54 -0
  160. package/src/NotifeeNativeModule.web.ts +24 -0
  161. package/src/index.ts +33 -0
  162. package/src/types/Library.ts +28 -0
  163. package/src/types/Module.ts +629 -0
  164. package/src/types/Notification.ts +518 -0
  165. package/src/types/NotificationAndroid.ts +1478 -0
  166. package/src/types/NotificationIOS.ts +683 -0
  167. package/src/types/NotificationWeb.ts +5 -0
  168. package/src/types/PowerManagerInfo.ts +43 -0
  169. package/src/types/Trigger.ts +136 -0
  170. package/src/utils/id.ts +13 -0
  171. package/src/utils/index.ts +46 -0
  172. package/src/utils/validate.ts +90 -0
  173. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +61 -0
  174. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
  175. package/src/validators/validate.ts +85 -0
  176. package/src/validators/validateAndroidAction.ts +54 -0
  177. package/src/validators/validateAndroidChannel.ts +188 -0
  178. package/src/validators/validateAndroidChannelGroup.ts +49 -0
  179. package/src/validators/validateAndroidFullScreenAction.ts +65 -0
  180. package/src/validators/validateAndroidInput.ts +67 -0
  181. package/src/validators/validateAndroidNotification.ts +734 -0
  182. package/src/validators/validateAndroidPressAction.ts +65 -0
  183. package/src/validators/validateAndroidStyle.ts +315 -0
  184. package/src/validators/validateIOSAttachment.ts +135 -0
  185. package/src/validators/validateIOSCategory.ts +150 -0
  186. package/src/validators/validateIOSCategoryAction.ts +65 -0
  187. package/src/validators/validateIOSInput.ts +38 -0
  188. package/src/validators/validateIOSNotification.ts +296 -0
  189. package/src/validators/validateIOSPermissions.ts +78 -0
  190. package/src/validators/validateNotification.ts +156 -0
  191. package/src/validators/validateTrigger.ts +142 -0
  192. package/src/version.ts +2 -0
  193. package/tsconfig.json +23 -0
@@ -0,0 +1,53 @@
1
+ import { Module } from './types/Module';
2
+ import { AndroidChannel, AndroidChannelGroup, NativeAndroidChannel, NativeAndroidChannelGroup } from './types/NotificationAndroid';
3
+ import { InitialNotification, Notification, Event, TriggerNotification, DisplayedNotification, NotificationSettings } from './types/Notification';
4
+ import { PowerManagerInfo } from './types/PowerManagerInfo';
5
+ import { Trigger } from './types/Trigger';
6
+ import NotifeeNativeModule, { NativeModuleConfig } from './NotifeeNativeModule';
7
+ import { IOSNotificationCategory, IOSNotificationPermissions } from './types/NotificationIOS';
8
+ export default class NotifeeApiModule extends NotifeeNativeModule implements Module {
9
+ constructor(config: NativeModuleConfig);
10
+ getTriggerNotificationIds: () => Promise<string[]>;
11
+ getTriggerNotifications: () => Promise<TriggerNotification[]>;
12
+ getDisplayedNotifications: () => Promise<DisplayedNotification[]>;
13
+ isChannelBlocked: (channelId: string) => Promise<boolean>;
14
+ isChannelCreated: (channelId: string) => Promise<boolean>;
15
+ cancelAllNotifications: (notificationIds?: string[], tag?: string) => Promise<void>;
16
+ cancelDisplayedNotifications: (notificationIds?: string[], tag?: string) => Promise<void>;
17
+ cancelTriggerNotifications: (notificationIds?: string[]) => Promise<void>;
18
+ cancelNotification: (notificationId: string, tag?: string) => Promise<void>;
19
+ cancelDisplayedNotification: (notificationId: string, tag?: string) => Promise<void>;
20
+ cancelTriggerNotification: (notificationId: string) => Promise<void>;
21
+ createChannel: (channel: AndroidChannel) => Promise<string>;
22
+ createChannels: (channels: AndroidChannel[]) => Promise<void>;
23
+ createChannelGroup: (channelGroup: AndroidChannelGroup) => Promise<string>;
24
+ createChannelGroups: (channelGroups: AndroidChannelGroup[]) => Promise<void>;
25
+ deleteChannel: (channelId: string) => Promise<void>;
26
+ deleteChannelGroup: (channelGroupId: string) => Promise<void>;
27
+ displayNotification: (notification: Notification) => Promise<string>;
28
+ openAlarmPermissionSettings: () => Promise<void>;
29
+ createTriggerNotification: (notification: Notification, trigger: Trigger) => Promise<string>;
30
+ getChannel: (channelId: string) => Promise<NativeAndroidChannel | null>;
31
+ getChannels: () => Promise<NativeAndroidChannel[]>;
32
+ getChannelGroup: (channelGroupId: string) => Promise<NativeAndroidChannelGroup | null>;
33
+ getChannelGroups: () => Promise<NativeAndroidChannelGroup[]>;
34
+ getInitialNotification: () => Promise<InitialNotification | null>;
35
+ onBackgroundEvent: (observer: (event: Event) => Promise<void>) => void;
36
+ onForegroundEvent: (observer: (event: Event) => void) => (() => void);
37
+ openNotificationSettings: (channelId?: string) => Promise<void>;
38
+ requestPermission: (permissions?: IOSNotificationPermissions) => Promise<NotificationSettings>;
39
+ registerForegroundService(runner: (notification: Notification) => Promise<void>): void;
40
+ setNotificationCategories: (categories: IOSNotificationCategory[]) => Promise<void>;
41
+ getNotificationCategories: () => Promise<IOSNotificationCategory[]>;
42
+ getNotificationSettings: () => Promise<NotificationSettings>;
43
+ getBadgeCount: () => Promise<number>;
44
+ setBadgeCount: (count: number) => Promise<void>;
45
+ incrementBadgeCount: (incrementBy?: number) => Promise<void>;
46
+ decrementBadgeCount: (decrementBy?: number) => Promise<void>;
47
+ isBatteryOptimizationEnabled: () => Promise<boolean>;
48
+ openBatteryOptimizationSettings: () => Promise<void>;
49
+ getPowerManagerInfo: () => Promise<PowerManagerInfo>;
50
+ openPowerManagerSettings: () => Promise<void>;
51
+ stopForegroundService: () => Promise<void>;
52
+ hideNotificationDrawer: () => void;
53
+ }
@@ -0,0 +1,609 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2016-present Invertase Limited
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const react_native_1 = require("react-native");
10
+ const NotificationAndroid_1 = require("./types/NotificationAndroid");
11
+ const Notification_1 = require("./types/Notification");
12
+ const NotifeeNativeModule_1 = __importDefault(require("./NotifeeNativeModule"));
13
+ const utils_1 = require("./utils");
14
+ const validateNotification_1 = __importDefault(require("./validators/validateNotification"));
15
+ const validateTrigger_1 = __importDefault(require("./validators/validateTrigger"));
16
+ const validateAndroidChannel_1 = __importDefault(require("./validators/validateAndroidChannel"));
17
+ const validateAndroidChannelGroup_1 = __importDefault(require("./validators/validateAndroidChannelGroup"));
18
+ const validateIOSCategory_1 = __importDefault(require("./validators/validateIOSCategory"));
19
+ const validateIOSPermissions_1 = __importDefault(require("./validators/validateIOSPermissions"));
20
+ let backgroundEventHandler;
21
+ let registeredForegroundServiceTask;
22
+ if (utils_1.isAndroid) {
23
+ // Register foreground service
24
+ react_native_1.AppRegistry.registerHeadlessTask(utils_1.kReactNativeNotifeeForegroundServiceHeadlessTask, () => {
25
+ if (!registeredForegroundServiceTask) {
26
+ console.warn('[notifee] no registered foreground service has been set for displaying a foreground notification.');
27
+ return () => Promise.resolve();
28
+ }
29
+ return ({ notification }) => registeredForegroundServiceTask(notification);
30
+ });
31
+ }
32
+ class NotifeeApiModule extends NotifeeNativeModule_1.default {
33
+ constructor(config) {
34
+ super(config);
35
+ if (utils_1.isAndroid) {
36
+ // Register background handler
37
+ react_native_1.AppRegistry.registerHeadlessTask(utils_1.kReactNativeNotifeeNotificationEvent, () => {
38
+ return (event) => {
39
+ if (!backgroundEventHandler) {
40
+ console.warn('[notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.');
41
+ return Promise.resolve();
42
+ }
43
+ return backgroundEventHandler(event);
44
+ };
45
+ });
46
+ }
47
+ else if (utils_1.isIOS) {
48
+ this.emitter.addListener(utils_1.kReactNativeNotifeeNotificationBackgroundEvent, (event) => {
49
+ if (!backgroundEventHandler) {
50
+ console.warn('[notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.');
51
+ return Promise.resolve();
52
+ }
53
+ return backgroundEventHandler(event);
54
+ });
55
+ }
56
+ }
57
+ getTriggerNotificationIds = () => {
58
+ if (utils_1.isAndroid || utils_1.isIOS) {
59
+ return this.native.getTriggerNotificationIds();
60
+ }
61
+ return Promise.resolve([]);
62
+ };
63
+ getTriggerNotifications = () => {
64
+ if (utils_1.isAndroid || utils_1.isIOS) {
65
+ return this.native.getTriggerNotifications();
66
+ }
67
+ return Promise.resolve([]);
68
+ };
69
+ getDisplayedNotifications = () => {
70
+ if (utils_1.isAndroid || utils_1.isIOS) {
71
+ return this.native.getDisplayedNotifications();
72
+ }
73
+ return Promise.resolve([]);
74
+ };
75
+ isChannelBlocked = (channelId) => {
76
+ if (!(0, utils_1.isString)(channelId)) {
77
+ throw new Error("notifee.isChannelBlocked(*) 'channelId' expected a string value.");
78
+ }
79
+ if (utils_1.isWeb || utils_1.isIOS || this.native.ANDROID_API_LEVEL < 26) {
80
+ return Promise.resolve(false);
81
+ }
82
+ return this.native.isChannelBlocked(channelId);
83
+ };
84
+ isChannelCreated = (channelId) => {
85
+ if (!(0, utils_1.isString)(channelId)) {
86
+ channelId;
87
+ throw new Error("notifee.isChannelCreated(*) 'channelId' expected a string value.");
88
+ }
89
+ if (utils_1.isWeb || utils_1.isIOS || this.native.ANDROID_API_LEVEL < 26) {
90
+ return Promise.resolve(true);
91
+ }
92
+ return this.native.isChannelCreated(channelId);
93
+ };
94
+ cancelAllNotifications = (notificationIds, tag) => {
95
+ if (utils_1.isAndroid || utils_1.isIOS) {
96
+ if (notificationIds) {
97
+ if (utils_1.isAndroid) {
98
+ return this.native.cancelAllNotificationsWithIds(notificationIds, utils_1.NotificationType.ALL, tag);
99
+ }
100
+ return this.native.cancelAllNotificationsWithIds(notificationIds);
101
+ }
102
+ return this.native.cancelAllNotifications();
103
+ }
104
+ return Promise.resolve();
105
+ };
106
+ cancelDisplayedNotifications = (notificationIds, tag) => {
107
+ if (utils_1.isAndroid || utils_1.isIOS) {
108
+ if (notificationIds) {
109
+ if (utils_1.isAndroid) {
110
+ return this.native.cancelAllNotificationsWithIds(notificationIds, utils_1.NotificationType.DISPLAYED, tag);
111
+ }
112
+ return this.native.cancelDisplayedNotificationsWithIds(notificationIds);
113
+ }
114
+ return this.native.cancelDisplayedNotifications();
115
+ }
116
+ return Promise.resolve();
117
+ };
118
+ cancelTriggerNotifications = (notificationIds) => {
119
+ if (utils_1.isAndroid || utils_1.isIOS) {
120
+ if (notificationIds) {
121
+ if (utils_1.isAndroid) {
122
+ return this.native.cancelAllNotificationsWithIds(notificationIds, utils_1.NotificationType.TRIGGER, null);
123
+ }
124
+ return this.native.cancelTriggerNotificationsWithIds(notificationIds);
125
+ }
126
+ return this.native.cancelTriggerNotifications();
127
+ }
128
+ return Promise.resolve();
129
+ };
130
+ cancelNotification = (notificationId, tag) => {
131
+ if (!(0, utils_1.isString)(notificationId)) {
132
+ throw new Error("notifee.cancelNotification(*) 'notificationId' expected a string value.");
133
+ }
134
+ if (utils_1.isAndroid) {
135
+ return this.native.cancelAllNotificationsWithIds([notificationId], utils_1.NotificationType.ALL, tag);
136
+ }
137
+ if (utils_1.isIOS) {
138
+ return this.native.cancelNotification(notificationId);
139
+ }
140
+ return Promise.resolve();
141
+ };
142
+ cancelDisplayedNotification = (notificationId, tag) => {
143
+ if (!(0, utils_1.isString)(notificationId)) {
144
+ throw new Error("notifee.cancelDisplayedNotification(*) 'notificationId' expected a string value.");
145
+ }
146
+ if (utils_1.isAndroid) {
147
+ return this.native.cancelAllNotificationsWithIds([notificationId], utils_1.NotificationType.DISPLAYED, tag);
148
+ }
149
+ if (utils_1.isIOS) {
150
+ return this.native.cancelDisplayedNotification(notificationId);
151
+ }
152
+ return Promise.resolve();
153
+ };
154
+ cancelTriggerNotification = (notificationId) => {
155
+ if (!(0, utils_1.isString)(notificationId)) {
156
+ throw new Error("notifee.cancelTriggerNotification(*) 'notificationId' expected a string value.");
157
+ }
158
+ if (utils_1.isAndroid) {
159
+ return this.native.cancelAllNotificationsWithIds([notificationId], utils_1.NotificationType.TRIGGER, null);
160
+ }
161
+ if (utils_1.isIOS) {
162
+ return this.native.cancelTriggerNotification(notificationId);
163
+ }
164
+ return Promise.resolve();
165
+ };
166
+ createChannel = (channel) => {
167
+ let options;
168
+ try {
169
+ options = (0, validateAndroidChannel_1.default)(channel);
170
+ }
171
+ catch (e) {
172
+ throw new Error(`notifee.createChannel(*) ${e.message}`);
173
+ }
174
+ if (utils_1.isAndroid) {
175
+ if (this.native.ANDROID_API_LEVEL < 26) {
176
+ return Promise.resolve(options.id);
177
+ }
178
+ return this.native.createChannel(options).then(() => {
179
+ return options.id;
180
+ });
181
+ }
182
+ return Promise.resolve('');
183
+ };
184
+ createChannels = (channels) => {
185
+ if (!(0, utils_1.isArray)(channels)) {
186
+ throw new Error("notifee.createChannels(*) 'channels' expected an array of AndroidChannel.");
187
+ }
188
+ const options = [];
189
+ try {
190
+ for (let i = 0; i < channels.length; i++) {
191
+ options[i] = (0, validateAndroidChannel_1.default)(channels[i]);
192
+ }
193
+ }
194
+ catch (e) {
195
+ throw new Error(`notifee.createChannels(*) 'channels' a channel is invalid: ${e.message}`);
196
+ }
197
+ if (utils_1.isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
198
+ return this.native.createChannels(options);
199
+ }
200
+ return Promise.resolve();
201
+ };
202
+ createChannelGroup = (channelGroup) => {
203
+ let options;
204
+ try {
205
+ options = (0, validateAndroidChannelGroup_1.default)(channelGroup);
206
+ }
207
+ catch (e) {
208
+ throw new Error(`notifee.createChannelGroup(*) ${e.message}`);
209
+ }
210
+ if (utils_1.isAndroid) {
211
+ if (this.native.ANDROID_API_LEVEL < 26) {
212
+ return Promise.resolve(options.id);
213
+ }
214
+ return this.native.createChannelGroup(options).then(() => {
215
+ return options.id;
216
+ });
217
+ }
218
+ return Promise.resolve('');
219
+ };
220
+ createChannelGroups = (channelGroups) => {
221
+ if (!(0, utils_1.isArray)(channelGroups)) {
222
+ throw new Error("notifee.createChannelGroups(*) 'channelGroups' expected an array of AndroidChannelGroup.");
223
+ }
224
+ const options = [];
225
+ try {
226
+ for (let i = 0; i < channelGroups.length; i++) {
227
+ options[i] = (0, validateAndroidChannelGroup_1.default)(channelGroups[i]);
228
+ }
229
+ }
230
+ catch (e) {
231
+ throw new Error(`notifee.createChannelGroups(*) 'channelGroups' a channel group is invalid: ${e.message}`);
232
+ }
233
+ if (utils_1.isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
234
+ return this.native.createChannelGroups(options);
235
+ }
236
+ return Promise.resolve();
237
+ };
238
+ deleteChannel = (channelId) => {
239
+ if (!(0, utils_1.isString)(channelId)) {
240
+ throw new Error("notifee.deleteChannel(*) 'channelId' expected a string value.");
241
+ }
242
+ if (utils_1.isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
243
+ return this.native.deleteChannel(channelId);
244
+ }
245
+ return Promise.resolve();
246
+ };
247
+ deleteChannelGroup = (channelGroupId) => {
248
+ if (!(0, utils_1.isString)(channelGroupId)) {
249
+ throw new Error("notifee.deleteChannelGroup(*) 'channelGroupId' expected a string value.");
250
+ }
251
+ if (utils_1.isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
252
+ return this.native.deleteChannelGroup(channelGroupId);
253
+ }
254
+ return Promise.resolve();
255
+ };
256
+ displayNotification = (notification) => {
257
+ let options;
258
+ try {
259
+ options = (0, validateNotification_1.default)(notification);
260
+ }
261
+ catch (e) {
262
+ throw new Error(`notifee.displayNotification(*) ${e.message}`);
263
+ }
264
+ if (utils_1.isIOS || utils_1.isAndroid) {
265
+ return this.native.displayNotification(options).then(() => {
266
+ return options.id;
267
+ });
268
+ }
269
+ return Promise.resolve('');
270
+ };
271
+ openAlarmPermissionSettings = () => {
272
+ if (utils_1.isAndroid) {
273
+ return this.native.openAlarmPermissionSettings();
274
+ }
275
+ return Promise.resolve();
276
+ };
277
+ createTriggerNotification = (notification, trigger) => {
278
+ let options;
279
+ let triggerOptions;
280
+ try {
281
+ options = (0, validateNotification_1.default)(notification);
282
+ }
283
+ catch (e) {
284
+ throw new Error(`notifee.createTriggerNotification(*) ${e.message}`);
285
+ }
286
+ try {
287
+ triggerOptions = (0, validateTrigger_1.default)(trigger);
288
+ }
289
+ catch (e) {
290
+ throw new Error(`notifee.createTriggerNotification(*) ${e.message}`);
291
+ }
292
+ if (utils_1.isIOS || utils_1.isAndroid) {
293
+ return this.native.createTriggerNotification(options, triggerOptions).then(() => {
294
+ return options.id;
295
+ });
296
+ }
297
+ return Promise.resolve('');
298
+ };
299
+ getChannel = (channelId) => {
300
+ if (!(0, utils_1.isString)(channelId)) {
301
+ throw new Error("notifee.getChannel(*) 'channelId' expected a string value.");
302
+ }
303
+ if (utils_1.isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
304
+ return this.native.getChannel(channelId);
305
+ }
306
+ return Promise.resolve(null);
307
+ };
308
+ getChannels = () => {
309
+ if (utils_1.isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
310
+ return this.native.getChannels();
311
+ }
312
+ return Promise.resolve([]);
313
+ };
314
+ getChannelGroup = (channelGroupId) => {
315
+ if (!(0, utils_1.isString)(channelGroupId)) {
316
+ throw new Error("notifee.getChannelGroup(*) 'channelGroupId' expected a string value.");
317
+ }
318
+ if (utils_1.isAndroid || this.native.ANDROID_API_LEVEL >= 26) {
319
+ return this.native.getChannelGroup(channelGroupId);
320
+ }
321
+ return Promise.resolve(null);
322
+ };
323
+ getChannelGroups = () => {
324
+ if (utils_1.isAndroid || this.native.ANDROID_API_LEVEL >= 26) {
325
+ return this.native.getChannelGroups();
326
+ }
327
+ return Promise.resolve([]);
328
+ };
329
+ getInitialNotification = () => {
330
+ if (utils_1.isIOS || utils_1.isAndroid) {
331
+ return this.native.getInitialNotification();
332
+ }
333
+ return Promise.resolve(null);
334
+ };
335
+ onBackgroundEvent = (observer) => {
336
+ if (!(0, utils_1.isFunction)(observer)) {
337
+ throw new Error("notifee.onBackgroundEvent(*) 'observer' expected a function.");
338
+ }
339
+ backgroundEventHandler = observer;
340
+ };
341
+ onForegroundEvent = (observer) => {
342
+ if (!(0, utils_1.isFunction)(observer)) {
343
+ throw new Error("notifee.onForegroundEvent(*) 'observer' expected a function.");
344
+ }
345
+ const subscriber = this.emitter.addListener(utils_1.kReactNativeNotifeeNotificationEvent,
346
+ // @ts-ignore See https://github.com/facebook/react-native/pull/36462
347
+ ({ type, detail }) => {
348
+ observer({ type, detail });
349
+ });
350
+ return () => {
351
+ subscriber.remove();
352
+ };
353
+ };
354
+ openNotificationSettings = (channelId) => {
355
+ if (!(0, utils_1.isUndefined)(channelId) && !(0, utils_1.isString)(channelId)) {
356
+ throw new Error("notifee.openNotificationSettings(*) 'channelId' expected a string value.");
357
+ }
358
+ if (utils_1.isAndroid) {
359
+ return this.native.openNotificationSettings(channelId || null);
360
+ }
361
+ return Promise.resolve();
362
+ };
363
+ requestPermission = (permissions = {}) => {
364
+ if (utils_1.isAndroid) {
365
+ return this.native
366
+ .requestPermission()
367
+ .then(({ authorizationStatus, android, }) => {
368
+ return {
369
+ authorizationStatus,
370
+ android,
371
+ ios: {
372
+ alert: 1,
373
+ badge: 1,
374
+ criticalAlert: 1,
375
+ showPreviews: 1,
376
+ sound: 1,
377
+ carPlay: 1,
378
+ lockScreen: 1,
379
+ announcement: 1,
380
+ notificationCenter: 1,
381
+ inAppNotificationSettings: 1,
382
+ authorizationStatus,
383
+ },
384
+ web: {},
385
+ };
386
+ });
387
+ }
388
+ if (utils_1.isIOS) {
389
+ let options;
390
+ try {
391
+ options = (0, validateIOSPermissions_1.default)(permissions);
392
+ }
393
+ catch (e) {
394
+ throw new Error(`notifee.requestPermission(*) ${e.message}`);
395
+ }
396
+ return this.native
397
+ .requestPermission(options)
398
+ .then(({ authorizationStatus, ios, }) => {
399
+ return {
400
+ authorizationStatus,
401
+ ios,
402
+ android: {
403
+ alarm: NotificationAndroid_1.AndroidNotificationSetting.ENABLED,
404
+ },
405
+ web: {},
406
+ };
407
+ });
408
+ }
409
+ // assume web
410
+ return Promise.resolve({
411
+ authorizationStatus: Notification_1.AuthorizationStatus.NOT_DETERMINED,
412
+ android: {
413
+ alarm: NotificationAndroid_1.AndroidNotificationSetting.ENABLED,
414
+ },
415
+ ios: {
416
+ alert: 1,
417
+ badge: 1,
418
+ criticalAlert: 1,
419
+ showPreviews: 1,
420
+ sound: 1,
421
+ carPlay: 1,
422
+ lockScreen: 1,
423
+ announcement: 1,
424
+ notificationCenter: 1,
425
+ inAppNotificationSettings: 1,
426
+ authorizationStatus: Notification_1.AuthorizationStatus.NOT_DETERMINED,
427
+ },
428
+ web: {},
429
+ });
430
+ };
431
+ registerForegroundService(runner) {
432
+ if (!(0, utils_1.isFunction)(runner)) {
433
+ throw new Error("notifee.registerForegroundService(_) 'runner' expected a function.");
434
+ }
435
+ if (utils_1.isAndroid) {
436
+ registeredForegroundServiceTask = runner;
437
+ }
438
+ return;
439
+ }
440
+ setNotificationCategories = (categories) => {
441
+ if (!utils_1.isIOS) {
442
+ return Promise.resolve();
443
+ }
444
+ if (!(0, utils_1.isArray)(categories)) {
445
+ throw new Error("notifee.setNotificationCategories(*) 'categories' expected an array of IOSCategory.");
446
+ }
447
+ const options = [];
448
+ try {
449
+ for (let i = 0; i < categories.length; i++) {
450
+ options[i] = (0, validateIOSCategory_1.default)(categories[i]);
451
+ }
452
+ }
453
+ catch (e) {
454
+ throw new Error(`notifee.setNotificationCategories(*) 'categories' a category is invalid: ${e.message}`);
455
+ }
456
+ return this.native.setNotificationCategories(categories);
457
+ };
458
+ getNotificationCategories = () => {
459
+ if (!utils_1.isIOS) {
460
+ return Promise.resolve([]);
461
+ }
462
+ return this.native.getNotificationCategories();
463
+ };
464
+ getNotificationSettings = () => {
465
+ if (utils_1.isAndroid) {
466
+ return this.native
467
+ .getNotificationSettings()
468
+ .then(({ authorizationStatus, android, }) => {
469
+ return {
470
+ authorizationStatus,
471
+ android,
472
+ ios: {
473
+ alert: 1,
474
+ badge: 1,
475
+ criticalAlert: 1,
476
+ showPreviews: 1,
477
+ sound: 1,
478
+ carPlay: 1,
479
+ lockScreen: 1,
480
+ announcement: 1,
481
+ notificationCenter: 1,
482
+ inAppNotificationSettings: 1,
483
+ authorizationStatus,
484
+ },
485
+ web: {},
486
+ };
487
+ });
488
+ }
489
+ if (utils_1.isIOS) {
490
+ return this.native
491
+ .getNotificationSettings()
492
+ .then(({ authorizationStatus, ios, }) => {
493
+ return {
494
+ authorizationStatus,
495
+ ios,
496
+ android: {
497
+ alarm: NotificationAndroid_1.AndroidNotificationSetting.ENABLED,
498
+ },
499
+ };
500
+ });
501
+ }
502
+ // assume web
503
+ return Promise.resolve({
504
+ authorizationStatus: Notification_1.AuthorizationStatus.NOT_DETERMINED,
505
+ android: {
506
+ alarm: NotificationAndroid_1.AndroidNotificationSetting.ENABLED,
507
+ },
508
+ ios: {
509
+ alert: 1,
510
+ badge: 1,
511
+ criticalAlert: 1,
512
+ showPreviews: 1,
513
+ sound: 1,
514
+ carPlay: 1,
515
+ lockScreen: 1,
516
+ announcement: 1,
517
+ notificationCenter: 1,
518
+ inAppNotificationSettings: 1,
519
+ authorizationStatus: Notification_1.AuthorizationStatus.NOT_DETERMINED,
520
+ },
521
+ web: {},
522
+ });
523
+ };
524
+ getBadgeCount = () => {
525
+ if (!utils_1.isIOS) {
526
+ return Promise.resolve(0);
527
+ }
528
+ return this.native.getBadgeCount();
529
+ };
530
+ setBadgeCount = (count) => {
531
+ if (!utils_1.isIOS) {
532
+ return Promise.resolve();
533
+ }
534
+ if (!(0, utils_1.isNumber)(count) || count < 0) {
535
+ throw new Error("notifee.setBadgeCount(*) 'count' expected a number value greater than 0.");
536
+ }
537
+ return this.native.setBadgeCount(Math.round(count));
538
+ };
539
+ incrementBadgeCount = (incrementBy) => {
540
+ if (!utils_1.isIOS) {
541
+ return Promise.resolve();
542
+ }
543
+ let value = 1;
544
+ if (!(0, utils_1.isUndefined)(incrementBy)) {
545
+ if (!(0, utils_1.isNumber)(incrementBy) || incrementBy < 1) {
546
+ throw new Error("notifee.decrementBadgeCount(*) 'incrementBy' expected a number value greater than 1.");
547
+ }
548
+ value = incrementBy;
549
+ }
550
+ return this.native.incrementBadgeCount(Math.round(value));
551
+ };
552
+ decrementBadgeCount = (decrementBy) => {
553
+ if (!utils_1.isIOS) {
554
+ return Promise.resolve();
555
+ }
556
+ let value = 1;
557
+ if (!(0, utils_1.isUndefined)(decrementBy)) {
558
+ if (!(0, utils_1.isNumber)(decrementBy) || decrementBy < 1) {
559
+ throw new Error("notifee.decrementBadgeCount(*) 'decrementBy' expected a number value greater than 1.");
560
+ }
561
+ value = decrementBy;
562
+ }
563
+ return this.native.decrementBadgeCount(Math.round(value));
564
+ };
565
+ isBatteryOptimizationEnabled = () => {
566
+ if (!utils_1.isAndroid) {
567
+ return Promise.resolve(false);
568
+ }
569
+ return this.native.isBatteryOptimizationEnabled();
570
+ };
571
+ openBatteryOptimizationSettings = () => {
572
+ if (!utils_1.isAndroid) {
573
+ return Promise.resolve();
574
+ }
575
+ return this.native.openBatteryOptimizationSettings();
576
+ };
577
+ getPowerManagerInfo = () => {
578
+ if (!utils_1.isAndroid) {
579
+ // only Android supports this, so instead we
580
+ // return a dummy response to allow the power manager
581
+ // flow work the same on all platforms
582
+ return Promise.resolve({
583
+ manufacturer: react_native_1.Platform.OS,
584
+ activity: null,
585
+ });
586
+ }
587
+ return this.native.getPowerManagerInfo();
588
+ };
589
+ openPowerManagerSettings = () => {
590
+ if (!utils_1.isAndroid) {
591
+ return Promise.resolve();
592
+ }
593
+ return this.native.openPowerManagerSettings();
594
+ };
595
+ stopForegroundService = () => {
596
+ if (!utils_1.isAndroid) {
597
+ return Promise.resolve();
598
+ }
599
+ return this.native.stopForegroundService();
600
+ };
601
+ hideNotificationDrawer = () => {
602
+ if (!utils_1.isAndroid) {
603
+ return;
604
+ }
605
+ return this.native.hideNotificationDrawer();
606
+ };
607
+ }
608
+ exports.default = NotifeeApiModule;
609
+ //# sourceMappingURL=NotifeeApiModule.js.map