Merge branch 'master-AIO' into feature/IO-3020-IO-3036-imex-lite-rome-lite

This commit is contained in:
Patrick Fic
2024-12-04 12:58:23 -08:00
81 changed files with 4206 additions and 3939 deletions

View File

@@ -0,0 +1,26 @@
// Load environment variables THIS MUST BE AT THE TOP
const path = require("path");
require("dotenv").config({
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
const { networkInterfaces, hostname } = require("node:os");
const getHostNameOrIP = () => {
// Try to get the hostname first
const hostName = hostname();
if (hostName) return hostName;
const interfaces = networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === "IPv4" && !iface.internal) {
return iface.address;
}
}
}
return "127.0.0.1";
};
module.exports = getHostNameOrIP;

View File

@@ -1,8 +1,12 @@
const applyIOHelpers = ({ app, api, io, logger }) => {
const getBodyshopRoom = (bodyshopID) => `bodyshop-broadcast-room:${bodyshopID}`;
// Messaging - conversation specific room to handle detailed messages when the user has a conversation open.
const getBodyshopConversationRoom = ({bodyshopId, conversationId}) =>
`bodyshop-conversation-room:${bodyshopId}:${conversationId}`;
const ioHelpersAPI = {
getBodyshopRoom
getBodyshopRoom,
getBodyshopConversationRoom
};
// Helper middleware

View File

@@ -8,10 +8,10 @@ const InstanceManager = require("../utils/instanceMgr").default;
const winston = require("winston");
const WinstonCloudWatch = require("winston-cloudwatch");
const { isString, isEmpty } = require("lodash");
const { networkInterfaces, hostname } = require("node:os");
const { uploadFileToS3 } = require("./s3");
const { v4 } = require("uuid");
const { InstanceRegion } = require("./instanceMgr");
const getHostNameOrIP = require("./getHostNameOrIP");
const LOG_LEVELS = {
error: { level: 0, name: "error" },
@@ -76,22 +76,6 @@ const createLogger = () => {
})();
};
const getHostNameOrIP = () => {
// Try to get the hostname first
const hostName = hostname();
if (hostName) return hostName;
const interfaces = networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === "IPv4" && !iface.internal) {
return iface.address;
}
}
}
return "127.0.0.1";
};
const createProductionTransport = (level, logStreamName, filters) => {
return new WinstonCloudWatch({
level,

View File

@@ -0,0 +1,52 @@
// Load environment variables THIS MUST BE AT THE TOP
const path = require("path");
const getHostNameOrIP = require("./getHostNameOrIP");
const logger = require("./logger");
require("dotenv").config({
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
const CrispStatusReporter = require("crisp-status-reporter").CrispStatusReporter;
const InstanceManager = require("../utils/instanceMgr").default;
function StartStatusReporter() {
//For ImEX Online.
return InstanceManager({
executeFunction: true,
args: [],
imex: () => {
if (
process.env.NODE_ENV === undefined ||
!process.env.CRISP_SECRET_TOKEN ||
!process.env.CRISP_SERVICE_IDENTIFIER ||
!process.env.CRISP_NODE_IDENTIFIER
) {
logger.log("crisp-status-update-error", "DEBUG", null, null, { message: "Environment Variables not set." });
return;
}
try {
const crispStatusReporter = new CrispStatusReporter({
token: process.env.CRISP_SECRET_TOKEN, // Your reporter token (given by Crisp)
service_id: process.env.CRISP_SERVICE_IDENTIFIER, // Service ID containing the parent Node for Replica (given by Crisp)
node_id: process.env.CRISP_NODE_IDENTIFIER, // Node ID containing Replica (given by Crisp)
replica_id: getHostNameOrIP(), // Unique Replica ID for instance (ie. your IP on the LAN)
interval: 30 // Reporting interval (in seconds; defaults to 30 seconds if not set)
// console: {
// debug: (log_message, data) => logger.log("crisp-status-update", "DEBUG", null, null, { log_message, data }),
// log: (log_message, data) => logger.log("crisp-status-update", "DEBUG", null, null, { log_message, data }),
// warn: (log_message, data) => logger.log("crisp-status-update", "WARN", null, null, { log_message, data }),
// error: (log_message, data) => logger.log("crisp-status-update", "ERROR", null, null, { log_message, data })
// } // Console instance if you need to debug issues,
});
return crispStatusReporter;
} catch (error) {
logger.log("crisp-status-update-error", "DEBUG", null, null, { error: error.message });
}
}
});
}
module.exports = StartStatusReporter;