import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, ConfigurationTypeResource } from '../types'; /** * ConfigurationTypes resource module for IT Glue API * * Provides methods to interact with the /configuration_types endpoint. * Configuration types define categories and templates for configurations, such as "Server", * "Workstation", "Network Device", etc. Each type defines what fields and traits are * available for configurations of that type. * * ## Related Resources * Configuration types are commonly used with: * - {@link Configurations} - IT assets that are classified by configuration types * - {@link ConfigurationStatuses} - Status options available for configurations of this type * - {@link ConfigurationInterfaces} - Network interfaces for configurations of this type * - {@link Organizations} - Organizations that own configurations of this type * - {@link Models} - Hardware/software models associated with configuration types * - {@link Manufacturers} - Manufacturers of hardware/software for configuration types * - {@link OperatingSystems} - Operating systems that run on configurations of this type * - {@link FlexibleAssets} - Custom tracking of configuration type relationships * - {@link Documents} - Documentation and templates for configuration types * - {@link RelatedItems} - Create relationships between configuration types and other resources * - {@link Tags} - Categorize configuration types by purpose or technology * * @see {@link Configurations#list} for retrieving configurations by type * @see {@link ConfigurationStatuses#list} for retrieving available statuses * @see {@link ConfigurationInterfaces#list} for managing configuration interfaces * @see {@link Models#list} for retrieving models associated with configuration types * * @example * import { ITGlueClient } from '../client'; * import { ConfigurationTypes } from './resources/configuration-types'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const configTypes = new ConfigurationTypes(client); * * // List configuration types * const list = await configTypes.list(); * * // Get a single configuration type * const type = await configTypes.get('123'); * * // Create a configuration type * const created = await configTypes.create({ * data: { * type: 'configuration_types', * attributes: { name: 'Database Server' } * } * }); * * // Update a configuration type * const updated = await configTypes.update('123', { * data: { * type: 'configuration_types', * attributes: { name: 'Updated Server Type' } * } * }); * * // Delete a configuration type * await configTypes.delete('123'); * * @category Configurations */ export declare class ConfigurationTypes { private client; private basePath; private paginationUtil; /** * Create a ConfigurationTypes resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all configuration types * @param {QueryUtilOptions} [options] - Optional query parameters (filter, sort, page, etc.) * @param {boolean} [allPages=false] - If true, fetches all pages automatically * @returns {Promise>} List of configuration types and pagination metadata * @example * // Basic usage - get first page of configuration types * const results = await client.configurationTypes.list(); * console.log(`Found ${results.data.length} configuration types`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with pagination and sorting * const results = await client.configurationTypes.list({ * page: { number: 2, size: 50 }, * sort: '-updated_at', // Sort by most recently updated * include: ['configurations'] // Include related configurations * }); * * @example * // Filtering results by name pattern * const filtered = await client.configurationTypes.list({ * filter: { * name: 'Server' * }, * sort: 'name' * }); * * console.log('Server types found:'); * filtered.data.forEach(type => { * console.log(`- ${type.attributes.name}: ${type.attributes.description || 'No description'}`); * }); * * @example * // Get all results across multiple pages with category grouping * const allResults = await client.configurationTypes.list({}, true); // allPages = true * * // Group by category for inventory management * const categories = {}; * allResults.data.forEach(type => { * const category = type.attributes.name.includes('Server') ? 'Servers' : * type.attributes.name.includes('Network') ? 'Network' : * type.attributes.name.includes('Workstation') ? 'Workstations' : 'Other'; * * if (!categories[category]) categories[category] = []; * categories[category].push(type); * }); * * console.log('Configuration types by category:', categories); * * @example * // Manual pagination handling for large datasets * async function getAllConfigurationTypes() { * let page = 1; * let allResults = []; * let hasMore = true; * * while (hasMore) { * const response = await client.configurationTypes.list({ * page: { number: page, size: 100 } * }); * * allResults = [...allResults, ...response.data]; * hasMore = response.meta.pagination.total_pages > page; * page++; * } * * return allResults; * } * * @example * // Error handling for list operations * try { * const results = await client.configurationTypes.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'); * } else { * console.log('Request failed:', error.message); * } * } */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single configuration type by ID * @param {string} id - Configuration type ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Configuration type resource * @example * // Basic usage - get configuration type by ID * const configType = await client.configurationTypes.get('123'); * console.log('Configuration type name:', configType.data.attributes.name); * console.log('Description:', configType.data.attributes.description); * console.log('Icon:', configType.data.attributes.icon); * * @example * // Get configuration type with related configurations * const configTypeWithConfigs = await client.configurationTypes.get('123', { * include: ['configurations'] * }); * * // Access included data * const included = configTypeWithConfigs.included || []; * const configurations = included.filter(item => item.type === 'configurations'); * console.log(`Found ${configurations.length} configurations of this type`); * * @example * // Safe get with existence check * async function safeGetConfigurationType(id) { * try { * const configType = await client.configurationTypes.get(id); * return configType.data; * } catch (error) { * if (error.response?.status === 404) { * return null; // Configuration type doesn't exist * } * throw error; // Re-throw other errors * } * } */ get(id: string, params?: QueryParams): Promise>; /** * Create a new configuration type * @param {RequestBody} data - Configuration type data (must be formatted according to JSON:API spec) * @returns {Promise>} Created configuration type resource * @example * // Basic creation with required fields * const newConfigType = await client.configurationTypes.create({ * data: { * type: 'configuration_types', * attributes: { * name: 'Database Server', * description: 'Database server configurations' * } * } * }); * * console.log('Created configuration type with ID:', newConfigType.data.id); * * @example * // Advanced creation with all fields and settings * const newConfigType = await client.configurationTypes.create({ * data: { * type: 'configuration_types', * attributes: { * name: 'Network Switch', * description: 'Network switching equipment for data center operations', * icon: 'network-switch', * show_in_summary: true, * enabled: true * } * } * }); * * @example * // Bulk creation with error handling * async function createMultipleConfigurationTypes(types) { * const results = []; * const errors = []; * * for (const typeData of types) { * try { * const created = await client.configurationTypes.create({ * data: { * type: 'configuration_types', * attributes: typeData * } * }); * results.push(created.data); * } catch (error) { * errors.push({ typeData, error: error.message }); * } * } * * return { results, errors }; * } * * // Usage * const typesToCreate = [ * { name: 'Web Server', description: 'Web application servers', icon: 'server' }, * { name: 'Load Balancer', description: 'Traffic distribution devices', icon: 'balance-scale' }, * { name: 'Firewall', description: 'Network security appliances', icon: 'shield-alt' } * ]; * * @example * // Error handling for validation failures * try { * const newConfigType = await client.configurationTypes.create({ * data: { * type: 'configuration_types', * attributes: { * // Missing required name field * description: 'Missing name field' * } * } * }); * } 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 type'); * } else if (error.response?.status === 409) { * console.log('Conflict - configuration type with this name already exists'); * } else { * console.log('Creation failed:', error.message); * } * } */ create(data: RequestBody): Promise>; /** * Update a configuration type by ID * @param {string} id - Configuration type ID * @param {RequestBody} data - Updated configuration type data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated configuration type resource * @example * // Basic update - modify specific fields * const updatedConfigType = await client.configurationTypes.update('123', { * data: { * type: 'configuration_types', * attributes: { * name: 'Updated Server Type', * description: 'Updated description for server configurations' * } * } * }); * * console.log('Updated configuration type:', updatedConfigType.data.attributes.name); * * @example * // Advanced update with icon and display settings * const updatedConfigType = await client.configurationTypes.update('123', { * data: { * type: 'configuration_types', * attributes: { * icon: 'server-rack', * show_in_summary: true, * enabled: true, * description: 'High-performance server configurations with enhanced monitoring' * } * } * }); * * @example * // Conditional update based on current state * async function conditionalUpdateConfigurationType(id, updates) { * try { * // First, get current state * const current = await client.configurationTypes.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 type is already up to date'); * return current; * } * * // Perform update * return await client.configurationTypes.update(id, { * data: { * type: 'configuration_types', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * * @example * // Error handling for update operations * try { * const updated = await client.configurationTypes.update('123', { * data: { * type: 'configuration_types', * attributes: { * name: '' // Invalid empty name * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Configuration type 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 type may have been modified by another user'); * } else { * console.log('Update failed:', error.message); * } * } */ update(id: string, data: RequestBody): Promise>; /** * Delete a configuration type by ID * @param {string} id - Configuration type ID * @returns {Promise} * @example * // Basic deletion * await client.configurationTypes.delete('123'); * console.log('Configuration type deleted successfully'); * * @example * // Safe deletion with confirmation * async function safeDeleteConfigurationType(id) { * try { * // First verify the configuration type exists * const configType = await client.configurationTypes.get(id); * console.log(`Deleting configuration type: ${configType.data.attributes.name}`); * * // Perform deletion * await client.configurationTypes.delete(id); * console.log('Configuration type deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Configuration type not found - may already be deleted'); * return false; * } * throw error; * } * } * * @example * // Bulk deletion with error handling * async function deleteMultipleConfigurationTypes(ids) { * const results = []; * * for (const id of ids) { * try { * await client.configurationTypes.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.configurationTypes.delete('123'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Configuration type not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete configuration type'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - configuration type is referenced by existing configurations'); * } else { * console.log('Deletion failed:', error.message); * } * } */ delete(id: string): Promise; }