@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.
- package/.gitattributes +3 -0
- package/LICENSE +44 -0
- package/README.md +131 -0
- package/RNNotifee.podspec +39 -0
- package/RNNotifeeCore.podspec +33 -0
- package/android/build.gradle +116 -0
- package/android/gradle.properties +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +9 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml +13 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.md5 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +1 -0
- package/android/lint.xml +5 -0
- package/android/proguard-rules.pro +74 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +349 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
- package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +244 -0
- package/app.plugin.js +1 -0
- package/dist/NotifeeApiModule.d.ts +53 -0
- package/dist/NotifeeApiModule.js +607 -0
- package/dist/NotifeeApiModule.js.map +1 -0
- package/dist/NotifeeJSEventEmitter.d.ts +3 -0
- package/dist/NotifeeJSEventEmitter.js +14 -0
- package/dist/NotifeeJSEventEmitter.js.map +1 -0
- package/dist/NotifeeNativeError.d.ts +15 -0
- package/dist/NotifeeNativeError.js +61 -0
- package/dist/NotifeeNativeError.js.map +1 -0
- package/dist/NotifeeNativeModule.d.ts +14 -0
- package/dist/NotifeeNativeModule.js +43 -0
- package/dist/NotifeeNativeModule.js.map +1 -0
- package/dist/NotifeeNativeModule.web.d.ts +12 -0
- package/dist/NotifeeNativeModule.web.js +19 -0
- package/dist/NotifeeNativeModule.web.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Library.d.ts +21 -0
- package/dist/types/Library.js +6 -0
- package/dist/types/Library.js.map +1 -0
- package/dist/types/Module.d.ts +572 -0
- package/dist/types/Module.js +6 -0
- package/dist/types/Module.js.map +1 -0
- package/dist/types/Notification.d.ts +450 -0
- package/dist/types/Notification.js +105 -0
- package/dist/types/Notification.js.map +1 -0
- package/dist/types/NotificationAndroid.d.ts +1276 -0
- package/dist/types/NotificationAndroid.js +380 -0
- package/dist/types/NotificationAndroid.js.map +1 -0
- package/dist/types/NotificationIOS.d.ts +537 -0
- package/dist/types/NotificationIOS.js +92 -0
- package/dist/types/NotificationIOS.js.map +1 -0
- package/dist/types/NotificationWeb.d.ts +5 -0
- package/dist/types/NotificationWeb.js +3 -0
- package/dist/types/NotificationWeb.js.map +1 -0
- package/dist/types/PowerManagerInfo.d.ts +36 -0
- package/dist/types/PowerManagerInfo.js +6 -0
- package/dist/types/PowerManagerInfo.js.map +1 -0
- package/dist/types/Trigger.d.ts +108 -0
- package/dist/types/Trigger.js +39 -0
- package/dist/types/Trigger.js.map +1 -0
- package/dist/utils/id.d.ts +1 -0
- package/dist/utils/id.js +16 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/index.js +52 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/validate.d.ts +15 -0
- package/dist/utils/validate.js +93 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +39 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
- package/dist/validators/validate.d.ts +25 -0
- package/dist/validators/validate.js +75 -0
- package/dist/validators/validate.js.map +1 -0
- package/dist/validators/validateAndroidAction.d.ts +2 -0
- package/dist/validators/validateAndroidAction.js +52 -0
- package/dist/validators/validateAndroidAction.js.map +1 -0
- package/dist/validators/validateAndroidChannel.d.ts +2 -0
- package/dist/validators/validateAndroidChannel.js +155 -0
- package/dist/validators/validateAndroidChannel.js.map +1 -0
- package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
- package/dist/validators/validateAndroidChannelGroup.js +42 -0
- package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
- package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
- package/dist/validators/validateAndroidFullScreenAction.js +50 -0
- package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
- package/dist/validators/validateAndroidInput.d.ts +2 -0
- package/dist/validators/validateAndroidInput.js +54 -0
- package/dist/validators/validateAndroidInput.js.map +1 -0
- package/dist/validators/validateAndroidNotification.d.ts +2 -0
- package/dist/validators/validateAndroidNotification.js +529 -0
- package/dist/validators/validateAndroidNotification.js.map +1 -0
- package/dist/validators/validateAndroidPressAction.d.ts +2 -0
- package/dist/validators/validateAndroidPressAction.js +50 -0
- package/dist/validators/validateAndroidPressAction.js.map +1 -0
- package/dist/validators/validateAndroidStyle.d.ts +22 -0
- package/dist/validators/validateAndroidStyle.js +231 -0
- package/dist/validators/validateAndroidStyle.js.map +1 -0
- package/dist/validators/validateIOSAttachment.d.ts +6 -0
- package/dist/validators/validateIOSAttachment.js +102 -0
- package/dist/validators/validateIOSAttachment.js.map +1 -0
- package/dist/validators/validateIOSCategory.d.ts +2 -0
- package/dist/validators/validateIOSCategory.js +124 -0
- package/dist/validators/validateIOSCategory.js.map +1 -0
- package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
- package/dist/validators/validateIOSCategoryAction.js +59 -0
- package/dist/validators/validateIOSCategoryAction.js.map +1 -0
- package/dist/validators/validateIOSInput.d.ts +2 -0
- package/dist/validators/validateIOSInput.js +32 -0
- package/dist/validators/validateIOSInput.js.map +1 -0
- package/dist/validators/validateIOSNotification.d.ts +2 -0
- package/dist/validators/validateIOSNotification.js +211 -0
- package/dist/validators/validateIOSNotification.js.map +1 -0
- package/dist/validators/validateIOSPermissions.d.ts +2 -0
- package/dist/validators/validateIOSPermissions.js +62 -0
- package/dist/validators/validateIOSPermissions.js.map +1 -0
- package/dist/validators/validateNotification.d.ts +11 -0
- package/dist/validators/validateNotification.js +129 -0
- package/dist/validators/validateNotification.js.map +1 -0
- package/dist/validators/validateTrigger.d.ts +2 -0
- package/dist/validators/validateTrigger.js +104 -0
- package/dist/validators/validateTrigger.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js.map +1 -0
- package/ios/NotifeeCore/Info.plist +22 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +72 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +37 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +242 -0
- package/ios/NotifeeCore/NotifeeCore.h +118 -0
- package/ios/NotifeeCore/NotifeeCore.m +784 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.h +82 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.m +793 -0
- package/ios/RNNotifee/NotifeeApiModule.h +25 -0
- package/ios/RNNotifee/NotifeeApiModule.m +371 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
- package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
- package/jest-mock.js +158 -0
- package/package.json +59 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.d.ts +5 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.js +24 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.js.map +1 -0
- package/plugin/src/index.ts +9 -0
- package/plugin/src/withNotifeeProjectGradlePlugin.ts +27 -0
- package/plugin/tsconfig.json +9 -0
- package/react-native.config.js +11 -0
- package/refresh-example.sh +71 -0
- package/src/NotifeeApiModule.ts +825 -0
- package/src/NotifeeJSEventEmitter.ts +11 -0
- package/src/NotifeeNativeError.ts +70 -0
- package/src/NotifeeNativeModule.ts +55 -0
- package/src/NotifeeNativeModule.web.ts +25 -0
- package/src/index.ts +33 -0
- package/src/types/Library.ts +28 -0
- package/src/types/Module.ts +625 -0
- package/src/types/Notification.ts +505 -0
- package/src/types/NotificationAndroid.ts +1443 -0
- package/src/types/NotificationIOS.ts +681 -0
- package/src/types/NotificationWeb.ts +5 -0
- package/src/types/PowerManagerInfo.ts +43 -0
- package/src/types/Trigger.ts +118 -0
- package/src/utils/id.ts +13 -0
- package/src/utils/index.ts +47 -0
- package/src/utils/validate.ts +92 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +45 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
- package/src/validators/validate.ts +85 -0
- package/src/validators/validateAndroidAction.ts +54 -0
- package/src/validators/validateAndroidChannel.ts +188 -0
- package/src/validators/validateAndroidChannelGroup.ts +49 -0
- package/src/validators/validateAndroidFullScreenAction.ts +65 -0
- package/src/validators/validateAndroidInput.ts +67 -0
- package/src/validators/validateAndroidNotification.ts +704 -0
- package/src/validators/validateAndroidPressAction.ts +65 -0
- package/src/validators/validateAndroidStyle.ts +315 -0
- package/src/validators/validateIOSAttachment.ts +136 -0
- package/src/validators/validateIOSCategory.ts +150 -0
- package/src/validators/validateIOSCategoryAction.ts +65 -0
- package/src/validators/validateIOSInput.ts +38 -0
- package/src/validators/validateIOSNotification.ts +296 -0
- package/src/validators/validateIOSPermissions.ts +78 -0
- package/src/validators/validateNotification.ts +156 -0
- package/src/validators/validateTrigger.ts +134 -0
- package/src/version.ts +2 -0
- 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
|
+
}
|