liveperson-functions-cli
Version:
LivePerson Functions CLI
80 lines • 2.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.httpClient = exports.HttpClient = void 0;
const HTTP = require("dropin-request");
const path_1 = require("path");
const headers_gen_1 = require("../shared/headers-gen");
const fsDefault = require("fs-extra");
const url_1 = require("url");
const defaultUrls = [
'adminlogin.liveperson.net',
'ams-a.liveperson.net',
'api.liveperson.net',
'*.ac.liveperson.net',
'*.acr.liveperson.net',
'*.agentvep.liveperson.net',
'*.data-mng.liveperson.net',
'*.enghist.liveperson.net',
'*.lp-msgewt.liveperson.net',
'*.msghist.liveperson.net',
'*.push.liveperson.net',
'*.v.liveperson.net',
'*.msg.liveperson.net',
'*.objectstorage.liveperson.net',
];
class HttpClient {
constructor({ fs = fsDefault, http = HTTP } = {}) {
this.fs = fs;
this.http = http;
}
async request(param1, param2) {
const url = typeof param1 === 'string' ? param1 : param1.uri ? param1.uri : param1.url;
if (!this.checkWhitelisting(url)) {
return new Promise((resolve) => {
resolve({
statusCode: 403,
body: 'You do not have access to the page or resource you are trying to reach\n',
});
});
}
return this.http({
uri: url,
rejectUnauthorized: false,
headers: (0, headers_gen_1.GenerateHeaders)(),
agentOptions: {
secureProtocol: 'TLSv1_2_method',
},
...(param2 && { ...param2 }),
...(typeof param1 === 'object' && { ...param1 }),
});
}
checkWhitelisting(uri) {
try {
const settings = JSON.parse(this.fs.readFileSync((0, path_1.join)(process.cwd(), 'functions', 'settings.json'), 'utf8'));
const whitelist = [...settings.whitelist, ...defaultUrls];
const hostname = (0, url_1.parse)(uri).hostname;
if (hostname && whitelist.includes(hostname)) {
return true;
}
else if (hostname) {
const splittedUrl = hostname.split('.');
const basedUrl = splittedUrl.slice(Math.max(splittedUrl.length - 2, 0));
const testUrl = `*.${basedUrl[0]}.${basedUrl[1]}`;
return whitelist.includes(testUrl);
}
else {
return false;
}
}
catch (err) {
throw new Error('Please make sure you have set up a settings.json');
}
}
}
exports.HttpClient = HttpClient;
const httpClient = (params1, params2) => {
const client = new HttpClient();
return client.request(params1, params2);
};
exports.httpClient = httpClient;
//# sourceMappingURL=httpClient.js.map