Add store/email/phone filtering, richer call-line formatting, CDR feed pagination and queueing, and split Jira poller enrichment into testable modules. Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
// services/jiraPoller/runEnrichment.js
|
|
// Run poller enrichment checks and merge markdown sections.
|
|
|
|
import { logger } from '../../utils/logger.js';
|
|
import { collectPhoneStatus } from '../phoneService.js';
|
|
import { collectDeviceStatus } from '../deviceService.js';
|
|
import { collectCallReport } from '../callReport/callReportService.js';
|
|
import { renderPhoneStatusMarkdown } from '../renderers/phoneStatusRenderer.js';
|
|
import { renderAvStatusMarkdown } from '../renderers/avStatusRenderer.js';
|
|
import { renderCallReportMarkdown } from '../renderers/callReportRenderer.js';
|
|
import { CHECK_IDS } from './enrichmentRules.js';
|
|
import { formatEnrichmentBody } from './formatBody.js';
|
|
|
|
const LOG_SCOPE = 'jira:poller:enrich';
|
|
|
|
const CHECK_RUNNERS = {
|
|
[CHECK_IDS.phonestatus]: async (storeNum) => {
|
|
const data = await collectPhoneStatus(storeNum);
|
|
return {
|
|
title: 'Phone status',
|
|
markdown: renderPhoneStatusMarkdown(data, {
|
|
storeNum,
|
|
detailed: true,
|
|
footer: false,
|
|
}),
|
|
};
|
|
},
|
|
[CHECK_IDS.avstatus]: async (storeNum) => {
|
|
const data = await collectDeviceStatus(storeNum);
|
|
return {
|
|
title: 'AV status',
|
|
markdown: renderAvStatusMarkdown(data, {
|
|
storeNum,
|
|
detailed: true,
|
|
footer: false,
|
|
}),
|
|
};
|
|
},
|
|
[CHECK_IDS.callreport]: async (storeNum, opts = {}) => {
|
|
const report = await collectCallReport(storeNum, {
|
|
dateArg: 'today',
|
|
onCdrQueued: ({ runAt, waitMs }) => {
|
|
logger(
|
|
LOG_SCOPE,
|
|
`CDR queued for store ${storeNum} — runs at ${runAt.toISOString()} (~${Math.ceil(waitMs / 1000)}s)`,
|
|
'info',
|
|
);
|
|
},
|
|
});
|
|
return {
|
|
title: 'Call report (today)',
|
|
markdown: renderCallReportMarkdown(report, { detail: false }),
|
|
};
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @param {string} storeNum
|
|
* @param {string[]} checks ordered check ids
|
|
* @param {object} [opts]
|
|
* @returns {Promise<{ sections: Array<{title: string, markdown: string}>, bodyMarkdown: string }>}
|
|
*/
|
|
export async function runEnrichmentChecks(storeNum, checks, opts = {}) {
|
|
const sections = [];
|
|
for (const checkId of checks) {
|
|
const runner = CHECK_RUNNERS[checkId];
|
|
if (!runner) {
|
|
throw new Error(`Unknown enrichment check: ${checkId}`);
|
|
}
|
|
const section = await runner(storeNum, opts);
|
|
sections.push(section);
|
|
}
|
|
|
|
const bodyMarkdown = formatEnrichmentBody(sections);
|
|
|
|
return { sections, bodyMarkdown };
|
|
}
|