UNPKG

n8n-nodes-ionos

Version:

n8n nodes for IONOS DNS, Domain, SSL/Certificate management, Cloud AI, Cloud Infrastructure, Container Registry, Database as a Service, CDN, VPN Gateway, Activity Log, Billing, Logging, Monitoring, Object Storage Management, Network File Storage, Identity

615 lines (614 loc) 25.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IonosCloudBilling = void 0; const baseUrl = 'https://api.ionos.com/billing'; class IonosCloudBilling { description = { displayName: 'IONOS Cloud Billing', name: 'ionosCloudBilling', icon: 'file:ionos.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["resource"]}} - {{$parameter["operation"]}}', description: 'Retrieve billing information, invoices, usage data, and resource utilization from IONOS Cloud. Developped with Love by Ascenzia (ascenzia.fr)', defaults: { name: 'IONOS Cloud Billing', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'ionosCloud', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'EVN (Usage Data)', value: 'evn', description: 'Provisioning itemized data (Einzelverbrauchsnachweis)', }, { name: 'Invoice', value: 'invoice', description: 'Invoice information', }, { name: 'Product', value: 'product', description: 'Available products', }, { name: 'Profile', value: 'profile', description: 'Billing profile information', }, { name: 'Traffic', value: 'traffic', description: 'Traffic utilization data', }, { name: 'Usage', value: 'usage', description: 'Resource usage information', }, { name: 'Utilization', value: 'utilization', description: 'Resource utilization details', }, ], default: 'invoice', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['evn'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get EVN information', action: 'Get EVN information', }, { name: 'Get by Period', value: 'getByPeriod', description: 'Get EVN for a specific period', action: 'Get EVN by period', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['invoice'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get invoice information', action: 'Get invoice information', }, { name: 'Get by ID', value: 'getById', description: 'Get invoice by ID', action: 'Get invoice by ID', }, { name: 'Get by Period', value: 'getByPeriod', description: 'Get invoices for a specific period', action: 'Get invoice by period', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['product'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get available products', action: 'Get available products', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['traffic'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get traffic information', action: 'Get traffic information', }, { name: 'Get by Period', value: 'getByPeriod', description: 'Get traffic for a specific period', action: 'Get traffic by period', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['usage'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get usage information', action: 'Get usage information', }, { name: 'Get by Datacenter', value: 'getByDatacenter', description: 'Get usage by datacenter', action: 'Get usage by datacenter', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['utilization'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get utilization information', action: 'Get utilization information', }, { name: 'Get by Period', value: 'getByPeriod', description: 'Get utilization for a specific period', action: 'Get utilization by period', }, { name: 'Get by ID', value: 'getById', description: 'Get daily utilization by ID', action: 'Get utilization by ID', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['profile'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get billing profile', action: 'Get billing profile', }, ], default: 'get', }, { displayName: 'Contract Number', name: 'contractNumber', type: 'string', required: true, displayOptions: { show: { resource: ['evn', 'product', 'traffic', 'usage', 'utilization'], }, }, default: '', placeholder: '12345678', description: 'Contract number', }, { displayName: 'Contract Number', name: 'contractNumber', type: 'string', required: true, displayOptions: { show: { resource: ['invoice'], operation: ['get', 'getById'], }, }, default: '', placeholder: '12345678', description: 'Contract number', }, { displayName: 'Contract Number', name: 'contractNumber', type: 'string', required: true, displayOptions: { show: { resource: ['invoice'], operation: ['getByPeriod'], }, }, default: '', placeholder: '12345678', description: 'Contract number', }, { displayName: 'Period', name: 'period', type: 'string', required: true, displayOptions: { show: { operation: ['getByPeriod'], }, }, default: '', placeholder: '2024-01', description: 'Period in YYYY-MM format', }, { displayName: 'Invoice ID', name: 'invoiceId', type: 'string', required: true, displayOptions: { show: { resource: ['invoice'], operation: ['getById'], }, }, default: '', placeholder: 'GY00101408', description: 'Invoice ID', }, { displayName: 'Datacenter ID', name: 'datacenterId', type: 'string', required: true, displayOptions: { show: { resource: ['usage'], operation: ['getByDatacenter'], }, }, default: '', placeholder: 'dc-uuid', description: 'Datacenter UUID', }, { displayName: 'Utilization ID', name: 'utilizationId', type: 'string', required: true, displayOptions: { show: { resource: ['utilization'], operation: ['getById'], }, }, default: '', placeholder: 'utilization-uuid', description: 'Utilization UUID', }, { displayName: 'Additional Options', name: 'additionalOptions', type: 'collection', placeholder: 'Add Option', default: {}, options: [ { displayName: 'Date', name: 'date', type: 'string', default: '', placeholder: '2024-01-01', description: 'Date for filtering (YYYY-MM-DD format)', displayOptions: { show: { '/resource': ['product'], }, }, }, { displayName: 'Date Format', name: 'dateFormat', type: 'options', options: [ { name: 'Short (YYYY-MM)', value: 'short', }, { name: 'Long (YYYY-MM-DD)', value: 'long', }, ], default: 'short', description: 'Date format for invoice dates', displayOptions: { show: { '/resource': ['invoice'], }, }, }, { displayName: 'IP Address', name: 'ip', type: 'string', default: '', placeholder: '192.168.1.1', description: 'Filter traffic by IP address', displayOptions: { show: { '/resource': ['traffic'], }, }, }, { displayName: 'Output Format', name: 'output', type: 'options', options: [ { name: 'JSON', value: 'json', }, { name: 'CSV', value: 'csv', }, ], default: 'json', description: 'Output format for traffic data', displayOptions: { show: { '/resource': ['traffic'], }, }, }, ], }, ], }; async execute() { const items = this.getInputData(); const returnData = []; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { try { let responseData = {}; if (resource === 'evn') { const contractNumber = this.getNodeParameter('contractNumber', i); if (operation === 'get') { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/evn`, }); } else if (operation === 'getByPeriod') { const period = this.getNodeParameter('period', i); responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/evn/${period}`, }); } } else if (resource === 'invoice') { const additionalOptions = this.getNodeParameter('additionalOptions', i, {}); if (operation === 'get') { const contractNumber = this.getNodeParameter('contractNumber', i); responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/invoices`, }); } else if (operation === 'getById') { const contractNumber = this.getNodeParameter('contractNumber', i); const invoiceId = this.getNodeParameter('invoiceId', i); const qs = {}; if (additionalOptions.dateFormat) { qs.dateFormat = additionalOptions.dateFormat; } responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/invoices/${invoiceId}`, qs, }); } else if (operation === 'getByPeriod') { const period = this.getNodeParameter('period', i); const contractNumber = this.getNodeParameter('contractNumber', i, ''); const qs = {}; if (contractNumber) { qs.contractId = contractNumber; } if (additionalOptions.dateFormat) { qs.dateFormat = additionalOptions.dateFormat; } responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/invoices/${period}`, qs, }); } } else if (resource === 'product') { if (operation === 'get') { const contractNumber = this.getNodeParameter('contractNumber', i); const additionalOptions = this.getNodeParameter('additionalOptions', i, {}); const qs = {}; if (additionalOptions.date) { qs.date = additionalOptions.date; } responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/products`, qs, }); } } else if (resource === 'profile') { if (operation === 'get') { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/profile`, }); } } else if (resource === 'traffic') { const contractNumber = this.getNodeParameter('contractNumber', i); const additionalOptions = this.getNodeParameter('additionalOptions', i, {}); const qs = {}; if (additionalOptions.ip) { qs.ip = additionalOptions.ip; } if (additionalOptions.output) { qs.output = additionalOptions.output; } if (operation === 'get') { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/traffic`, qs, }); } else if (operation === 'getByPeriod') { const period = this.getNodeParameter('period', i); responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/traffic/${period}`, qs, }); } } else if (resource === 'usage') { const contractNumber = this.getNodeParameter('contractNumber', i); if (operation === 'get') { const qs = {}; const additionalOptions = this.getNodeParameter('additionalOptions', i, {}); if (additionalOptions.period) { qs.period = additionalOptions.period; } responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/usage`, qs, }); } else if (operation === 'getByDatacenter') { const datacenterId = this.getNodeParameter('datacenterId', i); const qs = {}; const additionalOptions = this.getNodeParameter('additionalOptions', i, {}); if (additionalOptions.period) { qs.period = additionalOptions.period; } responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/usage/${datacenterId}`, qs, }); } } else if (resource === 'utilization') { const contractNumber = this.getNodeParameter('contractNumber', i); if (operation === 'get') { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/utilization`, }); } else if (operation === 'getByPeriod') { const period = this.getNodeParameter('period', i); responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/utilization/${period}`, }); } else if (operation === 'getById') { const utilizationId = this.getNodeParameter('utilizationId', i); responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/${contractNumber}/utilization/daily/${utilizationId}`, }); } } const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } }); returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } }); returnData.push(...executionData); continue; } throw error; } } return [returnData]; } } exports.IonosCloudBilling = IonosCloudBilling;