- Delete unused dataMerger, formatter, Device model, dead service exports, and the empty agents/ + .gitkeep placeholders. - Extract STORE_MODES and MDM device-type filters into a shared constants.js. - Anchor bot regexes (^help|^store|^analyze) so "analyze store 305" no longer fires both handlers; replace catch-all noise. - Hoist inline require() calls in integrations to top-of-file imports. - Harden WebSocket server: Authorization header support, single-agent enforcement, bounded pending requests, server-level error handler, coalesced cache refresh in Meraki client. - Wrap Meraki/MDM network calls with withRetry; add request timeouts. - Migrate all console.* calls onto utils/logger.js (LOG_LEVEL aware); drive Webex framework logLevel from env. - Refactor storeDetail.js: shared renderClientLine + buildMdmSection helpers cut duplication roughly in half. - Refresh README structure, document LOG_LEVEL, add npm run agent script, add jest testMatch + new tests (handlers, HealthReport, Store, ws). Verified: npm run lint clean, 7 suites / 31 tests passing. Co-authored-by: Cursor <cursoragent@cursor.com>
73 lines
1.9 KiB
JavaScript
73 lines
1.9 KiB
JavaScript
/**
|
|
* Domain model for Store Health Report.
|
|
* Encapsulates score, issues, and summary generation.
|
|
*/
|
|
|
|
class HealthReport {
|
|
constructor(storeNumber, storeName = 'Unknown Store') {
|
|
this.storeNumber = storeNumber;
|
|
this.storeName = storeName;
|
|
this.overallScore = 100;
|
|
this.issues = [];
|
|
this.sections = [];
|
|
}
|
|
|
|
deduct(points, reason) {
|
|
this.overallScore = Math.max(0, this.overallScore - points);
|
|
if (reason) {
|
|
this.issues.push(reason);
|
|
}
|
|
}
|
|
|
|
addSection(title, content) {
|
|
this.sections.push({ title, content });
|
|
}
|
|
|
|
addIssue(issue) {
|
|
if (issue && !this.issues.includes(issue)) {
|
|
this.issues.push(issue);
|
|
}
|
|
}
|
|
|
|
finalize() {
|
|
this.overallScore = Math.round(this.overallScore);
|
|
|
|
const statusEmoji = this.overallScore >= 90 ? '🟢' : this.overallScore >= 70 ? '🟡' : '🔴';
|
|
const statusText =
|
|
this.overallScore >= 90 ? 'Good' : this.overallScore >= 70 ? 'Fair' : 'Needs Attention';
|
|
|
|
let summary = `**📊 Store ${this.storeNumber} Health Summary - ${this.storeName}**\n\n`;
|
|
|
|
this.sections.forEach(section => {
|
|
summary += section.content + '\n';
|
|
});
|
|
|
|
summary += `\n**Overall Status**: ${statusEmoji} ${statusText} (${this.overallScore}% healthy)\n\n`;
|
|
|
|
if (this.issues.length > 0) {
|
|
summary += `**⚠️ Issues Detected**\n`;
|
|
this.issues.forEach(issue => (summary += `- ${issue}\n`));
|
|
} else {
|
|
summary += `**✅ No major issues detected**\n`;
|
|
}
|
|
|
|
this.summary = summary;
|
|
return this;
|
|
}
|
|
|
|
toJSON() {
|
|
return {
|
|
storeNumber: this.storeNumber,
|
|
storeName: this.storeName,
|
|
overallScore: this.overallScore,
|
|
issues: [...this.issues],
|
|
summary: this.summary,
|
|
};
|
|
}
|
|
}
|
|
|
|
function createHealthReport(storeNumber, storeName) {
|
|
return new HealthReport(storeNumber, storeName);
|
|
}
|
|
|
|
module.exports = { HealthReport, createHealthReport };
|