UNPKG

@notifee/react-native

Version:

Notifee - a feature rich notifications library for React Native.

173 lines 6.41 kB
"use strict"; /* * Copyright (c) 2016-present Invertase Limited */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils"); const validateIOSAttachment_1 = __importDefault(require("./validateIOSAttachment")); function validateIOSNotification(ios) { const out = { foregroundPresentationOptions: { alert: true, badge: true, sound: true, }, }; if (utils_1.isUndefined(ios)) { return out; } /* Skip validating if Android in release */ if (utils_1.isAndroid && !__DEV__) return out; /** * attachments */ if (utils_1.objectHasProperty(ios, 'attachments')) { if (!utils_1.isArray(ios.attachments)) { throw new Error("'notification.ios.attachments' expected an array value."); } const attachments = []; for (let i = 0; i < ios.attachments.length; i++) { try { attachments.push(validateIOSAttachment_1.default(ios.attachments[i])); } catch (e) { throw new Error(`'notification.ios.attachments' invalid IOSNotificationAttachment. ${e.message}.`); } } if (attachments.length) { out.attachments = attachments; } } /** * critical */ if (utils_1.objectHasProperty(ios, 'critical')) { if (!utils_1.isBoolean(ios.critical)) { throw new Error("'notification.ios.critical' must be a boolean value if specified."); } else { out.critical = ios.critical; } } /** * criticalVolume */ if (utils_1.objectHasProperty(ios, 'criticalVolume')) { if (!utils_1.isNumber(ios.criticalVolume)) { throw new Error("'notification.ios.criticalVolume' must be a number value if specified."); } else { if (ios.criticalVolume < 0 || ios.criticalVolume > 1) { throw new Error("'notification.ios.criticalVolume' must be a float value between 0.0 and 1.0."); } out.criticalVolume = ios.criticalVolume; } } /** * sound */ if (utils_1.objectHasProperty(ios, 'sound')) { if (utils_1.isString(ios.sound)) { out.sound = ios.sound; } else { throw new Error("'notification.sound' must be a string value if specified."); } } /** * badgeCount */ if (utils_1.objectHasProperty(ios, 'badgeCount')) { if (!utils_1.isNumber(ios.badgeCount) || ios.badgeCount < 0) { throw new Error("'notification.ios.badgeCount' expected a number value >=0."); } out.badgeCount = ios.badgeCount; } /** * categoryId */ if (utils_1.objectHasProperty(ios, 'categoryId')) { if (!utils_1.isString(ios.categoryId)) { throw new Error("'notification.ios.categoryId' expected a of string value"); } out.categoryId = ios.categoryId; } /** * groupId */ if (utils_1.objectHasProperty(ios, 'threadId')) { if (!utils_1.isString(ios.threadId)) { throw new Error("'notification.ios.threadId' expected a string value."); } out.threadId = ios.threadId; } /** * summaryArgument */ if (utils_1.objectHasProperty(ios, 'summaryArgument')) { if (!utils_1.isString(ios.summaryArgument)) { throw new Error("'notification.ios.summaryArgument' expected a string value."); } out.summaryArgument = ios.summaryArgument; } /** * summaryArgumentCount */ if (utils_1.objectHasProperty(ios, 'summaryArgumentCount')) { if (!utils_1.isNumber(ios.summaryArgumentCount) || ios.summaryArgumentCount <= 0) { throw new Error("'notification.ios.summaryArgumentCount' expected a positive number greater than 0."); } out.summaryArgumentCount = ios.summaryArgumentCount; } /** * launchImageName */ if (utils_1.objectHasProperty(ios, 'launchImageName')) { if (!utils_1.isString(ios.launchImageName)) { throw new Error("'notification.ios.launchImageName' expected a string value."); } out.launchImageName = ios.launchImageName; } /** * sound */ if (utils_1.objectHasProperty(ios, 'sound')) { if (!utils_1.isString(ios.sound)) { throw new Error("'notification.ios.sound' expected a string value."); } out.sound = ios.sound; } /** * ForegroundPresentationOptions */ if (utils_1.objectHasProperty(ios, 'foregroundPresentationOptions')) { if (!utils_1.isObject(ios.foregroundPresentationOptions)) { throw new Error("'notification.ios.foregroundPresentationOptions' expected a valid IOSForegroundPresentationOptions object."); } if (utils_1.objectHasProperty(ios.foregroundPresentationOptions, 'alert')) { if (!utils_1.isBoolean(ios.foregroundPresentationOptions.alert)) { throw new Error("'notification.ios.foregroundPresentationOptions.alert' expected a boolean value."); } out.foregroundPresentationOptions.alert = ios.foregroundPresentationOptions.alert; } if (utils_1.objectHasProperty(ios.foregroundPresentationOptions, 'sound')) { if (!utils_1.isBoolean(ios.foregroundPresentationOptions.sound)) { throw new Error("'notification.ios.foregroundPresentationOptions.sound' expected a boolean value."); } out.foregroundPresentationOptions.sound = ios.foregroundPresentationOptions.sound; } if (utils_1.objectHasProperty(ios.foregroundPresentationOptions, 'badge')) { if (!utils_1.isBoolean(ios.foregroundPresentationOptions.badge)) { throw new Error("'notification.ios.foregroundPresentationOptions.badge' expected a boolean value."); } out.foregroundPresentationOptions.badge = ios.foregroundPresentationOptions.badge; } } return out; } exports.default = validateIOSNotification; //# sourceMappingURL=validateIOSNotification.js.map