import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, ContactTypeResource } from '../types'; /** * ContactTypes resource module for IT Glue API * * Provides methods to interact with the /contact_types endpoint. * Contact types define categorizations for contacts in IT Glue (Employee, Manager, Vendor, etc.). * These types help organize and classify contacts based on their role or relationship to your organization. * * ## Related Resources * Contact types are commonly used with: * - {@link Contacts} - People categorized by these contact types * - {@link Organizations} - Organizations associated with contacts of specific types * - {@link OrganizationTypes} - Business classifications that align with contact types * - {@link OrganizationStatuses} - Status classifications for organizations with specific contact types * - {@link Locations} - Physical sites where contacts of specific types work * - {@link Documents} - Documentation related to contact types and organizational roles * - {@link FlexibleAssets} - Custom tracking of contact type-specific information * - {@link Passwords} - Credentials associated with contacts of specific types * - {@link RelatedItems} - Create relationships between contact types and other resources * - {@link Tags} - Additional categorization of contact types * - {@link Attachments} - Store documentation related to contact types and roles * - {@link UserMetrics} - Track user activity for contacts of specific types * * @see {@link Contacts#list} for retrieving contacts by type * @see {@link Organizations#list} for retrieving organizations by contact type * @see {@link OrganizationTypes#list} for retrieving organization types * @see {@link Documents#list} for retrieving contact type documentation * * @example * import { ITGlueClient } from '../client'; * import { ContactTypes } from './resources/contact-types'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const contactTypes = new ContactTypes(client); * * // List contact types * const list = await contactTypes.list(); * * // Get a single contact type * const contactType = await contactTypes.get('123'); * * // Create a contact type * const created = await contactTypes.create({ * data: { * type: 'contact_types', * attributes: { name: 'Technical Lead' } * } * }); * * // Update a contact type * const updated = await contactTypes.update('123', { * data: { * type: 'contact_types', * attributes: { name: 'Senior Technical Lead' } * } * }); * * // Delete a contact type * await contactTypes.delete('123'); * * @category Organizations */ export declare class ContactTypes { private client; private basePath; private paginationUtil; /** * Create a ContactTypes resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all contact 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 contact types and pagination metadata * @example * // Basic usage - get first page of contact types * const results = await client.contactTypes.list(); * console.log(`Found ${results.data.length} contact types`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with pagination and sorting * const results = await client.contactTypes.list({ * page: { number: 2, size: 50 }, * sort: '-updated_at', // Sort by most recently updated * include: ['contacts'] // Include related contacts * }); * * @example * // Filtering results by role category * const filtered = await client.contactTypes.list({ * filter: { * name: 'Manager' * }, * sort: 'name' * }); * * console.log('Manager-type contacts found:'); * filtered.data.forEach(type => { * console.log(`- ${type.attributes.name}: ${type.attributes.description || 'No description'}`); * }); * * @example * // Get all results across multiple pages with role categorization * const allResults = await client.contactTypes.list({}, true); // allPages = true * * // Group by role category for organizational structure * const roleCategories = {}; * allResults.data.forEach(type => { * const category = type.attributes.name.toLowerCase().includes('manager') ? 'Management' : * type.attributes.name.toLowerCase().includes('director') ? 'Executive' : * type.attributes.name.toLowerCase().includes('lead') ? 'Leadership' : * type.attributes.name.toLowerCase().includes('vendor') ? 'External' : 'Staff'; * * if (!roleCategories[category]) roleCategories[category] = []; * roleCategories[category].push(type); * }); * * console.log('Contact types by role category:', roleCategories); * * @example * // Manual pagination handling for large datasets * async function getAllContactTypes() { * let page = 1; * let allResults = []; * let hasMore = true; * * while (hasMore) { * const response = await client.contactTypes.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.contactTypes.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 contact type by ID * @param {string} id - Contact type ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Contact type resource * @example * // Basic usage - get contact type by ID * const contactType = await client.contactTypes.get('123'); * console.log('Contact type name:', contactType.data.attributes.name); * console.log('Description:', contactType.data.attributes.description); * * @example * // Get contact type with related contacts * const contactTypeWithContacts = await client.contactTypes.get('123', { * include: ['contacts'] * }); * * // Access included data * const included = contactTypeWithContacts.included || []; * const contacts = included.filter(item => item.type === 'contacts'); * console.log(`Found ${contacts.length} contacts with this type`); * * @example * // Error handling for get operations * try { * const contactType = await client.contactTypes.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Contact type not found'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions'); * } else { * console.log('Error retrieving contact type:', error.message); * } * } * * @example * // Safe get with existence check * async function safeGetContactType(id) { * try { * const contactType = await client.contactTypes.get(id); * return contactType.data; * } catch (error) { * if (error.response?.status === 404) { * return null; // Contact type doesn't exist * } * throw error; // Re-throw other errors * } * } */ get(id: string, params?: QueryParams): Promise>; /** * Create a new contact type * @param {RequestBody} data - Contact type data (must be formatted according to JSON:API spec) * @returns {Promise>} Created contact type resource * @example * // Basic creation with required fields * const newContactType = await client.contactTypes.create({ * data: { * type: 'contact_types', * attributes: { * name: 'Technical Lead' * } * } * }); * * console.log('Created contact type with ID:', newContactType.data.id); * * @example * // Advanced creation with description and organizational context * const newContactType = await client.contactTypes.create({ * data: { * type: 'contact_types', * attributes: { * name: 'Senior DevOps Engineer', * description: 'Senior-level DevOps professionals responsible for infrastructure automation and deployment pipelines' * } * } * }); * * @example * // Bulk creation with error handling * async function createMultipleContactTypes(types) { * const results = []; * const errors = []; * * for (const typeData of types) { * try { * const created = await client.contactTypes.create({ * data: { * type: 'contact_types', * attributes: typeData * } * }); * results.push(created.data); * } catch (error) { * errors.push({ typeData, error: error.message }); * } * } * * return { results, errors }; * } * * // Usage * const typesToCreate = [ * { name: 'Security Analyst', description: 'Information security professionals' }, * { name: 'Network Administrator', description: 'Network infrastructure specialists' }, * { name: 'Database Administrator', description: 'Database management professionals' } * ]; * * @example * // Error handling for validation failures * try { * const newContactType = await client.contactTypes.create({ * data: { * type: 'contact_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 contact type'); * } else if (error.response?.status === 409) { * console.log('Conflict - contact type with this name already exists'); * } else { * console.log('Creation failed:', error.message); * } * } */ create(data: RequestBody): Promise>; /** * Update a contact type by ID * @param {string} id - Contact type ID * @param {RequestBody} data - Updated contact type data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated contact type resource * @example * // Basic update - modify specific fields * const updatedContactType = await client.contactTypes.update('123', { * data: { * type: 'contact_types', * attributes: { * name: 'Senior Technical Lead' * } * } * }); * * console.log('Updated contact type:', updatedContactType.data.attributes.name); * * @example * // Advanced update with description and role clarification * const updatedContactType = await client.contactTypes.update('123', { * data: { * type: 'contact_types', * attributes: { * name: 'Principal Engineer', * description: 'Principal-level engineering professionals with architectural responsibilities and technical leadership duties' * } * } * }); * * @example * // Conditional update based on current state * async function conditionalUpdateContactType(id, updates) { * try { * // First, get current state * const current = await client.contactTypes.get(id); * * // Check if update is needed * const needsUpdate = Object.keys(updates).some( * key => current.data.attributes[key] !== updates[key] * ); * * if (!needsUpdate) { * console.log('Contact type is already up to date'); * return current; * } * * // Perform update * return await client.contactTypes.update(id, { * data: { * type: 'contact_types', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * * @example * // Error handling for update operations * try { * const updated = await client.contactTypes.update('123', { * data: { * type: 'contact_types', * attributes: { * name: '' // Invalid empty name * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Contact 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 - contact type may have been modified by another user'); * } else { * console.log('Update failed:', error.message); * } * } */ update(id: string, data: RequestBody): Promise>; /** * Delete a contact type by ID * @param {string} id - Contact type ID * @returns {Promise} * @example * // Basic deletion * await client.contactTypes.delete('123'); * console.log('Contact type deleted successfully'); * * @example * // Safe deletion with confirmation * async function safeDeleteContactType(id) { * try { * // First verify the contact type exists * const contactType = await client.contactTypes.get(id); * console.log(`Deleting contact type: ${contactType.data.attributes.name}`); * * // Perform deletion * await client.contactTypes.delete(id); * console.log('Contact type deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Contact type not found - may already be deleted'); * return false; * } * throw error; * } * } * * @example * // Bulk deletion with error handling * async function deleteMultipleContactTypes(ids) { * const results = []; * * for (const id of ids) { * try { * await client.contactTypes.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.contactTypes.delete('123'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Contact type not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete contact type'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - contact type is referenced by existing contacts'); * } else { * console.log('Deletion failed:', error.message); * } * } */ delete(id: string): Promise; }