UNPKG

@carboncollins/mobileconfig

Version:

Create and sign iOS mobileconfig configuration files

232 lines (196 loc) 10.6 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _payload = require('./payload.js'); var _payload2 = _interopRequireDefault(_payload); var _safe = require('../safe.js'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * @description generates a plist safe dictionary * @author Steven Collins <steven@carboncollins.uk> * @param {Object} value an object of app lock options * @returns {Object[]} an array of plist safe app lock options object * @private */ function toSafeOptions() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (value === undefined || value === null || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== _typeof({}) || Object.keys(value) === 0) { return null; } var appObj = { DisableTouch: (0, _safe.toSafeBoolean)(value.disableTouch), DisableDeviceRotation: (0, _safe.toSafeBoolean)(value.disableDeviceRotation), DisableVolumeButtons: (0, _safe.toSafeBoolean)(value.disableVolumeButtons), DisableRingerSwitch: (0, _safe.toSafeBoolean)(value.disableRingerSwitch), DisableSleepWakeButton: (0, _safe.toSafeBoolean)(value.disableSleepWakeButton), DisableAutoLock: (0, _safe.toSafeBoolean)(value.disableAutoLock), EnableVoiceOver: (0, _safe.toSafeBoolean)(value.enableVoiceOver), EnableZoom: (0, _safe.toSafeBoolean)(value.enableZoom), EnableInvertColors: (0, _safe.toSafeBoolean)(value.enableInvertColors), EnableAssistiveTouch: (0, _safe.toSafeBoolean)(value.enableAssistiveTouch), EnableSpeakSelection: (0, _safe.toSafeBoolean)(value.enableSpeakSelection), EnableMonoAudio: (0, _safe.toSafeBoolean)(value.enableMonoAudio) }; return (0, _safe.deleteEmptyKeys)(appObj); } /** * @description generates a plist safe dictionary * @author Steven Collins <steven@carboncollins.uk> * @param {Object} value an object of app lock user enabed options * @returns {Object[]} an array of plist safe app lock user enabled options object * @private */ function toSafeUserEnabledOptions() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (value === undefined || value === null || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== _typeof({}) || Object.keys(value) === 0) { return null; } var appObj = { VoiceOver: (0, _safe.toSafeBoolean)(value.voiceOver), Zoom: (0, _safe.toSafeBoolean)(value.zoom), InvertColors: (0, _safe.toSafeBoolean)(value.invertColors), AssistiveTouch: (0, _safe.toSafeBoolean)(value.assistiveTouch) }; return (0, _safe.deleteEmptyKeys)(appObj); } /** * @description generates a plist safe dictionary * @author Steven Collins <steven@carboncollins.uk> * @param {Object} value an object of app lock settings * @returns {Object[]} an array of plist safe app lock object * @private */ function toSafeAppList() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (value === undefined || value === null || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== _typeof({}) || Object.keys(value) === 0) { return null; } var appObj = { Identifier: (0, _safe.toSafeString)(value.identifier || null), Options: toSafeOptions(value.options), UserEnabledOptions: toSafeUserEnabledOptions(this.userEnabledOptions) }; return (0, _safe.deleteEmptyKeys)(appObj); } /** * @class AppLockPayload * @description Structured model data for the AirPlay payload * @author CarbonCollins <toastyghost@carboncollins.uk> * @memberof module:@carboncollins/mobileconfig * @extends module:@carboncollins/mobileconfig.MobileConfigPayload */ var AppLockPayload = function (_MobileConfigPayload) { _inherits(AppLockPayload, _MobileConfigPayload); /** * @constructor * @description creates an instance of AppLockPayload * @param {Object|module:@carboncollins/mobileconfig.AppLockPayload} [options={}] An object of * options */ function AppLockPayload() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, AppLockPayload); /** * @member {AppDescriptor} [app={}] * @memberof module:@carboncollins/mobileconfig.AppLockPayload * @description An object containing information about the app. */ var _this = _possibleConstructorReturn(this, (AppLockPayload.__proto__ || Object.getPrototypeOf(AppLockPayload)).call(this, Object.assign({}, options, { type: 'com.apple.app.lock' }))); _this.app = options.app || {}; return _this; } /** * @description generates a plist safe js object with all the required information for generating * a mobileconfig profile * @readonly * @memberof module:@carboncollins/mobileconfig.AppLockPayload * @author CarbonCollins <toastyghost@carboncollins.uk> * @returns {Object} a plist object encoded into a js object */ _createClass(AppLockPayload, [{ key: 'plistSafeObject', get: function get() { var plistObj = { App: toSafeAppList(Object.assign({}, this.app)) }; return Object.assign({}, _get(AppLockPayload.prototype.__proto__ || Object.getPrototypeOf(AppLockPayload.prototype), 'plistSafeObject', this), plistObj); } }]); return AppLockPayload; }(_payload2.default); /** * @typedef {Object} AppDescriptor * @description an object containing the various app information and options * * @property {String} identifier The bundle identifier of the application. * * @property {AppOptionsDescriptor} options Optional. Availability: Available only in iOS 7.0 and * later. * * @property {UserEnabledOptionsDescriptor} userEnabledOptions Optional. Availability: Available * only in iOS 7.0 and later. */ /** * @typedef {Object} AppOptionsDescriptor * @description an object containing the various app options * * @property {Boolean} [disableTouch=false] Optional. If `true`, the touch screen is disabled. * Default is `false`. Available in tvOS 10.2 and later. * * @property {Boolean} [disableDeviceRotation=false] Optional. If `true`, device rotation * sensing is disabled. Default is `false`. * * @property {Boolean} [disableVolumeButtons=false] Optional. If `true`, the volume buttons * are disabled. Default to `false`. * * @property {Boolean} [disableRingerSwitch=false] Optional. If `true`, the ringer switch is * disabled. Default is `false`. When disabled, the ringer behavior depends on what position * the switch was in when it was first disabled. * * @property {Boolean} [disableSleepWakeButton=false] Optional. If `true`, the sleep/wake button is * disabled. Default is `false`. * * @property {Boolean} [disableAutoLock=false] Optional. If `true`, the device will not * automatically go to sleep after an idle period. Available in tvOS 10.2 and later. * * @property {Boolean} [enableVoiceOver=false] Optional. If `true`, VoiceOver is turned on. Default * is `false`. Available in tvOS 10.2 and later. * * @property {Boolean} [enableZoom=false] Optional. If `true`, Zoom is turned on. Default is * `false`. Available in tvOS 10.2 and later. * * @property {Boolean} [enableInvertColors=false] Optional. If `true`, Invert Colors is turned on. * Default is `false`. Available in tvOS 10.2 and later. * * @property {Boolean} [enableAssistiveTouch=false] Optional. If `true`, AssistiveTouch is turned * on. Default is `false`. * * @property {Boolean} [enableSpeakSelection=false] Optional. If `true`, Speak Selection is turned * on. Default is `false`. * * @property {Boolean} [enableMonoAudio=false] Optional. If `true`, Mono Audio is turned on. Default * is `false`. */ /** * @typedef {Object} UserEnabledOptionsDescriptor * @description an object containing the various user enabled options * * @property {Boolean} [voiceOver=false] Optional. If `true`, allow VoiceOver adjustment. Default * is `false`. * * @property {Boolean} [zoom=false] Optional. If `true`, allow Zoom adjustment. Default is `false`. * * @property {Boolean} [invertColors=false] Optional. If `true`, allow Invert Colors adjustment. * Default is `false`. * * @property {Boolean} [assistiveTouch=false] Optional. If `true`, allow AssistiveTouch adjustment. * Default is `false`. */ exports.default = AppLockPayload;