import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, FlexibleAssetTypeResource } from '../types'; /** * FlexibleAssetTypes resource module for IT Glue API * * Provides methods to interact with the /flexible_asset_types endpoint. * Flexible asset types define the structure, fields, and templates for flexible assets. * They act as blueprints that determine what custom fields (traits) are available * when creating flexible assets. Each type can define various field types including * text, numbers, dates, tags, relationships, and more. Common examples include * "Passwords", "Licenses", "Contracts", and "Network Equipment" types. * * ## Related Resources * Flexible asset types are commonly used with: * - {@link FlexibleAssets} - Assets created from flexible asset type templates * - {@link FlexibleAssetFields} - Individual field definitions within flexible asset types * - {@link Organizations} - Organizations that use flexible asset types * - {@link Contacts} - People associated with flexible asset type management * - {@link Documents} - Documentation and templates for flexible asset types * - {@link Passwords} - Credentials stored using password-type flexible assets * - {@link Configurations} - IT assets related to flexible asset types * - {@link RelatedItems} - Create relationships between flexible asset types and other resources * - {@link Tags} - Categorize flexible asset types by purpose or function * - {@link Attachments} - Store files and documentation related to flexible asset types * * @see {@link FlexibleAssets#list} for retrieving assets by type * @see {@link FlexibleAssetFields#list} for retrieving fields for a flexible asset type * @see {@link Organizations#list} for retrieving organizations using flexible asset types * @see {@link FlexibleAssets#create} for creating assets from flexible asset types * * @example * import { ITGlueClient } from '../client'; * import { FlexibleAssetTypes } from './resources/flexible-asset-types'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const flexibleAssetTypes = new FlexibleAssetTypes(client); * * // List flexible asset types * const list = await flexibleAssetTypes.list(); * * // Get a single flexible asset type * const type = await flexibleAssetTypes.get('456'); * * // Create a flexible asset type * const created = await flexibleAssetTypes.create({ * data: { * type: 'flexible_asset_types', * attributes: { * name: 'Network Equipment', * description: 'Network hardware information' * } * } * }); * * // Update a flexible asset type * const updated = await flexibleAssetTypes.update('456', { * data: { * type: 'flexible_asset_types', * attributes: { * name: 'Updated Network Equipment' * } * } * }); * * // Delete a flexible asset type * await flexibleAssetTypes.delete('123'); * * @category Assets */ export declare class FlexibleAssetTypes { private client; private basePath; private paginationUtil; /** * Create a FlexibleAssetTypes resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all flexible asset 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 flexible asset types and pagination metadata * @example * // Basic usage - get first page of flexible asset types * const results = await client.flexibleAssetTypes.list(); * console.log(`Found ${results.data.length} flexible asset types`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with pagination and sorting * const results = await client.flexibleAssetTypes.list({ * page: { number: 2, size: 50 }, * sort: 'name', // Sort alphabetically * include: ['flexible_asset_fields'] // Include field definitions * }); * * // Access type information * results.data.forEach(type => { * console.log(`Type: ${type.attributes.name}`); * console.log(`Description: ${type.attributes.description || 'N/A'}`); * console.log(`Icon: ${type.attributes.icon || 'N/A'}`); * console.log(`Enabled: ${type.attributes.enabled}`); * }); * * @example * // Filtering types by name pattern * const licenseTypes = await client.flexibleAssetTypes.list({ * filter: { * name: 'License' * }, * sort: 'name' * }); * * console.log(`Found ${licenseTypes.data.length} license-related types`); * * @example * // Get all types for template management * const allTypes = await client.flexibleAssetTypes.list({}, true); // allPages = true * console.log(`Retrieved all ${allTypes.data.length} flexible asset types`); * * // Create type lookup map for asset creation * const typeLookup = {}; * allTypes.data.forEach(type => { * typeLookup[type.id] = { * name: type.attributes.name, * description: type.attributes.description, * icon: type.attributes.icon, * enabled: type.attributes.enabled * }; * }); * * // Group types by category for organization * const typesByCategory = { * security: [], * infrastructure: [], * software: [], * documentation: [], * other: [] * }; * * allTypes.data.forEach(type => { * const name = type.attributes.name.toLowerCase(); * if (name.includes('password') || name.includes('certificate') || name.includes('key')) { * typesByCategory.security.push(type.attributes.name); * } else if (name.includes('server') || name.includes('network') || name.includes('hardware')) { * typesByCategory.infrastructure.push(type.attributes.name); * } else if (name.includes('license') || name.includes('software') || name.includes('application')) { * typesByCategory.software.push(type.attributes.name); * } else if (name.includes('document') || name.includes('procedure') || name.includes('policy')) { * typesByCategory.documentation.push(type.attributes.name); * } else { * typesByCategory.other.push(type.attributes.name); * } * }); * * @example * // Manual pagination for large type datasets * async function getAllTypesWithFields() { * let page = 1; * let allTypes = []; * let hasMore = true; * * while (hasMore) { * const response = await client.flexibleAssetTypes.list({ * page: { number: page, size: 100 }, * sort: 'name', * include: ['flexible_asset_fields'] * }); * * allTypes = [...allTypes, ...response.data]; * hasMore = response.meta.pagination.total_pages > page; * page++; * } * * return allTypes; * } * * @example * // Error handling for list operations * try { * const results = await client.flexibleAssetTypes.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 types'); * } else { * console.log('Request failed:', error.message); * } * } */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single flexible asset type by ID * @param {string} id - Flexible asset type ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Flexible asset type resource * @example * // Basic usage - get type by ID * const type = await client.flexibleAssetTypes.get('456'); * console.log('Type name:', type.data.attributes.name); * console.log('Description:', type.data.attributes.description); * console.log('Icon:', type.data.attributes.icon); * console.log('Enabled:', type.data.attributes.enabled); * * @example * // Get type with related fields and assets * const typeWithRelated = await client.flexibleAssetTypes.get('456', { * include: ['flexible_asset_fields', 'flexible_assets'] * }); * * // Access included data * const included = typeWithRelated.included || []; * const fields = included.filter(item => item.type === 'flexible_asset_fields'); * const assets = included.filter(item => item.type === 'flexible_assets'); * * console.log(`Type: ${typeWithRelated.data.attributes.name}`); * console.log(`Fields: ${fields.length} custom fields defined`); * console.log(`Assets: ${assets.length} assets using this type`); * * fields.forEach(field => { * console.log(`- ${field.attributes.name} (${field.attributes.kind})`); * }); * * @example * // Error handling for get operations * try { * const type = await client.flexibleAssetTypes.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Flexible asset type not found'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions'); * } else { * console.log('Error retrieving type:', error.message); * } * } * * @example * // Safe get with existence check for template validation * async function safeGetFlexibleAssetType(id) { * try { * const type = await client.flexibleAssetTypes.get(id); * return { * id: type.data.id, * name: type.data.attributes.name, * description: type.data.attributes.description, * icon: type.data.attributes.icon, * enabled: type.data.attributes.enabled * }; * } catch (error) { * if (error.response?.status === 404) { * return null; // Type doesn't exist * } * throw error; // Re-throw other errors * } * } */ get(id: string, params?: QueryParams): Promise>; /** * Create a new flexible asset type * @param {RequestBody} data - Flexible asset type data (must be formatted according to JSON:API spec) * @returns {Promise>} Created flexible asset type resource * @example * // Basic creation with required fields * const newType = await client.flexibleAssetTypes.create({ * data: { * type: 'flexible_asset_types', * attributes: { * name: 'Software Licenses', * description: 'Track software licensing information', * icon: 'fa-certificate', * show_in_menu: true * } * } * }); * * console.log('Created type with ID:', newType.data.id); * * @example * // Creation with comprehensive configuration * const newType = await client.flexibleAssetTypes.create({ * data: { * type: 'flexible_asset_types', * attributes: { * name: 'Network Equipment', * description: 'Network hardware and configuration tracking', * icon: 'fa-network-wired', * show_in_menu: true, * enabled: true, * color: '#2196F3' * } * } * }); * * console.log(`Created "${newType.data.attributes.name}" type`); * console.log(`Type ID: ${newType.data.id}`); * console.log(`Menu visibility: ${newType.data.attributes.show_in_menu}`); * * @example * // Bulk creation with error handling * async function createMultipleTypes(typeDefinitions) { * const results = []; * const errors = []; * * for (const typeDef of typeDefinitions) { * try { * const created = await client.flexibleAssetTypes.create({ * data: { * type: 'flexible_asset_types', * attributes: typeDef * } * }); * results.push(created.data); * } catch (error) { * errors.push({ typeDef, error: error.message }); * } * } * * return { results, errors }; * } * * const typeDefinitions = [ * { * name: 'SSL Certificates', * description: 'SSL/TLS certificate tracking', * icon: 'fa-shield-alt', * show_in_menu: true * }, * { * name: 'API Keys', * description: 'API key and token management', * icon: 'fa-key', * show_in_menu: true * } * ]; * * const { results, errors } = await createMultipleTypes(typeDefinitions); * * @example * // Error handling for validation failures * try { * const newType = await client.flexibleAssetTypes.create({ * data: { * type: 'flexible_asset_types', * attributes: { * // Missing required name field * description: 'Test type' * } * } * }); * } 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 flexible asset types'); * } else { * console.log('Creation failed:', error.message); * } * } */ create(data: RequestBody): Promise>; /** * Update a flexible asset type by ID * @param {string} id - Flexible asset type ID * @param {RequestBody} data - Updated flexible asset type data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated flexible asset type resource * @example * // Basic update - modify specific fields * const updatedType = await client.flexibleAssetTypes.update('456', { * data: { * type: 'flexible_asset_types', * attributes: { * name: 'Updated Network Equipment', * description: 'Enhanced network hardware tracking' * } * } * }); * * console.log('Updated type:', updatedType.data.attributes.name); * * @example * // Update display settings and configuration * const updatedType = await client.flexibleAssetTypes.update('456', { * data: { * type: 'flexible_asset_types', * attributes: { * icon: 'fa-server', * show_in_menu: false, * enabled: true, * color: '#FF5722' * } * } * }); * * console.log(`Updated display settings for "${updatedType.data.attributes.name}"`); * console.log(`New icon: ${updatedType.data.attributes.icon}`); * console.log(`Menu visibility: ${updatedType.data.attributes.show_in_menu}`); * * @example * // Conditional update based on current state * async function conditionalUpdateType(id, updates) { * try { * // First, get current state * const current = await client.flexibleAssetTypes.get(id); * * // Check if update is needed * const needsUpdate = Object.keys(updates).some( * key => current.data.attributes[key] !== updates[key] * ); * * if (!needsUpdate) { * console.log('Type is already up to date'); * return current; * } * * // Perform update * return await client.flexibleAssetTypes.update(id, { * data: { * type: 'flexible_asset_types', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * * @example * // Error handling for update operations * try { * const updated = await client.flexibleAssetTypes.update('456', { * data: { * type: 'flexible_asset_types', * attributes: { * name: '' // Invalid empty name * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Flexible asset 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 - type may have been modified by another user'); * } else { * console.log('Update failed:', error.message); * } * } */ update(id: string, data: RequestBody): Promise>; /** * Delete a flexible asset type by ID * @param {string} id - Flexible asset type ID * @returns {Promise} * @example * // Basic deletion * await client.flexibleAssetTypes.delete('456'); * console.log('Flexible asset type deleted successfully'); * * @example * // Safe deletion with confirmation * async function safeDeleteType(id) { * try { * // First verify the type exists and check for dependencies * const type = await client.flexibleAssetTypes.get(id, { * include: ['flexible_assets'] * }); * * const included = type.included || []; * const assets = included.filter(item => item.type === 'flexible_assets'); * * if (assets.length > 0) { * console.log(`Warning: Type "${type.data.attributes.name}" has ${assets.length} associated assets`); * console.log('Consider migrating assets before deletion'); * return false; * } * * console.log(`Deleting type: ${type.data.attributes.name}`); * await client.flexibleAssetTypes.delete(id); * console.log('Type deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Type not found - may already be deleted'); * return false; * } * throw error; * } * } * * @example * // Bulk deletion with error handling * async function deleteMultipleTypes(ids) { * const results = []; * * for (const id of ids) { * try { * await client.flexibleAssetTypes.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.flexibleAssetTypes.delete('456'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Type not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete flexible asset types'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - type has associated assets or dependencies'); * } else { * console.log('Deletion failed:', error.message); * } * } */ delete(id: string): Promise; }