import { ITGlueClient } from '../client'; import { QueryUtilOptions, QueryParams, RequestBody, BaseListResponse, BaseItemResponse, LocationResource } from '../types'; /** * Locations resource module for IT Glue API * Provides methods to interact with the /locations endpoint. * Locations represent physical or virtual sites associated with organizations in IT Glue. * They can include offices, data centers, remote sites, or any other location where IT assets are deployed. * ## Related Resources * Locations are commonly used with: * - {@link Organizations} - Parent organizations that own locations * - {@link Contacts} - People based at or responsible for locations * - {@link Configurations} - IT assets deployed at locations * - {@link Countries} - Geographic countries where locations are situated * - {@link Regions} - Administrative regions (states/provinces) where locations are situated * - {@link Documents} - Documentation related to locations (site plans, procedures) * - {@link Passwords} - Credentials for location-specific systems * - {@link FlexibleAssets} - Custom location tracking and facility management * - {@link RelatedItems} - Create relationships between locations and other resources * - {@link Tags} - Categorize and label locations for better organization * - {@link Attachments} - Store files and documents related to locations * @see {@link Organizations.getLocations} for retrieving locations by organization * @see {@link Organizations#get} for retrieving the parent organization * @see {@link Countries#list} for retrieving available countries * @see {@link Regions#list} for retrieving available regions * @see {@link Contacts#list} for retrieving contacts at locations * @example * import { ITGlueClient } from '../client'; * import { Locations } from './resources/locations'; * const client = new ITGlueClient({ apiKey: 'your-api-key' }); * const locations = new Locations(client); * // List locations * const list = await locations.list(); * // Get a single location * const location = await locations.get('456'); * // Create a location * const created = await locations.create({ * data: { * type: 'locations', * attributes: { name: 'HQ', address: '123 Main St' } * } * }); * // Update a location * const updated = await locations.update('456', { * data: { * type: 'locations', * attributes: { name: 'Branch Office' } * } * }); * // Delete a location * await locations.delete('456'); * @category Organizations */ export declare class Locations { private client; private basePath; private paginationUtil; /** * Create a Locations resource instance * @param {ITGlueClient} client - ITGlueClient instance */ constructor(client: ITGlueClient); /** * List all locations * @param {QueryUtilOptions} [options] - Optional query parameters (filter, sort, page, etc.) * @param {boolean} [allPages=false] - If true, fetches all pages automatically * @returns {Promise>} List of locations and pagination metadata * @example * // Basic usage - get first page of locations * const results = await client.locations.list(); * console.log(`Found ${results.data.length} locations`); * console.log('Total pages:', results.meta.pagination.total_pages); * @example * // Advanced usage with pagination and sorting * const results = await client.locations.list({ * page: { number: 2, size: 50 }, * sort: 'name', // Sort by name alphabetically * include: ['organization', 'contacts'] // Include related data * }); * @example * // Filtering locations by organization and region * const eastCoastOffices = await client.locations.list({ * filter: { * organization_id: '123', * region: 'NY' * }, * sort: ['region', 'city', 'name'] * }); * @example * // Get all locations across multiple pages * const allLocations = await client.locations.list({}, true); // allPages = true * console.log(`Retrieved all ${allLocations.data.length} locations`); * @example * // Manual pagination for location inventory * async function getAllLocationsByOrganization(orgId) { * let page = 1; * let allLocations = []; * let hasMore = true; * while (hasMore) { * const response = await client.locations.list({ * filter: { organization_id: orgId }, * page: { number: page, size: 100 }, * sort: ['region', 'city', 'name'] * }); * allLocations = [...allLocations, ...response.data]; * hasMore = response.meta.pagination.total_pages > page; * page++; * } * return allLocations; * } * @example * // Error handling for list operations * try { * const results = await client.locations.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 locations'); * } else { * console.log('Request failed:', error.message); * } * } */ list(options?: QueryUtilOptions, allPages?: boolean): Promise>; /** * Get a single location by ID * @param {string} id - Location ID * @param {QueryParams} [params] - Optional query parameters * @returns {Promise>} Location resource * @example * // Basic usage - get location by ID * const location = await client.locations.get('456'); * console.log('Location name:', location.data.attributes.name); * console.log('Address:', location.data.attributes.address); * console.log('City:', location.data.attributes.city); * console.log('Region:', location.data.attributes.region); * @example * // Get location with related data included * const locationWithRelated = await client.locations.get('456', { * include: ['organization', 'contacts', 'configurations'] * }); * // Access included data * const included = locationWithRelated.included || []; * const organization = included.find(item => item.type === 'organizations'); * const contacts = included.filter(item => item.type === 'contacts'); * @example * // Error handling for get operations * try { * const location = await client.locations.get('invalid-id'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Location not found'); * } else if (error.response?.status === 403) { * console.log('Access denied - insufficient permissions'); * } else { * console.log('Error retrieving location:', error.message); * } * } * @example * // Safe get with existence check * async function safeGetLocation(id) { * try { * const location = await client.locations.get(id); * return location.data; * } catch (error) { * if (error.response?.status === 404) { * return null; // Location doesn't exist * } * throw error; // Re-throw other errors * } * } * @see * {@link Organizations#get} - Get specific organization details * {@link Organizations#list} - List organizations related to locations * {@link Countries#get} - Get specific countrie details * {@link Countries#list} - List countries related to locations */ get(id: string, params?: QueryParams): Promise>; /** * Create a new location * @param {RequestBody} data - Location data (must be formatted according to JSON:API spec) * @returns {Promise>} Created location resource * @example * // Basic location creation * const newLocation = await client.locations.create({ * data: { * type: 'locations', * attributes: { * name: 'Headquarters', * address: '123 Main Street, Suite 100', * city: 'New York', * region: 'NY', * country: 'USA', * postal_code: '10001' * }, * relationships: { * organization: { * data: { type: 'organizations', id: '123' } * } * } * } * }); * console.log('Created location with ID:', newLocation.data.id); * @example * // Advanced location creation with comprehensive details * const newLocation = await client.locations.create({ * data: { * type: 'locations', * attributes: { * name: 'Data Center West', * address: '789 Tech Park Drive, Building A', * city: 'San Francisco', * region: 'CA', * country: 'USA', * postal_code: '94105', * phone: '+1-415-555-0100', * fax: '+1-415-555-0101', * notes: 'Primary West Coast data center with 24/7 operations', * latitude: 37.7749, * longitude: -122.4194 * }, * relationships: { * organization: { * data: { type: 'organizations', id: '123' } * } * } * } * }); * @example * // Bulk location creation with error handling * async function createMultipleLocations(locationList) { * const results = []; * const errors = []; * for (const locationData of locationList) { * try { * const created = await client.locations.create({ * data: { * type: 'locations', * attributes: locationData, * relationships: { * organization: { * data: { type: 'organizations', id: locationData.organizationId } * } * } * } * }); * results.push(created.data); * } catch (error) { * errors.push({ locationData, error: error.message }); * } * } * return { results, errors }; * } * @example * // Error handling for location creation * try { * const created = await client.locations.create({ * data: { * type: 'locations', * attributes: { * // Missing required name field * address: '123 Test Street' * } * } * }); * } 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 location'); * } else { * console.log('Creation failed:', error.message); * } * } * @see * {@link Organizations#create} - Create new organization * {@link Organizations#list} - List organizations related to locations * {@link Countries#list} - List countries related to locations */ create(data: RequestBody): Promise>; /** * Update a location by ID * @param {string} id - Location ID * @param {RequestBody} data - Updated location data (must be formatted according to JSON:API spec) * @returns {Promise>} Updated location resource * @example * // Basic update - modify location details * const updatedLocation = await client.locations.update('456', { * data: { * type: 'locations', * attributes: { * name: 'Regional Branch Office', * phone: '+1-555-123-4567' * } * } * }); * console.log('Location updated successfully'); * @example * // Update location with comprehensive address changes * const updatedLocation = await client.locations.update('456', { * data: { * type: 'locations', * attributes: { * name: 'Data Center East - Relocated', * address: '789 Tech Park Drive, Building B', * city: 'Boston', * region: 'MA', * postal_code: '02101', * phone: '+1-617-555-0200', * notes: 'Relocated to new facility with expanded capacity', * latitude: 42.3601, * longitude: -71.0589 * } * } * }); * @example * // Conditional update based on current state * async function conditionalUpdateLocation(id, updates) { * try { * // First, get current state * const current = await client.locations.get(id); * // Check if update is needed * const needsUpdate = Object.keys(updates).some( * key => current.data.attributes[key] !== updates[key] * ); * if (!needsUpdate) { * console.log('Location is already up to date'); * return current; * } * // Perform update * return await client.locations.update(id, { * data: { * type: 'locations', * attributes: updates * } * }); * } catch (error) { * console.error('Update failed:', error.message); * throw error; * } * } * @example * // Error handling for location updates * try { * const updated = await client.locations.update('456', { * data: { * type: 'locations', * attributes: { * postal_code: 'INVALID-CODE' * } * } * }); * } catch (error) { * if (error.response?.status === 404) { * console.log('Location 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 - location may have been modified by another user'); * } else { * console.log('Update failed:', error.message); * } * } * @see * {@link Organizations#update} - Update organization * {@link Organizations#get} - Get specific organization details * {@link Countries#get} - Get specific countrie details */ update(id: string, data: RequestBody): Promise>; /** * Delete a location by ID * @param {string} id - Location ID * @returns {Promise} * @example * // Basic deletion * await client.locations.delete('456'); * console.log('Location deleted successfully'); * @example * // Safe deletion with confirmation * async function safeDeleteLocation(id) { * try { * // First verify the location exists * const location = await client.locations.get(id); * console.log(`Deleting location: ${location.data.attributes.name}`); * // Perform deletion * await client.locations.delete(id); * console.log('Location deleted successfully'); * return true; * } catch (error) { * if (error.response?.status === 404) { * console.log('Location not found - may already be deleted'); * return false; * } * throw error; * } * } * @example * // Bulk deletion with error handling * async function deleteMultipleLocations(locationIds) { * const results = []; * for (const id of locationIds) { * try { * await client.locations.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.locations.delete('456'); * } catch (error) { * if (error.response?.status === 404) { * console.log('Location not found - may already be deleted'); * } else if (error.response?.status === 403) { * console.log('Permission denied - cannot delete location'); * } else if (error.response?.status === 409) { * console.log('Cannot delete - location is referenced by other resources'); * } else { * console.log('Deletion failed:', error.message); * } * } * @see * {@link Organizations#list} - List organizations related to locations * {@link Organizations#get} - Get specific organization details * {@link Countries#list} - List countries related to locations * {@link Countries#get} - Get specific countrie details */ delete(id: string): Promise; }