UNPKG

@carboncollins/mobileconfig

Version:

Create and sign iOS mobileconfig configuration files

144 lines (115 loc) 6.48 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 airprint list * @author Steven Collins <steven@carboncollins.uk> * @param {apnDescriptior[]} value an array of apn objects * @returns {Object[]} an array of plist safe apn objects * @private */ function toSafeAPNList(value) { if (value === undefined || value === null || !Array.isArray(value)) { return null; } var apnList = []; for (var i = 0, iLength = value.length; i < iLength; i += 1) { apnList.push({ apn: (0, _safe.toSafeString)(value[i].apn), username: (0, _safe.toSafeString)(value[i].username), password: (0, _safe.toSafeData)(value[i].password), Proxy: (0, _safe.toSafeString)(value[i].proxy), ProxyPort: (0, _safe.toSafeInteger)(value[i].proxyPort) }); } return apnList.length === 0 ? null : apnList; } /** * @class APNPayload * @description Structured model data for the AirPlay payload. Deprecated in iOS 7 onwards. * @author CarbonCollins <toastyghost@carboncollins.uk> * @memberof module:@carboncollins/mobileconfig * @extends module:@carboncollins/mobileconfig.MobileConfigPayload * @deprecated */ var APNPayload = function (_MobileConfigPayload) { _inherits(APNPayload, _MobileConfigPayload); /** * @constructor * @description creates an instance of APNPayload * @param {Object|module:@carboncollins/mobileconfig.APNPayload} [options={}] An object of * options */ function APNPayload() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, APNPayload); /** * @member {Object} [defaultsData={}] * @memberof module:@carboncollins/mobileconfig.APNPayload * @description This dictionary contains two key/value pairs. */ var _this = _possibleConstructorReturn(this, (APNPayload.__proto__ || Object.getPrototypeOf(APNPayload)).call(this, Object.assign({}, options, { type: 'com.apple.apn.managed' }))); _this.defaultsData = options.defaultsData || {}; /** * @member {String} [defaultsDomainName=com.apple.managedCarrier] * @memberof module:@carboncollins/mobileconfig.APNPayload * @description The only allowed value is com.apple.managedCarrier. */ _this.defaultsDomainName = options.defaultsDomainName || 'com.apple.managedCarrier'; /** * @member {apnDescriptior[]} [apns=[]] * @memberof module:@carboncollins/mobileconfig.APNPayload * @description The only allowed value is com.apple.managedCarrier. */ _this.apns = options.apns || []; return _this; } /** * @description generates a plist safe js object with all the required information for generating * a mobileconfig profile * @readonly * @memberof module:@carboncollins/mobileconfig.APNPayload * @author CarbonCollins <toastyghost@carboncollins.uk> * @returns {Object} a plist object encoded into a js object */ _createClass(APNPayload, [{ key: 'plistSafeObject', get: function get() { var plistObj = { DefaultsData: Object.assign({}, this.defaultsData), DefaultsDomainName: (0, _safe.toSafeString)(this.defaultsDomainName), apns: toSafeAPNList(this.apns.slice(0)) }; return Object.assign({}, _get(APNPayload.prototype.__proto__ || Object.getPrototypeOf(APNPayload.prototype), 'plistSafeObject', this), plistObj); } }]); return APNPayload; }(_payload2.default); /** * @typedef {Object} apnDescriptior * @description an object containing the various apn infomration * * @property {String} apn This string specifies the Access Point Name. * * @property {String} username This string specifies the user name for this APN. If it is missing, * the device prompts for it during profile installation. * * @property {Buffer} [password] Optional. This data represents the password for the user for this * APN. For obfuscation purposes, the password is encoded. If it is missing from the payload, the * device prompts for the password during profile installation. * * @property {String} [proxy] Optional. The IP address or URL of the APN proxy. * * @property {Number} [proxyPort] Optional. The port number of the APN proxy. */ exports.default = APNPayload;