merge l0nestar's updates
This commit is contained in:
commit
d93093fe00
47
lib/index.js
47
lib/index.js
|
@ -11,7 +11,7 @@ const PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
|
||||||
|
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
baseUrl: PRODUCTION_URL
|
baseUrl: SANDBOX_URL
|
||||||
};
|
};
|
||||||
|
|
||||||
function extend(obj) {
|
function extend(obj) {
|
||||||
|
@ -53,7 +53,9 @@ module.exports.create = function (config) {
|
||||||
assign(requestParams,params);
|
assign(requestParams,params);
|
||||||
|
|
||||||
var url = requestUrl(baseUrl, requestParams);
|
var url = requestUrl(baseUrl, requestParams);
|
||||||
// console.log(url);
|
console.log('DEBUG >>> url: ' + url);
|
||||||
|
console.log('DEBUG >>> requestParams: ' + JSON.stringify(requestParams, null, 2));
|
||||||
|
|
||||||
return request({
|
return request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -64,7 +66,7 @@ module.exports.create = function (config) {
|
||||||
// check response status
|
// check response status
|
||||||
if (result['ApiResponse']['$']['Status'] === 'ERROR') {
|
if (result['ApiResponse']['$']['Status'] === 'ERROR') {
|
||||||
for (let i = 0; i < result['ApiResponse']['Errors'].length; i++) {
|
for (let i = 0; i < result['ApiResponse']['Errors'].length; i++) {
|
||||||
console.log(result['ApiResponse']['Errors'][i])
|
console.log('DEBUG >>> error: ' + JSON.stringify(result['ApiResponse']['Errors'][i]['Error'][0], null, 2));
|
||||||
}
|
}
|
||||||
throw new Error('API Error');
|
throw new Error('API Error');
|
||||||
} else { // Status="OK"
|
} else { // Status="OK"
|
||||||
|
@ -92,15 +94,29 @@ module.exports.create = function (config) {
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function (data) {
|
set: function (data) {
|
||||||
|
console.log(`DEBUG >>> data: ${JSON.stringify(data, null, 2)}`);
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
var txt = ch.dnsAuthorization;
|
var txt = ch.dnsAuthorization;
|
||||||
|
|
||||||
var params = {};
|
var params = {};
|
||||||
var zone = ch.dnsZone;
|
// var zone = ch.dnsZone;
|
||||||
|
var zone = ch.identifier.value;
|
||||||
|
console.log(`DEBUG >>> zone: ${zone}`);
|
||||||
|
|
||||||
// the domain is the first part
|
// the domain is the first part
|
||||||
params['SLD'] = zone.split('.')[0];
|
// params['SLD'] = zone.split('.')[0];
|
||||||
// the rest of the components are the TLD
|
// the rest of the components are the TLD
|
||||||
params['TLD'] = zone.split('.').splice(1).join('.');
|
// params['TLD'] = zone.split('.').splice(1).join('.');
|
||||||
|
|
||||||
|
var domains = zone.split('.');
|
||||||
|
console.log('DEBUG >>> ' + domains);
|
||||||
|
|
||||||
|
// if you have subdomain foo.blah.com, SLD = blah and TLD = com
|
||||||
|
params['TLD'] = domains[domains.length - 1];
|
||||||
|
params['SLD'] = domains[domains.length - 2];
|
||||||
|
|
||||||
|
console.log(`DEBUG >>> SLD: ${params['SLD']}`);
|
||||||
|
console.log(`DEBUG >>> TLD: ${params['TLD']}`);
|
||||||
|
|
||||||
// setting a host record overwrites all existing,
|
// setting a host record overwrites all existing,
|
||||||
// adding a new records means you've have to send back all previous records too
|
// adding a new records means you've have to send back all previous records too
|
||||||
|
@ -139,11 +155,11 @@ module.exports.create = function (config) {
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
|
|
||||||
var params = {};
|
var params = {};
|
||||||
var zone = ch.dnsZone;
|
var zone = ch.identifier.value;
|
||||||
// the domain is the first part
|
var domains = zone.split('.');
|
||||||
params['SLD'] = zone.split('.')[0];
|
|
||||||
// the rest of the components are the TLD
|
params['TLD'] = domains[domains.length - 1];
|
||||||
params['TLD'] = zone.split('.').splice(1).join('.');
|
params['SLD'] = domains[domains.length - 2];
|
||||||
|
|
||||||
// setting a host record overwrites all existing,
|
// setting a host record overwrites all existing,
|
||||||
// removing a new records means you've have to send back all previous records without removed
|
// removing a new records means you've have to send back all previous records without removed
|
||||||
|
@ -176,12 +192,11 @@ module.exports.create = function (config) {
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
|
|
||||||
var params = {};
|
var params = {};
|
||||||
var zone = ch.dnsZone;
|
var zone = ch.identifier.value;
|
||||||
|
var domains = zone.split('.');
|
||||||
|
|
||||||
// the domain is the first part
|
params['TLD'] = domains[domains.length - 1];
|
||||||
params['SLD'] = zone.split('.')[0];
|
params['SLD'] = domains[domains.length - 2];
|
||||||
// the rest of the components are the TLD
|
|
||||||
params['TLD'] = zone.split('.').splice(1).join('.');
|
|
||||||
|
|
||||||
return api('namecheap.domains.dns.getHosts',params).then(function (hostsResponse) {
|
return api('namecheap.domains.dns.getHosts',params).then(function (hostsResponse) {
|
||||||
// console.log('hosts');
|
// console.log('hosts');
|
||||||
|
|
Loading…
Reference in New Issue