n8n-nodes-awx
Version:
n8n node to interact with Ansible AWX/Tower with improved type safety
61 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JobResources = void 0;
class JobResources {
constructor(apiClient) {
this.apiClient = apiClient;
}
async list(params) {
const url = this.buildUrl('/api/v2/jobs/', params);
const response = await this.apiClient.get(url);
return response.data.results;
}
async get(id) {
if (!id) {
throw new Error('Job ID is required');
}
const response = await this.apiClient.get(`/api/v2/jobs/${id}/`);
return response.data;
}
async getByName(name) {
const url = this.buildUrl('/api/v2/jobs/', { name });
const response = await this.apiClient.get(url);
if (response.data.count === 0) {
return null;
}
if (response.data.count > 1) {
throw new Error(`Multiple jobs found with name: ${name}`);
}
return response.data.results[0];
}
async cancel(id) {
if (!id) {
throw new Error('Job ID is required');
}
const response = await this.apiClient.post(`/api/v2/jobs/${id}/cancel/`, {});
return response.data;
}
async getStdout(id) {
if (!id) {
throw new Error('Job ID is required');
}
const response = await this.apiClient.get(`/api/v2/jobs/${id}/stdout/`);
return response.data;
}
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.JobResources = JobResources;
//# sourceMappingURL=JobResources.js.map