import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, PasswordCategoryResource } from '../types'; /** * PasswordCategories resource module for IT Glue API * * Provides methods to interact with the /password_categories endpoint. * Password categories help organize and classify password entries into logical groups * such as "Server Admin", "Email Accounts", "Network Equipment", "Database Access", etc. * Categories provide a way to structure and filter password collections, making it easier * to manage large numbers of credentials across different systems and services. * * ## Related Resources * Password categories are commonly used with: * - {@link Passwords} - Credentials that are classified by password categories * - {@link PasswordFolders} - Organizational folders that contain categorized passwords * - {@link Organizations} - Organizations that use password categories for credential management * - {@link Configurations} - IT assets that have passwords in specific categories * - {@link Contacts} - People responsible for passwords in specific categories * - {@link FlexibleAssets} - Custom password tracking using categorized credentials * - {@link Documents} - Password policies and procedures related to categories * - {@link RelatedItems} - Create relationships between password categories and other resources * - {@link Tags} - Additional categorization and labeling of password categories * - {@link Attachments} - Store documentation related to password categories * * @see {@link Passwords#list} for retrieving passwords by category * @see {@link PasswordCategories#list} for retrieving password folders * @see {@link Organizations#list} for retrieving organizations using password categories * @see {@link Configurations#list} for retrieving configurations with categorized passwords * * @example * import { ITGlueClient } from '../client'; * import { PasswordCategories } from './resources/password-categories'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const passwordCategories = new PasswordCategories(client); * * // List password categories * const list = await passwordCategories.list(); * * // Get a single password category * const category = await passwordCategories.get('123'); * * // Create a new password category * const created = await passwordCategories.create({ * data: { * type: 'password_categories', * attributes: { * name: 'Database Admin' * } * } * }); * * // Update a password category * const updated = await passwordCategories.update('123', { * data: { * type: 'password_categories', * attributes: { * name: 'System Administrator' * } * } * }); * * // Delete a password category * await passwordCategories.delete('123'); * * @category Access Management */ export declare class PasswordCategories { private client; private basePath; private paginationUtil; /** * Create a PasswordCategories resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all password categories * @param {QueryUtilOptions} [options] - Optional query parameters (filter, sort, page, etc.) * @param {boolean} [allPages=false] - If true, fetches all pages automatically * @returns {Promise>} List of password categories and pagination metadata * @example * // Basic usage - get first page of password categories * const results = await client.passwordCategories.list(); * console.log(`Found ${results.data.length} password categories`); * console.log('Total pages:', results.meta.pagination.total_pages); * * @example * // Advanced usage with filtering and sorting * const adminCategories = await client.passwordCategories.list({ * filter: { name: 'Admin' }, * sort: 'name', * page: { number: 1, size: 50 } * }); * * console.log('Admin-related categories:'); * adminCategories.data.forEach(category => { * console.log(`- ${category.attributes.name}: ${category.attributes.description || 'No description'}`); * }); * * @example * // Get all categories with usage analysis * const allCategories = await client.passwordCategories.list({}, true); // allPages = true * * // Group categories by type for organization analysis * const categoryTypes = {}; * allCategories.data.forEach(category => { * const type = category.attributes.name.toLowerCase().includes('admin') ? 'Administrative' : * category.attributes.name.toLowerCase().includes('server') ? 'Infrastructure' : * category.attributes.name.toLowerCase().includes('email') ? 'Communication' : * category.attributes.name.toLowerCase().includes('database') ? 'Database' : 'Other'; * * if (!categoryTypes[type]) categoryTypes[type] = []; * categoryTypes[type].push(category); * }); * * console.log('Categories by type:', Object.keys(categoryTypes)); * * @example * // Manual pagination for large category datasets * async function getAllCategoriesWithDetails() { * let page = 1; * let allCategories = []; * let hasMore = true; * * while (hasMore) { * const response = await client.passwordCategories.list({ * page: { number: page, size: 100 }, * sort: 'name' * }); * * allCategories = [...allCategories, ...response.data]; * hasMore = response.meta.pagination.total_pages > page; * page++; * * console.log(`Loaded page ${page - 1}, total categories: ${allCategories.length}`); * } * * return allCategories; * } * * @example * // Filter categories for credential organization * const securityCategories = await client.passwordCategories.list({ * filter: { * name: ['Security', 'Admin', 'Root', 'Privileged'] * }, * sort: 'name' * }); * * // Build security credential hierarchy * const securityHierarchy = securityCategories.data.map(category => ({ * id: category.id, * name: category.attributes.name, * description: category.attributes.description, * riskLevel: category.attributes.name.toLowerCase().includes('root') ? 'Critical' : * category.attributes.name.toLowerCase().includes('admin') ? 'High' : 'Medium' * })); * * console.log('Security credential categories:', securityHierarchy); * * @example * // Error handling for category listing * try { * const categories = await client.passwordCategories.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 categories'); * } else { * console.log('Request failed:', error.message); * } * } */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single password category by ID * @param {string} id - Password category ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Password category resource * @example * const category = await passwordCategories.get('123'); * @example * // Get category with additional parameters * const category = await passwordCategories.get('123', { * include: ['passwords'] * }); */ get(id: string, params?: QueryParams): Promise>; /** * Create a new password category * * Creates a new password category that can be used to organize and classify * password entries. Categories help maintain structure in password management * and make it easier to filter and locate specific types of credentials. * * @param {RequestBody} data - Password category data (must be formatted according to JSON:API spec) * @returns {Promise>} Created password category resource * @throws {Error} When validation fails (422) or unauthorized (401) * @example * // Create a basic password category * const created = await passwordCategories.create({ * data: { * type: 'password_categories', * attributes: { * name: 'Database Admin' * } * } * }); * @example * // Create category with description * const created = await passwordCategories.create({ * data: { * type: 'password_categories', * attributes: { * name: 'Cloud Services', * description: 'Login credentials for cloud platforms and SaaS applications' * } * } * }); * @example * // Error handling for category creation * try { * const created = await passwordCategories.create({ * data: { * type: 'password_categories', * attributes: { * name: '' // Invalid empty name * } * } * }); * } catch (error) { * if (error.response?.status === 422) { * console.log('Validation failed:', error.response.data.errors); * } * } */ create(data: RequestBody): Promise>; /** * Update a password category by ID * * Updates an existing password category. Changes to category names or descriptions * will be reflected in all associated passwords that use this category. * * @param {string} id - Password category ID * @param {RequestBody} data - Updated password category data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated password category resource * @throws {Error} When category not found (404) or validation fails (422) * @example * // Update category name * const updated = await passwordCategories.update('123', { * data: { * type: 'password_categories', * attributes: { * name: 'System Administrator' * } * } * }); * @example * // Update category with description * const updated = await passwordCategories.update('123', { * data: { * type: 'password_categories', * attributes: { * name: 'Network Infrastructure', * description: 'Credentials for routers, switches, firewalls, and network management systems' * } * } * }); * @example * // Error handling for category updates * try { * const updated = await passwordCategories.update('123', { * data: { * type: 'password_categories', * attributes: { * name: 'Updated Category' * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Category not found'); * } else if (error.response?.status === 422) { * console.log('Validation failed:', error.response.data.errors); * } * } */ update(id: string, data: RequestBody): Promise>; /** * Delete a password category by ID * * Deletes a password category. Note that this operation may fail if there are * passwords still associated with this category. Consider reassigning passwords * to other categories before deletion. * * @param {string} id - Password category ID * @returns {Promise} * @throws {Error} When category not found (404) or has associated passwords (409) * @example * await passwordCategories.delete('123'); * @example * // Error handling for category deletion * try { * await passwordCategories.delete('123'); * } catch (error) { * if (error.response?.status === 409) { * console.log('Cannot delete category: passwords are still associated with it'); * } * } */ delete(id: string): Promise; }