commit 0b056739e902ab3c1639beb0236b5f4685cd9606 Author: jmcqueen Date: Fri Jul 17 08:34:47 2026 -0400 Add modular Jira-to-Webex approvals service with Docker deployment. Stabilize logging, correlation IDs, service-account Jira auth, and direct approver reminder DMs while splitting the monolith into focused modules with Compose-based deployment. Co-authored-by: Cursor diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..23644cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +node_modules +logs +.env +.env.local +.git +.gitignore +.DS_Store +*.md +config/config.local.json diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..72654cc --- /dev/null +++ b/.env.example @@ -0,0 +1,24 @@ +# Server +PORT=1345 +SERVER_NAME=aeoApprovals +LOG_LEVEL=info + +# Jira Cloud — service account (same pattern as wxccai) +# Preferred: set JIRA_CLOUD_ID to use the api.atlassian.com gateway. +JIRA_CLOUD_ID= +JIRA_BASE_URL=https://aeo.atlassian.net +JIRA_AUTH_TYPE=basic +JIRA_EMAIL=your-bot@serviceaccount.atlassian.com +JIRA_API_TOKEN= + +# Webex bots +WEBEX_TOKEN= +JIRA_NOTIFIER_TOKEN= + +# Webex rooms +WEBEX_ROOM_ID= +APPROVAL_ROOM_ID= +SUPPORT_ROOM_ID= + +# Only set if you have a specific TLS/certificate issue to work around +# NODE_TLS_REJECT_UNAUTHORIZED=0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e26abd3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +node_modules/ +logs/ +.env +.env.local +.env.*.local +.DS_Store + +# Local secrets — use config.example.json + .env instead +config/config.json +config/config.local.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9c350fe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:20 +WORKDIR /usr/src/app + +COPY package*.json ./ +RUN npm install + +COPY . . + +EXPOSE 1345 +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD node -e "fetch('http://127.0.0.1:' + (process.env.PORT || 1345) + '/healthCheck').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))" + +CMD [ "node", "index.js" ] diff --git a/app.js b/app.js new file mode 100644 index 0000000..a3e377b --- /dev/null +++ b/app.js @@ -0,0 +1,8 @@ +import express from 'express'; +import bodyParser from 'body-parser'; + +export function createApp() { + const app = express(); + app.use(bodyParser.json({ limit: '200mb' })); + return app; +} diff --git a/config/config.example.json b/config/config.example.json new file mode 100644 index 0000000..c0e0739 --- /dev/null +++ b/config/config.example.json @@ -0,0 +1,25 @@ +{ + "logLevel": "info", + "webex": { + "whUrl": "http://localhost:1345/", + "botName": "AEO Approvals", + "botUserName": "aeoapprovals@webex.bot", + "room": { + "title": "Pending Approvals | Testing" + } + }, + "server": { + "port": "1345", + "name": "aeoApprovals" + }, + "rooms": { + "approval": "your-approval-room-id", + "support": "your-support-room-id" + }, + "jiraCloud": { + "cloudId": "your-atlassian-cloud-id", + "host": "https://aeo.atlassian.net", + "authType": "basic", + "email": "your-bot@serviceaccount.atlassian.com" + } +} diff --git a/config/requests.json b/config/requests.json new file mode 100644 index 0000000..e830803 --- /dev/null +++ b/config/requests.json @@ -0,0 +1,226 @@ +{ + "177": { + "name": "Request a Change", + "transitions": { + "171": { + "name": "Ready for Approval" + }, + "271": { + "name": "Emergency" + } + } + }, + "193": { + "name": "Onboard New Hire / Modify Existing User", + "transitions": { + "151": { + "name": "Manager Approval" + }, + "261": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "209": { + "name": "Application Access", + "transitions": { + "1111": { + "name": "Manager Approval" + }, + "1011": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "202": { + "name": "Enterprise Access", + "transitions": { + "1111": { + "name": "Manager Approval" + }, + "1011": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "189": { + "name": "IBMi Access", + "transitions": { + "1111": { + "name": "Manager Approval" + }, + "1011": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "188": { + "name": "DI Access", + "transitions": { + "81": { + "name": "Manager Approval" + }, + "171": { + "name": "Escalate to Tier 2 Manager" + }, + "101": { + "name": "Finance Approval" + } + } + }, + "183": { + "name": "Firewall Access", + "transitions": { + "1071": { + "name": "Ready for Approvals" + } + } + }, + "191": { + "name": "Desktop Requests", + "transitions": { + "81": { + "name": "Manager Approval" + }, + "221": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "382": { + "name": "Service Request", + "transitions": { + "81": { + "name": "Manager Approval" + }, + "101": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "211": { + "name": "Database Access", + "transitions": { + "981": { + "name": "Manager Approval" + }, + "991": { + "name": "Business Approval" + }, + "1001": { + "name": "Technical Approval" + }, + "1051": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "192": { + "name": "Contractor Conversion", + "transitions": { + "151": { + "name": "Manager Approval" + }, + "261": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "197": { + "name": "Control M Job Request", + "transitions": { + "81": { + "name": "Manager Approval" + }, + "101": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "200": { + "name": "Corporate Credit Card Request", + "transitions": { + "11": { + "name": "Manager Approval" + }, + "121": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "203": { + "name": "Clarity Onboarding", + "transitions": { + "11": { + "name": "Manager Approval" + }, + "61": { + "name": "PM Approval" + }, + "21": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + "190": { + "name": "Server Access", + "transitions": { + "11": { + "name": "Pending Approval" + }, + "141": { + "name": "Pending Approval" + } + } + }, + "199": { + "name": "Contractor Extension", + "transitions": { + "1111": { + "name": "Manager Approval" + }, + "1011": { + "name": "Escalate to Tier 2 Manager" + } + } + }, + + "179": { + "name": "Customer Technology Production Change", + "transitions": { + "1071": { + "name": "Ready for Approvals" + } + } + }, + "204": { + "name": "Server Decommission Request", + "transitions": { + "141": { + "name": "Pending Approval" + }, + "11": { + "name": "Pending Approval" + } + } + }, + "186": { + "name": "Request Store Fixtures", + "transitions": { + "21": { + "name": "Finance Approval" + } + } + }, + "187": { + "name": "New Server Build Request", + "transitions": { + "141": { + "name": "Pending Approval" + }, + "211": { + "name": "Technical Approval" + } + } + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8254a5d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,35 @@ +services: + aeo-approvals: + build: . + container_name: aeo-approvals + ports: + - "${PORT:-1345}:1345" + env_file: + - path: .env + required: false + environment: + PORT: ${PORT:-1345} + LOG_LEVEL: ${LOG_LEVEL:-info} + SERVER_NAME: ${SERVER_NAME:-aeoApprovals} + JIRA_CLOUD_ID: ${JIRA_CLOUD_ID:-} + JIRA_BASE_URL: ${JIRA_BASE_URL:-https://aeo.atlassian.net} + JIRA_AUTH_TYPE: ${JIRA_AUTH_TYPE:-basic} + JIRA_EMAIL: ${JIRA_EMAIL:-} + JIRA_API_TOKEN: ${JIRA_API_TOKEN:-} + volumes: + - ./logs:/usr/src/app/logs + - ./config/config.json:/usr/src/app/config/config.json:ro + - ./config/requests.json:/usr/src/app/config/requests.json:ro + restart: unless-stopped + healthcheck: + test: + [ + "CMD", + "node", + "-e", + "fetch('http://127.0.0.1:' + (process.env.PORT || 1345) + '/healthCheck').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))", + ] + interval: 30s + timeout: 5s + retries: 3 + start_period: 10s diff --git a/index.js b/index.js new file mode 100644 index 0000000..0175b1b --- /dev/null +++ b/index.js @@ -0,0 +1,64 @@ +import fs from 'fs'; +import { loadConfig, loadRequests, getMissingSecrets, describeJiraIdentity } from './lib/config.js'; +import { createLogger } from './lib/logger.js'; +import { createJiraClient } from './services/jiraClient.js'; +import { createJiraService } from './services/jira.js'; +import { createWebexService } from './services/webex.js'; +import { createJiraProcessor } from './services/jiraProcessor.js'; +import { createPendingApprovalsJob, cleanupOldLogs } from './jobs/pendingApprovals.js'; +import { scheduleJobs } from './jobs/cron.js'; +import { createWebhookRoutes } from './routes/webhooks.js'; +import { createApp } from './app.js'; + +const config = loadConfig(); +const requests = loadRequests(); +const log = createLogger(config); + +if (!fs.existsSync('./logs')) { + fs.mkdirSync('./logs', { recursive: true }); +} + +const missingSecrets = getMissingSecrets(config); +if (missingSecrets.length > 0) { + log.writeLog('warn', 'startup', `Missing configuration — set env vars or config.json: ${missingSecrets.join(', ')}`); +} +if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') { + log.writeLog('warn', 'startup', 'NODE_TLS_REJECT_UNAUTHORIZED=0 is set — TLS certificate verification is disabled'); +} +log.logger('startup', `Jira identity: ${describeJiraIdentity(config)}`); + +const jiraClient = createJiraClient(config); +const jiraService = createJiraService(jiraClient, log); +const webexService = createWebexService(config, log); +const jiraProcessor = createJiraProcessor({ config, requests, jiraService, webexService, log }); +const pendingApprovalsJob = createPendingApprovalsJob({ jiraService, webexService, log }); + +scheduleJobs({ + runPendingApprovals: pendingApprovalsJob.runPendingApprovals, + cleanupOldLogs: () => cleanupOldLogs(log), + log, +}); + +const app = createApp(); +const webhookRoutes = createWebhookRoutes({ config, jiraProcessor, webexService, log }); +webhookRoutes.registerRoutes(app); + +const server = app.listen(config.server.port, () => { + log.logger('startup', `${config.server.name} running on port ${config.server.port}.`); +}); + +process.on('SIGINT', () => { + server.close(() => { + log.logger('shutdown', `${config.server.name} stopped!`); + process.exit(); + }); +}); + +process.on('unhandledRejection', (reason) => { + log.logError('process', 'Unhandled promise rejection', reason); +}); + +process.on('uncaughtException', (err) => { + log.logError('process', 'Uncaught exception — shutting down', err); + process.exit(1); +}); diff --git a/jobs/cron.js b/jobs/cron.js new file mode 100644 index 0000000..0013d3b --- /dev/null +++ b/jobs/cron.js @@ -0,0 +1,18 @@ +import cron from 'node-cron'; +import { createCorrelationId, runWithCorrelationId } from '../lib/correlation.js'; + +export function scheduleJobs({ runPendingApprovals, cleanupOldLogs, log }) { + cron.schedule('0 30 9 * * *', async function () { + const correlationId = createCorrelationId({ routeName: 'cron' }); + await runWithCorrelationId(correlationId, async () => { + try { + log.logger('cron', 'Starting scheduled job'); + await runPendingApprovals(); + await cleanupOldLogs(); + log.logger('cron', 'Scheduled job completed'); + } catch (error) { + log.logError('cron', 'Scheduled job failed', error); + } + }); + }); +} diff --git a/jobs/pendingApprovals.js b/jobs/pendingApprovals.js new file mode 100644 index 0000000..90e331d --- /dev/null +++ b/jobs/pendingApprovals.js @@ -0,0 +1,100 @@ +import fs from 'fs'; +import path from 'path'; +import { formatDuration } from '../lib/util.js'; + +export function createPendingApprovalsJob({ jiraService, webexService, log }) { + const { logger, logWarn, logError, logDebug } = log; + + function sendApprovalReminder(personEmail, approvals) { + return new Promise(function (resolve, reject) { + let msgText = 'You have the following pending approvals:\n'; + + for (const approval of approvals) { + msgText += `- [${approval.key}](https://aeo.atlassian.net/servicedesk/customer/portal/135/${approval.key}): ${approval.summary} ${approval.duration}\n`; + } + + msgText += '\nYou can find these in the [Requests Pending Approvals](https://aeo.atlassian.net/servicedesk/customer/user/approvals?page=1) portal. If you have any questions or experience issues, please submit a [support request](https://aeo.atlassian.net/servicedesk/customer/portals).'; + + logDebug('sendApprovalReminder', `Sending direct reminder to ${personEmail}:\n${msgText}`); + + webexService.sendWebexMessage({ + toPersonEmail: personEmail, + markdown: msgText, + }) + .then(result => resolve(result)) + .catch(error => reject(error)); + }); + } + + function runPendingApprovals() { + return jiraService.searchUnapprovedRequests() + .then(async function (tickets) { + if (!tickets || tickets.length === 0) { + logger('runPendingApprovals', 'No pending approval tickets found.'); + return; + } + + const needApproval = {}; + for (const ticket of tickets) { + if (ticket.fields.customfield_10033) { + for (const approvals of ticket.fields.customfield_10033) { + if (approvals.approvers.length > 0 && approvals.finalDecision == 'pending') { + for (const approver of approvals.approvers) { + if (approver.approverDecision != 'approved' && new Date(approvals.createdDate.iso8601) < new Date(new Date() - (24 * 60 * 60 * 1000))) { + if (!needApproval[approver.approver.emailAddress]) { + needApproval[approver.approver.emailAddress] = []; + } + needApproval[approver.approver.emailAddress].push({ + key: ticket.key, + summary: ticket.fields.summary, + reporter: ticket.fields.reporter.displayName, + duration: formatDuration(approvals.createdDate.iso8601), + }); + } + } + } + } + } else { + logWarn('runPendingApprovals', `No approvals setup in customfield_10033 for ${ticket.key}.`); + } + } + + for (const approver in needApproval) { + await sendApprovalReminder(approver, needApproval[approver]) + .then(() => logger('runPendingApprovals', `Sent reminder to ${approver}.`)) + .catch(error => logError('runPendingApprovals', `Failed to send reminder to ${approver}`, error)); + } + }) + .catch(error => logError('runPendingApprovals', 'Failed to run pending approvals job', error)); + } + + return { runPendingApprovals }; +} + +export async function cleanupOldLogs(log) { + const { logger, logError } = log; + const now = Date.now(); + const directory = './logs'; + const sevenDaysInMs = 7 * 24 * 60 * 60 * 1000; + + let files; + try { + files = await fs.promises.readdir(directory); + } catch (error) { + logError('cleanupOldLogs', `Failed to read log directory ${directory}`, error); + return; + } + + for (const file of files) { + const filePath = path.join(directory, file); + try { + const stats = await fs.promises.stat(filePath); + if (stats.isFile() && (now - stats.mtimeMs) > sevenDaysInMs) { + await fs.promises.unlink(filePath); + logger('cleanupOldLogs', `Deleted old log file: ${file}`); + } + } catch (error) { + logError('cleanupOldLogs', `Failed to process log file ${file}`, error); + } + } +} diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..c0d46b5 --- /dev/null +++ b/lib/config.js @@ -0,0 +1,91 @@ +import dotenv from 'dotenv'; +import fs from 'fs'; + +dotenv.config(); + +function envOrConfig(envKey, configValue) { + const envValue = process.env[envKey]; + if (envValue !== undefined && envValue !== '') { + return envValue; + } + return configValue; +} + +function resolveJiraHost(fileConfig) { + const cloudId = envOrConfig('JIRA_CLOUD_ID', fileConfig.jiraCloud?.cloudId)?.trim(); + let baseUrl = envOrConfig('JIRA_BASE_URL', fileConfig.jiraCloud?.host || 'https://aeo.atlassian.net')?.trim(); + + if (cloudId) { + return `https://api.atlassian.com/ex/jira/${cloudId}`; + } + + return baseUrl.replace(/\/$/, ''); +} + +export function loadConfig() { + const fileConfig = JSON.parse(fs.readFileSync('./config/config.json')); + + const config = { + ...fileConfig, + logLevel: envOrConfig('LOG_LEVEL', fileConfig.logLevel), + server: { + ...fileConfig.server, + port: envOrConfig('PORT', fileConfig.server?.port), + name: envOrConfig('SERVER_NAME', fileConfig.server?.name), + }, + webex: { + ...fileConfig.webex, + token: envOrConfig('WEBEX_TOKEN', fileConfig.webex?.token), + room: { + ...fileConfig.webex?.room, + id: envOrConfig('WEBEX_ROOM_ID', fileConfig.webex?.room?.id), + }, + }, + jiraNotifier: { + ...fileConfig.jiraNotifier, + token: envOrConfig('JIRA_NOTIFIER_TOKEN', fileConfig.jiraNotifier?.token), + }, + jiraCloud: { + ...fileConfig.jiraCloud, + cloudId: envOrConfig('JIRA_CLOUD_ID', fileConfig.jiraCloud?.cloudId) || null, + host: resolveJiraHost(fileConfig), + siteUrl: (envOrConfig('JIRA_BASE_URL', fileConfig.jiraCloud?.host || 'https://aeo.atlassian.net') || '').replace(/\/$/, ''), + authType: (envOrConfig('JIRA_AUTH_TYPE', fileConfig.jiraCloud?.authType) || 'basic').toLowerCase(), + email: envOrConfig('JIRA_EMAIL', fileConfig.jiraCloud?.email), + token: envOrConfig('JIRA_API_TOKEN', fileConfig.jiraCloud?.token), + }, + rooms: { + approval: envOrConfig( + 'APPROVAL_ROOM_ID', + fileConfig.rooms?.approval || 'Y2lzY29zcGFyazovL3VzL1JPT00vZWQ4ZWY3OTAtMGE5NC0xMWVjLWExZDUtM2I5ZWNlNWFlNDI5' + ), + support: envOrConfig( + 'SUPPORT_ROOM_ID', + fileConfig.rooms?.support || 'Y2lzY29zcGFyazovL3VzL1JPT00vZWY4MmExNjAtNzYzNS0xMWU4LWFlYWMtNjNjMGMyMTExYTVm' + ), + }, + }; + + return config; +} + +export function loadRequests() { + return JSON.parse(fs.readFileSync('./config/requests.json')); +} + +export function getMissingSecrets(config) { + const missing = []; + if (!config.jiraCloud?.email) missing.push('JIRA_EMAIL'); + if (!config.jiraCloud?.token) missing.push('JIRA_API_TOKEN'); + if (!config.webex?.token) missing.push('WEBEX_TOKEN'); + if (!config.jiraNotifier?.token) missing.push('JIRA_NOTIFIER_TOKEN'); + return missing; +} + +export function describeJiraIdentity(config) { + const email = config.jiraCloud?.email || '(not set)'; + const host = config.jiraCloud?.host || '(not set)'; + const authType = config.jiraCloud?.authType || 'basic'; + const viaCloudId = config.jiraCloud?.cloudId ? `cloudId=${config.jiraCloud.cloudId}` : 'site URL'; + return `${email} (${authType}, ${viaCloudId}) → ${host}`; +} diff --git a/lib/correlation.js b/lib/correlation.js new file mode 100644 index 0000000..4aaf3a4 --- /dev/null +++ b/lib/correlation.js @@ -0,0 +1,23 @@ +import { AsyncLocalStorage } from 'async_hooks'; +import { randomUUID } from 'crypto'; + +const correlationStore = new AsyncLocalStorage(); + +export function createCorrelationId({ issueKey, routeName } = {}) { + const shortId = randomUUID().split('-')[0]; + if (issueKey) { + return `${issueKey}-${shortId}`; + } + if (routeName) { + return `${routeName}-${shortId}`; + } + return shortId; +} + +export function getCorrelationId() { + return correlationStore.getStore(); +} + +export function runWithCorrelationId(correlationId, fn) { + return correlationStore.run(correlationId, fn); +} diff --git a/lib/logger.js b/lib/logger.js new file mode 100644 index 0000000..5940776 --- /dev/null +++ b/lib/logger.js @@ -0,0 +1,88 @@ +import fs from 'fs'; +import path from 'path'; +import { createCorrelationId, getCorrelationId, runWithCorrelationId } from './correlation.js'; + +const LOG_LEVELS = { error: 0, warn: 1, info: 2, debug: 3 }; + +export function createLogger(config) { + const currentLogLevel = LOG_LEVELS[config.logLevel?.toLowerCase()] ?? LOG_LEVELS.info; + + function formatError(error) { + if (!error) return 'Unknown error'; + if (typeof error === 'string') return error; + if (error.response?.data) { + return `${error.message || 'Request failed'}: ${JSON.stringify(error.response.data)}`; + } + return error.stack || error.message || String(error); + } + + function correlationPrefix() { + const correlationId = getCorrelationId(); + return correlationId ? `[${correlationId}] ` : ''; + } + + function writeLog(level, activeFunction, message) { + if (LOG_LEVELS[level] > currentLogLevel) return; + const line = `${new Date().toISOString()} [${level.toUpperCase()}] ${correlationPrefix()}${activeFunction}: ${message}`; + if (level === 'error') console.error(line); + else if (level === 'warn') console.warn(line); + else console.log(line); + } + + function logger(activeFunction, logLine) { + writeLog('info', activeFunction, logLine); + } + + function logWarn(activeFunction, logLine) { + writeLog('warn', activeFunction, logLine); + } + + function logError(activeFunction, logLine, error) { + const detail = error !== undefined ? ` ${formatError(error)}` : ''; + writeLog('error', activeFunction, `${logLine}${detail}`); + } + + function logDebug(activeFunction, logLine) { + writeLog('debug', activeFunction, logLine); + } + + function safeProcess(context, fn, meta = {}) { + const correlationId = meta.correlationId || createCorrelationId(meta); + runWithCorrelationId(correlationId, () => { + Promise.resolve() + .then(fn) + .catch(error => logError(context, 'Unhandled error during async processing', error)); + }); + } + + function logFile(provider, jsonData) { + const d = new Date(); + const year = d.getFullYear(); + const month = (d.getMonth() + 1).toString().padStart(2, '0'); + const day = d.getDate().toString().padStart(2, '0'); + const logFilePath = path.join(`./logs/${provider}-${year}${month}${day}.log`); + const correlationId = getCorrelationId(); + const correlationLine = correlationId ? ` [${correlationId}]` : ''; + const content = `${d.toISOString()}${correlationLine}\n${JSON.stringify(jsonData)}\n`; + + fs.appendFile(logFilePath, content, (error) => { + if (error) { + logError('logFile', `Failed to write ${provider} webhook log`, error); + } + }); + } + + return { + logger, + logWarn, + logError, + logDebug, + safeProcess, + logFile, + writeLog, + formatError, + runWithCorrelationId, + createCorrelationId, + getCorrelationId, + }; +} diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 0000000..04d95bb --- /dev/null +++ b/lib/util.js @@ -0,0 +1,30 @@ +export function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +export function formatDuration(timestamp, locale = 'en') { + let value; + const diff = (new Date().getTime() - new Date(timestamp).getTime()) / 1000; + const minutes = Math.floor(diff / 60); + const hours = Math.floor(minutes / 60); + const days = Math.floor(hours / 24); + const months = Math.floor(days / 30); + const years = Math.floor(months / 12); + const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }); + + if (years > 0) { + value = rtf.format(0 - years, 'year'); + } else if (months > 0) { + value = rtf.format(0 - months, 'month'); + } else if (days > 0) { + value = rtf.format(0 - days, 'day'); + } else if (hours > 0) { + value = rtf.format(0 - hours, 'hour'); + } else if (minutes > 0) { + value = rtf.format(0 - minutes, 'minute'); + } else { + value = rtf.format(0 - diff, 'second'); + } + + return `(Submitted ${value})`; +} diff --git a/lib/validate.js b/lib/validate.js new file mode 100644 index 0000000..3289ff5 --- /dev/null +++ b/lib/validate.js @@ -0,0 +1,23 @@ +export function validateJiraWebhook(body) { + if (!body || typeof body !== 'object') { + return { valid: false, error: 'Payload must be a JSON object' }; + } + if (!body.issue?.key || typeof body.issue.key !== 'string') { + return { valid: false, error: 'Missing or invalid issue.key' }; + } + if (!body.issue.fields || typeof body.issue.fields !== 'object') { + return { valid: false, error: 'Missing issue.fields' }; + } + return { valid: true, issueKey: body.issue.key }; +} + +export function validateSupportWebhook(body) { + const base = validateJiraWebhook(body); + if (!base.valid) { + return base; + } + if (!body.webhookEvent || typeof body.webhookEvent !== 'string') { + return { valid: false, error: 'Missing or invalid webhookEvent' }; + } + return { valid: true, issueKey: base.issueKey }; +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..5352839 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1128 @@ +{ + "name": "aeorequests", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "aeorequests", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "body-parser": "^2.2.0", + "dotenv": "^17.4.2", + "express": "^5.1.0", + "jira.js": "^5.3.0", + "node-cron": "^4.2.1", + "node-fetch": "^3.3.2" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.13.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.5.tgz", + "integrity": "sha512-cz4ur7Vb0xS4/KUN0tPWe44eqxrIu31me+fbang3ijiNscE129POzipJJA6zniq2C/Z6sJCjMimjS8Lc/GAs8Q==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.11", + "form-data": "^4.0.5", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/body-parser": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz", + "integrity": "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.0", + "http-errors": "^2.0.0", + "iconv-lite": "^0.6.3", + "on-finished": "^2.4.1", + "qs": "^6.14.0", + "raw-body": "^3.0.0", + "type-is": "^2.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/content-disposition": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.0.tgz", + "integrity": "sha512-Au9nRL8VNUut/XSzbQA38+M78dzP4D+eqg3gfJHMIHHYa3bg067xj1KxMUWj+VULbiZMowKngFFbKczUrNJ1mg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dotenv": { + "version": "17.4.2", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz", + "integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz", + "integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.0", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/finalhandler": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz", + "integrity": "sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.11", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz", + "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz", + "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/form-data/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "license": "MIT", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "license": "MIT", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/http-errors/node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/jira.js": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/jira.js/-/jira.js-5.3.0.tgz", + "integrity": "sha512-yalIuW4UvIDf31WHvozHwFp/2JGJmLhKGxduZOwXwIlV2mwpm2Pf5kUErDBN9XgB1jZFShINrfA3n5IRs8SCMQ==", + "license": "MIT", + "dependencies": { + "axios": "^1.13.3", + "mime": "^4.1.0", + "zod": "^4.3.6" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-4.1.0.tgz", + "integrity": "sha512-X5ju04+cAzsojXKes0B/S4tcYtFAJ6tTMuSPBEn9CPGlrWr8Fiw7qYeLT0XyH80HSoAoqWCaz+MWKh22P7G1cw==", + "funding": [ + "https://github.com/sponsors/broofa" + ], + "license": "MIT", + "bin": { + "mime": "bin/cli.js" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz", + "integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-cron": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-4.2.1.tgz", + "integrity": "sha512-lgimEHPE/QDgFlywTd8yTR61ptugX3Qer29efeyWw2rv259HtGBNn1vZVmp8lB9uo9wC0t/AT4iGqXxia+CJFg==", + "license": "ISC", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "deprecated": "Use your platform's native DOMException instead", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "license": "MIT", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz", + "integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, + "node_modules/qs": { + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.1.tgz", + "integrity": "sha512-9G8cA+tuMS75+6G/TzW8OtLzmBDMo8p1JRxN5AZ+LAp8uxGA8V8GZm4GQ4/N5QNQEnLmg6SS7wyuSmbKepiKqA==", + "license": "MIT", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.7.0", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/raw-body/node_modules/iconv-lite": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.0.tgz", + "integrity": "sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.0.tgz", + "integrity": "sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw==", + "license": "MIT", + "dependencies": { + "debug": "^4.3.5", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "mime-types": "^3.0.1", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/serve-static": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-61g9pCh0Vnh7IutZjtLGGpTA355+OPn2TyDv/6ivP2h/AdAVX9azsoxmg2/M6nZeQZNYBEwIcsne1mJd9oQItQ==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/zod": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz", + "integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..46dd281 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "aeorequests", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "start": "node index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "type": "module", + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "body-parser": "^2.2.0", + "dotenv": "^17.4.2", + "express": "^5.1.0", + "jira.js": "^5.3.0", + "node-cron": "^4.2.1", + "node-fetch": "^3.3.2" + } +} diff --git a/routes/webhooks.js b/routes/webhooks.js new file mode 100644 index 0000000..5fe28f8 --- /dev/null +++ b/routes/webhooks.js @@ -0,0 +1,68 @@ +import { validateJiraWebhook, validateSupportWebhook } from '../lib/validate.js'; + +const WEBHOOK_LOG_PROVIDERS = { + 'jira-request': 'jira', + request: 'request', +}; + +export function createWebhookRoutes({ config, jiraProcessor, webexService, log }) { + const { logger, logWarn, safeProcess, logFile, runWithCorrelationId, createCorrelationId } = log; + + function healthCheck(req, res) { + res.status(200).json({ status: 'alive' }); + } + + function handleJiraWebhook(routeName, req, res) { + res.status(201).send(); + const validation = validateJiraWebhook(req.body); + const correlationMeta = { routeName, issueKey: validation.issueKey || req.body?.issue?.key }; + + if (!validation.valid) { + runWithCorrelationId(createCorrelationId(correlationMeta), () => { + logWarn(routeName, `Invalid webhook payload: ${validation.error}`); + }); + return; + } + + safeProcess(routeName, () => { + logFile(WEBHOOK_LOG_PROVIDERS[routeName] || routeName, req.body); + jiraProcessor.processJiraTicket(req.body); + }, correlationMeta); + } + + function registerRoutes(app) { + app.get('/healthCheck', healthCheck); + app.get('/heathCheck', healthCheck); + + app.post('/jira-request', (req, res) => handleJiraWebhook('jira-request', req, res)); + app.post('/request', (req, res) => handleJiraWebhook('request', req, res)); + + app.post('/support', (req, res) => { + res.status(201).send(); + const validation = validateSupportWebhook(req.body); + const correlationMeta = { routeName: 'support', issueKey: validation.issueKey || req.body?.issue?.key }; + + if (!validation.valid) { + runWithCorrelationId(createCorrelationId(correlationMeta), () => { + logWarn('support', `Invalid webhook payload: ${validation.error}`); + }); + return; + } + + safeProcess('support', () => { + logFile('support', req.body); + logger('support', `Received support webhook for ${validation.issueKey}`); + webexService.processHighSeverity(req.body, config.rooms.support); + }, correlationMeta); + }); + + app.use((err, req, res, next) => { + log.logError('express', `${req.method} ${req.path}`, err); + if (!res.headersSent) { + res.status(500).json({ error: 'Internal server error' }); + } + }); + } + + return { registerRoutes }; +} diff --git a/services/approvalCards.js b/services/approvalCards.js new file mode 100644 index 0000000..78302f8 --- /dev/null +++ b/services/approvalCards.js @@ -0,0 +1,122 @@ +export function buildChangeApproval(jiraTicket, log) { + return new Promise(function (resolve) { + let cardText = ''; + cardText += `[${jiraTicket.issue.key}](https://aeo.atlassian.net/servicedesk/customer/portal/135/${jiraTicket.issue.key}) - ${jiraTicket.issue.fields.status.name}\n`; + + if (jiraTicket.issue.fields.customfield_10010) { + if (jiraTicket.issue.fields.customfield_10010.errorMessage) { + cardText += `**Request Type:** ${jiraTicket.issue.fields.customfield_10010.errorMessage}\n`; + } else { + cardText += `**Request Type:** ${jiraTicket.issue.fields.customfield_10010.requestType.name}\n`; + } + } + cardText += `**Summary:** ${jiraTicket.issue.fields.summary}\n`; + + let detailText = ''; + detailText += `**Description:** ${jiraTicket.issue.fields.description}\n`; + detailText += '**Details:**\n'; + if (jiraTicket.issue.fields.customfield_10010) { detailText += ` - **Type:** ${jiraTicket.issue.fields.customfield_10010.requestType.name}\n`; } + if (jiraTicket.issue.fields.customfield_10080) { detailText += ` - **Risk:** ${jiraTicket.issue.fields.customfield_10080.value}\n`; } + if (jiraTicket.issue.fields.customfield_10004) { detailText += ` - **Impact:** ${jiraTicket.issue.fields.customfield_10004.value}\n`; } + if (jiraTicket.issue.fields.customfield_10256) { detailText += ` - **Business Impact:** ${jiraTicket.issue.fields.customfield_10256}\n`; } + if (jiraTicket.issue.fields.customfield_10252) { detailText += ` - **Business Justification:** ${jiraTicket.issue.fields.customfield_10252}\n`; } + if (jiraTicket.issue.fields.customfield_10257) { + const changeDate = new Date(jiraTicket.issue.fields.customfield_10257).toLocaleDateString(); + const changeTime = new Date(jiraTicket.issue.fields.customfield_10257).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: true }); + detailText += `**Implementation Date:** ${changeDate} ${changeTime}\n`; + } + + let assignmentText = ''; + if (jiraTicket.issue.fields.reporter) { assignmentText += `**Reporter:** ${jiraTicket.issue.fields.reporter.displayName}\n`; } + if (jiraTicket.issue.fields.customfield_10302) { assignmentText += `**Implementer:** ${jiraTicket.issue.fields.customfield_10302.displayName}\n`; } + + const requestCard = { + type: 'AdaptiveCard', + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', + version: '1.2', + body: [ + { type: 'TextBlock', text: cardText.trim(), wrap: true }, + { type: 'TextBlock', wrap: true, text: detailText.trim(), separator: true }, + { type: 'TextBlock', text: assignmentText.trim(), wrap: true, separator: true }, + ], + actions: [ + { + type: 'Action.OpenUrl', + title: 'Open Request', + url: `https://aeo.atlassian.net/servicedesk/customer/portal/135/${jiraTicket.issue.key}`, + }, + { + type: 'Action.Submit', + title: 'Remove Card', + style: 'destructive', + data: { cardType: 'requestApproval', action: 'removeCard' }, + }, + ], + }; + + let requestText = cardText; + requestText += `---\n${detailText}`; + requestText += `---\n${assignmentText}`; + + log.logDebug('buildChangeApproval', `Built card for ${jiraTicket.issue.key}`); + resolve({ card: requestCard, message: requestText }); + }); +} + +export function buildRequestApproval(jiraTicket) { + return new Promise(function (resolve) { + let cardText = ''; + cardText += `[${jiraTicket.issue.key}](https://aeo.atlassian.net/servicedesk/customer/portal/135/${jiraTicket.issue.key}) - ${jiraTicket.issue.fields.status.name}\n`; + + if (jiraTicket.issue.fields.customfield_10010) { + if (jiraTicket.issue.fields.customfield_10010.errorMessage) { + cardText += `**Request Type:** ${jiraTicket.issue.fields.customfield_10010.errorMessage}\n`; + } else { + cardText += `**Request Type:** ${jiraTicket.issue.fields.customfield_10010.requestType.name}\n`; + } + } + cardText += `**Summary:** ${jiraTicket.issue.fields.summary}\n`; + + let detailText = ''; + detailText += '**Details:**\n'; + if (jiraTicket.issue.fields.customfield_10314) { + detailText += ` - **Person:** ${jiraTicket.issue.fields.customfield_10346}, ${jiraTicket.issue.fields.customfield_10314}`; + if (jiraTicket.issue.fields.customfield_10310) { detailText += ` (${jiraTicket.issue.fields.customfield_10310.value})`; } + detailText += '\n'; + } + if (jiraTicket.issue.fields.customfield_10318) { detailText += ` - **Position:** ${jiraTicket.issue.fields.customfield_10318}\n`; } + + let assignmentText = ''; + assignmentText += `**Reporter:** ${jiraTicket.issue.fields.reporter.displayName}\n`; + + const requestCard = { + type: 'AdaptiveCard', + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', + version: '1.2', + body: [ + { type: 'TextBlock', text: cardText.trim(), wrap: true }, + { type: 'TextBlock', wrap: true, text: detailText.trim(), separator: true }, + { type: 'TextBlock', text: assignmentText.trim(), wrap: true, separator: true }, + ], + actions: [ + { + type: 'Action.OpenUrl', + title: 'Open Request', + url: `https://aeo.atlassian.net/servicedesk/customer/portal/135/${jiraTicket.issue.key}`, + }, + { + type: 'Action.Submit', + title: 'Remove Card', + style: 'destructive', + data: { cardType: 'requestApproval', action: 'removeCard' }, + }, + ], + }; + + let requestText = cardText; + requestText += `---\n${detailText}`; + requestText += `---\n${assignmentText}`; + + resolve({ card: requestCard, message: requestText }); + }); +} diff --git a/services/jira.js b/services/jira.js new file mode 100644 index 0000000..81810e3 --- /dev/null +++ b/services/jira.js @@ -0,0 +1,62 @@ +import { sleep } from '../lib/util.js'; + +export function createJiraService(jiraClient, log) { + const { logger, logError } = log; + + function buildApprovers(issueKey) { + return new Promise(async function (resolve, reject) { + const startTime = new Date().getTime(); + logger(`buildApprovers(${issueKey})`, 'Building approval list'); + const approvalList = []; + await sleep(10000); + + jiraClient.issues.getIssue({ issueIdOrKey: issueKey }) + .then(issueApprovers => { + for (const approvals of issueApprovers.fields.customfield_10033) { + for (const approver of approvals.approvers) { + if (approver.approverDecision == 'pending') { + approvalList.push(approver.approver.emailAddress); + } + } + } + logger('buildApprovers', `${issueKey}: Found ${approvalList.length} approvers pending. (${new Date().getTime() - startTime}ms)`); + resolve(approvalList); + }) + .catch(error => { + logError('buildApprovers', `${issueKey}: Error looking up approvers`, error); + reject(error); + }); + }); + } + + async function searchUnapprovedRequests() { + try { + const response = await jiraClient.issueSearch.searchForIssuesUsingJqlEnhancedSearchPost({ + jql: 'status in (Escalated, "Pending Approval", "Technical Approval", "Business Approval", "Technical / IT Approval")', + maxResults: 200, + fields: ['summary', 'status', 'created', 'reporter', 'updated', 'comment', 'customfield_10032', 'customfield_10033'], + }); + + logger('searchUnapprovedRequests', `Total matching issues: ${response.issues?.total}`); + logger('searchUnapprovedRequests', `Issues found: ${response.issues?.length || 0}`); + + if (response.issues && response.issues.length > 0) { + response.issues.forEach(issue => { + logger('searchUnapprovedRequests', `- ${issue.key}: ${issue.fields.summary || 'No summary'} (Status: ${issue.fields.status?.name || 'Unknown'})`); + }); + } else { + logger('searchUnapprovedRequests', 'No issues found matching the JQL.'); + } + + return response.issues || []; + } catch (error) { + logError('searchUnapprovedRequests', 'Jira search failed', error); + return []; + } + } + + return { + buildApprovers, + searchUnapprovedRequests, + }; +} diff --git a/services/jiraClient.js b/services/jiraClient.js new file mode 100644 index 0000000..8564b21 --- /dev/null +++ b/services/jiraClient.js @@ -0,0 +1,21 @@ +import { Version3Client } from 'jira.js'; + +export function createJiraClient(config) { + const jira = config.jiraCloud; + const clientConfig = { host: jira.host }; + + if (jira.authType === 'bearer') { + clientConfig.authentication = { + oauth2: { accessToken: jira.token }, + }; + } else { + clientConfig.authentication = { + basic: { + email: jira.email, + apiToken: jira.token, + }, + }; + } + + return new Version3Client(clientConfig); +} diff --git a/services/jiraProcessor.js b/services/jiraProcessor.js new file mode 100644 index 0000000..8ea44e1 --- /dev/null +++ b/services/jiraProcessor.js @@ -0,0 +1,84 @@ +import { buildChangeApproval, buildRequestApproval } from './approvalCards.js'; + +export function createJiraProcessor({ config, requests, jiraService, webexService, log }) { + const { logger, logWarn, logError } = log; + const approvalRoomId = config.rooms.approval; + + function handleApprovalNotifications(issueKey, jiraTicket, buildApprovalFn) { + buildApprovalFn(jiraTicket, log) + .then(approvalCard => jiraService.buildApprovers(issueKey).then(approvers => ({ approvalCard, approvers }))) + .then(({ approvalCard, approvers }) => { + const cardPayload = { + text: approvalCard.message, + attachments: [{ contentType: 'application/vnd.microsoft.card.adaptive', content: approvalCard.card }], + }; + for (const approver of approvers) { + logger('processJiraTicket', `Notifying ${issueKey} --> ${approver}`); + webexService.sendTicketCard(issueKey, { toPersonEmail: approver, ...cardPayload }); + } + if (approvers.length > 0) { + webexService.sendTicketCard(issueKey, { roomId: approvalRoomId, ...cardPayload }); + } + }) + .catch(error => logError('processJiraTicket', `Failed approval notifications for ${issueKey}`, error)); + } + + function processJiraTicket(jiraTicket) { + if (!jiraTicket?.issue?.key) { + logError('processJiraTicket', 'Missing issue key in webhook payload'); + return; + } + + const issueKey = jiraTicket.issue.key; + let requestType; + let transitionId; + + logger('processJiraTicket', `Processing ${issueKey}.`); + + if (jiraTicket.transition) { + logger('processJiraTicket', `${issueKey} Transition: ${jiraTicket.transition.transitionId}.`); + const requestTypeField = jiraTicket.issue.fields?.customfield_10010; + if (requestTypeField?.requestType?.id) { + requestType = requestTypeField.requestType.id; + transitionId = jiraTicket.transition.transitionId; + } else { + logWarn('processJiraTicket', `${issueKey} - missing requestType: ${JSON.stringify(requestTypeField)}`); + } + } + + if (!issueKey || !requestType || !requests[requestType]) { + return; + } + + logger('processJiraTicket', `${issueKey} RequestType: ${requestType} Requests?: ${JSON.stringify(requests[requestType])}`); + + if (requests[requestType].transitions[transitionId]) { + if (jiraTicket.issue.fields.project.key == 'CHANGE') { + logger('processJiraTicket', `${issueKey} is a CHANGE.`); + handleApprovalNotifications(issueKey, jiraTicket, buildChangeApproval); + } else if (jiraTicket.issue.fields.project.key == 'REQUEST') { + logger('processJiraTicket', `${issueKey} is a REQUEST.`); + handleApprovalNotifications(issueKey, jiraTicket, buildRequestApproval); + } + return; + } + + if (!jiraTicket.changelog) { + return; + } + + const approvalStatuses = ['Pending Approval', 'Emergency Approval', 'Waiting for approval']; + for (const change of jiraTicket.changelog.items) { + if (change.field != 'Approvers' || !approvalStatuses.includes(jiraTicket.issue.fields.status.name)) { + continue; + } + if (jiraTicket.issue.fields.project.key == 'CHANGE') { + handleApprovalNotifications(issueKey, jiraTicket, buildChangeApproval); + } else { + handleApprovalNotifications(issueKey, jiraTicket, buildRequestApproval); + } + } + } + + return { processJiraTicket }; +} diff --git a/services/webex.js b/services/webex.js new file mode 100644 index 0000000..263f0be --- /dev/null +++ b/services/webex.js @@ -0,0 +1,121 @@ +import fetch from 'node-fetch'; + +export function createWebexService(config, log) { + const { logger, logError } = log; + + function handleWebexResponse(context, issueKey, response, responseText) { + if (!response.ok) { + logError(context, `Webex API error for ${issueKey} (HTTP ${response.status})`, responseText); + return false; + } + logger(context, `Successfully sent notification for ${issueKey}`); + return true; + } + + function sendTicketCard(issueKey, body) { + const requestOptions = { + method: 'POST', + headers: { + Authorization: `Bearer ${config.webex.token}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(body), + redirect: 'follow', + }; + + fetch('https://webexapis.com/v1/messages', requestOptions) + .then(response => response.text().then(text => ({ response, text }))) + .then(({ response, text }) => handleWebexResponse('sendTicketCard', issueKey, response, text)) + .catch(error => logError('sendTicketCard', `Network error sending to Webex for ${issueKey}`, error)); + } + + function sendWebexMessage(body) { + return new Promise(function (resolve, reject) { + const requestOptions = { + method: 'POST', + headers: { + Authorization: `Bearer ${config.webex.token}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(body), + redirect: 'follow', + }; + + fetch('https://webexapis.com/v1/messages', requestOptions) + .then(response => response.text().then(text => ({ response, text }))) + .then(({ response, text }) => { + if (!response.ok) { + return reject(new Error(`Webex API error (HTTP ${response.status}): ${text}`)); + } + try { + resolve(JSON.parse(text)); + } catch { + reject(new Error(`Invalid JSON response from Webex: ${text}`)); + } + }) + .catch(error => reject(error)); + }); + } + + function sendHighPriorityMessage(body) { + const requestOptions = { + method: 'POST', + headers: { + Authorization: `Bearer ${config.jiraNotifier.token}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(body), + redirect: 'follow', + }; + + fetch('https://webexapis.com/v1/messages', requestOptions) + .then(response => response.text().then(text => ({ response, text }))) + .then(({ response, text }) => handleWebexResponse('sendHighPriorityMessage', body.roomId || 'unknown', response, text)) + .catch(error => logError('sendHighPriorityMessage', 'Network error sending to Webex', error)); + } + + function processHighSeverity(jiraTicket, roomId) { + const jiraKey = jiraTicket.issue.key; + + if (jiraTicket.webhookEvent == 'comment_created' && jiraTicket.comment) { + const action = jiraTicket.comment.created == jiraTicket.comment.updated ? 'added a comment' : 'edited a comment'; + const userName = jiraTicket.comment.updateAuthor.displayName; + const projectKey = jiraTicket.issue.fields.project.name; + const comment = jiraTicket.comment.body; + sendHighPriorityMessage({ + markdown: `${userName} ${action} on the [${jiraKey}](https://aeo.atlassian.net/browse/${jiraKey}) issue in the ${projectKey} project to read as follows:\n${comment}`, + roomId, + }); + } + + if (jiraTicket.webhookEvent == 'jira:issue_updated' && jiraTicket.changelog) { + const userName = jiraTicket.user.displayName; + const statuses = ['status', 'Severity', 'priority', 'Severity (migrated)']; + let text = ''; + let addDescription = 0; + + for (const change of jiraTicket.changelog.items) { + if (statuses.includes(change.field)) { + text += `${userName} changed ${change.field} from ${change.fromString} to ${change.toString} for issue [${jiraKey}](https://aeo.atlassian.net/browse/${jiraKey}).\n`; + } + if (change.field == 'Severity' || change.field == 'priority') { + addDescription = 1; + } + } + + if (addDescription > 0) { + text += `Description / Details: ${jiraTicket.issue.fields.description}\n`; + } + + log.logDebug('processHighSeverity', `Sending high-priority update for ${jiraKey}`); + sendHighPriorityMessage({ markdown: text, roomId }); + } + } + + return { + sendTicketCard, + sendWebexMessage, + sendHighPriorityMessage, + processHighSeverity, + }; +}