@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
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited
3
+ */
4
+
5
+ import { NotificationPressAction } from '../types/Notification';
6
+ import { isObject, isString, isUndefined, isArray, isNumber } from '../utils';
7
+
8
+ const LAUNCH_ACTIVITY_DEFAULT_VALUE = 'default';
9
+ const PRESS_ACTION_DEFAULT_VALUE = 'default';
10
+
11
+ export default function validateAndroidPressAction(
12
+ pressAction: NotificationPressAction,
13
+ ): NotificationPressAction {
14
+ if (!isObject(pressAction)) {
15
+ throw new Error("'pressAction' expected an object value.");
16
+ }
17
+
18
+ if (!isString(pressAction.id) || pressAction.id.length === 0) {
19
+ throw new Error("'id' expected a non-empty string value.");
20
+ }
21
+
22
+ const out: NotificationPressAction = {
23
+ id: pressAction.id,
24
+ };
25
+
26
+ if (!isUndefined(pressAction.launchActivity)) {
27
+ if (!isString(pressAction.launchActivity)) {
28
+ throw new Error("'launchActivity' expected a string value.");
29
+ }
30
+
31
+ out.launchActivity = pressAction.launchActivity;
32
+ } else if (pressAction.id === PRESS_ACTION_DEFAULT_VALUE) {
33
+ // Set default value for launchActivity
34
+ out.launchActivity = LAUNCH_ACTIVITY_DEFAULT_VALUE;
35
+ }
36
+
37
+ if (!isUndefined(pressAction.launchActivityFlags)) {
38
+ if (!isArray(pressAction.launchActivityFlags)) {
39
+ throw new Error(
40
+ "'launchActivityFlags' must be an array of `AndroidLaunchActivityFlag` values.",
41
+ );
42
+ }
43
+
44
+ // quick sanity check on first item only
45
+ if (pressAction.launchActivityFlags.length) {
46
+ if (!isNumber(pressAction.launchActivityFlags[0])) {
47
+ throw new Error(
48
+ "'launchActivityFlags' must be an array of `AndroidLaunchActivityFlag` values.",
49
+ );
50
+ }
51
+ }
52
+
53
+ out.launchActivityFlags = pressAction.launchActivityFlags;
54
+ }
55
+
56
+ if (!isUndefined(pressAction.mainComponent)) {
57
+ if (!isString(pressAction.mainComponent)) {
58
+ throw new Error("'mainComponent' expected a string value.");
59
+ }
60
+
61
+ out.mainComponent = pressAction.mainComponent;
62
+ }
63
+
64
+ return out;
65
+ }
@@ -0,0 +1,315 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited
3
+ */
4
+ import { Image } from 'react-native';
5
+ import {
6
+ AndroidBigPictureStyle,
7
+ AndroidBigTextStyle,
8
+ AndroidInboxStyle,
9
+ AndroidMessagingStyle,
10
+ AndroidMessagingStyleMessage,
11
+ AndroidPerson,
12
+ AndroidStyle,
13
+ } from '../types/NotificationAndroid';
14
+ import { objectHasProperty, isArray, isBoolean, isNumber, isObject, isString } from '../utils';
15
+
16
+ /**
17
+ * Validates a BigPictureStyle
18
+ */
19
+ export function validateAndroidBigPictureStyle(
20
+ style: AndroidBigPictureStyle,
21
+ ): AndroidBigPictureStyle {
22
+ if (
23
+ (!isString(style.picture) && !isNumber(style.picture) && !isObject(style.picture)) ||
24
+ (isString(style.picture) && !style.picture.length)
25
+ ) {
26
+ throw new Error(
27
+ "'notification.android.style' BigPictureStyle: 'picture' expected a number or object created using the 'require()' method or a valid string URL.",
28
+ );
29
+ }
30
+
31
+ // Defaults
32
+ const out: AndroidBigPictureStyle = {
33
+ type: AndroidStyle.BIGPICTURE,
34
+ picture: style.picture,
35
+ };
36
+
37
+ if (isNumber(style.picture) || isObject(style.picture)) {
38
+ const image = Image.resolveAssetSource(style.picture);
39
+
40
+ out.picture = image.uri;
41
+ }
42
+
43
+ if (objectHasProperty(style, 'largeIcon')) {
44
+ if (
45
+ style.largeIcon !== null &&
46
+ !isString(style.largeIcon) &&
47
+ !isNumber(style.largeIcon) &&
48
+ !isObject(style.largeIcon)
49
+ ) {
50
+ throw new Error(
51
+ "'notification.android.style' BigPictureStyle: 'largeIcon' expected a React Native ImageResource value or a valid string URL.",
52
+ );
53
+ }
54
+ if (isNumber(style.largeIcon) || isObject(style.largeIcon)) {
55
+ const image = Image.resolveAssetSource(style.largeIcon);
56
+
57
+ out.largeIcon = image.uri;
58
+ } else {
59
+ out.largeIcon = style.largeIcon;
60
+ }
61
+ }
62
+
63
+ if (objectHasProperty(style, 'title')) {
64
+ if (!isString(style.title)) {
65
+ throw new Error(
66
+ "'notification.android.style' BigPictureStyle: 'title' expected a string value.",
67
+ );
68
+ }
69
+
70
+ out.title = style.title;
71
+ }
72
+
73
+ if (objectHasProperty(style, 'summary')) {
74
+ if (!isString(style.summary)) {
75
+ throw new Error(
76
+ "'notification.android.style' BigPictureStyle: 'summary' expected a string value.",
77
+ );
78
+ }
79
+
80
+ out.summary = style.summary;
81
+ }
82
+
83
+ return out;
84
+ }
85
+
86
+ /**
87
+ * Validates a BigTextStyle
88
+ */
89
+ export function validateAndroidBigTextStyle(style: AndroidBigTextStyle): AndroidBigTextStyle {
90
+ if (!isString(style.text) || !style.text) {
91
+ throw new Error(
92
+ "'notification.android.style' BigTextStyle: 'text' expected a valid string value.",
93
+ );
94
+ }
95
+
96
+ // Defaults
97
+ const out: AndroidBigTextStyle = {
98
+ type: AndroidStyle.BIGTEXT,
99
+ text: style.text,
100
+ };
101
+
102
+ if (objectHasProperty(style, 'title')) {
103
+ if (!isString(style.title)) {
104
+ throw new Error(
105
+ "'notification.android.style' BigTextStyle: 'title' expected a string value.",
106
+ );
107
+ }
108
+
109
+ out.title = style.title;
110
+ }
111
+
112
+ if (objectHasProperty(style, 'summary')) {
113
+ if (!isString(style.summary)) {
114
+ throw new Error(
115
+ "'notification.android.style' BigTextStyle: 'summary' expected a string value.",
116
+ );
117
+ }
118
+
119
+ out.summary = style.summary;
120
+ }
121
+
122
+ return out;
123
+ }
124
+
125
+ /**
126
+ * Validates a InboxStyle
127
+ */
128
+ export function validateAndroidInboxStyle(style: AndroidInboxStyle): AndroidInboxStyle {
129
+ if (!isArray(style.lines)) {
130
+ throw new Error("'notification.android.style' InboxStyle: 'lines' expected an array.");
131
+ }
132
+
133
+ for (let i = 0; i < style.lines.length; i++) {
134
+ const line = style.lines[i];
135
+
136
+ if (!isString(line)) {
137
+ throw new Error(
138
+ `'notification.android.style' InboxStyle: 'lines' expected a string value at array index ${i}.`,
139
+ );
140
+ }
141
+ }
142
+
143
+ const out: AndroidInboxStyle = {
144
+ type: AndroidStyle.INBOX,
145
+ lines: style.lines,
146
+ };
147
+
148
+ if (objectHasProperty(style, 'title')) {
149
+ if (!isString(style.title)) {
150
+ throw new Error("'notification.android.style' InboxStyle: 'title' expected a string value.");
151
+ }
152
+
153
+ out.title = style.title;
154
+ }
155
+
156
+ if (objectHasProperty(style, 'summary')) {
157
+ if (!isString(style.summary)) {
158
+ throw new Error(
159
+ "'notification.android.style' InboxStyle: 'summary' expected a string value.",
160
+ );
161
+ }
162
+
163
+ out.summary = style.summary;
164
+ }
165
+
166
+ return out;
167
+ }
168
+
169
+ /**
170
+ * Validates an AndroidPerson
171
+ */
172
+ export function validateAndroidPerson(person: AndroidPerson): AndroidPerson {
173
+ if (!isString(person.name)) {
174
+ throw new Error("'person.name' expected a string value.");
175
+ }
176
+
177
+ const out: AndroidPerson = {
178
+ name: person.name,
179
+ bot: false,
180
+ important: false,
181
+ };
182
+
183
+ if (objectHasProperty(person, 'id')) {
184
+ if (!isString(person.id)) {
185
+ throw new Error("'person.id' expected a string value.");
186
+ }
187
+
188
+ out.id = person.id;
189
+ }
190
+
191
+ if (objectHasProperty(person, 'bot')) {
192
+ if (!isBoolean(person.bot)) {
193
+ throw new Error("'person.bot' expected a boolean value.");
194
+ }
195
+
196
+ out.bot = person.bot;
197
+ }
198
+
199
+ if (objectHasProperty(person, 'important')) {
200
+ if (!isBoolean(person.important)) {
201
+ throw new Error("'person.important' expected a boolean value.");
202
+ }
203
+
204
+ out.important = person.important;
205
+ }
206
+
207
+ if (objectHasProperty(person, 'icon')) {
208
+ if (!isString(person.icon)) {
209
+ throw new Error("'person.icon' expected a string value.");
210
+ }
211
+
212
+ out.icon = person.icon;
213
+ }
214
+
215
+ if (objectHasProperty(person, 'uri')) {
216
+ if (!isString(person.uri)) {
217
+ throw new Error("'person.uri' expected a string value.");
218
+ }
219
+
220
+ out.uri = person.uri;
221
+ }
222
+
223
+ return out;
224
+ }
225
+
226
+ export function validateAndroidMessagingStyleMessage(
227
+ message: AndroidMessagingStyleMessage,
228
+ ): AndroidMessagingStyleMessage {
229
+ //text, timestamp, person
230
+ if (!isString(message.text)) {
231
+ throw new Error("'message.text' expected a string value.");
232
+ }
233
+
234
+ if (!isNumber(message.timestamp)) {
235
+ throw new Error("'message.timestamp' expected a number value.");
236
+ }
237
+
238
+ const out: AndroidMessagingStyleMessage = {
239
+ text: message.text,
240
+ timestamp: message.timestamp,
241
+ };
242
+
243
+ if (objectHasProperty(message, 'person') && message.person !== undefined) {
244
+ try {
245
+ out.person = validateAndroidPerson(message.person);
246
+ } catch (e: any) {
247
+ throw new Error(`'message.person' is invalid. ${e.message}`);
248
+ }
249
+ }
250
+
251
+ return out;
252
+ }
253
+
254
+ /**
255
+ * Validates a MessagingStyle
256
+ */
257
+ export function validateAndroidMessagingStyle(style: AndroidMessagingStyle): AndroidMessagingStyle {
258
+ if (!isObject(style.person)) {
259
+ throw new Error("'notification.android.style' MessagingStyle: 'person' an object value.");
260
+ }
261
+
262
+ let person;
263
+ const messages: AndroidMessagingStyleMessage[] = [];
264
+
265
+ try {
266
+ person = validateAndroidPerson(style.person);
267
+ } catch (e: any) {
268
+ throw new Error(`'notification.android.style' MessagingStyle: ${e.message}.`);
269
+ }
270
+
271
+ if (!isArray(style.messages)) {
272
+ throw new Error(
273
+ "'notification.android.style' MessagingStyle: 'messages' expected an array value.",
274
+ );
275
+ }
276
+
277
+ for (let i = 0; i < style.messages.length; i++) {
278
+ try {
279
+ messages.push(validateAndroidMessagingStyleMessage(style.messages[i]));
280
+ } catch (e: any) {
281
+ throw new Error(
282
+ `'notification.android.style' MessagingStyle: invalid message at index ${i}. ${e.message}`,
283
+ );
284
+ }
285
+ }
286
+
287
+ const out: AndroidMessagingStyle = {
288
+ type: AndroidStyle.MESSAGING,
289
+ person,
290
+ messages,
291
+ group: false,
292
+ };
293
+
294
+ if (objectHasProperty(style, 'title')) {
295
+ if (!isString(style.title)) {
296
+ throw new Error(
297
+ "'notification.android.style' MessagingStyle: 'title' expected a string value.",
298
+ );
299
+ }
300
+
301
+ out.title = style.title;
302
+ }
303
+
304
+ if (objectHasProperty(style, 'group')) {
305
+ if (!isBoolean(style.group)) {
306
+ throw new Error(
307
+ "'notification.android.style' MessagingStyle: 'group' expected a boolean value.",
308
+ );
309
+ }
310
+
311
+ out.group = style.group;
312
+ }
313
+
314
+ return out;
315
+ }
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited
3
+ */
4
+
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-ignore
7
+ import { Image } from 'react-native';
8
+
9
+ import {
10
+ generateId,
11
+ isBoolean,
12
+ isNumber,
13
+ isObject,
14
+ isString,
15
+ isUndefined,
16
+ objectHasProperty,
17
+ } from '../utils';
18
+ import {
19
+ IOSAttachmentThumbnailClippingRect,
20
+ IOSNotificationAttachment,
21
+ } from '../types/NotificationIOS';
22
+
23
+ export default function validateIOSAttachment(
24
+ attachment: IOSNotificationAttachment,
25
+ ): IOSNotificationAttachment {
26
+ if (!isObject(attachment)) {
27
+ throw new Error("'attachment' expected an object value.");
28
+ }
29
+
30
+ if (
31
+ (!isString(attachment.url) && !isNumber(attachment.url) && !isObject(attachment.url)) ||
32
+ (isString(attachment.url) && !attachment.url.length)
33
+ ) {
34
+ throw new Error(
35
+ "'attachment.url' expected a React Native ImageResource value or a valid string URL.",
36
+ );
37
+ }
38
+
39
+ const out: IOSNotificationAttachment = {
40
+ url: attachment.url,
41
+ thumbnailHidden: false,
42
+ };
43
+
44
+ if (isNumber(attachment.url) || isObject(attachment.url)) {
45
+ const image = Image.resolveAssetSource(attachment.url);
46
+ out.url = image.uri;
47
+ }
48
+
49
+ if (objectHasProperty(attachment, 'id') && !isUndefined(attachment.id)) {
50
+ if (!isString(attachment.id)) {
51
+ throw new Error("'attachment.id' expected a string value.");
52
+ }
53
+ out.id = attachment.id;
54
+ } else {
55
+ out.id = generateId();
56
+ }
57
+
58
+ if (objectHasProperty(attachment, 'typeHint') && !isUndefined(attachment.typeHint)) {
59
+ if (!isString(attachment.typeHint)) {
60
+ throw new Error("'attachment.typeHint' expected a string value.");
61
+ }
62
+
63
+ out.typeHint = attachment.typeHint;
64
+ }
65
+
66
+ if (
67
+ objectHasProperty(attachment, 'thumbnailClippingRect') &&
68
+ !isUndefined(attachment.thumbnailClippingRect)
69
+ ) {
70
+ try {
71
+ out.thumbnailClippingRect = validateThumbnailClippingRect(attachment.thumbnailClippingRect);
72
+ } catch (e: any) {
73
+ throw new Error(`'attachment.thumbnailClippingRect' is invalid. ${e.message}`);
74
+ }
75
+ }
76
+
77
+ if (
78
+ objectHasProperty(attachment, 'thumbnailHidden') &&
79
+ !isUndefined(attachment.thumbnailHidden)
80
+ ) {
81
+ if (!isBoolean(attachment.thumbnailHidden)) {
82
+ throw new Error("'attachment.thumbnailHidden' must be a boolean value if specified.");
83
+ }
84
+
85
+ out.thumbnailHidden = attachment.thumbnailHidden;
86
+ }
87
+
88
+ if (objectHasProperty(attachment, 'thumbnailTime') && !isUndefined(attachment.thumbnailTime)) {
89
+ if (!isNumber(attachment.thumbnailTime)) {
90
+ throw new Error("'attachment.thumbnailTime' must be a number value if specified.");
91
+ } else {
92
+ out.thumbnailTime = attachment.thumbnailTime;
93
+ }
94
+ }
95
+
96
+ return out;
97
+ }
98
+
99
+ /**
100
+ * Validates a ThumbnailClippingRect
101
+ */
102
+ export function validateThumbnailClippingRect(
103
+ thumbnailClippingRect: IOSAttachmentThumbnailClippingRect,
104
+ ): IOSAttachmentThumbnailClippingRect {
105
+ if (objectHasProperty(thumbnailClippingRect, 'x')) {
106
+ if (!isNumber(thumbnailClippingRect.x)) {
107
+ throw new Error("'thumbnailClippingRect.x' expected a number value.");
108
+ }
109
+ }
110
+
111
+ if (objectHasProperty(thumbnailClippingRect, 'y')) {
112
+ if (!isNumber(thumbnailClippingRect.y)) {
113
+ throw new Error("'thumbnailClippingRect.y' expected a number value.");
114
+ }
115
+ }
116
+
117
+ if (objectHasProperty(thumbnailClippingRect, 'width')) {
118
+ if (!isNumber(thumbnailClippingRect.width)) {
119
+ throw new Error("'thumbnailClippingRect.width' expected a number value.");
120
+ }
121
+ }
122
+
123
+ if (objectHasProperty(thumbnailClippingRect, 'height')) {
124
+ if (!isNumber(thumbnailClippingRect.height)) {
125
+ throw new Error("'thumbnailClippingRect.height' expected a number value.");
126
+ }
127
+ }
128
+
129
+ // Defaults
130
+ return {
131
+ x: thumbnailClippingRect.x,
132
+ y: thumbnailClippingRect.y,
133
+ height: thumbnailClippingRect.height,
134
+ width: thumbnailClippingRect.width,
135
+ };
136
+ }
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited
3
+ */
4
+ import {
5
+ IOSIntentIdentifier,
6
+ IOSNotificationCategory,
7
+ IOSNotificationCategoryAction,
8
+ } from '../types/NotificationIOS';
9
+ import { objectHasProperty, isArray, isObject, isString, isBoolean } from '../utils';
10
+ import validateIOSCategoryAction from './validateIOSCategoryAction';
11
+
12
+ export default function validateIOSCategory(
13
+ category: IOSNotificationCategory,
14
+ ): IOSNotificationCategory {
15
+ if (!isObject(category)) {
16
+ throw new Error("'category' expected an object value.");
17
+ }
18
+
19
+ /**
20
+ * id
21
+ */
22
+ if (!isString(category.id)) {
23
+ throw new Error("'category.id' expected a string value.");
24
+ }
25
+
26
+ // empty check
27
+ if (!category.id) {
28
+ throw new Error("'category.id' expected a valid string id.");
29
+ }
30
+
31
+ const out: IOSNotificationCategory = {
32
+ id: category.id,
33
+ allowInCarPlay: false,
34
+ allowAnnouncement: false,
35
+ hiddenPreviewsShowTitle: false,
36
+ hiddenPreviewsShowSubtitle: false,
37
+ };
38
+
39
+ /**
40
+ * summaryFormat
41
+ */
42
+ if (objectHasProperty(category, 'summaryFormat')) {
43
+ if (!isString(category.summaryFormat)) {
44
+ throw new Error("'category.summaryFormat' expected a string value.");
45
+ }
46
+
47
+ out.summaryFormat = category.summaryFormat;
48
+ }
49
+
50
+ /**
51
+ * allowInCarPlay
52
+ */
53
+ if (objectHasProperty(category, 'allowInCarPlay')) {
54
+ if (!isBoolean(category.allowInCarPlay)) {
55
+ throw new Error("'category.allowInCarPlay' expected a boolean value.");
56
+ }
57
+
58
+ out.allowInCarPlay = category.allowInCarPlay;
59
+ }
60
+
61
+ /**
62
+ * allowAnnouncement
63
+ */
64
+ if (objectHasProperty(category, 'allowAnnouncement')) {
65
+ if (!isBoolean(category.allowAnnouncement)) {
66
+ throw new Error("'category.allowAnnouncement' expected a boolean value.");
67
+ }
68
+
69
+ out.allowAnnouncement = category.allowAnnouncement;
70
+ }
71
+
72
+ /**
73
+ * hiddenPreviewsShowTitle
74
+ */
75
+ if (objectHasProperty(category, 'hiddenPreviewsShowTitle')) {
76
+ if (!isBoolean(category.hiddenPreviewsShowTitle)) {
77
+ throw new Error("'category.hiddenPreviewsShowTitle' expected a boolean value.");
78
+ }
79
+
80
+ out.hiddenPreviewsShowTitle = category.hiddenPreviewsShowTitle;
81
+ }
82
+
83
+ /**
84
+ * hiddenPreviewsShowSubtitle
85
+ */
86
+ if (objectHasProperty(category, 'hiddenPreviewsShowSubtitle')) {
87
+ if (!isBoolean(category.hiddenPreviewsShowSubtitle)) {
88
+ throw new Error("'category.hiddenPreviewsShowSubtitle' expected a boolean value.");
89
+ }
90
+
91
+ out.hiddenPreviewsShowSubtitle = category.hiddenPreviewsShowSubtitle;
92
+ }
93
+
94
+ /**
95
+ * summaryFormat
96
+ */
97
+ if (objectHasProperty(category, 'hiddenPreviewsBodyPlaceholder')) {
98
+ if (!isString(category.hiddenPreviewsBodyPlaceholder)) {
99
+ throw new Error("'category.hiddenPreviewsBodyPlaceholder' expected a string value.");
100
+ }
101
+
102
+ out.hiddenPreviewsBodyPlaceholder = category.hiddenPreviewsBodyPlaceholder;
103
+ }
104
+
105
+ /**
106
+ * intentIdentifiers
107
+ */
108
+ if (objectHasProperty(category, 'intentIdentifiers')) {
109
+ if (!isArray(category.intentIdentifiers)) {
110
+ throw new Error("'category.intentIdentifiers' expected an array value.");
111
+ }
112
+
113
+ const identifiers = Object.values(IOSIntentIdentifier);
114
+
115
+ for (let i = 0; i < category.intentIdentifiers.length; i++) {
116
+ const intentIdentifier = category.intentIdentifiers[i];
117
+
118
+ if (!identifiers.includes(intentIdentifier)) {
119
+ throw new Error(
120
+ `'category.intentIdentifiers' unexpected intentIdentifier "${intentIdentifier}" at array index "${i}".`,
121
+ );
122
+ }
123
+ }
124
+
125
+ out.intentIdentifiers = category.intentIdentifiers;
126
+ }
127
+
128
+ /**
129
+ * actions
130
+ */
131
+ if (objectHasProperty(category, 'actions')) {
132
+ if (!isArray(category.actions)) {
133
+ throw new Error("'category.actions' expected an array value.");
134
+ }
135
+
136
+ const actions: IOSNotificationCategoryAction[] = [];
137
+
138
+ for (let i = 0; i < category.actions.length; i++) {
139
+ try {
140
+ actions[i] = validateIOSCategoryAction(category.actions[i]);
141
+ } catch (e) {
142
+ throw new Error(`'category.actions' invalid action at index "${i}". ${e}`);
143
+ }
144
+ }
145
+
146
+ out.actions = actions;
147
+ }
148
+
149
+ return out;
150
+ }