import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, GroupResource } from '../types'; /** * Groups resource module for IT Glue API * * Provides methods to interact with the /groups endpoint. * Groups represent user groups within your IT Glue organization, providing * a way to organize users and manage permissions collectively. Groups enable * administrators to assign roles, control access to resources, and streamline * user management by applying permissions to multiple users simultaneously. * * ## Related Resources * Groups are commonly used with: * - {@link Users} - Individual users who are members of groups * - {@link UserMetrics} - Activity metrics aggregated by group membership * - {@link Organizations} - Organizations that groups have access to manage * - {@link Configurations} - IT assets accessible to group members * - {@link Documents} - Documentation accessible based on group permissions * - {@link Passwords} - Password entries accessible to group members * - {@link FlexibleAssets} - Custom assets accessible based on group roles * - {@link Contacts} - Contact information accessible to group members * - {@link Locations} - Physical locations accessible to group members * - {@link RelatedItems} - Cross-resource relationships created by group members * - {@link Tags} - Categorization tags applied by group members * - {@link Exports} - Data exports accessible to group members * * @see {@link Users#list} for retrieving users by group membership * @see {@link UserMetrics#list} for retrieving group activity metrics * @see {@link Organizations#list} for retrieving organizations accessible to groups * @see {@link Configurations#list} for retrieving assets accessible to groups * * @example * import { ITGlueClient } from '../client'; * import { Groups } from './resources/groups'; * * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const groups = new Groups(client); * * // List groups * const list = await groups.list(); * * // Get a single group * const group = await groups.get('123'); * * // Create a group * const created = await groups.create({ * data: { type: 'groups', attributes: { name: 'New Group' } }, * }); * * // Update a group * const updated = await groups.update('123', { * data: { type: 'groups', attributes: { name: 'Updated Group' } }, * }); * * // Delete a group * await groups.delete('123'); * * @category System & Audit */ export declare class Groups { private client; private basePath; private paginationUtil; /** * Create a Groups resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all groups * * Retrieves a list of all user groups in your IT Glue organization. * This includes group information, member counts, permissions, and * associated organizations. Use filtering options to find specific * groups by name, role, or organization access. * * @param {QueryUtilOptions} [options] - Optional query parameters (filter, sort, page, etc.) * @param {boolean} [allPages=false] - If true, fetches all pages automatically * @returns {Promise>} List of groups and pagination metadata * @example * // List all groups * await groups.list(); * @example * // List groups with filtering and sorting * await groups.list({ * filter: { name: 'Admin' }, * sort: 'name', * include: ['users'] * }); * @example * // List groups with pagination * await groups.list({ * page: { number: 1, size: 25 }, * sort: '-created_at', * include: ['users', 'organizations'] * }); */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single group by ID * * Retrieves detailed information about a specific user group, including * group members, permissions, organization access, and role assignments. * This is useful for reviewing group configurations and member management. * * @param {string} id - Group ID (required) * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Group resource * @throws {Error} When group not found (404) or access denied (403) * @example * // Get a specific group * await groups.get('123'); * @example * // Get group with members and organizations included * await groups.get('123', { * include: ['users', 'organizations', 'permissions'] * }); * @example * // Error handling for group retrieval * try { * const group = await groups.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Group not found'); * } else if (error.response?.status === 403) { * console.log('Access denied to group'); * } * } * @see * {@link Organizations#get} - Get specific organization details * {@link Organizations#list} - List organizations related to groups * {@link Users#get} - Get specific user details * {@link Users#list} - List users related to groups */ get(id: string, params?: QueryParams): Promise>; /** * Create a new group * * Creates a new user group with specified permissions and settings. * Groups can be configured with various access levels, organization * permissions, and role assignments to control user access effectively. * * @param {RequestBody} data - Group data (must be formatted according to JSON:API spec) * @returns {Promise>} Created group resource * @throws {Error} When validation fails (422) or access denied (403) * @example * // Create a basic group * await groups.create({ * data: { * type: 'groups', * attributes: { * name: 'IT Department', * description: 'Internal IT team members' * } * } * }); * @example * // Create group with permissions and organization access * await groups.create({ * data: { * type: 'groups', * attributes: { * name: 'Client Managers', * description: 'Client-facing team members', * role: 'Manager' * }, * relationships: { * organizations: { * data: [ * { type: 'organizations', id: '123' }, * { type: 'organizations', id: '456' } * ] * } * } * } * }); * @example * // Error handling for group creation * try { * const created = await groups.create(groupData); * } catch (error) { * if (error.response?.status === 422) { * console.log('Validation failed:', error.response.data.errors); * } else if (error.response?.status === 403) { * console.log('Insufficient permissions to create group'); * } * } * @see * {@link Organizations#create} - Create new organization * {@link Organizations#list} - List organizations related to groups * {@link Users#create} - Create new user * {@link Users#list} - List users related to groups */ create(data: RequestBody): Promise>; /** * Update a group by ID * * Updates an existing user group's properties, permissions, or member * assignments. This allows modification of group settings, role changes, * and organization access adjustments without recreating the group. * * @param {string} id - Group ID (required) * @param {RequestBody} data - Updated group data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated group resource * @throws {Error} When group not found (404), access denied (403), or validation fails (422) * @example * // Update group name and description * await groups.update('123', { * data: { * type: 'groups', * attributes: { * name: 'Senior IT Department', * description: 'Senior IT team members with elevated access' * } * } * }); * @example * // Update group permissions and role * await groups.update('123', { * data: { * type: 'groups', * attributes: { * role: 'Administrator', * permissions: ['read', 'write', 'delete'] * } * } * }); * @example * // Error handling for group updates * try { * const updated = await groups.update('123', updateData); * } catch (error) { * if (error.response?.status === 404) { * console.log('Group not found'); * } else if (error.response?.status === 403) { * console.log('Insufficient permissions to update group'); * } else if (error.response?.status === 422) { * console.log('Validation failed:', error.response.data.errors); * } * } * @see * {@link Organizations#update} - Update organization * {@link Organizations#get} - Get specific organization details * {@link Users#update} - Update user * {@link Users#get} - Get specific user details */ update(id: string, data: RequestBody): Promise>; /** * Delete a group by ID * * Permanently removes a user group from the system. This action will * remove group memberships for all users but will not delete the users * themselves. Ensure users have alternative group memberships or direct * permissions before deleting groups. * * @param {string} id - Group ID (required) * @returns {Promise} * @throws {Error} When group not found (404), access denied (403), or group has dependencies (409) * @example * // Delete a group * await groups.delete('123'); * @example * // Error handling for group deletion * try { * await groups.delete('123'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Group not found'); * } else if (error.response?.status === 403) { * console.log('Insufficient permissions to delete group'); * } else if (error.response?.status === 409) { * console.log('Cannot delete group with active dependencies'); * } * } * @example * // Safe group deletion with member check * const group = await groups.get('123', { include: ['users'] }); * if (group.data.relationships?.users?.data?.length === 0) { * await groups.delete('123'); * } else { * console.log('Group has members, reassign before deletion'); * } * @see * {@link Organizations#list} - List organizations related to groups * {@link Organizations#get} - Get specific organization details * {@link Users#list} - List users related to groups * {@link Users#get} - Get specific user details */ delete(id: string): Promise; }