kas-api
Version:
Simple Library for calling the ALL-INKL KAS API
58 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.KasApi = void 0;
const soap_1 = require("soap");
const xml2js_1 = require("xml2js");
const api_result_transformer_1 = require("./api-result-transformer");
class KasApi {
constructor(account, password) {
this.account = account;
this.password = password;
}
async call(action, data) {
const soapClient = await (0, soap_1.createClientAsync)(KasApi.endpoint, {
disableCache: true,
// @ts-ignore
suppressStack: true,
});
const payload = JSON.stringify({
KasAuthData: this.password,
KasAuthType: "plain",
KasRequestParams: data || {},
KasRequestType: action,
KasUser: this.account,
});
let response;
try {
// @ts-ignore
response = await soapClient.KasApiAsync({ params: payload });
}
catch (e) {
return e;
}
const jsonResponse = await new Promise((res, rej) => {
(0, xml2js_1.parseString)(response[1], {
async: true,
explicitArray: false,
ignoreAttrs: true,
mergeAttrs: true,
trim: true,
}, (err, result) => {
if (err) {
rej(err);
}
res(result);
});
});
const parsedResponse = api_result_transformer_1.APIResultTransformer.transform(jsonResponse);
// @ts-ignore
if (parsedResponse.Response.ReturnString !== "TRUE") {
throw new Error("Request wasn't successful.");
}
// @ts-ignore
return parsedResponse.Response.ReturnInfo;
}
}
exports.KasApi = KasApi;
KasApi.endpoint = "https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl";
//# sourceMappingURL=kas-api.js.map