import dotenv from 'dotenv'; dotenv.config(); const cloudId = process.env.JIRA_CLOUD_ID?.trim(); let baseUrl = process.env.JIRA_BASE_URL?.trim(); if (cloudId) { // When JIRA_CLOUD_ID is provided, use the api.atlassian.com/ex/jira gateway form. // This is the current style for addressing a specific Jira Cloud site (e.g. for // /rest/servicedeskapi/... and /rest/api/3/... calls). Falls back to JIRA_BASE_URL // for legacy site-based URLs like https://your-site.atlassian.net when no cloud ID is set. baseUrl = `https://api.atlassian.com/ex/jira/${cloudId}`; } else if (baseUrl) { // Normalize legacy site base (remove trailing slash) baseUrl = baseUrl.replace(/\/$/, ''); } // Validate required environment variables const requiredEnvVars = [ 'JIRA_EMAIL', 'JIRA_API_TOKEN', 'XAI_API_KEY' ]; const missingVars = requiredEnvVars.filter(env => !process.env[env]); if (missingVars.length > 0) { console.warn(`Missing required environment variables: ${missingVars.join(', ')}`); } export const config = { port: process.env.PORT || 1866, nodeEnv: process.env.NODE_ENV || 'development', jira: { baseUrl, cloudId: cloudId || null, authType: (process.env.JIRA_AUTH_TYPE || 'basic').toLowerCase(), // 'basic' or 'bearer' email: process.env.JIRA_EMAIL, apiToken: process.env.JIRA_API_TOKEN, serviceDeskId: process.env.JIRA_SERVICE_DESK_ID, // Role used for restricted/internal visibility on summary comments. // Common values: "Administrators", or a project role you have defined. commentVisibilityRole: process.env.JIRA_COMMENT_VISIBILITY_ROLE || 'Administrators', // Assets / CMDB configuration for Store Number object references. // These are used for the "service object" / Assets object lookup when creating SS tickets. // The lookup now uses the api.atlassian.com workspace-scoped endpoint: // https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/object/aql assetsWorkspaceId: process.env.JIRA_ASSETS_WORKSPACE_ID, // (optional) numeric schema or object type details assetsStoreSchemaId: process.env.JIRA_ASSETS_STORE_SCHEMA_ID, assetsStoreObjectTypeId: process.env.JIRA_ASSETS_STORE_OBJECT_TYPE_ID || '109', assetsStoreNumberAttribute: process.env.JIRA_ASSETS_STORE_NUMBER_ATTRIBUTE || 'Store Number', // If you know the attribute ID (e.g. 635 from schema), we can try "attribute[635]" form in AQL assetsStoreNumberAttributeId: process.env.JIRA_ASSETS_STORE_NUMBER_ATTRIBUTE_ID || null, // The custom field ID on the request that holds the Store Assets reference storeCustomFieldId: process.env.JIRA_STORE_CUSTOM_FIELD_ID || 'customfield_10261', }, xai: { apiKey: process.env.XAI_API_KEY, baseUrl: process.env.XAI_BASE_URL || 'https://api.x.ai/v1', } }; export default config;