// discover-ss-fields.js // One-off helper to dump JSM request-type field definitions for the Store // Support service desk. Output files (ss-fields-.json) are used to keep // REQUEST_TYPE_MAP in src/services/jiraService.js in sync with what JSM // actually accepts. // // Usage: node discover-ss-fields.js // Reads credentials from .env — never commit real tokens into this file. import 'dotenv/config'; import fetch from 'node-fetch'; import fs from 'fs/promises'; const BASE_URL = (process.env.JIRA_BASE_URL || 'https://your-site.atlassian.net').replace(/\/$/, ''); const SERVICE_DESK_ID = process.env.JIRA_SERVICE_DESK_ID || '170'; 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 headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Basic ' + Buffer.from(`${EMAIL}:${TOKEN}`).toString('base64') }; // Request-type ids that we care about (matches REQUEST_TYPE_MAP in jiraService.js). const importantTypes = [269, 266, 273, 274, 267, 275, 272, 268, 271, 270, 426, 493]; async function getFields(requestTypeId) { console.log(`Fetching fields for request type ${requestTypeId}...`); const res = await fetch(`${BASE_URL}/rest/servicedeskapi/servicedesk/${SERVICE_DESK_ID}/requesttype/${requestTypeId}/field`, { headers }); const data = await res.json(); if (res.ok) { await fs.writeFile(`ss-fields-${requestTypeId}.json`, JSON.stringify(data, null, 2)); console.log(` saved ss-fields-${requestTypeId}.json`); } else { console.error(' error:', data); } return data; } for (const id of importantTypes) { await getFields(id); } console.log('\nDone. Check the generated ss-fields-*.json files.');