import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, OrganizationTypeResource } from '../types'; /** * OrganizationTypes resource module for IT Glue API * * Provides methods to interact with the /organization_types endpoint. * Organization types classify organizations by their business type (Client, Vendor, Partner, etc.). * These types help categorize and organize your organizations for better management and reporting. * * ## Related Resources * Organization types are commonly used with: * - {@link Organizations} - Organizations that are classified by these types * - {@link OrganizationStatuses} - Status classifications used alongside organization types * - {@link Contacts} - People associated with organizations of specific types * - {@link Locations} - Physical sites for organizations of specific types * - {@link Configurations} - IT assets belonging to organizations of specific types * - {@link Documents} - Documentation related to organization types and policies * - {@link FlexibleAssets} - Custom tracking of organization type-specific data * - {@link Passwords} - Credentials associated with organizations of specific types * - {@link RelatedItems} - Create relationships between organization types and other resources * - {@link Tags} - Additional categorization of organization types * - {@link Contracts} - Business agreements specific to organization types * - {@link Attachments} - Store documentation related to organization types * * @see {@link Organizations#list} for retrieving organizations by type * @see {@link OrganizationStatuses#list} for retrieving organization statuses * @see {@link Contacts#list} for retrieving contacts by organization type * @see {@link Configurations#list} for retrieving assets by organization type * * @example * import { ITGlueClient } from '../client'; * import { OrganizationTypes } from './resources/organization-types'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const orgTypes = new OrganizationTypes(client); * * // List organization types * const list = await orgTypes.list(); * * // Get a single organization type * const type = await orgTypes.get('123'); * * // Create a new organization type * const created = await orgTypes.create({ * data: { * type: 'organization_types', * attributes: { * name: 'Strategic Partner' * } * } * }); * * // Update an organization type * const updated = await orgTypes.update('123', { * data: { * type: 'organization_types', * attributes: { * name: 'Premium Client' * } * } * }); * * // Delete an organization type * await orgTypes.delete('123'); * * @category Organizations */ export declare class OrganizationTypes { private client; private basePath; private paginationUtil; /** * Create an OrganizationTypes resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all organization 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 organization types and pagination metadata * @example * // Basic usage - get first page of organization types * const results = await client.organizationTypes.list(); * console.log(`Found ${results.data.length} organization types`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with pagination and sorting * const results = await client.organizationTypes.list({ * page: { number: 2, size: 50 }, * sort: '-updated_at', // Sort by most recently updated * include: ['organizations'] // Include related organizations * }); * * @example * // Filtering results by business category * const filtered = await client.organizationTypes.list({ * filter: { * name: 'Client' * }, * sort: 'name' * }); * * console.log('Client-type organizations found:'); * filtered.data.forEach(type => { * console.log(`- ${type.attributes.name}: ${type.attributes.description || 'No description'}`); * }); * * @example * // Get all results across multiple pages with business categorization * const allResults = await client.organizationTypes.list({}, true); // allPages = true * * // Group by business relationship category * const businessCategories = {}; * allResults.data.forEach(type => { * const category = type.attributes.name.toLowerCase().includes('client') ? 'Clients' : * type.attributes.name.toLowerCase().includes('vendor') ? 'Vendors' : * type.attributes.name.toLowerCase().includes('partner') ? 'Partners' : * type.attributes.name.toLowerCase().includes('internal') ? 'Internal' : 'Other'; * * if (!businessCategories[category]) businessCategories[category] = []; * businessCategories[category].push(type); * }); * * console.log('Organization types by business category:', businessCategories); * * @example * // Manual pagination handling for large datasets * async function getAllOrganizationTypes() { * let page = 1; * let allResults = []; * let hasMore = true; * * while (hasMore) { * const response = await client.organizationTypes.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.organizationTypes.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 organization type by ID * @param {string} id - Organization type ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Organization type resource * @example * // Basic usage - get organization type by ID * const orgType = await client.organizationTypes.get('123'); * console.log('Organization type name:', orgType.data.attributes.name); * console.log('Description:', orgType.data.attributes.description); * * @example * // Get organization type with related organizations * const orgTypeWithOrgs = await client.organizationTypes.get('123', { * include: ['organizations'] * }); * * // Access included data * const included = orgTypeWithOrgs.included || []; * const organizations = included.filter(item => item.type === 'organizations'); * console.log(`Found ${organizations.length} organizations with this type`); * * @example * // Error handling for get operations * try { * const orgType = await client.organizationTypes.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Organization type not found'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions'); * } else { * console.log('Error retrieving organization type:', error.message); * } * } * * @example * // Safe get with existence check * async function safeGetOrganizationType(id) { * try { * const orgType = await client.organizationTypes.get(id); * return orgType.data; * } catch (error) { * if (error.response?.status === 404) { * return null; // Organization type doesn't exist * } * throw error; // Re-throw other errors * } * } */ get(id: string, params?: QueryParams): Promise>; /** * Create a new organization type * @param {RequestBody} data - Organization type data (must be formatted according to JSON:API spec) * @returns {Promise>} Created organization type resource * @example * // Basic creation with required fields * const newOrgType = await client.organizationTypes.create({ * data: { * type: 'organization_types', * attributes: { * name: 'Strategic Partner' * } * } * }); * * console.log('Created organization type with ID:', newOrgType.data.id); * * @example * // Advanced creation with description and business context * const newOrgType = await client.organizationTypes.create({ * data: { * type: 'organization_types', * attributes: { * name: 'Enterprise Client', * description: 'Large enterprise customers with complex IT infrastructure and multi-year service agreements' * } * } * }); * * @example * // Bulk creation with error handling * async function createMultipleOrganizationTypes(types) { * const results = []; * const errors = []; * * for (const typeData of types) { * try { * const created = await client.organizationTypes.create({ * data: { * type: 'organization_types', * attributes: typeData * } * }); * results.push(created.data); * } catch (error) { * errors.push({ typeData, error: error.message }); * } * } * * return { results, errors }; * } * * // Usage * const typesToCreate = [ * { name: 'Premium Vendor', description: 'High-priority vendor relationships with SLA requirements' }, * { name: 'Technology Partner', description: 'Strategic technology partnerships and integrations' }, * { name: 'Managed Service Client', description: 'Clients under comprehensive managed service agreements' } * ]; * * @example * // Error handling for validation failures * try { * const newOrgType = await client.organizationTypes.create({ * data: { * type: 'organization_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 organization type'); * } else if (error.response?.status === 409) { * console.log('Conflict - organization type with this name already exists'); * } else { * console.log('Creation failed:', error.message); * } * } */ create(data: RequestBody): Promise>; /** * Update an organization type by ID * @param {string} id - Organization type ID * @param {RequestBody} data - Updated organization type data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated organization type resource * @example * // Basic update - modify specific fields * const updatedOrgType = await client.organizationTypes.update('123', { * data: { * type: 'organization_types', * attributes: { * name: 'Premium Client' * } * } * }); * * console.log('Updated organization type:', updatedOrgType.data.attributes.name); * * @example * // Advanced update with description and business classification * const updatedOrgType = await client.organizationTypes.update('123', { * data: { * type: 'organization_types', * attributes: { * name: 'Enterprise Partner', * description: 'Large enterprise partners with strategic business relationships and joint technology initiatives' * } * } * }); * * @example * // Conditional update based on current state * async function conditionalUpdateOrganizationType(id, updates) { * try { * // First, get current state * const current = await client.organizationTypes.get(id); * * // Check if update is needed * const needsUpdate = Object.keys(updates).some( * key => current.data.attributes[key] !== updates[key] * ); * * if (!needsUpdate) { * console.log('Organization type is already up to date'); * return current; * } * * // Perform update * return await client.organizationTypes.update(id, { * data: { * type: 'organization_types', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * * @example * // Error handling for update operations * try { * const updated = await client.organizationTypes.update('123', { * data: { * type: 'organization_types', * attributes: { * name: '' // Invalid empty name * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Organization 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 - organization type may have been modified by another user'); * } else { * console.log('Update failed:', error.message); * } * } */ update(id: string, data: RequestBody): Promise>; /** * Delete an organization type by ID * @param {string} id - Organization type ID * @returns {Promise} * @example * // Basic deletion * await client.organizationTypes.delete('123'); * console.log('Organization type deleted successfully'); * * @example * // Safe deletion with confirmation * async function safeDeleteOrganizationType(id) { * try { * // First verify the organization type exists * const orgType = await client.organizationTypes.get(id); * console.log(`Deleting organization type: ${orgType.data.attributes.name}`); * * // Perform deletion * await client.organizationTypes.delete(id); * console.log('Organization type deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Organization type not found - may already be deleted'); * return false; * } * throw error; * } * } * * @example * // Bulk deletion with error handling * async function deleteMultipleOrganizationTypes(ids) { * const results = []; * * for (const id of ids) { * try { * await client.organizationTypes.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.organizationTypes.delete('123'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Organization type not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete organization type'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - organization type is referenced by existing organizations'); * } else { * console.log('Deletion failed:', error.message); * } * } */ delete(id: string): Promise; }