bug fixes

This commit is contained in:
Hitesh 2019-07-22 22:45:32 -07:00
parent 0aa6f28f85
commit 9071b0c048
2 changed files with 32 additions and 17 deletions

View File

@ -11,7 +11,7 @@ const PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
var defaults = {
baseUrl: PRODUCTION_URL
baseUrl: SANDBOX_URL
};
function extend(obj) {
@ -53,7 +53,9 @@ module.exports.create = function (config) {
assign(requestParams,params);
var url = requestUrl(baseUrl, requestParams);
// console.log(url);
console.log('DEBUG >>> url: ' + url);
console.log('DEBUG >>> requestParams: ' + JSON.stringify(requestParams, null, 2));
return request({
method: 'POST',
url: url,
@ -64,7 +66,7 @@ module.exports.create = function (config) {
// check response status
if (result['ApiResponse']['$']['Status'] === 'ERROR') {
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');
} else { // Status="OK"
@ -92,15 +94,29 @@ module.exports.create = function (config) {
},
set: function (data) {
console.log(`DEBUG >>> data: ${JSON.stringify(data, null, 2)}`);
var ch = data.challenge;
var txt = ch.dnsAuthorization;
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
params['SLD'] = zone.split('.')[0];
// params['SLD'] = zone.split('.')[0];
// 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,
// 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 params = {};
var zone = ch.dnsZone;
// the domain is the first part
params['SLD'] = zone.split('.')[0];
// the rest of the components are the TLD
params['TLD'] = zone.split('.').splice(1).join('.');
var zone = ch.identifier.value;
var domains = zone.split('.');
params['TLD'] = domains[domains.length - 1];
params['SLD'] = domains[domains.length - 2];
// setting a host record overwrites all existing,
// 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 params = {};
var zone = ch.dnsZone;
var zone = ch.identifier.value;
var domains = zone.split('.');
// the domain is the first part
params['SLD'] = zone.split('.')[0];
// the rest of the components are the TLD
params['TLD'] = zone.split('.').splice(1).join('.');
params['TLD'] = domains[domains.length - 1];
params['SLD'] = domains[domains.length - 2];
return api('namecheap.domains.dns.getHosts',params).then(function (hostsResponse) {
// console.log('hosts');

View File

@ -11,7 +11,7 @@ var challenger = require('./index.js').create({
apiUser:process.argv[3],
apiKey : process.argv[4],
clientIp:process.argv[5],
username: process.argv[6]||process.argv[3]
username: process.argv[6] || process.argv[3]
});