eppface
Version:
epp api
208 lines (196 loc) • 8.02 kB
JavaScript
'use strict';
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; }; })();
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
var Admin = require('./admin.js');
var Users = require('./users.js');
var eppAPI = (function () {
function eppAPI(gate, cookie) {
_classCallCheck(this, eppAPI);
this.gate = gate;
this.cookie = cookie;
}
_createClass(eppAPI, [{
key: 'login',
value: function login(Username, Password, cb) {
var users = new Users(this.gate, this.cookie);
users.login(Username, Password, cb);
}
}, {
key: 'passwd',
value: function passwd(newPW, cb) {
if (typeof newPW === 'function') {
newPW('1000', this.cookie.pass);
} else if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users.passwd(newPW, cb);
} else cb('2501');
}
}, {
key: 'check',
value: function check(obj, name, cb) {
if (this.cookie) {
var users = new Users(this.gate, this.cookie);
users.check(obj, name, function (data, code) {
return cb(code, data);
});
} else cb('2501');
}
}, {
key: 'info',
value: function info(obj, name, cb) {
if (this.cookie) {
var users = new Users(this.gate, this.cookie);
users.info(obj, name, function (data, code) {
return cb(code, data);
});
} else cb('2501');
}
}, {
key: 'delete',
value: function _delete(obj, name, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users.delete(obj, name, function (data, code) {
return cb(code, data);
});
} else cb('2501');
}
}, {
key: 'renew',
value: function renew(name, y, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users.renew(name, y, function (data, code) {
return cb(code, data);
});
} else cb('2501');
}
}, {
key: 'autorenew',
value: function autorenew(params, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users.autorenew(params.id, params.ack, cb);
} else cb('2501');
}
}, {
key: 'transfer',
value: function transfer(op, id, cb) {
if (this.cookie) {
switch (this.cookie.kind) {
case 'admin':
var admin = new Admin(this.gate);
var func = admin['server_' + op];
if (!func) break;
func(id, cb);
return;
case 'user':
var users = new Users(this.gate, this.cookie);
var func = users['transfer_' + op];
if (!func) break;
func(id, function (data, code) {
return cb(code, data);
});
return;
}
}
cb('2501');
}
}, {
key: 'create',
value: function create(obj, params, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users['create_' + obj](params, function (data, code) {
return cb(code, data);
});
} else cb('2501');
}
}, {
key: 'update',
value: function update(obj, params, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users['update_' + obj](params, function (data, code) {
return cb(code, data);
});
} else cb('2501');
}
}, {
key: 'restore',
value: function restore(params, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
(typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object' ? users.restore_report(params, function (data, code) {
return cb(code, data);
}) : users.restore_request(params, function (data, code) {
return cb(code, data);
});
} else cb('2501');
}
}, {
key: 'show',
value: function show(obj, name, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users['show_' + obj](name, cb);
} else cb('2501');
}
}, {
key: 'list',
value: function list(obj, posts) {
var page = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2];
var where = arguments[3];
var cb = arguments[4];
if (typeof where === 'function') {
cb = where;
where = {};
}
var transfer = ({
transferDomain: { obj: 'domain' },
transferContact: { obj: 'contact' },
transferInDomain: { obj: 'domain', io: 'in' },
transferInContact: { obj: 'contact', io: 'in' },
transferOutDomain: { obj: 'domain', io: 'out' },
transferOutContact: { obj: 'contact', io: 'out' }
})[obj];
if (transfer) obj = 'transfer';
if (this.cookie) {
switch (this.cookie.kind) {
case 'admin':
var admin = new Admin(this.gate, posts);
var func = admin['list_' + obj];
if (!func) break;
func(page, cb, transfer || where);
return;
case 'user':
var users = new Users(this.gate, this.cookie, posts);
var func = users['list_' + obj];
if (!func) break;
func(page, cb, transfer || where);
return;
}
}
cb('2501');
}
}, {
key: 'pdns',
value: function pdns(action, domain, record, cb) {
if (this.cookie && this.cookie.kind === 'user') {
var users = new Users(this.gate, this.cookie);
users.pdns_records(action, domain, record, cb);
} else cb('2501');
}
}, {
key: 'logout',
value: function logout(cb) {
cb('1500');
}
}]);
return eppAPI;
})();
exports.default = eppAPI;