@ammarahmed/notifee-react-native 7.3.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 (215) hide show
  1. package/.gitattributes +3 -0
  2. package/LICENSE +44 -0
  3. package/README.md +131 -0
  4. package/RNNotifee.podspec +39 -0
  5. package/RNNotifeeCore.podspec +33 -0
  6. package/android/build.gradle +116 -0
  7. package/android/gradle.properties +1 -0
  8. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
  9. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +1 -0
  10. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +1 -0
  11. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +1 -0
  12. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +1 -0
  13. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +9 -0
  14. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +1 -0
  15. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +1 -0
  16. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +1 -0
  17. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +1 -0
  18. package/android/libs/app/notifee/core/maven-metadata.xml +13 -0
  19. package/android/libs/app/notifee/core/maven-metadata.xml.md5 +1 -0
  20. package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +1 -0
  21. package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +1 -0
  22. package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +1 -0
  23. package/android/lint.xml +5 -0
  24. package/android/proguard-rules.pro +74 -0
  25. package/android/settings.gradle +1 -0
  26. package/android/src/main/AndroidManifest.xml +12 -0
  27. package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +349 -0
  28. package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
  29. package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
  30. package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
  31. package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +244 -0
  32. package/app.plugin.js +1 -0
  33. package/dist/NotifeeApiModule.d.ts +53 -0
  34. package/dist/NotifeeApiModule.js +607 -0
  35. package/dist/NotifeeApiModule.js.map +1 -0
  36. package/dist/NotifeeJSEventEmitter.d.ts +3 -0
  37. package/dist/NotifeeJSEventEmitter.js +14 -0
  38. package/dist/NotifeeJSEventEmitter.js.map +1 -0
  39. package/dist/NotifeeNativeError.d.ts +15 -0
  40. package/dist/NotifeeNativeError.js +61 -0
  41. package/dist/NotifeeNativeError.js.map +1 -0
  42. package/dist/NotifeeNativeModule.d.ts +14 -0
  43. package/dist/NotifeeNativeModule.js +43 -0
  44. package/dist/NotifeeNativeModule.js.map +1 -0
  45. package/dist/NotifeeNativeModule.web.d.ts +12 -0
  46. package/dist/NotifeeNativeModule.web.js +19 -0
  47. package/dist/NotifeeNativeModule.web.js.map +1 -0
  48. package/dist/index.d.ts +8 -0
  49. package/dist/index.js +43 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/types/Library.d.ts +21 -0
  52. package/dist/types/Library.js +6 -0
  53. package/dist/types/Library.js.map +1 -0
  54. package/dist/types/Module.d.ts +572 -0
  55. package/dist/types/Module.js +6 -0
  56. package/dist/types/Module.js.map +1 -0
  57. package/dist/types/Notification.d.ts +450 -0
  58. package/dist/types/Notification.js +105 -0
  59. package/dist/types/Notification.js.map +1 -0
  60. package/dist/types/NotificationAndroid.d.ts +1276 -0
  61. package/dist/types/NotificationAndroid.js +380 -0
  62. package/dist/types/NotificationAndroid.js.map +1 -0
  63. package/dist/types/NotificationIOS.d.ts +537 -0
  64. package/dist/types/NotificationIOS.js +92 -0
  65. package/dist/types/NotificationIOS.js.map +1 -0
  66. package/dist/types/NotificationWeb.d.ts +5 -0
  67. package/dist/types/NotificationWeb.js +3 -0
  68. package/dist/types/NotificationWeb.js.map +1 -0
  69. package/dist/types/PowerManagerInfo.d.ts +36 -0
  70. package/dist/types/PowerManagerInfo.js +6 -0
  71. package/dist/types/PowerManagerInfo.js.map +1 -0
  72. package/dist/types/Trigger.d.ts +108 -0
  73. package/dist/types/Trigger.js +39 -0
  74. package/dist/types/Trigger.js.map +1 -0
  75. package/dist/utils/id.d.ts +1 -0
  76. package/dist/utils/id.js +16 -0
  77. package/dist/utils/id.js.map +1 -0
  78. package/dist/utils/index.d.ts +16 -0
  79. package/dist/utils/index.js +52 -0
  80. package/dist/utils/index.js.map +1 -0
  81. package/dist/utils/validate.d.ts +15 -0
  82. package/dist/utils/validate.js +93 -0
  83. package/dist/utils/validate.js.map +1 -0
  84. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
  85. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +39 -0
  86. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
  87. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
  88. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
  89. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
  90. package/dist/validators/validate.d.ts +25 -0
  91. package/dist/validators/validate.js +75 -0
  92. package/dist/validators/validate.js.map +1 -0
  93. package/dist/validators/validateAndroidAction.d.ts +2 -0
  94. package/dist/validators/validateAndroidAction.js +52 -0
  95. package/dist/validators/validateAndroidAction.js.map +1 -0
  96. package/dist/validators/validateAndroidChannel.d.ts +2 -0
  97. package/dist/validators/validateAndroidChannel.js +155 -0
  98. package/dist/validators/validateAndroidChannel.js.map +1 -0
  99. package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
  100. package/dist/validators/validateAndroidChannelGroup.js +42 -0
  101. package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
  102. package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
  103. package/dist/validators/validateAndroidFullScreenAction.js +50 -0
  104. package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
  105. package/dist/validators/validateAndroidInput.d.ts +2 -0
  106. package/dist/validators/validateAndroidInput.js +54 -0
  107. package/dist/validators/validateAndroidInput.js.map +1 -0
  108. package/dist/validators/validateAndroidNotification.d.ts +2 -0
  109. package/dist/validators/validateAndroidNotification.js +529 -0
  110. package/dist/validators/validateAndroidNotification.js.map +1 -0
  111. package/dist/validators/validateAndroidPressAction.d.ts +2 -0
  112. package/dist/validators/validateAndroidPressAction.js +50 -0
  113. package/dist/validators/validateAndroidPressAction.js.map +1 -0
  114. package/dist/validators/validateAndroidStyle.d.ts +22 -0
  115. package/dist/validators/validateAndroidStyle.js +231 -0
  116. package/dist/validators/validateAndroidStyle.js.map +1 -0
  117. package/dist/validators/validateIOSAttachment.d.ts +6 -0
  118. package/dist/validators/validateIOSAttachment.js +102 -0
  119. package/dist/validators/validateIOSAttachment.js.map +1 -0
  120. package/dist/validators/validateIOSCategory.d.ts +2 -0
  121. package/dist/validators/validateIOSCategory.js +124 -0
  122. package/dist/validators/validateIOSCategory.js.map +1 -0
  123. package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
  124. package/dist/validators/validateIOSCategoryAction.js +59 -0
  125. package/dist/validators/validateIOSCategoryAction.js.map +1 -0
  126. package/dist/validators/validateIOSInput.d.ts +2 -0
  127. package/dist/validators/validateIOSInput.js +32 -0
  128. package/dist/validators/validateIOSInput.js.map +1 -0
  129. package/dist/validators/validateIOSNotification.d.ts +2 -0
  130. package/dist/validators/validateIOSNotification.js +211 -0
  131. package/dist/validators/validateIOSNotification.js.map +1 -0
  132. package/dist/validators/validateIOSPermissions.d.ts +2 -0
  133. package/dist/validators/validateIOSPermissions.js +62 -0
  134. package/dist/validators/validateIOSPermissions.js.map +1 -0
  135. package/dist/validators/validateNotification.d.ts +11 -0
  136. package/dist/validators/validateNotification.js +129 -0
  137. package/dist/validators/validateNotification.js.map +1 -0
  138. package/dist/validators/validateTrigger.d.ts +2 -0
  139. package/dist/validators/validateTrigger.js +104 -0
  140. package/dist/validators/validateTrigger.js.map +1 -0
  141. package/dist/version.d.ts +1 -0
  142. package/dist/version.js.map +1 -0
  143. package/ios/NotifeeCore/Info.plist +22 -0
  144. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
  145. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +72 -0
  146. package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
  147. package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
  148. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +37 -0
  149. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +242 -0
  150. package/ios/NotifeeCore/NotifeeCore.h +118 -0
  151. package/ios/NotifeeCore/NotifeeCore.m +784 -0
  152. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
  153. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
  154. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
  155. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
  156. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
  157. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
  158. package/ios/NotifeeCore/NotifeeCoreUtil.h +82 -0
  159. package/ios/NotifeeCore/NotifeeCoreUtil.m +793 -0
  160. package/ios/RNNotifee/NotifeeApiModule.h +25 -0
  161. package/ios/RNNotifee/NotifeeApiModule.m +371 -0
  162. package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
  163. package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
  164. package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
  165. package/jest-mock.js +158 -0
  166. package/package.json +59 -0
  167. package/plugin/build/index.d.ts +3 -0
  168. package/plugin/build/index.js +12 -0
  169. package/plugin/build/index.js.map +1 -0
  170. package/plugin/build/withNotifeeProjectGradlePlugin.d.ts +5 -0
  171. package/plugin/build/withNotifeeProjectGradlePlugin.js +24 -0
  172. package/plugin/build/withNotifeeProjectGradlePlugin.js.map +1 -0
  173. package/plugin/src/index.ts +9 -0
  174. package/plugin/src/withNotifeeProjectGradlePlugin.ts +27 -0
  175. package/plugin/tsconfig.json +9 -0
  176. package/react-native.config.js +11 -0
  177. package/refresh-example.sh +71 -0
  178. package/src/NotifeeApiModule.ts +825 -0
  179. package/src/NotifeeJSEventEmitter.ts +11 -0
  180. package/src/NotifeeNativeError.ts +70 -0
  181. package/src/NotifeeNativeModule.ts +55 -0
  182. package/src/NotifeeNativeModule.web.ts +25 -0
  183. package/src/index.ts +33 -0
  184. package/src/types/Library.ts +28 -0
  185. package/src/types/Module.ts +625 -0
  186. package/src/types/Notification.ts +505 -0
  187. package/src/types/NotificationAndroid.ts +1443 -0
  188. package/src/types/NotificationIOS.ts +681 -0
  189. package/src/types/NotificationWeb.ts +5 -0
  190. package/src/types/PowerManagerInfo.ts +43 -0
  191. package/src/types/Trigger.ts +118 -0
  192. package/src/utils/id.ts +13 -0
  193. package/src/utils/index.ts +47 -0
  194. package/src/utils/validate.ts +92 -0
  195. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +45 -0
  196. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
  197. package/src/validators/validate.ts +85 -0
  198. package/src/validators/validateAndroidAction.ts +54 -0
  199. package/src/validators/validateAndroidChannel.ts +188 -0
  200. package/src/validators/validateAndroidChannelGroup.ts +49 -0
  201. package/src/validators/validateAndroidFullScreenAction.ts +65 -0
  202. package/src/validators/validateAndroidInput.ts +67 -0
  203. package/src/validators/validateAndroidNotification.ts +704 -0
  204. package/src/validators/validateAndroidPressAction.ts +65 -0
  205. package/src/validators/validateAndroidStyle.ts +315 -0
  206. package/src/validators/validateIOSAttachment.ts +136 -0
  207. package/src/validators/validateIOSCategory.ts +150 -0
  208. package/src/validators/validateIOSCategoryAction.ts +65 -0
  209. package/src/validators/validateIOSInput.ts +38 -0
  210. package/src/validators/validateIOSNotification.ts +296 -0
  211. package/src/validators/validateIOSPermissions.ts +78 -0
  212. package/src/validators/validateNotification.ts +156 -0
  213. package/src/validators/validateTrigger.ts +134 -0
  214. package/src/version.ts +2 -0
  215. package/tsconfig.json +23 -0
