// discover-ss-request-types.js // One-off helper to list all JSM request types on the Store Support service // desk. Produces ss-request-types.json (raw) and ss-request-types-clean.json // (id/name/issueTypeId only) — both useful for maintaining REQUEST_TYPE_MAP // in src/services/jiraService.js. // // Usage: node discover-ss-request-types.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') }; async function getRequestTypes() { console.log(`Fetching request types for service desk ${SERVICE_DESK_ID}...\n`); const res = await fetch(`${BASE_URL}/rest/servicedeskapi/servicedesk/${SERVICE_DESK_ID}/requesttype?limit=100`, { headers }); const data = await res.json(); if (!res.ok) { console.error('Error:', data); return; } console.log(`Found ${data.values.length} request types.\n`); await fs.writeFile('ss-request-types.json', JSON.stringify(data, null, 2)); console.log('Full list saved to ss-request-types.json'); const mapping = data.values.map(rt => ({ id: rt.id, name: rt.name, defaultName: rt.defaultName, description: rt.description, issueTypeId: rt.issueTypeId, groupIds: rt.groupIds, canCreateRequest: rt.canCreateRequest })); await fs.writeFile('ss-request-types-clean.json', JSON.stringify(mapping, null, 2)); console.log('Clean mapping saved to ss-request-types-clean.json'); } async function getFieldsForRequestType(requestTypeId) { console.log(`\nFetching 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) { console.error('Error:', data); return null; } await fs.writeFile(`fields-requesttype-${requestTypeId}.json`, JSON.stringify(data, null, 2)); console.log(`Fields saved to fields-requesttype-${requestTypeId}.json`); return data; } await getRequestTypes(); // Fetch fields for specific request types by uncommenting below. // await getFieldsForRequestType(269); // Register Not Functioning Properly // await getFieldsForRequestType(266); // Broken Device / Hardware // await getFieldsForRequestType(426); // UKG Pro / Workforce Management Issues