UNPKG

n8n-nodes-awx

Version:

n8n node to interact with Ansible AWX/Tower with improved type safety

69 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GroupResources = void 0; class GroupResources { constructor(apiClient) { this.apiClient = apiClient; } async list(params) { const url = this.buildUrl('/api/v2/groups/', params); const response = await this.apiClient.get(url); return response.data.results; } async get(id) { if (!id) { throw new Error('Group ID is required'); } const response = await this.apiClient.get(`/api/v2/groups/${id}/`); return response.data; } async getByName(name) { const url = this.buildUrl('/api/v2/groups/', { name }); const response = await this.apiClient.get(url); if (response.data.count === 0) { return null; } if (response.data.count > 1) { throw new Error(`Multiple groups found with name: ${name}`); } return response.data.results[0]; } async create(data) { const requiredFields = ['name', 'inventory']; const missingFields = requiredFields.filter(field => data[field] === undefined || data[field] === null); if (missingFields.length > 0) { throw new Error(`Missing required fields: ${missingFields.join(', ')}`); } const response = await this.apiClient.post('/api/v2/groups/', data); return response.data; } async update(id, data) { if (!id) { throw new Error('Group ID is required'); } const response = await this.apiClient.put(`/api/v2/groups/${id}/`, data); return response.data; } async delete(id) { if (!id) { throw new Error('Group ID is required'); } await this.apiClient.delete(`/api/v2/groups/${id}/`); } buildUrl(path, params) { if (!params) return path; const queryParts = []; Object.entries(params).forEach(([key, value]) => { if (value !== undefined && value !== null) { const encodedKey = encodeURIComponent(key); const encodedValue = encodeURIComponent(String(value)); queryParts.push(`${encodedKey}=${encodedValue}`); } }); const queryString = queryParts.join('&'); return queryString ? `${path}?${queryString}` : path; } } exports.GroupResources = GroupResources; //# sourceMappingURL=GroupResources.js.map