@@ -0,0 +1,65 @@
1
+ import { IOSNotificationCategoryAction } from '../types/NotificationIOS';
2
+ import { objectHasProperty, isBoolean, isObject, isString, isUndefined } from '../utils';
3
+ import validateIOSInput from './validateIOSInput';
4
+
5
+ export default function validateIOSCategoryAction(
6
+ action: IOSNotificationCategoryAction,
7
+ ): IOSNotificationCategoryAction {
8
+ if (!isObject(action)) {
9
+ throw new Error('"action" expected an object value');
10
+ }
11
+
12
+ if (!isString(action.id) || action.id.length === 0) {
13
+ throw new Error('"action.id" expected a valid string value.');
14
+ }
15
+
16
+ if (!isString(action.title) || action.title.length === 0) {
17
+ throw new Error('"action.title" expected a valid string value.');
18
+ }
19
+
20
+ const out: IOSNotificationCategoryAction = {
21
+ id: action.id,
22
+ title: action.title,
23
+ destructive: false,
24
+ foreground: false,
25
+ authenticationRequired: false,
26
+ };
27
+
28
+ if (objectHasProperty(action, 'input') && !isUndefined(action.input)) {
29
+ if (action.input === true) {
30
+ out.input = true;
31
+ } else {
32
+ try {
33
+ out.input = validateIOSInput(action.input);
34
+ } catch (e: any) {
35
+ throw new Error(`'action' ${e.message}.`);
36
+ }
37
+ }
38
+ }
39
+
40
+ if (objectHasProperty(action, 'destructive')) {
41
+ if (!isBoolean(action.destructive)) {
42
+ throw new Error("'destructive' expected a boolean value.");
43
+ }
44
+
45
+ out.destructive = action.destructive;
46
+ }
47
+
48
+ if (objectHasProperty(action, 'foreground')) {
49
+ if (!isBoolean(action.foreground)) {
50
+ throw new Error("'foreground' expected a boolean value.");
51
+ }
52
+
53
+ out.foreground = action.foreground;
54
+ }
55
+
56
+ if (objectHasProperty(action, 'authenticationRequired')) {
57
+ if (!isBoolean(action.authenticationRequired)) {
58
+ throw new Error("'authenticationRequired' expected a boolean value.");
59
+ }
60
+
61
+ out.authenticationRequired = action.authenticationRequired;
62
+ }
63
+
64
+ return out;
65
+ }
@@ -0,0 +1,38 @@
1
+ import { IOSInput } from '../types/NotificationIOS';
2
+ import { objectHasProperty, isBoolean, isObject, isString, isUndefined } from '../utils';
3
+
4
+ export default function validateIOSInput(input?: IOSInput): IOSInput {
5
+ const out: IOSInput = {};
6
+
7
+ // default value
8
+ if (!input) {
9
+ return out;
10
+ }
11
+
12
+ // if true, empty object
13
+ if (isBoolean(input)) {
14
+ return out;
15
+ }
16
+
17
+ if (!isObject(input)) {
18
+ throw new Error('expected an object value.');
19
+ }
20
+
21
+ if (objectHasProperty(input, 'buttonText') && !isUndefined(input.buttonText)) {
22
+ if (!isString(input.buttonText)) {
23
+ throw new Error("'buttonText' expected a string value.");
24
+ }
25
+
26
+ out.buttonText = input.buttonText;
27
+ }
28
+
29
+ if (objectHasProperty(input, 'placeholderText') && !isUndefined(input.placeholderText)) {
30
+ if (!isString(input.placeholderText)) {
31
+ throw new Error("'placeholderText' expected a string value.");
32
+ }
33
+
34
+ out.placeholderText = input.placeholderText;
35
+ }
36
+
37
+ return out;
38
+ }
@@ -0,0 +1,296 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited
3
+ */
4
+
5
+ import {
6
+ NotificationIOS,
7
+ IOSForegroundPresentationOptions,
8
+ IOSNotificationAttachment,
9
+ } from '../types/NotificationIOS';
10
+ import {
11
+ objectHasProperty,
12
+ isBoolean,
13
+ isNumber,
14
+ isString,
15
+ isUndefined,
16
+ isObject,
17
+ isArray,
18
+ isAndroid,
19
+ } from '../utils';
20
+ import validateIOSCommunicationInfo from './iosCommunicationInfo/validateIOSCommunicationInfo';
21
+ import validateIOSAttachment from './validateIOSAttachment';
22
+
23
+ export default function validateIOSNotification(ios?: NotificationIOS): NotificationIOS {
24
+ const out: NotificationIOS & {
25
+ foregroundPresentationOptions: IOSForegroundPresentationOptions;
26
+ } = {
27
+ foregroundPresentationOptions: {
28
+ alert: true,
29
+ badge: true,
30
+ sound: true,
31
+ banner: true,
32
+ list: true,
33
+ },
34
+ };
35
+
36
+ if (isUndefined(ios)) {
37
+ return out;
38
+ }
39
+
40
+ /* Skip validating if Android in release */
41
+ if (isAndroid && !__DEV__) return out;
42
+
43
+ /**
44
+ * attachments
45
+ */
46
+ if (objectHasProperty(ios, 'attachments')) {
47
+ if (!isArray(ios.attachments)) {
48
+ throw new Error("'notification.ios.attachments' expected an array value.");
49
+ }
50
+
51
+ const attachments: IOSNotificationAttachment[] = [];
52
+
53
+ for (let i = 0; i < ios.attachments.length; i++) {
54
+ try {
55
+ attachments.push(validateIOSAttachment(ios.attachments[i]));
56
+ } catch (e: any) {
57
+ throw new Error(
58
+ `'notification.ios.attachments' invalid IOSNotificationAttachment. ${e.message}.`,
59
+ );
60
+ }
61
+ }
62
+
63
+ if (attachments.length) {
64
+ out.attachments = attachments;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * communicationInfo
70
+ */
71
+ if (objectHasProperty(ios, 'communicationInfo') && !isUndefined(ios.communicationInfo)) {
72
+ try {
73
+ out.communicationInfo = validateIOSCommunicationInfo(ios.communicationInfo);
74
+ } catch (e: any) {
75
+ throw new Error(`'ios.communicationInfo' ${e.message}`);
76
+ }
77
+ }
78
+
79
+ /**
80
+ * interruptionLevel
81
+ */
82
+ if (objectHasProperty(ios, 'interruptionLevel')) {
83
+ if (
84
+ isString(ios.interruptionLevel) &&
85
+ ['active', 'critical', 'passive', 'timeSensitive'].includes(ios.interruptionLevel)
86
+ ) {
87
+ out.interruptionLevel = ios.interruptionLevel;
88
+ } else {
89
+ throw new Error(
90
+ "'notification.ios.interruptionLevel' must be a string value: 'active','critical','passive','timeSensitive'.",
91
+ );
92
+ }
93
+ }
94
+
95
+ /**
96
+ * critical
97
+ */
98
+ if (objectHasProperty(ios, 'critical')) {
99
+ if (!isBoolean(ios.critical)) {
100
+ throw new Error("'notification.ios.critical' must be a boolean value if specified.");
101
+ } else {
102
+ out.critical = ios.critical;
103
+ }
104
+ }
105
+
106
+ /**
107
+ * criticalVolume
108
+ */
109
+ if (objectHasProperty(ios, 'criticalVolume')) {
110
+ if (!isNumber(ios.criticalVolume)) {
111
+ throw new Error("'notification.ios.criticalVolume' must be a number value if specified.");
112
+ } else {
113
+ if (ios.criticalVolume < 0 || ios.criticalVolume > 1) {
114
+ throw new Error(
115
+ "'notification.ios.criticalVolume' must be a float value between 0.0 and 1.0.",
116
+ );
117
+ }
118
+ out.criticalVolume = ios.criticalVolume;
119
+ }
120
+ }
121
+
122
+ /**
123
+ * sound
124
+ */
125
+ if (objectHasProperty(ios, 'sound')) {
126
+ if (isString(ios.sound)) {
127
+ out.sound = ios.sound;
128
+ } else {
129
+ throw new Error("'notification.sound' must be a string value if specified.");
130
+ }
131
+ }
132
+
133
+ /**
134
+ * badgeCount
135
+ */
136
+ if (objectHasProperty(ios, 'badgeCount')) {
137
+ if (!isNumber(ios.badgeCount) || ios.badgeCount < 0) {
138
+ throw new Error("'notification.ios.badgeCount' expected a number value >=0.");
139
+ }
140
+
141
+ out.badgeCount = ios.badgeCount;
142
+ }
143
+
144
+ /**
145
+ * categoryId
146
+ */
147
+ if (objectHasProperty(ios, 'categoryId')) {
148
+ if (!isString(ios.categoryId)) {
149
+ throw new Error("'notification.ios.categoryId' expected a of string value");
150
+ }
151
+
152
+ out.categoryId = ios.categoryId;
153
+ }
154
+
155
+ /**
156
+ * groupId
157
+ */
158
+ if (objectHasProperty(ios, 'threadId')) {
159
+ if (!isString(ios.threadId)) {
160
+ throw new Error("'notification.ios.threadId' expected a string value.");
161
+ }
162
+
163
+ out.threadId = ios.threadId;
164
+ }
165
+
166
+ /**
167
+ * summaryArgument
168
+ */
169
+ if (objectHasProperty(ios, 'summaryArgument')) {
170
+ if (!isString(ios.summaryArgument)) {
171
+ throw new Error("'notification.ios.summaryArgument' expected a string value.");
172
+ }
173
+
174
+ out.summaryArgument = ios.summaryArgument;
175
+ }
176
+
177
+ /**
178
+ * summaryArgumentCount
179
+ */
180
+ if (objectHasProperty(ios, 'summaryArgumentCount')) {
181
+ if (!isNumber(ios.summaryArgumentCount) || ios.summaryArgumentCount <= 0) {
182
+ throw new Error(
183
+ "'notification.ios.summaryArgumentCount' expected a positive number greater than 0.",
184
+ );
185
+ }
186
+
187
+ out.summaryArgumentCount = ios.summaryArgumentCount;
188
+ }
189
+
190
+ /**
191
+ * launchImageName
192
+ */
193
+ if (objectHasProperty(ios, 'launchImageName')) {
194
+ if (!isString(ios.launchImageName)) {
195
+ throw new Error("'notification.ios.launchImageName' expected a string value.");
196
+ }
197
+
198
+ out.launchImageName = ios.launchImageName;
199
+ }
200
+
201
+ /**
202
+ * sound
203
+ */
204
+ if (objectHasProperty(ios, 'sound')) {
205
+ if (!isString(ios.sound)) {
206
+ throw new Error("'notification.ios.sound' expected a string value.");
207
+ }
208
+
209
+ out.sound = ios.sound;
210
+ }
211
+
212
+ /**
213
+ * ForegroundPresentationOptions
214
+ */
215
+ if (objectHasProperty(ios, 'foregroundPresentationOptions')) {
216
+ if (!isObject(ios.foregroundPresentationOptions)) {
217
+ throw new Error(
218
+ "'notification.ios.foregroundPresentationOptions' expected a valid IOSForegroundPresentationOptions object.",
219
+ );
220
+ }
221
+
222
+ if (
223
+ objectHasProperty<IOSForegroundPresentationOptions>(
224
+ ios.foregroundPresentationOptions,
225
+ 'alert',
226
+ )
227
+ ) {
228
+ if (!isBoolean(ios.foregroundPresentationOptions.alert)) {
229
+ throw new Error(
230
+ "'notification.ios.foregroundPresentationOptions.alert' expected a boolean value.",
231
+ );
232
+ }
233
+
234
+ out.foregroundPresentationOptions.alert = ios.foregroundPresentationOptions.alert;
235
+ }
236
+
237
+ if (
238
+ objectHasProperty<IOSForegroundPresentationOptions>(
239
+ ios.foregroundPresentationOptions,
240
+ 'sound',
241
+ )
242
+ ) {
243
+ if (!isBoolean(ios.foregroundPresentationOptions.sound)) {
244
+ throw new Error(
245
+ "'notification.ios.foregroundPresentationOptions.sound' expected a boolean value.",
246
+ );
247
+ }
248
+
249
+ out.foregroundPresentationOptions.sound = ios.foregroundPresentationOptions.sound;
250
+ }
251
+
252
+ if (
253
+ objectHasProperty<IOSForegroundPresentationOptions>(
254
+ ios.foregroundPresentationOptions,
255
+ 'badge',
256
+ )
257
+ ) {
258
+ if (!isBoolean(ios.foregroundPresentationOptions.badge)) {
259
+ throw new Error(
260
+ "'notification.ios.foregroundPresentationOptions.badge' expected a boolean value.",
261
+ );
262
+ }
263
+
264
+ out.foregroundPresentationOptions.badge = ios.foregroundPresentationOptions.badge;
265
+ }
266
+
267
+ if (
268
+ objectHasProperty<IOSForegroundPresentationOptions>(
269
+ ios.foregroundPresentationOptions,
270
+ 'banner',
271
+ )
272
+ ) {
273
+ if (!isBoolean(ios.foregroundPresentationOptions.banner)) {
274
+ throw new Error(
275
+ "'notification.ios.foregroundPresentationOptions.banner' expected a boolean value.",
276
+ );
277
+ }
278
+
279
+ out.foregroundPresentationOptions.banner = ios.foregroundPresentationOptions.banner;
280
+ }
281
+
282
+ if (
283
+ objectHasProperty<IOSForegroundPresentationOptions>(ios.foregroundPresentationOptions, 'list')
284
+ ) {
285
+ if (!isBoolean(ios.foregroundPresentationOptions.list)) {
286
+ throw new Error(
287
+ "'notification.ios.foregroundPresentationOptions.list' expected a boolean value.",
288
+ );
289
+ }
290
+
291
+ out.foregroundPresentationOptions.list = ios.foregroundPresentationOptions.list;
292
+ }
293
+ }
294
+
295
+ return out;
296
+ }
@@ -0,0 +1,78 @@
1
+ import { IOSNotificationPermissions } from '../types/NotificationIOS';
2
+ import { objectHasProperty, isBoolean } from '../utils';
3
+
4
+ export default function validateIOSPermissions(
5
+ permissions: IOSNotificationPermissions,
6
+ ): IOSNotificationPermissions {
7
+ const out: IOSNotificationPermissions = {
8
+ alert: true,
9
+ badge: true,
10
+ sound: true,
11
+ carPlay: true,
12
+ provisional: false,
13
+ announcement: false,
14
+ criticalAlert: false,
15
+ };
16
+
17
+ if (!permissions) {
18
+ return out;
19
+ }
20
+
21
+ if (objectHasProperty(permissions, 'alert')) {
22
+ if (!isBoolean(permissions.alert)) {
23
+ throw new Error("'alert' expected a boolean value.");
24
+ }
25
+
26
+ out.alert = permissions.alert;
27
+ }
28
+
29
+ if (objectHasProperty(permissions, 'badge')) {
30
+ if (!isBoolean(permissions.badge)) {
31
+ throw new Error("'alert' badge a boolean value.");
32
+ }
33
+
34
+ out.badge = permissions.badge;
35
+ }
36
+
37
+ if (objectHasProperty(permissions, 'sound')) {
38
+ if (!isBoolean(permissions.sound)) {
39
+ throw new Error("'sound' expected a boolean value.");
40
+ }
41
+
42
+ out.sound = permissions.sound;
43
+ }
44
+
45
+ if (objectHasProperty(permissions, 'carPlay')) {
46
+ if (!isBoolean(permissions.carPlay)) {
47
+ throw new Error("'carPlay' expected a boolean value.");
48
+ }
49
+
50
+ out.carPlay = permissions.carPlay;
51
+ }
52
+
53
+ if (objectHasProperty(permissions, 'provisional')) {
54
+ if (!isBoolean(permissions.provisional)) {
55
+ throw new Error("'provisional' expected a boolean value.");
56
+ }
57
+
58
+ out.provisional = permissions.provisional;
59
+ }
60
+
61
+ if (objectHasProperty(permissions, 'announcement')) {
62
+ if (!isBoolean(permissions.announcement)) {
63
+ throw new Error("'announcement' expected a boolean value.");
64
+ }
65
+
66
+ out.announcement = permissions.announcement;
67
+ }
68
+
69
+ if (objectHasProperty(permissions, 'criticalAlert')) {
70
+ if (!isBoolean(permissions.criticalAlert)) {
71
+ throw new Error("'criticalAlert' expected a boolean value.");
72
+ }
73
+
74
+ out.criticalAlert = permissions.criticalAlert;
75
+ }
76
+
77
+ return out;
78
+ }
@@ -0,0 +1,156 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited
3
+ */
4
+
5
+ import {
6
+ generateId,
7
+ objectHasProperty,
8
+ isObject,
9
+ isString,
10
+ isAndroid,
11
+ isIOS,
12
+ isNumber,
13
+ } from '../utils';
14
+
15
+ import validateAndroidNotification from './validateAndroidNotification';
16
+ import validateIOSNotification from './validateIOSNotification';
17
+ import { Notification } from '../types/Notification';
18
+ import { Platform } from 'react-native';
19
+ import { NotificationAndroid } from '../types/NotificationAndroid';
20
+ import { NotificationIOS } from '..';
21
+
22
+ /**
23
+ * Validate platform-specific notification
24
+ *
25
+ * Only throws a validation error if the device is on the same platform
26
+ * Otherwise, will show a debug log in the console
27
+ */
28
+ export const validatePlatformSpecificNotification = (
29
+ out: Notification,
30
+ specifiedPlatform: string,
31
+ ): NotificationAndroid | NotificationIOS => {
32
+ try {
33
+ if (specifiedPlatform === 'ios') {
34
+ return validateIOSNotification(out.ios);
35
+ } else {
36
+ return validateAndroidNotification(out.android);
37
+ }
38
+ } catch (error) {
39
+ const isRunningOnSamePlatform = specifiedPlatform === Platform.OS;
40
+ if (isRunningOnSamePlatform) {
41
+ throw error;
42
+ } else {
43
+ console.debug(`Invalid ${specifiedPlatform} notification ->`, error);
44
+ return {};
45
+ }
46
+ }
47
+ };
48
+
49
+ export default function validateNotification(notification: Notification): Notification {
50
+ if (!isObject(notification)) {
51
+ throw new Error("'notification' expected an object value.");
52
+ }
53
+
54
+ // Defaults
55
+ const out: Notification = {
56
+ id: '',
57
+ data: {},
58
+ };
59
+
60
+ if (isAndroid) {
61
+ /* istanbul ignore next */
62
+ out.android = {};
63
+ } else if (isIOS) {
64
+ out.ios = {};
65
+ }
66
+
67
+ /**
68
+ * id
69
+ */
70
+ if (objectHasProperty(notification, 'id')) {
71
+ if (!isString(notification.id) || !notification.id) {
72
+ throw new Error("'notification.id' invalid notification ID, expected a unique string value.");
73
+ }
74
+
75
+ out.id = notification.id;
76
+ } else {
77
+ out.id = generateId();
78
+ }
79
+
80
+ /**
81
+ * title
82
+ */
83
+ if (objectHasProperty(notification, 'title')) {
84
+ if (notification.title !== undefined && !isString(notification.title)) {
85
+ throw new Error("'notification.title' expected a string value or undefined.");
86
+ }
87
+
88
+ out.title = notification.title;
89
+ }
90
+
91
+ /**
92
+ * body
93
+ */
94
+ if (objectHasProperty(notification, 'body')) {
95
+ if (notification.body !== undefined && !isString(notification.body)) {
96
+ throw new Error("'notification.body' expected a string value or undefined.");
97
+ }
98
+
99
+ out.body = notification.body;
100
+ }
101
+
102
+ /**
103
+ * subtitle
104
+ */
105
+ if (objectHasProperty(notification, 'subtitle')) {
106
+ if (notification.subtitle !== undefined && !isString(notification.subtitle)) {
107
+ throw new Error("'notification.subtitle' expected a string value or undefined.");
108
+ }
109
+
110
+ out.subtitle = notification.subtitle;
111
+ }
112
+
113
+ /**
114
+ * data
115
+ */
116
+ if (objectHasProperty(notification, 'data') && notification.data !== undefined) {
117
+ if (!isObject(notification.data)) {
118
+ throw new Error("'notification.data' expected an object value containing key/value pairs.");
119
+ }
120
+
121
+ const entries = Object.entries(notification.data);
122
+
123
+ for (let i = 0; i < entries.length; i++) {
124
+ const [key, value] = entries[i];
125
+ if (!isString(value) && !isNumber(value) && !isObject(value)) {
126
+ throw new Error(
127
+ `'notification.data' value for key "${key}" is invalid, expected a string value.`,
128
+ );
129
+ }
130
+ }
131
+
132
+ out.data = notification.data;
133
+ }
134
+
135
+ /**
136
+ * android
137
+ */
138
+ const validatedAndroid = validatePlatformSpecificNotification(
139
+ notification,
140
+ 'android',
141
+ ) as NotificationAndroid;
142
+
143
+ if (isAndroid) {
144
+ out.android = validatedAndroid;
145
+ }
146
+
147
+ /**
148
+ * ios
149
+ */
150
+ const validatedIOS = validatePlatformSpecificNotification(notification, 'ios') as NotificationIOS;
151
+ if (isIOS) {
152
+ out.ios = validatedIOS;
153
+ }
154
+
155
+ return out;
156
+ }