Introduces integration-based webhook registration, message parsing, dry-run monitoring, JSM ticket creation, and OAuth token refresh for DC Ops spaces. Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
2.3 KiB
JavaScript
70 lines
2.3 KiB
JavaScript
// Dump JSM request-type field definitions for validation and config review.
|
|
//
|
|
// Usage:
|
|
// JIRA_SERVICE_DESK_ID=171 node scripts/discover-jsm-fields.js 289
|
|
// node scripts/discover-jsm-fields.js 289 270
|
|
|
|
import dotenv from 'dotenv';
|
|
import fetch from 'node-fetch';
|
|
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
|
|
dotenv.config();
|
|
|
|
const cloudId = process.env.JIRA_CLOUD_ID?.trim();
|
|
const baseUrl = cloudId
|
|
? `https://api.atlassian.com/ex/jira/${cloudId}`
|
|
: (process.env.JIRA_BASE_URL || 'https://aeo.atlassian.net').replace(/\/$/, '');
|
|
const serviceDeskId = process.env.JIRA_SERVICE_DESK_ID || '171';
|
|
const email = process.env.JIRA_EMAIL;
|
|
const token = process.env.JIRA_API_TOKEN;
|
|
|
|
if (!email || !token) {
|
|
console.error('JIRA_EMAIL and JIRA_API_TOKEN must be set in .env');
|
|
process.exit(1);
|
|
}
|
|
|
|
const requestTypeIds = process.argv.slice(2).map(Number).filter(Boolean);
|
|
if (requestTypeIds.length === 0) {
|
|
console.error('Usage: node scripts/discover-jsm-fields.js <requestTypeId> [requestTypeId...]');
|
|
process.exit(1);
|
|
}
|
|
|
|
const headers = {
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Basic ${Buffer.from(`${email}:${token}`).toString('base64')}`,
|
|
};
|
|
|
|
async function getFields(requestTypeId) {
|
|
console.log(`Fetching fields for service desk ${serviceDeskId}, request type ${requestTypeId}...`);
|
|
const url = `${baseUrl}/rest/servicedeskapi/servicedesk/${serviceDeskId}/requesttype/${requestTypeId}/field`;
|
|
const response = await fetch(url, { headers });
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
console.error(` error (${response.status}):`, data);
|
|
return null;
|
|
}
|
|
|
|
const outputPath = path.join('config', `jsm-fields-${requestTypeId}.json`);
|
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
await fs.writeFile(outputPath, JSON.stringify(data, null, 2));
|
|
console.log(` saved ${outputPath}`);
|
|
|
|
const required = (data.requestTypeFields || []).filter(field => field.required);
|
|
if (required.length > 0) {
|
|
console.log(' required fields:');
|
|
for (const field of required) {
|
|
console.log(` - ${field.fieldId} (${field.name})`);
|
|
}
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
for (const requestTypeId of requestTypeIds) {
|
|
await getFields(requestTypeId);
|
|
}
|
|
|
|
console.log('\nDone.');
|