netcup-node
Version:
A node wrapper for the Netcup CCP API (https://www.netcup-wiki.de/wiki/CCP_API)
66 lines (65 loc) • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultResponseHandler = void 0;
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const Actions_1 = require("./@types/Actions");
const Formats_1 = require("./@types/Formats");
const utils_1 = require("./utils");
function defaultResponseHandler(response) {
if (response.data && response.data.statuscode !== 2000) {
throw new Error(response.data.longmessage);
}
return response;
}
exports.defaultResponseHandler = defaultResponseHandler;
class NetcupRestApi {
axios = axios_1.default.create();
format = Formats_1.Formats.JSON;
constructor(format) {
if (format) {
this.format = format;
}
this.axios.interceptors.response.use(defaultResponseHandler);
}
async postJson(url, data, options) {
const res = await this.axios.post(url, data, {
...options,
responseType: 'json',
});
return res.data;
}
login(params) {
return this.postJson((0, utils_1.getFormattedUrl)(this.format), {
action: Actions_1.Actions.login,
param: {
...params,
},
});
}
infoDnsZone(params) {
return this.postJson((0, utils_1.getFormattedUrl)(this.format), {
action: Actions_1.Actions.infoDnsZone,
param: {
...params,
},
});
}
infoDnsRecords(params) {
return this.postJson((0, utils_1.getFormattedUrl)(this.format), {
action: Actions_1.Actions.infoDnsRecords,
param: {
...params,
},
});
}
updateDnsRecords(params) {
return this.postJson((0, utils_1.getFormattedUrl)(this.format), {
action: Actions_1.Actions.updateDnsRecords,
param: {
...params,
},
});
}
}
exports.default = NetcupRestApi;