unifi-client
Version:
NodeJs client for Unifi products (https://www.ui.com/)
327 lines (326 loc) • 15.3 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Network = void 0;
var Validate_1 = require("../commons/Validate");
var Errors_1 = require("../Errors");
var util_1 = require("../util");
var commons_1 = require("../commons");
var debug = (0, util_1.createDebugger)('Network');
var Network = /** @class */ (function (_super) {
__extends(Network, _super);
function Network(config, props) {
var _this = _super.call(this, config) || this;
if (!props._id) {
throw new Errors_1.ClientError('_id is mandatory for a network.', Errors_1.EErrorsCodes.UNKNOWN_ERROR);
}
_this._id = props._id;
_this.debug = debug.extend(_this.name);
_this.import(props);
return _this;
}
Network.prototype.import = function (props) {
if (!Validate_1.Validate.isUndefined(props.name)) {
this.name = props.name;
}
if (!Validate_1.Validate.isUndefined(props.site_id)) {
this.site_id = props.site_id;
}
if (!Validate_1.Validate.isUndefined(props.purpose)) {
this.purpose = props.purpose;
}
if (!Validate_1.Validate.isUndefined(props.attr_hidden_id)) {
this.attr_hidden_id = props.attr_hidden_id;
}
if (!Validate_1.Validate.isUndefined(props.attr_no_delete)) {
this.attr_no_delete = props.attr_no_delete;
}
if (!Validate_1.Validate.isUndefined(props.setting_preference)) {
this.setting_preference = props.setting_preference;
}
if (!Validate_1.Validate.isUndefined(props.attr_hidden_id)) {
this.attr_hidden_id = props.attr_hidden_id;
}
if (!Validate_1.Validate.isUndefined(props.attr_no_delete)) {
this.attr_no_delete = props.attr_no_delete;
}
if (!Validate_1.Validate.isUndefined(props.mac_override_enabled)) {
this.mac_override_enabled = props.mac_override_enabled;
}
if (!Validate_1.Validate.isUndefined(props.wan_load_balance_type)) {
this.wan_load_balance_type = props.wan_load_balance_type;
}
if (!Validate_1.Validate.isUndefined(props.wan_dns1)) {
this.wan_dns1 = props.wan_dns1;
}
if (!Validate_1.Validate.isUndefined(props.wan_dns2)) {
this.wan_dns2 = props.wan_dns2;
}
if (!Validate_1.Validate.isUndefined(props.wan_networkgroup)) {
this.wan_networkgroup = props.wan_networkgroup;
}
if (!Validate_1.Validate.isUndefined(props.wan_type_v6)) {
this.wan_type_v6 = props.wan_type_v6;
}
if (!Validate_1.Validate.isUndefined(props.wan_provider_capabilities)) {
this.wan_provider_capabilities = props.wan_provider_capabilities;
}
if (!Validate_1.Validate.isUndefined(props.wan_smartq_enabled)) {
this.wan_smartq_enabled = props.wan_smartq_enabled;
}
if (!Validate_1.Validate.isUndefined(props.wan_dns_preference)) {
this.wan_dns_preference = props.wan_dns_preference;
}
if (!Validate_1.Validate.isUndefined(props.mac_override)) {
this.mac_override = props.mac_override;
}
if (!Validate_1.Validate.isUndefined(props.wan_load_balance_weight)) {
this.wan_load_balance_weight = props.wan_load_balance_weight;
}
if (!Validate_1.Validate.isUndefined(props.report_wan_event)) {
this.report_wan_event = props.report_wan_event;
}
if (!Validate_1.Validate.isUndefined(props.wan_type)) {
this.wan_type = props.wan_type;
}
if (!Validate_1.Validate.isUndefined(props.igmp_proxy_upstream)) {
this.igmp_proxy_upstream = props.igmp_proxy_upstream;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_leasetime)) {
this.dhcpd_leasetime = props.dhcpd_leasetime;
}
if (!Validate_1.Validate.isUndefined(props.igmp_snooping)) {
this.igmp_snooping = props.igmp_snooping;
}
if (!Validate_1.Validate.isUndefined(props.dhcpguard_enabled)) {
this.dhcpguard_enabled = props.dhcpguard_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_gateway_enabled)) {
this.dhcpd_gateway_enabled = props.dhcpd_gateway_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_time_offset_enabled)) {
this.dhcpd_time_offset_enabled = props.dhcpd_time_offset_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_dns_1)) {
this.dhcpd_dns_1 = props.dhcpd_dns_1;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_start)) {
this.dhcpd_start = props.dhcpd_start;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_unifi_controller)) {
this.dhcpd_unifi_controller = props.dhcpd_unifi_controller;
}
if (!Validate_1.Validate.isUndefined(props.ipv6_ra_enabled)) {
this.ipv6_ra_enabled = props.ipv6_ra_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_stop)) {
this.dhcpd_stop = props.dhcpd_stop;
}
if (!Validate_1.Validate.isUndefined(props.enabled)) {
this.enabled = props.enabled;
}
if (!Validate_1.Validate.isUndefined(props.domain_name)) {
this.domain_name = props.domain_name;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_enabled)) {
this.dhcpd_enabled = props.dhcpd_enabled;
}
if (!Validate_1.Validate.isUndefined(props.ip_subnet)) {
this.ip_subnet = props.ip_subnet;
}
if (!Validate_1.Validate.isUndefined(props.dhpcd_wpad_url)) {
this.dhpcd_wpad_url = props.dhpcd_wpad_url;
}
if (!Validate_1.Validate.isUndefined(props.ipv6_interface_type)) {
this.ipv6_interface_type = props.ipv6_interface_type;
}
if (!Validate_1.Validate.isUndefined(props.dhpcd_dns_2)) {
this.dhpcd_dns_2 = props.dhpcd_dns_2;
}
if (!Validate_1.Validate.isUndefined(props.networkgroup)) {
this.networkgroup = props.networkgroup;
}
if (!Validate_1.Validate.isUndefined(props.dhpcd_dns_3)) {
this.dhpcd_dns_3 = props.dhpcd_dns_3;
}
if (!Validate_1.Validate.isUndefined(props.vlan_enabled)) {
this.vlan_enabled = props.vlan_enabled;
}
if (!Validate_1.Validate.isUndefined(props.is_nat)) {
this.is_nat = props.is_nat;
}
if (!Validate_1.Validate.isUndefined(props.dhcpdv6_enabled)) {
this.dhcpdv6_enabled = props.dhcpdv6_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_dns_enabled)) {
this.dhcpd_dns_enabled = props.dhcpd_dns_enabled;
}
if (!Validate_1.Validate.isUndefined(props.gateway_type)) {
this.gateway_type = props.gateway_type;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_relay_enabled)) {
this.dhcpd_relay_enabled = props.dhcpd_relay_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_boot_enabled)) {
this.dhcpd_boot_enabled = props.dhcpd_boot_enabled;
}
if (!Validate_1.Validate.isUndefined(props.igmp_proxy_downstream)) {
this.igmp_proxy_downstream = props.igmp_proxy_downstream;
}
if (!Validate_1.Validate.isUndefined(props.upnp_lan_enabled)) {
this.upnp_lan_enabled = props.upnp_lan_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhcpd_ntp_enabled)) {
this.dhcpd_ntp_enabled = props.dhcpd_ntp_enabled;
}
if (!Validate_1.Validate.isUndefined(props.mdns_enabled)) {
this.mdns_enabled = props.mdns_enabled;
}
if (!Validate_1.Validate.isUndefined(props.lte_lan_enabled)) {
this.lte_lan_enabled = props.lte_lan_enabled;
}
if (!Validate_1.Validate.isUndefined(props.dhpcd_tftp_server)) {
this.dhpcd_tftp_server = props.dhpcd_tftp_server;
}
if (!Validate_1.Validate.isUndefined(props.auto_scale_enabled)) {
this.auto_scale_enabled = props.auto_scale_enabled;
}
if (!Validate_1.Validate.isUndefined(props.vlan)) {
this.vlan = props.vlan;
}
if (!Validate_1.Validate.isUndefined(props.l2tp_allow_weak_ciphers)) {
this.l2tp_allow_weak_ciphers = props.l2tp_allow_weak_ciphers;
}
if (!Validate_1.Validate.isUndefined(props.l2tp_local_wan_ip)) {
this.l2tp_local_wan_ip = props.l2tp_local_wan_ip;
}
if (!Validate_1.Validate.isUndefined(props.vpn_type)) {
this.vpn_type = props.vpn_type;
}
if (!Validate_1.Validate.isUndefined(props.radiusprofile_id)) {
this.radiusprofile_id = props.radiusprofile_id;
}
if (!Validate_1.Validate.isUndefined(props.dhpcd_wins_enabled)) {
this.dhpcd_wins_enabled = props.dhpcd_wins_enabled;
}
if (!Validate_1.Validate.isUndefined(props.require_mschapv2)) {
this.require_mschapv2 = props.require_mschapv2;
}
if (!Validate_1.Validate.isUndefined(props.l2tp_interface)) {
this.l2tp_interface = props.l2tp_interface;
}
if (!Validate_1.Validate.isUndefined(props.exposed_to_site_vpn)) {
this.exposed_to_site_vpn = props.exposed_to_site_vpn;
}
if (!Validate_1.Validate.isUndefined(props.x_ipsec_pre_shared_key)) {
this.x_ipsec_pre_shared_key = props.x_ipsec_pre_shared_key;
}
return this;
};
Network.prototype.update = function (props) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this._id) {
throw new Error('Cannot update network without _id');
}
return [4 /*yield*/, this.instance.put('/rest/networkconf/:id', props, {
urlParams: {
id: this._id
}
})];
case 1:
_a.sent();
this.import(props);
return [2 /*return*/];
}
});
});
};
Network.prototype.save = function () {
return __awaiter(this, void 0, void 0, function () {
var network;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this._id) {
throw new Error('Cannot save network without _id');
}
network = __assign({}, this);
return [4 /*yield*/, this.instance.put('/rest/networkconf/:id', network, {
urlParams: {
id: this._id
}
})];
case 1:
_a.sent();
return [2 /*return*/, this];
}
});
});
};
return Network;
}(commons_1._ObjectSubSite));
exports.Network = Network;