/** * OperatingSystems resource module for IT Glue API * * Provides methods to interact with the /operating_systems endpoint. * Operating systems represent the software platforms that run on hardware devices * and virtual machines tracked in IT Glue. They serve as reference data for * organizing configurations, assets, and software inventory by their underlying * operating system. Examples include Windows Server 2022, Ubuntu 22.04 LTS, * macOS Ventura, iOS 16, and various Linux distributions. * * ## Related Resources * Operating systems are commonly used with: * - {@link Configurations} - IT assets and devices that run these operating systems * - {@link ConfigurationTypes} - Hardware and software categories that use operating systems * - {@link Models} - Hardware and software models compatible with operating systems * - {@link Platforms} - Hardware/software platforms that support operating systems * - {@link Manufacturers} - Companies that produce devices compatible with operating systems * - {@link Organizations} - Organizations that deploy and manage operating systems * - {@link FlexibleAssets} - Custom tracking of OS licenses, patches, and compliance * - {@link Documents} - Installation guides, policies, and OS documentation * - {@link Passwords} - System credentials and admin accounts for operating systems * - {@link RelatedItems} - Create relationships between operating systems and other resources * - {@link Tags} - Categorize operating systems by version, support status, or purpose * - {@link Attachments} - Store installation media, patches, and OS documentation * * @see {@link Configurations#list} for retrieving configurations by operating system * @see {@link ConfigurationTypes#list} for retrieving configuration types * @see {@link Models#list} for retrieving compatible hardware/software models * @see {@link Platforms#list} for retrieving supported platforms * * @example * import { ITGlueClient } from '../client'; * import { OperatingSystems } from './resources/operating-systems'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const operatingSystems = new OperatingSystems(client); * * // List operating systems * const list = await operatingSystems.list(); * * // Get a single operating system * const os = await operatingSystems.get('123'); * * // Create an operating system * const created = await operatingSystems.create({ * data: { * type: 'operating_systems', * attributes: { * name: 'Ubuntu 22.04 LTS' * } * } * }); * * // Update an operating system * const updated = await operatingSystems.update('123', { * data: { * type: 'operating_systems', * attributes: { * name: 'Ubuntu 22.04.3 LTS' * } * } * }); * * // Delete an operating system * await operatingSystems.delete('123'); * * @category Reference Data */ import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, OperatingSystemResource } from '../types'; export declare class OperatingSystems { private client; private basePath; private paginationUtil; /** * Create an OperatingSystems resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all operating systems * @param {QueryUtilOptions} [options] - Optional query parameters (filter, sort, page, etc.) * @param {boolean} [allPages=false] - If true, fetches all pages automatically * @returns {Promise>} List of operating systems and pagination metadata * @example * // Basic usage - get first page of operating systems * const results = await client.operatingSystems.list(); * console.log(`Found ${results.data.length} operating systems`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with pagination and sorting * const results = await client.operatingSystems.list({ * page: { number: 2, size: 50 }, * sort: 'name', // Sort alphabetically * include: ['configurations', 'models'] // Include related data * }); * * // Access operating system information * results.data.forEach(os => { * console.log(`OS: ${os.attributes.name}`); * console.log(`Notes: ${os.attributes.notes || 'No notes'}`); * }); * * @example * // Filtering operating systems by name pattern * const windowsOS = await client.operatingSystems.list({ * filter: { * name: 'Windows' * }, * sort: 'name' * }); * * console.log(`Found ${windowsOS.data.length} Windows operating systems`); * * @example * // Get all operating systems for inventory management * const allOS = await client.operatingSystems.list({}, true); // allPages = true * console.log(`Retrieved all ${allOS.data.length} operating systems`); * * // Group by OS family * const osByFamily = {}; * allOS.data.forEach(os => { * const name = os.attributes.name.toLowerCase(); * let family = 'Other'; * * if (name.includes('windows')) family = 'Windows'; * else if (name.includes('ubuntu') || name.includes('debian')) family = 'Debian'; * else if (name.includes('centos') || name.includes('rhel') || name.includes('fedora')) family = 'Red Hat'; * else if (name.includes('macos') || name.includes('mac os')) family = 'macOS'; * else if (name.includes('linux')) family = 'Linux'; * * if (!osByFamily[family]) osByFamily[family] = []; * osByFamily[family].push(os.attributes.name); * }); * * @example * // Manual pagination for large OS datasets * async function getAllOperatingSystemsWithDetails() { * let page = 1; * let allOS = []; * let hasMore = true; * * while (hasMore) { * const response = await client.operatingSystems.list({ * page: { number: page, size: 100 }, * sort: 'name', * include: ['configurations'] * }); * * allOS = [...allOS, ...response.data]; * hasMore = response.meta.pagination.total_pages > page; * page++; * } * * return allOS; * } * * @example * // Error handling for list operations * try { * const results = await client.operatingSystems.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 operating systems'); * } else { * console.log('Request failed:', error.message); * } * } */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single operating system by ID * @param {string} id - Operating system ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Operating system resource * @example * // Basic usage - get operating system by ID * const os = await client.operatingSystems.get('123'); * console.log('OS name:', os.data.attributes.name); * console.log('Notes:', os.data.attributes.notes); * console.log('Created:', os.data.attributes.created_at); * * @example * // Get operating system with related data included * const osWithRelated = await client.operatingSystems.get('123', { * include: ['configurations', 'models'] * }); * * // Access included data * const included = osWithRelated.included || []; * const configurations = included.filter(item => item.type === 'configurations'); * const models = included.filter(item => item.type === 'models'); * * console.log(`OS has ${configurations.length} configurations and ${models.length} models`); * * @example * // Error handling for get operations * try { * const os = await client.operatingSystems.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Operating system not found'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions'); * } else { * console.log('Error retrieving operating system:', error.message); * } * } * * @example * // Safe get with existence check * async function safeGetOperatingSystem(id) { * try { * const os = await client.operatingSystems.get(id); * return os.data; * } catch (error) { * if (error.response?.status === 404) { * return null; // Operating system doesn't exist * } * throw error; // Re-throw other errors * } * } */ get(id: string, params?: QueryParams): Promise>; /** * Create a new operating system * * Creates a new operating system entry in IT Glue. Operating systems serve as * reference data for organizing configurations and assets by their underlying * platform. Ensure the OS name includes version information and follows * standard naming conventions for consistency. * * @param {RequestBody} data - Operating system data (must be formatted according to JSON:API spec) * @returns {Promise>} Created operating system resource * @throws {Error} When validation fails (422) or unauthorized (401) * @example * // Basic operating system creation * const newOS = await client.operatingSystems.create({ * data: { * type: 'operating_systems', * attributes: { * name: 'Windows Server 2022 Standard', * notes: 'Latest Windows Server version with enhanced security features' * } * } * }); * * console.log('Created operating system with ID:', newOS.data.id); * * @example * // Create Linux distribution with detailed information * const newOS = await client.operatingSystems.create({ * data: { * type: 'operating_systems', * attributes: { * name: 'Ubuntu 22.04.3 LTS (Jammy Jellyfish)', * notes: 'Long-term support release with 5 years of updates. Includes enhanced security features and improved hardware support.' * } * } * }); * * @example * // Bulk operating system creation with error handling * async function createMultipleOperatingSystems(osList) { * const results = []; * const errors = []; * * for (const osData of osList) { * try { * const created = await client.operatingSystems.create({ * data: { * type: 'operating_systems', * attributes: osData * } * }); * results.push(created.data); * } catch (error) { * errors.push({ osData, error: error.message }); * } * } * * return { results, errors }; * } * * // Usage * const osesToCreate = [ * { name: 'Windows 11 Pro', notes: 'Latest Windows desktop OS' }, * { name: 'macOS Ventura 13.6', notes: 'Latest macOS version' }, * { name: 'CentOS Stream 9', notes: 'Rolling release RHEL upstream' } * ]; * * @example * // Error handling for operating system creation * try { * const created = await client.operatingSystems.create({ * data: { * type: 'operating_systems', * attributes: { * name: '' // Invalid empty name * } * } * }); * } 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 operating system'); * } else if (error.response?.status === 409) { * console.log('Conflict - operating system with this name may already exist'); * } else { * console.log('Creation failed:', error.message); * } * } */ create(data: RequestBody): Promise>; /** * Update an operating system by ID * * Updates an existing operating system. Changes to operating system information * will be reflected in all associated configurations and assets that reference * this OS. Use caution when updating OS names as this may affect asset tracking, * compliance reporting, and software inventory management. * * @param {string} id - Operating system ID * @param {RequestBody} data - Updated operating system data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated operating system resource * @throws {Error} When operating system not found (404) or validation fails (422) * @example * // Basic update - modify OS name and notes * const updatedOS = await client.operatingSystems.update('123', { * data: { * type: 'operating_systems', * attributes: { * name: 'Windows Server 2022 Datacenter', * notes: 'Upgraded to Datacenter edition for virtualization features' * } * } * }); * * console.log('Operating system updated successfully'); * * @example * // Update Linux distribution with patch level * const updatedOS = await client.operatingSystems.update('123', { * data: { * type: 'operating_systems', * attributes: { * name: 'Ubuntu 22.04.3 LTS (Jammy Jellyfish)', * notes: 'Updated to latest patch release with security fixes and kernel updates' * } * } * }); * * @example * // Conditional update based on current state * async function conditionalUpdateOS(id, updates) { * try { * // First, get current state * const current = await client.operatingSystems.get(id); * * // Check if update is needed * const needsUpdate = Object.keys(updates).some( * key => current.data.attributes[key] !== updates[key] * ); * * if (!needsUpdate) { * console.log('Operating system is already up to date'); * return current; * } * * // Perform update * return await client.operatingSystems.update(id, { * data: { * type: 'operating_systems', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * * @example * // Error handling for operating system updates * try { * const updated = await client.operatingSystems.update('invalid-id', { * data: { * type: 'operating_systems', * attributes: { * name: 'New OS Name' * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Operating system 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 - operating system name may already be in use'); * } else { * console.log('Update failed:', error.message); * } * } */ update(id: string, data: RequestBody): Promise>; /** * Delete an operating system by ID * * Permanently removes an operating system from IT Glue. This operation will fail * if the operating system is referenced by any configurations, assets, or other * resources. Consider updating or removing dependent resources before deleting * the operating system to maintain data integrity. * * @param {string} id - Operating system ID * @returns {Promise} * @throws {Error} When operating system not found (404) or has dependent resources (409) * @example * // Basic deletion * await client.operatingSystems.delete('123'); * console.log('Operating system deleted successfully'); * * @example * // Safe deletion with confirmation * async function safeDeleteOperatingSystem(id) { * try { * // First verify the operating system exists * const os = await client.operatingSystems.get(id); * console.log(`Deleting operating system: ${os.data.attributes.name}`); * * // Perform deletion * await client.operatingSystems.delete(id); * console.log('Operating system deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Operating system not found - may already be deleted'); * return false; * } * throw error; * } * } * * @example * // Bulk deletion with error handling * async function deleteMultipleOperatingSystems(osIds) { * const results = []; * * for (const id of osIds) { * try { * await client.operatingSystems.delete(id); * results.push({ id, status: 'deleted' }); * } catch (error) { * let errorType = 'unknown'; * if (error.response?.status === 404) errorType = 'not_found'; * else if (error.response?.status === 409) errorType = 'has_dependencies'; * * results.push({ * id, * status: 'error', * error: errorType, * message: error.message * }); * } * } * * return results; * } * * @example * // Error handling for operating system deletion * try { * await client.operatingSystems.delete('123'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Operating system not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete operating system'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - operating system is referenced by configurations or assets'); * console.log('Remove dependent resources first, then retry deletion'); * } else { * console.log('Deletion failed:', error.message); * } * } */ delete(id: string): Promise; }