n8n-nodes-awx
Version:
n8n node to interact with Ansible AWX/Tower with improved type safety
225 lines • 9.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkflowJobTemplateResources = void 0;
class WorkflowJobTemplateResources {
constructor(apiClient) {
this.apiClient = apiClient;
}
async get(id) {
if (!id) {
throw new Error('Workflow Job Template ID is required');
}
const response = await this.apiClient.get(`/api/v2/workflow_job_templates/${id}/`);
return response.data;
}
async getByName(name) {
const url = this.buildUrl('/api/v2/workflow_job_templates/', { name });
const response = await this.apiClient.get(url);
if (response.data.count === 0) {
return null;
}
if (response.data.count > 1) {
throw new Error(`Multiple workflow job templates found with name: ${name}`);
}
return response.data.results[0];
}
async list(params) {
const url = this.buildUrl('/api/v2/workflow_job_templates/', params);
const response = await this.apiClient.get(url);
return response.data.results;
}
async create(data) {
if (!data.name) {
throw new Error('Name is required to create a workflow job template');
}
const response = await this.apiClient.post('/api/v2/workflow_job_templates/', data);
return response.data;
}
async update(id, data) {
if (!id) {
throw new Error('Workflow Job Template ID is required');
}
const response = await this.apiClient.put(`/api/v2/workflow_job_templates/${id}/`, data);
return response.data;
}
async delete(id) {
if (!id) {
throw new Error('Workflow Job Template ID is required');
}
await this.apiClient.delete(`/api/v2/workflow_job_templates/${id}/`);
}
async launch(id, params = {}) {
if (!id) {
throw new Error('Workflow Job Template ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${id}/launch/`, params);
return response.data;
}
async associateLabel(templateId, labelId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!labelId) {
throw new Error('Label ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/labels/`, { id: labelId });
return response.data;
}
async disassociateLabel(templateId, labelId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!labelId) {
throw new Error('Label ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/labels/`, { id: labelId, disassociate: true });
return response.data;
}
async getSchedules(templateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
const response = await this.apiClient.get(`/api/v2/workflow_job_templates/${templateId}/schedules/`);
return response.data.results;
}
async createSchedule(templateId, scheduleData) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!scheduleData) {
throw new Error('Schedule data is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/schedules/`, scheduleData);
return response.data;
}
async getNotificationTemplatesError(templateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
const response = await this.apiClient.get(`/api/v2/workflow_job_templates/${templateId}/notification_templates_error/`);
return response.data.results;
}
async associateNotificationTemplateError(templateId, notificationTemplateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!notificationTemplateId) {
throw new Error('Notification Template ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/notification_templates_error/`, { id: notificationTemplateId });
return response.data;
}
async disassociateNotificationTemplateError(templateId, notificationTemplateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!notificationTemplateId) {
throw new Error('Notification Template ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/notification_templates_error/`, { id: notificationTemplateId, disassociate: true });
return response.data;
}
async getNotificationTemplatesStarted(templateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
const response = await this.apiClient.get(`/api/v2/workflow_job_templates/${templateId}/notification_templates_started/`);
return response.data.results;
}
async associateNotificationTemplateStarted(templateId, notificationTemplateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!notificationTemplateId) {
throw new Error('Notification Template ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/notification_templates_started/`, { id: notificationTemplateId });
return response.data;
}
async disassociateNotificationTemplateStarted(templateId, notificationTemplateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!notificationTemplateId) {
throw new Error('Notification Template ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/notification_templates_started/`, { id: notificationTemplateId, disassociate: true });
return response.data;
}
async getNotificationTemplatesSuccess(templateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
const response = await this.apiClient.get(`/api/v2/workflow_job_templates/${templateId}/notification_templates_success/`);
return response.data.results;
}
async associateNotificationTemplateSuccess(templateId, notificationTemplateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!notificationTemplateId) {
throw new Error('Notification Template ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/notification_templates_success/`, { id: notificationTemplateId });
return response.data;
}
async disassociateNotificationTemplateSuccess(templateId, notificationTemplateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!notificationTemplateId) {
throw new Error('Notification Template ID is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/notification_templates_success/`, { id: notificationTemplateId, disassociate: true });
return response.data;
}
async getSurveySpec(templateId) {
var _a;
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
try {
const response = await this.apiClient.get(`/api/v2/workflow_job_templates/${templateId}/survey_spec/`);
return response.data;
}
catch (error) {
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
return null;
}
throw error;
}
}
async createSurveySpec(templateId, surveySpec) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
if (!surveySpec) {
throw new Error('Survey spec is required');
}
const response = await this.apiClient.post(`/api/v2/workflow_job_templates/${templateId}/survey_spec/`, surveySpec);
return response.data;
}
async deleteSurveySpec(templateId) {
if (!templateId) {
throw new Error('Workflow Job Template ID is required');
}
await this.apiClient.delete(`/api/v2/workflow_job_templates/${templateId}/survey_spec/`);
}
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.WorkflowJobTemplateResources = WorkflowJobTemplateResources;
//# sourceMappingURL=WorkflowJobTemplateResources.js.map