/** * Manufacturers resource module for IT Glue API * * Provides methods to interact with the /manufacturers endpoint. * Manufacturers represent the companies that produce hardware and software products * tracked in IT Glue. They serve as reference data for organizing models, configurations, * and other assets by their manufacturer. Common examples include Dell, HP, Microsoft, * Cisco, VMware, and other technology vendors. * * Manufacturers are typically associated with: * - Models (specific product models from the manufacturer) * - Configurations (hardware/software items from the manufacturer) * - Assets (physical or virtual items produced by the manufacturer) * * ## Related Resources * Manufacturers are commonly used with: * - {@link Models} - Specific product models produced by manufacturers * - {@link Configurations} - IT assets and systems from specific manufacturers * - {@link FlexibleAssets} - Custom tracking of manufacturer relationships and contracts * - {@link Documents} - Manufacturer documentation, warranties, and support contracts * - {@link Contacts} - Manufacturer representatives and support contacts * - {@link Organizations} - Vendor organizations and manufacturer partnerships * - {@link RelatedItems} - Create relationships between manufacturers and other resources * - {@link Tags} - Categorize manufacturers by type, region, or partnership status * - {@link Attachments} - Store manufacturer documentation and product sheets * * @see {@link Models#list} for retrieving models by manufacturer * @see {@link Configurations#list} for retrieving configurations by manufacturer * @see {@link Organizations#list} for retrieving vendor organizations * @see {@link Contacts#list} for retrieving manufacturer contacts * * @example * import { ITGlueClient } from '../client'; * import { Manufacturers } from './resources/manufacturers'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const manufacturers = new Manufacturers(client); * * // List manufacturers * const list = await manufacturers.list(); * * // Get a single manufacturer * const manufacturer = await manufacturers.get('123'); * * // Create a manufacturer * const created = await manufacturers.create({ * data: { * type: 'manufacturers', * attributes: { * name: 'Acme Corporation' * } * } * }); * * // Update a manufacturer * const updated = await manufacturers.update('123', { * data: { * type: 'manufacturers', * attributes: { * name: 'Updated Manufacturer Name' * } * } * }); * * // Delete a manufacturer * await manufacturers.delete('123'); * * @category Reference Data */ import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, ManufacturerResource } from '../types'; export declare class Manufacturers { private client; private basePath; private paginationUtil; /** * Create a Manufacturers resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all manufacturers * @param {QueryUtilOptions} [options] - Optional query parameters (filter, sort, page, etc.) * @param {boolean} [allPages=false] - If true, fetches all pages automatically * @returns {Promise>} List of manufacturers and pagination metadata * @example * // Basic usage - get first page of manufacturers * const results = await client.manufacturers.list(); * console.log(`Found ${results.data.length} manufacturers`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with pagination and sorting * const results = await client.manufacturers.list({ * page: { number: 2, size: 50 }, * sort: 'name', // Sort alphabetically * include: ['models'] // Include related models * }); * * // Access manufacturer information * results.data.forEach(manufacturer => { * console.log(`Manufacturer: ${manufacturer.attributes.name}`); * console.log(`Notes: ${manufacturer.attributes.notes || 'No notes'}`); * }); * * @example * // Filtering manufacturers by name pattern * const techManufacturers = await client.manufacturers.list({ * filter: { * name: 'Tech' * }, * sort: 'name' * }); * * console.log(`Found ${techManufacturers.data.length} manufacturers with 'Tech' in name`); * * @example * // Get all manufacturers for vendor management * const allManufacturers = await client.manufacturers.list({}, true); // allPages = true * console.log(`Retrieved all ${allManufacturers.data.length} manufacturers`); * * // Group by manufacturer type/category * const manufacturersByType = { * hardware: [], * software: [], * networking: [], * other: [] * }; * * allManufacturers.data.forEach(manufacturer => { * const name = manufacturer.attributes.name.toLowerCase(); * const notes = (manufacturer.attributes.notes || '').toLowerCase(); * * if (name.includes('cisco') || name.includes('juniper') || notes.includes('network')) { * manufacturersByType.networking.push(manufacturer.attributes.name); * } else if (name.includes('microsoft') || name.includes('adobe') || notes.includes('software')) { * manufacturersByType.software.push(manufacturer.attributes.name); * } else if (name.includes('dell') || name.includes('hp') || name.includes('lenovo')) { * manufacturersByType.hardware.push(manufacturer.attributes.name); * } else { * manufacturersByType.other.push(manufacturer.attributes.name); * } * }); * * @example * // Manual pagination for large manufacturer datasets * async function getAllManufacturersWithModels() { * let page = 1; * let allManufacturers = []; * let hasMore = true; * * while (hasMore) { * const response = await client.manufacturers.list({ * page: { number: page, size: 100 }, * sort: 'name', * include: ['models'] * }); * * allManufacturers = [...allManufacturers, ...response.data]; * hasMore = response.meta.pagination.total_pages > page; * page++; * } * * return allManufacturers; * } * * @example * // Error handling for list operations * try { * const results = await client.manufacturers.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 manufacturers'); * } else { * console.log('Request failed:', error.message); * } * } */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single manufacturer by ID * @param {string} id - Manufacturer ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Manufacturer resource * @example * // Basic usage - get manufacturer by ID * const manufacturer = await client.manufacturers.get('123'); * console.log('Manufacturer name:', manufacturer.data.attributes.name); * console.log('Notes:', manufacturer.data.attributes.notes); * console.log('Created:', manufacturer.data.attributes.created_at); * * @example * // Get manufacturer with related models included * const manufacturerWithModels = await client.manufacturers.get('123', { * include: ['models'] * }); * * // Access included data * const included = manufacturerWithModels.included || []; * const models = included.filter(item => item.type === 'models'); * * console.log(`Manufacturer has ${models.length} models`); * models.forEach(model => { * console.log(`- Model: ${model.attributes.name}`); * }); * * @example * // Error handling for get operations * try { * const manufacturer = await client.manufacturers.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Manufacturer not found'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions'); * } else { * console.log('Error retrieving manufacturer:', error.message); * } * } * * @example * // Safe get with existence check * async function safeGetManufacturer(id) { * try { * const manufacturer = await client.manufacturers.get(id); * return manufacturer.data; * } catch (error) { * if (error.response?.status === 404) { * return null; // Manufacturer doesn't exist * } * throw error; // Re-throw other errors * } * } * @see * {@link Models#get} - Get specific model details * {@link Models#list} - List models related to manufacturers * {@link Configurations#get} - Get specific configuration details * {@link Configurations#list} - List configurations related to manufacturers */ get(id: string, params?: QueryParams): Promise>; /** * Create a new manufacturer * * Creates a new manufacturer entry in IT Glue. Manufacturers serve as reference data * for organizing models, configurations, and assets by their producer. Ensure the * manufacturer name is unique and follows standard naming conventions. * * @param {RequestBody} data - Manufacturer data (must be formatted according to JSON:API spec) * @returns {Promise>} Created manufacturer resource * @throws {Error} When validation fails (422) or unauthorized (401) * @example * // Basic manufacturer creation * const newManufacturer = await client.manufacturers.create({ * data: { * type: 'manufacturers', * attributes: { * name: 'Acme Corporation', * notes: 'Leading provider of enterprise solutions' * } * } * }); * * console.log('Created manufacturer with ID:', newManufacturer.data.id); * * @example * // Create technology vendor with detailed information * const newManufacturer = await client.manufacturers.create({ * data: { * type: 'manufacturers', * attributes: { * name: 'TechVendor Solutions Inc.', * notes: 'Specializes in enterprise networking equipment and cloud infrastructure solutions. Founded in 2010, serves Fortune 500 companies globally.' * } * } * }); * * @example * // Bulk manufacturer creation with error handling * async function createMultipleManufacturers(manufacturerList) { * const results = []; * const errors = []; * * for (const manufacturerData of manufacturerList) { * try { * const created = await client.manufacturers.create({ * data: { * type: 'manufacturers', * attributes: manufacturerData * } * }); * results.push(created.data); * } catch (error) { * errors.push({ manufacturerData, error: error.message }); * } * } * * return { results, errors }; * } * * // Usage * const manufacturersToCreate = [ * { name: 'CloudTech Systems', notes: 'Cloud infrastructure provider' }, * { name: 'SecureNet Solutions', notes: 'Cybersecurity hardware manufacturer' }, * { name: 'DataFlow Technologies', notes: 'Storage and backup solutions' } * ]; * * @example * // Error handling for manufacturer creation * try { * const created = await client.manufacturers.create({ * data: { * type: 'manufacturers', * 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 manufacturer'); * } else if (error.response?.status === 409) { * console.log('Conflict - manufacturer with this name may already exist'); * } else { * console.log('Creation failed:', error.message); * } * } * @see * {@link Models#create} - Create new model * {@link Models#list} - List models related to manufacturers * {@link Configurations#create} - Create new configuration * {@link Configurations#list} - List configurations related to manufacturers */ create(data: RequestBody): Promise>; /** * Update a manufacturer by ID * * Updates an existing manufacturer. Changes to manufacturer information will be * reflected in all associated models, configurations, and assets that reference * this manufacturer. Use caution when updating manufacturer names as this may * affect reporting and asset organization. * * @param {string} id - Manufacturer ID * @param {RequestBody} data - Updated manufacturer data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated manufacturer resource * @throws {Error} When manufacturer not found (404) or validation fails (422) * @example * // Basic update - modify manufacturer name and notes * const updatedManufacturer = await client.manufacturers.update('123', { * data: { * type: 'manufacturers', * attributes: { * name: 'Updated Corporation Name', * notes: 'Company rebranded after merger' * } * } * }); * * console.log('Manufacturer updated successfully'); * * @example * // Update manufacturer with acquisition information * const updatedManufacturer = await client.manufacturers.update('123', { * data: { * type: 'manufacturers', * attributes: { * name: 'TechVendor Solutions Inc. (acquired by MegaCorp)', * notes: 'Acquired by MegaCorp in 2024. Continuing operations under new ownership with expanded product portfolio.' * } * } * }); * * @example * // Conditional update based on current state * async function conditionalUpdateManufacturer(id, updates) { * try { * // First, get current state * const current = await client.manufacturers.get(id); * * // Check if update is needed * const needsUpdate = Object.keys(updates).some( * key => current.data.attributes[key] !== updates[key] * ); * * if (!needsUpdate) { * console.log('Manufacturer is already up to date'); * return current; * } * * // Perform update * return await client.manufacturers.update(id, { * data: { * type: 'manufacturers', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * * @example * // Error handling for manufacturer updates * try { * const updated = await client.manufacturers.update('invalid-id', { * data: { * type: 'manufacturers', * attributes: { * name: 'New Name' * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Manufacturer 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 - manufacturer name may already be in use'); * } else { * console.log('Update failed:', error.message); * } * } * @see * {@link Models#update} - Update model * {@link Models#get} - Get specific model details * {@link Configurations#update} - Update configuration * {@link Configurations#get} - Get specific configuration details */ update(id: string, data: RequestBody): Promise>; /** * Delete a manufacturer by ID * * Permanently removes a manufacturer from IT Glue. This operation will fail if * the manufacturer is referenced by any models, configurations, or other assets. * Consider updating or removing dependent resources before deleting the manufacturer. * * @param {string} id - Manufacturer ID * @returns {Promise} * @throws {Error} When manufacturer not found (404) or has dependent resources (409) * @example * // Basic deletion * await client.manufacturers.delete('123'); * console.log('Manufacturer deleted successfully'); * * @example * // Safe deletion with confirmation * async function safeDeleteManufacturer(id) { * try { * // First verify the manufacturer exists * const manufacturer = await client.manufacturers.get(id); * console.log(`Deleting manufacturer: ${manufacturer.data.attributes.name}`); * * // Perform deletion * await client.manufacturers.delete(id); * console.log('Manufacturer deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Manufacturer not found - may already be deleted'); * return false; * } * throw error; * } * } * * @example * // Bulk deletion with error handling * async function deleteMultipleManufacturers(manufacturerIds) { * const results = []; * * for (const id of manufacturerIds) { * try { * await client.manufacturers.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 manufacturer deletion * try { * await client.manufacturers.delete('123'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Manufacturer not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete manufacturer'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - manufacturer is referenced by models or assets'); * console.log('Remove dependent resources first, then retry deletion'); * } else { * console.log('Deletion failed:', error.message); * } * } * @see * {@link Models#list} - List models related to manufacturers * {@link Models#get} - Get specific model details * {@link Configurations#list} - List configurations related to manufacturers * {@link Configurations#get} - Get specific configuration details */ delete(id: string): Promise; }