import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, ConfigurationResource } from '../types'; /** * Configurations resource module for IT Glue API * * Provides methods to interact with the /configurations endpoint and related resources. * Configurations represent IT assets and infrastructure items tracked in IT Glue, such as servers, * workstations, network devices, software installations, and other technology components. * Each configuration has a type that defines its category and available fields. * * ## Related Resources * Configurations are commonly used with: * - {@link Organizations} - Parent organizations that own configurations * - {@link ConfigurationTypes} - Classify configurations by type (server, workstation, network device) * - {@link ConfigurationStatuses} - Track configuration lifecycle and status * - {@link ConfigurationInterfaces} - Manage network interfaces for configurations * - {@link Contacts} - People responsible for or associated with configurations * - {@link Locations} - Physical locations where configurations are deployed * - {@link Passwords} - Credentials associated with configuration access * - {@link Documents} - Documentation related to configurations * - {@link Manufacturers} - Hardware/software manufacturers of configurations * - {@link Models} - Specific product models of configurations * - {@link OperatingSystems} - Operating systems running on configurations * - {@link RelatedItems} - Create relationships between configurations and other resources * - {@link Tags} - Categorize and label configurations for better organization * - {@link Attachments} - Store files and documents related to configurations * * @see {@link Organizations#list} for retrieving configurations by organization * @see {@link ConfigurationTypes#list} for retrieving available configuration types * @see {@link ConfigurationStatuses#list} for retrieving available configuration statuses * @see {@link ConfigurationInterfaces#list} for managing configuration network interfaces * @see {@link Contacts#list} for retrieving contacts associated with configurations * * @example * import { ITGlueClient } from '../client'; * import { Configurations } from './resources/configurations'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const configurations = new Configurations(client); * * // List configurations * const list = await configurations.list(); * * // Get a single configuration * const config = await configurations.get('456'); * * // Create a configuration * const created = await configurations.create({ * data: { * type: 'configurations', * attributes: { name: 'Web Server 01' } * } * }); * * // Update a configuration * const updated = await configurations.update('456', { * data: { * type: 'configurations', * attributes: { name: 'Updated Web Server' } * } * }); * * // Delete a configuration * await configurations.delete('456'); * * @category Configurations */ export declare class Configurations { private client; private basePath; private paginationUtil; /** * Create a Configurations resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all configurations * @param {QueryUtilOptions} [options] - Optional query parameters (filter, sort, page, etc.) * @param {boolean} [allPages=false] - If true, fetches all pages automatically * @returns {Promise>} List of configurations and pagination metadata * @example * // Basic usage - get first page of configurations * const results = await client.configurations.list(); * console.log(`Found ${results.data.length} configurations`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with pagination and sorting * const results = await client.configurations.list({ * page: { number: 2, size: 50 }, * sort: '-updated_at', // Sort by most recently updated * include: ['configuration_type', 'organization', 'configuration_status'] // Include related data * }); * * @example * // Filtering configurations by type and organization * const servers = await client.configurations.list({ * filter: { * organization_id: '123', * configuration_type_id: '456', // Server type * configuration_status_id: '789' // Active status * }, * sort: 'name' * }); * * @example * // Get all configurations across multiple pages * const allConfigurations = await client.configurations.list({}, true); // allPages = true * console.log(`Retrieved all ${allConfigurations.data.length} configurations`); * * @example * // Manual pagination for configuration inventory * async function getAllConfigurationsByType(typeId) { * let page = 1; * let allConfigurations = []; * let hasMore = true; * * while (hasMore) { * const response = await client.configurations.list({ * filter: { configuration_type_id: typeId }, * page: { number: page, size: 100 }, * sort: 'name' * }); * * allConfigurations = [...allConfigurations, ...response.data]; * hasMore = response.meta.pagination.total_pages > page; * page++; * } * * return allConfigurations; * } * * @example * // Error handling for list operations * try { * const results = await client.configurations.list({ * filter: { invalid_field: 'value' } * }); * } catch (error) { * if (error.response?.status === 400) { * console.log('Invalid filter parameters:', error.response.data.errors); * } else if (error.response?.status === 401) { * console.log('Authentication failed - check your API key'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions to list configurations'); * } else { * console.log('Request failed:', error.message); * } * } */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single configuration by ID * @param {string} id - Configuration ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Configuration resource * @example * // Basic usage - get configuration by ID * const config = await client.configurations.get('456'); * console.log('Configuration name:', config.data.attributes.name); * console.log('Hostname:', config.data.attributes.hostname); * console.log('Primary IP:', config.data.attributes.primary_ip); * * @example * // Get configuration with related data included * const configWithRelated = await client.configurations.get('456', { * include: ['configuration_type', 'organization', 'contacts', 'configuration_status'] * }); * * // Access included data * const included = configWithRelated.included || []; * const configType = included.find(item => item.type === 'configuration_types'); * const organization = included.find(item => item.type === 'organizations'); * * @example * // Error handling for get operations * try { * const config = await client.configurations.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Configuration not found'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions'); * } else { * console.log('Error retrieving configuration:', error.message); * } * } * * @example * // Safe get with existence check * async function safeGetConfiguration(id) { * try { * const config = await client.configurations.get(id); * return config.data; * } catch (error) { * if (error.response?.status === 404) { * return null; // Configuration doesn't exist * } * throw error; // Re-throw other errors * } * } * @see * {@link Organizations#get} - Get specific organization details * {@link Organizations#list} - List organizations that owns this configuration * {@link ConfigurationTypes#get} - Get specific configurationtype details * {@link ConfigurationTypes#list} - List configurationtypes for this configuration category */ get(id: string, params?: QueryParams): Promise>; /** * Create a new configuration * @param {RequestBody} data - Configuration data (must be formatted according to JSON:API spec) * @returns {Promise>} Created configuration resource * @example * // Basic configuration creation * const newConfig = await client.configurations.create({ * data: { * type: 'configurations', * attributes: { * name: 'Web Server 01', * hostname: 'web01.company.com', * primary_ip: '192.168.1.100' * }, * relationships: { * organization: { * data: { type: 'organizations', id: '123' } * }, * configuration_type: { * data: { type: 'configuration_types', id: '456' } * } * } * } * }); * * console.log('Created configuration with ID:', newConfig.data.id); * * @example * // Advanced configuration creation with all fields and traits * const newConfig = await client.configurations.create({ * data: { * type: 'configurations', * attributes: { * name: 'Database Server Prod-01', * hostname: 'db-prod-01.company.com', * primary_ip: '10.0.1.50', * mac_address: '00:1B:44:11:3A:B7', * serial_number: 'DB2024-001', * asset_tag: 'ASSET-DB-001', * notes: 'Primary production database server', * traits: { * 'operating-system': 'Ubuntu 22.04 LTS', * 'cpu-cores': 16, * 'memory-gb': 64, * 'storage-tb': 2, * 'warranty-expiry': '2027-12-31', * 'backup-schedule': 'Daily at 2:00 AM' * } * }, * relationships: { * organization: { * data: { type: 'organizations', id: '123' } * }, * configuration_type: { * data: { type: 'configuration_types', id: '456' } * }, * configuration_status: { * data: { type: 'configuration_statuses', id: '789' } * } * } * } * }); * * @example * // Bulk configuration creation with error handling * async function createMultipleConfigurations(configList) { * const results = []; * const errors = []; * * for (const configData of configList) { * try { * const created = await client.configurations.create({ * data: { * type: 'configurations', * attributes: configData, * relationships: { * organization: { * data: { type: 'organizations', id: configData.organizationId } * }, * configuration_type: { * data: { type: 'configuration_types', id: configData.typeId } * } * } * } * }); * results.push(created.data); * } catch (error) { * errors.push({ configData, error: error.message }); * } * } * * return { results, errors }; * } * * @example * // Error handling for configuration creation * try { * const created = await client.configurations.create({ * data: { * type: 'configurations', * attributes: { * // Missing required name field * hostname: 'test.example.com' * } * } * }); * } catch (error) { * if (error.response?.status === 422) { * console.log('Validation errors:'); * error.response.data.errors.forEach(err => { * console.log(`- ${err.detail} (${err.source?.pointer})`); * }); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot create configuration'); * } else { * console.log('Creation failed:', error.message); * } * } * @see * {@link Organizations#create} - Create new organization * {@link Organizations#list} - List organizations that owns this configuration * {@link ConfigurationTypes#create} - Create new configurationtype * {@link ConfigurationTypes#list} - List configurationtypes for this configuration category */ create(data: RequestBody): Promise>; /** * Update a configuration by ID * @param {string} id - Configuration ID * @param {RequestBody} data - Updated configuration data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated configuration resource * @example * // Basic update - modify configuration details * const updatedConfig = await client.configurations.update('456', { * data: { * type: 'configurations', * attributes: { * name: 'Updated Web Server', * notes: 'Updated server configuration after maintenance' * } * } * }); * * console.log('Configuration updated successfully'); * * @example * // Update configuration traits and technical details * const updatedConfig = await client.configurations.update('456', { * data: { * type: 'configurations', * attributes: { * primary_ip: '10.0.1.51', * traits: { * 'memory-gb': 128, // Upgraded memory * 'cpu-cores': 24, // Upgraded CPU * 'last-maintenance': new Date().toISOString().split('T')[0], * 'next-maintenance': '2024-06-15' * } * } * } * }); * * @example * // Conditional update based on current state * async function conditionalUpdateConfiguration(id, updates) { * try { * // First, get current state * const current = await client.configurations.get(id); * * // Check if update is needed * const needsUpdate = Object.keys(updates).some( * key => current.data.attributes[key] !== updates[key] * ); * * if (!needsUpdate) { * console.log('Configuration is already up to date'); * return current; * } * * // Perform update * return await client.configurations.update(id, { * data: { * type: 'configurations', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * * @example * // Error handling for configuration updates * try { * const updated = await client.configurations.update('456', { * data: { * type: 'configurations', * attributes: { * primary_ip: 'invalid-ip-address' * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Configuration not found'); * } else if (error.response?.status === 422) { * console.log('Validation failed:', error.response.data.errors); * } else if (error.response?.status === 409) { * console.log('Conflict - configuration may have been modified by another user'); * } else { * console.log('Update failed:', error.message); * } * } * @see * {@link Organizations#update} - Update organization * {@link Organizations#get} - Get specific organization details * {@link ConfigurationTypes#update} - Update configurationtype * {@link ConfigurationTypes#get} - Get specific configurationtype details */ update(id: string, data: RequestBody): Promise>; /** * Delete a configuration by ID * @param {string} id - Configuration ID * @returns {Promise} * @example * // Basic deletion * await client.configurations.delete('456'); * console.log('Configuration deleted successfully'); * * @example * // Safe deletion with confirmation * async function safeDeleteConfiguration(id) { * try { * // First verify the configuration exists * const config = await client.configurations.get(id); * console.log(`Deleting configuration: ${config.data.attributes.name}`); * * // Perform deletion * await client.configurations.delete(id); * console.log('Configuration deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Configuration not found - may already be deleted'); * return false; * } * throw error; * } * } * * @example * // Bulk deletion with error handling * async function deleteMultipleConfigurations(configIds) { * const results = []; * * for (const id of configIds) { * try { * await client.configurations.delete(id); * results.push({ id, status: 'deleted' }); * } catch (error) { * results.push({ * id, * status: 'error', * error: error.response?.status === 404 ? 'not_found' : error.message * }); * } * } * * return results; * } * * @example * // Error handling for delete operations * try { * await client.configurations.delete('456'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Configuration not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete configuration'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - configuration is referenced by other resources'); * } else { * console.log('Deletion failed:', error.message); * } * } * @see * {@link Organizations#list} - List organizations that owns this configuration * {@link Organizations#get} - Get specific organization details * {@link ConfigurationTypes#list} - List configurationtypes for this configuration category * {@link ConfigurationTypes#get} - Get specific configurationtype details */ delete(id: string): Promise; }