pink-bears
Version:
Intelligent rate limiting middleware with MongoDB integration and caching for Node.js applications
57 lines • 1.51 kB
JavaScript
const {
emitEvent
} = require("./errorEmitter");
const {
errorConstants
} = require("./constants");
const axiosWrapper = require('./AxiosWrapper');
let Axios;
class Reply {
constructor(domain, token, productId, traceId, appId, accountId, userId) {
this.domain = domain;
this.token = token;
this.productId = productId;
this.traceId = traceId;
this.appId = appId;
this.accountId = accountId;
this.userId = userId;
this.initializeAxiosWrapper();
}
initializeAxiosWrapper = () => {
const AxiosWrapper = new axiosWrapper(this.domain, this.userId);
Axios = AxiosWrapper.getAxiosInstance();
};
renderHTML = async (s3Link, headers) => {
try {
let response = {
s3Url: s3Link,
isApp: false
};
if (!s3Link) {
const responseContent = await Axios.get(`${this.domain}/api/app/details?app_id=${this.appId}`, {
headers: {
"Content-type": "application/json; charset=UTF-8",
auth: this.token
}
});
response = {
s3Url: responseContent?.data?.sourceLink,
isApp: true
};
}
if (headers) {
return {
appnest_app_headers: headers,
appnest_app_response: response
};
}
return response;
} catch (error) {
await emitEvent(errorConstants.reply, error);
return {
error: "Error while returning response in incoming webhook"
};
}
};
}
module.exports = Reply;