UNPKG

@carboncollins/mobileconfig

Version:

Create and sign iOS mobileconfig configuration files

143 lines (112 loc) 6.41 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 _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 whitelist list * @author Steven Collins <steven@carboncollins.uk> * @param {Object[]} value an array of whitelist objects * @returns {Object[]} an array of plist safe whitelist objects * @private */ function toSafeWhitelist(value) { if (value === undefined || value === null || !Array.isArray(value)) { return null; } var whitelist = []; for (var i = 0, iLength = value.length; i < iLength; i += 1) { var deviceId = (0, _safe.toSafeString)(value[i].deviceId); if (deviceId !== null) { whitelist.push({ DeviceID: deviceId }); } } return whitelist.length === 0 ? null : whitelist; } /** * @description generates a plist safe password list * @author Steven Collins <steven@carboncollins.uk> * @param {Object[]} value an arrray of airplay password objects * @returns {Object[]} an array of airplay password objects * @private */ function toSafePasswords(value) { if (value === undefined || value === null || !Array.isArray(value)) { return null; } var passwords = []; for (var i = 0, iLength = value.length; i < iLength; i += 1) { var deviceName = (0, _safe.toSafeString)(value[i].deviceName); var deviceId = (0, _safe.toSafeString)(value[i].deviceId); var password = (0, _safe.toSafeString)(value[i].password); if (deviceName !== null && deviceId !== null && password !== null) { passwords.push({ DeviceName: deviceName, DeviceID: deviceId, Password: password }); } } return passwords.length === 0 ? null : passwords; } /** * @class AirPlayPayload * @description Structured model data for the AirPlay payload * @author CarbonCollins <toastyghost@carboncollins.uk> * @memberof module:@carboncollins/mobileconfig * @extends module:@carboncollins/mobileconfig.MobileConfigPayload */ var AirPlayPayload = function (_MobileConfigPayload) { _inherits(AirPlayPayload, _MobileConfigPayload); /** * @constructor * @description creates an instance of AirPlayPayload * @param {Object|module:@carboncollins/mobileconfig.AirPlayPayload} [options={}] An object of * options */ function AirPlayPayload() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, AirPlayPayload); /** * @member {String[]} [whitelist=[]] * @memberof module:@carboncollins/mobileconfig.AirPlayPayload * @description Supervised only (ignored otherwise). If present, only AirPlay destinations * present in this list are available to the device. The dictionary format is described below. */ var _this = _possibleConstructorReturn(this, (AirPlayPayload.__proto__ || Object.getPrototypeOf(AirPlayPayload)).call(this, Object.assign({}, options, { type: 'com.apple.airplay' }))); _this.whitelist = options.whitelist || []; // array of strings, each being an airplay id /** * @member {String[]} [passwords=[]] * @memberof module:@carboncollins/mobileconfig.AirPlayPayload * @description If present, sets passwords for known AirPlay destinations. The dictionary * format is described below. */ _this.passwords = options.passwords || []; // array of objects in the following format: // { deviceName: '', deviceId: '', password: '' } return _this; } /** * @description generates a plist safe js object with all the required information for generating * a mobileconfig profile * @readonly * @memberof module:@carboncollins/mobileconfig.AirPlayPayload * @author CarbonCollins <toastyghost@carboncollins.uk> * @returns {Object} a plist object encoded into a js object */ _createClass(AirPlayPayload, [{ key: 'plistSafeObject', get: function get() { var plistObj = { Whitelist: toSafeWhitelist(this.whitelist.slice(0)), Passwords: toSafePasswords(this.passwords.slice(0)) }; return Object.assign({}, _get(AirPlayPayload.prototype.__proto__ || Object.getPrototypeOf(AirPlayPayload.prototype), 'plistSafeObject', this), plistObj); } }]); return AirPlayPayload; }(_payload2.default); exports.default = AirPlayPayload;