n8n-nodes-ovh
Version:
Comprehensive n8n nodes for OVH API integration - Developed by Ascenzia, experts in AI agent creation
1,451 lines • 68 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.OvhDomain = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const crypto = __importStar(require("crypto"));
class OvhDomain {
constructor() {
this.description = {
displayName: 'OVH Domain',
name: 'ovhDomain',
icon: 'file:ovh.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Manage OVH domains',
defaults: {
name: 'OVH Domain',
},
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: 'ovhApi',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Contact',
value: 'contact',
},
{
name: 'DNS Record',
value: 'record',
},
{
name: 'Domain',
value: 'domain',
},
{
name: 'Nameserver',
value: 'nameserver',
},
{
name: 'Zone',
value: 'zone',
},
],
default: 'domain',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['domain'],
},
},
options: [
{
name: 'Get',
value: 'get',
description: 'Get domain information',
action: 'Get domain information',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many domains',
action: 'Get many domains',
},
{
name: 'Update',
value: 'update',
description: 'Update domain information',
action: 'Update domain information',
},
],
default: 'get',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['zone'],
},
},
options: [
{
name: 'Export',
value: 'export',
description: 'Export DNS zone',
action: 'Export DNS zone',
},
{
name: 'Import',
value: 'import',
description: 'Import DNS zone',
action: 'Import DNS zone',
},
{
name: 'Refresh',
value: 'refresh',
description: 'Refresh DNS zone',
action: 'Refresh DNS zone',
},
],
default: 'export',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['nameserver'],
},
},
options: [
{
name: 'Get',
value: 'get',
description: 'Get nameserver information',
action: 'Get nameserver information',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many nameservers for domain',
action: 'Get many nameservers for domain',
},
{
name: 'Update',
value: 'update',
description: 'Update domain nameservers',
action: 'Update domain nameservers',
},
],
default: 'getAll',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['contact'],
},
},
options: [
{
name: 'Get',
value: 'get',
description: 'Get domain contact information',
action: 'Get domain contact information',
},
{
name: 'Update',
value: 'update',
description: 'Update domain contacts',
action: 'Update domain contacts',
},
],
default: 'get',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['record'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a DNS record',
action: 'Create a DNS record',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a DNS record',
action: 'Delete a DNS record',
},
{
name: 'Get',
value: 'get',
description: 'Get DNS record information',
action: 'Get DNS record information',
},
{
name: 'Get All Detailed',
value: 'getAllDetailed',
description: 'Get detailed information for all DNS records',
action: 'Get detailed information for all DNS records',
},
{
name: 'Update',
value: 'update',
description: 'Update a DNS record',
action: 'Update a DNS record',
},
],
default: 'get',
},
{
displayName: 'Domain Name or ID',
name: 'domain',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getDomains',
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['domain'],
operation: ['get', 'update'],
},
},
description: 'The domain name to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Zone Name or ID',
name: 'zoneName',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getZones',
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['record'],
},
},
description: 'The DNS zone name. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Record Name or ID',
name: 'recordId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordIds',
loadOptionsDependsOn: ['zoneName'],
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['record'],
operation: ['get', 'update', 'delete'],
},
},
description: 'The DNS record ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Record Type',
name: 'recordType',
type: 'options',
displayOptions: {
show: {
resource: ['record'],
operation: ['create', 'getAllDetailed'],
},
},
options: [
{
name: 'A',
value: 'A',
},
{
name: 'AAAA',
value: 'AAAA',
},
{
name: 'CNAME',
value: 'CNAME',
},
{
name: 'MX',
value: 'MX',
},
{
name: 'NS',
value: 'NS',
},
{
name: 'PTR',
value: 'PTR',
},
{
name: 'SRV',
value: 'SRV',
},
{
name: 'TXT',
value: 'TXT',
},
],
default: 'A',
description: 'The type of DNS record to filter by or create',
},
{
displayName: 'Subdomain',
name: 'subdomain',
type: 'string',
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
},
},
default: '',
placeholder: 'www',
description: 'The subdomain (leave empty for root domain)',
},
{
displayName: 'Target',
name: 'target',
type: 'string',
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
},
},
default: '',
required: true,
placeholder: '192.168.1.1',
description: 'The target value for the DNS record',
},
{
displayName: 'TTL',
name: 'ttl',
type: 'number',
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
},
},
default: 3600,
description: 'Time to live in seconds',
},
{
displayName: 'Priority',
name: 'priority',
type: 'number',
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
recordType: ['MX', 'SRV'],
},
},
default: 10,
description: 'Priority for MX and SRV records',
},
{
displayName: 'Domain Name or ID',
name: 'zoneNameForZone',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getZones',
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['zone'],
},
},
description: 'The domain zone name. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Update Fields',
name: 'recordUpdateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['record'],
operation: ['update'],
},
},
options: [
{
displayName: 'Subdomain',
name: 'subdomain',
type: 'string',
default: '',
placeholder: 'www',
},
{
displayName: 'Target',
name: 'target',
type: 'string',
default: '',
placeholder: '192.168.1.1',
description: 'The target value',
},
{
displayName: 'TTL',
name: 'ttl',
type: 'number',
default: 3600,
description: 'Time to live in seconds',
},
{
displayName: 'Priority',
name: 'priority',
type: 'number',
default: 10,
description: 'Priority for MX and SRV records',
},
],
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['domain'],
operation: ['update'],
},
},
options: [
{
displayName: 'Transfer Lock Status',
name: 'transferLockStatus',
type: 'options',
options: [
{
name: 'Locked',
value: 'locked',
},
{
name: 'Locking',
value: 'locking',
},
{
name: 'Unlocked',
value: 'unlocked',
},
{
name: 'Unlocking',
value: 'unlocking',
},
],
default: 'locked',
description: 'Transfer lock status of the domain',
},
],
},
{
displayName: 'Zone Content',
name: 'zoneContent',
type: 'string',
typeOptions: {
rows: 10,
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['zone'],
operation: ['import'],
},
},
description: 'The zone file content to import',
},
{
displayName: 'Domain Name or ID',
name: 'domainNameNS',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getDomains',
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['nameserver', 'contact'],
},
},
description: 'The domain name to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Nameserver Name or ID',
name: 'nameserver',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getNameservers',
loadOptionsDependsOn: ['domainNameNS'],
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['nameserver'],
operation: ['get'],
},
},
description: 'The nameserver to get information for. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Nameservers',
name: 'nameservers',
type: 'collection',
typeOptions: {
multipleValues: true,
},
default: {},
displayOptions: {
show: {
resource: ['nameserver'],
operation: ['update'],
},
},
options: [
{
displayName: 'Nameserver',
name: 'nameserver',
type: 'string',
default: '',
placeholder: 'ns1.example.com',
description: 'Nameserver hostname',
},
],
description: 'List of nameservers to set for the domain',
},
{
displayName: 'Contact Type',
name: 'contactType',
type: 'options',
displayOptions: {
show: {
resource: ['contact'],
operation: ['get', 'update'],
},
},
options: [
{
name: 'Admin',
value: 'admin',
},
{
name: 'Billing',
value: 'billing',
},
{
name: 'Owner',
value: 'owner',
},
{
name: 'Tech',
value: 'tech',
},
],
default: 'owner',
description: 'Type of contact to retrieve or update',
},
{
displayName: 'Contact Name or ID',
name: 'contactId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getContacts',
},
default: '',
required: true,
displayOptions: {
show: {
resource: ['contact'],
operation: ['update'],
},
},
description: 'New contact ID to assign. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
],
};
this.methods = {
loadOptions: {
async getDomains() {
const returnData = [];
try {
const credentials = await this.getCredentials('ovhApi');
const endpoint = credentials.endpoint;
const applicationKey = credentials.applicationKey;
const applicationSecret = credentials.applicationSecret;
const consumerKey = credentials.consumerKey;
const path = '/domain';
const method = 'GET';
const timestamp = Math.round(Date.now() / 1000);
const fullUrl = `${endpoint}${path}`;
const signatureElements = [
applicationSecret,
consumerKey,
method,
fullUrl,
'',
timestamp,
];
const signature = '$1$' + crypto.createHash('sha1').update(signatureElements.join('+')).digest('hex');
const options = {
method,
url: fullUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': signature,
'X-Ovh-Timestamp': timestamp.toString(),
},
};
let responseData = await this.helpers.request(options);
if (typeof responseData === 'string') {
try {
responseData = JSON.parse(responseData);
}
catch (error) {
}
}
if (Array.isArray(responseData)) {
for (const domain of responseData) {
returnData.push({
name: domain,
value: domain,
});
}
}
}
catch (error) {
console.error('Error loading domains:', error);
}
return returnData;
},
async getZones() {
const returnData = [];
try {
const credentials = await this.getCredentials('ovhApi');
const endpoint = credentials.endpoint;
const applicationKey = credentials.applicationKey;
const applicationSecret = credentials.applicationSecret;
const consumerKey = credentials.consumerKey;
const path = '/domain/zone';
const method = 'GET';
const timestamp = Math.round(Date.now() / 1000);
const fullUrl = `${endpoint}${path}`;
const signatureElements = [
applicationSecret,
consumerKey,
method,
fullUrl,
'',
timestamp,
];
const signature = '$1$' + crypto.createHash('sha1').update(signatureElements.join('+')).digest('hex');
const options = {
method,
url: fullUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': signature,
'X-Ovh-Timestamp': timestamp.toString(),
},
};
let responseData = await this.helpers.request(options);
if (typeof responseData === 'string') {
try {
responseData = JSON.parse(responseData);
}
catch (error) {
}
}
if (Array.isArray(responseData)) {
for (const zone of responseData) {
returnData.push({
name: zone,
value: zone,
});
}
}
}
catch (error) {
console.error('Error loading zones:', error);
}
return returnData;
},
async getRecordIds() {
const returnData = [];
try {
const zoneName = this.getNodeParameter('zoneName');
if (!zoneName || zoneName.trim() === '') {
return returnData;
}
const credentials = await this.getCredentials('ovhApi');
const endpoint = credentials.endpoint;
const applicationKey = credentials.applicationKey;
const applicationSecret = credentials.applicationSecret;
const consumerKey = credentials.consumerKey;
const zoneNameTrimmed = zoneName.trim();
const path = `/domain/zone/${zoneNameTrimmed}/record`;
const method = 'GET';
const timestamp = Math.round(Date.now() / 1000);
const fullUrl = `${endpoint}${path}`;
const signatureElements = [
applicationSecret,
consumerKey,
method,
fullUrl,
'',
timestamp,
];
const signature = '$1$' + crypto.createHash('sha1').update(signatureElements.join('+')).digest('hex');
const options = {
method,
url: fullUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': signature,
'X-Ovh-Timestamp': timestamp.toString(),
},
};
let responseData = await this.helpers.request(options);
if (typeof responseData === 'string') {
try {
responseData = JSON.parse(responseData);
}
catch (error) {
}
}
if (Array.isArray(responseData)) {
for (const recordId of responseData) {
try {
const detailPath = `/domain/zone/${zoneNameTrimmed}/record/${recordId}`;
const detailUrl = `${endpoint}${detailPath}`;
const detailTimestamp = Math.round(Date.now() / 1000);
const detailSignatureElements = [
applicationSecret,
consumerKey,
'GET',
detailUrl,
'',
detailTimestamp,
];
const detailSignature = '$1$' + crypto.createHash('sha1').update(detailSignatureElements.join('+')).digest('hex');
const detailOptions = {
method: 'GET',
url: detailUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': detailSignature,
'X-Ovh-Timestamp': detailTimestamp.toString(),
},
};
let detailResponse = await this.helpers.request(detailOptions);
if (typeof detailResponse === 'string') {
try {
detailResponse = JSON.parse(detailResponse);
}
catch (error) {
}
}
const record = detailResponse;
const subdomain = record.subDomain || '@';
const type = record.fieldType || 'Unknown';
const target = record.target || '';
returnData.push({
name: `${subdomain} (${type}) -> ${target} [ID: ${recordId}]`,
value: recordId,
});
}
catch (error) {
returnData.push({
name: `Record ID: ${recordId}`,
value: recordId,
});
}
}
}
}
catch (error) {
console.error('Error loading record IDs:', error);
}
return returnData;
},
async getNameservers() {
const returnData = [];
try {
const domainName = this.getNodeParameter('domainNameNS');
if (!domainName || domainName.trim() === '') {
return returnData;
}
const credentials = await this.getCredentials('ovhApi');
const endpoint = credentials.endpoint;
const applicationKey = credentials.applicationKey;
const applicationSecret = credentials.applicationSecret;
const consumerKey = credentials.consumerKey;
const domainNameTrimmed = domainName.trim();
const path = `/domain/${domainNameTrimmed}`;
const method = 'GET';
const timestamp = Math.round(Date.now() / 1000);
const fullUrl = `${endpoint}${path}`;
const signatureElements = [
applicationSecret,
consumerKey,
method,
fullUrl,
'',
timestamp,
];
const signature = '$1$' + crypto.createHash('sha1').update(signatureElements.join('+')).digest('hex');
const options = {
method,
url: fullUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': signature,
'X-Ovh-Timestamp': timestamp.toString(),
},
};
let responseData = await this.helpers.request(options);
if (typeof responseData === 'string') {
try {
responseData = JSON.parse(responseData);
}
catch (error) {
}
}
if (responseData && typeof responseData === 'object' && responseData.nameServers) {
const nameServers = responseData.nameServers;
if (Array.isArray(nameServers)) {
for (const ns of nameServers) {
if (ns && ns.nameServer) {
returnData.push({
name: ns.nameServer,
value: ns.nameServer,
});
}
}
}
}
}
catch (error) {
console.error('Error loading nameservers:', error);
}
return returnData;
},
async getContacts() {
const returnData = [];
try {
const credentials = await this.getCredentials('ovhApi');
const endpoint = credentials.endpoint;
const applicationKey = credentials.applicationKey;
const applicationSecret = credentials.applicationSecret;
const consumerKey = credentials.consumerKey;
const path = '/me/contact';
const method = 'GET';
const timestamp = Math.round(Date.now() / 1000);
const fullUrl = `${endpoint}${path}`;
const signatureElements = [
applicationSecret,
consumerKey,
method,
fullUrl,
'',
timestamp,
];
const signature = '$1$' + crypto.createHash('sha1').update(signatureElements.join('+')).digest('hex');
const options = {
method,
url: fullUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': signature,
'X-Ovh-Timestamp': timestamp.toString(),
},
};
let responseData = await this.helpers.request(options);
if (typeof responseData === 'string') {
try {
responseData = JSON.parse(responseData);
}
catch (error) {
}
}
if (Array.isArray(responseData)) {
for (const contactId of responseData) {
try {
const detailPath = `/me/contact/${contactId}`;
const detailUrl = `${endpoint}${detailPath}`;
const detailTimestamp = Math.round(Date.now() / 1000);
const detailSignatureElements = [
applicationSecret,
consumerKey,
'GET',
detailUrl,
'',
detailTimestamp,
];
const detailSignature = '$1$' + crypto.createHash('sha1').update(detailSignatureElements.join('+')).digest('hex');
const detailOptions = {
method: 'GET',
url: detailUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': detailSignature,
'X-Ovh-Timestamp': detailTimestamp.toString(),
},
};
let detailResponse = await this.helpers.request(detailOptions);
if (typeof detailResponse === 'string') {
try {
detailResponse = JSON.parse(detailResponse);
}
catch (error) {
}
}
const contact = detailResponse;
const name = `${contact.firstName || ''} ${contact.lastName || ''}`.trim() || 'Unknown';
const email = contact.email || '';
returnData.push({
name: `${name} (${email}) - ${contactId}`,
value: contactId,
});
}
catch (error) {
returnData.push({
name: contactId,
value: contactId,
});
}
}
}
}
catch (error) {
console.error('Error loading contacts:', error);
}
return returnData;
},
},
};
}
async execute() {
var _a, _b, _c, _d;
const items = this.getInputData();
const returnData = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const credentials = await this.getCredentials('ovhApi');
const endpoint = credentials.endpoint;
const applicationKey = credentials.applicationKey;
const applicationSecret = credentials.applicationSecret;
const consumerKey = credentials.consumerKey;
for (let i = 0; i < items.length; i++) {
try {
let responseData;
let method = 'GET';
let path = '';
let body = {};
if (resource === 'domain') {
if (operation === 'get') {
const domain = this.getNodeParameter('domain', i);
if (!domain || domain.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Domain name is required', {
itemIndex: i,
});
}
path = `/domain/${domain.trim()}`;
}
else if (operation === 'getAll') {
path = '/domain';
}
else if (operation === 'update') {
method = 'PUT';
const domain = this.getNodeParameter('domain', i);
if (!domain || domain.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Domain name is required', {
itemIndex: i,
});
}
path = `/domain/${domain.trim()}`;
const updateFields = this.getNodeParameter('updateFields', i);
if (updateFields.transferLockStatus) {
body.transferLockStatus = updateFields.transferLockStatus;
}
}
}
else if (resource === 'record') {
const zoneName = this.getNodeParameter('zoneName', i);
if (!zoneName || zoneName.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zone name is required', { itemIndex: i });
}
const zoneNameTrimmed = zoneName.trim();
if (operation === 'get') {
const recordId = this.getNodeParameter('recordId', i);
path = `/domain/zone/${zoneNameTrimmed}/record/${recordId}`;
}
else if (operation === 'getAllDetailed') {
path = `/domain/zone/${zoneNameTrimmed}/record`;
const recordType = this.getNodeParameter('recordType', i);
path += `?fieldType=${recordType}`;
}
else if (operation === 'create') {
method = 'POST';
const recordType = this.getNodeParameter('recordType', i);
const subdomain = this.getNodeParameter('subdomain', i);
const target = this.getNodeParameter('target', i);
const ttl = this.getNodeParameter('ttl', i);
path = `/domain/zone/${zoneNameTrimmed}/record`;
body = {
fieldType: recordType,
subDomain: subdomain,
target,
ttl,
};
if (recordType === 'MX' || recordType === 'SRV') {
const priority = this.getNodeParameter('priority', i);
body.target = `${priority} ${target}`;
}
}
else if (operation === 'update') {
method = 'PUT';
const recordId = this.getNodeParameter('recordId', i);
const recordUpdateFields = this.getNodeParameter('recordUpdateFields', i);
path = `/domain/zone/${zoneNameTrimmed}/record/${recordId}`;
if (recordUpdateFields.subdomain !== undefined)
body.subDomain = recordUpdateFields.subdomain;
if (recordUpdateFields.target) {
let target = recordUpdateFields.target;
if (recordUpdateFields.priority) {
target = `${recordUpdateFields.priority} ${target}`;
}
body.target = target;
}
if (recordUpdateFields.ttl)
body.ttl = recordUpdateFields.ttl;
}
else if (operation === 'delete') {
method = 'DELETE';
const recordId = this.getNodeParameter('recordId', i);
path = `/domain/zone/${zoneNameTrimmed}/record/${recordId}`;
}
}
else if (resource === 'zone') {
const zoneName = this.getNodeParameter('zoneNameForZone', i);
if (!zoneName || zoneName.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Domain zone name is required', {
itemIndex: i,
});
}
const zoneNameTrimmed = zoneName.trim();
if (operation === 'export') {
path = `/domain/zone/${zoneNameTrimmed}/export`;
}
else if (operation === 'import') {
method = 'POST';
path = `/domain/zone/${zoneNameTrimmed}/import`;
const zoneContent = this.getNodeParameter('zoneContent', i);
body = { zoneContent };
}
else if (operation === 'refresh') {
method = 'POST';
path = `/domain/zone/${zoneNameTrimmed}/refresh`;
}
}
else if (resource === 'nameserver') {
const domainName = this.getNodeParameter('domainNameNS', i);
if (!domainName || domainName.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Domain name is required', {
itemIndex: i,
});
}
const domainNameTrimmed = domainName.trim();
if (operation === 'get') {
const nameserver = this.getNodeParameter('nameserver', i);
if (!nameserver || nameserver.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Nameserver is required', {
itemIndex: i,
});
}
path = `/domain/${domainNameTrimmed}/nameServer/${encodeURIComponent(nameserver.trim())}`;
}
else if (operation === 'getAll') {
path = `/domain/${domainNameTrimmed}`;
}
else if (operation === 'update') {
method = 'PUT';
const nameservers = this.getNodeParameter('nameservers', i);
path = `/domain/${domainNameTrimmed}/nameServer`;
body = {
nameServers: nameservers.map((ns) => ns.nameserver),
};
}
}
else if (resource === 'contact') {
const domainName = this.getNodeParameter('domainNameNS', i);
if (!domainName || domainName.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Domain name is required', {
itemIndex: i,
});
}
const domainNameTrimmed = domainName.trim();
const contactType = this.getNodeParameter('contactType', i);
if (operation === 'get') {
path = `/domain/${domainNameTrimmed}`;
}
else if (operation === 'update') {
method = 'POST';
const contactId = this.getNodeParameter('contactId', i);
if (!contactId || contactId.trim() === '') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Contact ID is required', {
itemIndex: i,
});
}
path = `/domain/${domainNameTrimmed}/changeContact`;
body = {
contactType: contactType,
contactId: contactId.trim(),
};
}
}
const timestamp = Math.round(Date.now() / 1000);
const fullUrl = `${endpoint}${path}`;
let bodyForSignature = '';
if (method === 'POST' || method === 'PUT') {
if (Object.keys(body).length > 0) {
bodyForSignature = JSON.stringify(body).replace(/[\u0080-\uFFFF]/g, (m) => {
return '\\u' + ('0000' + m.charCodeAt(0).toString(16)).slice(-4);
});
}
}
const signatureElements = [
applicationSecret,
consumerKey,
method,
fullUrl,
bodyForSignature,
timestamp,
];
const signature = '$1$' + crypto.createHash('sha1').update(signatureElements.join('+')).digest('hex');
const headers = {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': signature,
'X-Ovh-Timestamp': timestamp.toString(),
};
const options = {
method,
url: fullUrl,
headers,
};
if (method === 'POST' || method === 'PUT') {
if (Object.keys(body).length > 0) {
options.body = body;
options.json = true;
headers['Content-Type'] = 'application/json';
}
}
responseData = await this.helpers.request(options);
if (method === 'GET' && typeof responseData === 'string') {
try {
responseData = JSON.parse(responseData);
}
catch (error) {
}
}
if (operation === 'get' &&
resource === 'contact' &&
responseData &&
typeof responseData === 'object') {
const contactType = this.getNodeParameter('contactType', i);
const rawResponse = responseData;
const contactInfo = {
domain: rawResponse.domain || rawResponse.serviceName || '',
contactType: contactType,
};
const contactFields = {
owner: ((_a = rawResponse.contactOwner) === null || _a === void 0 ? void 0 : _a.id) || null,
admin: ((_b = rawResponse.contactAdmin) === null || _b === void 0 ? void 0 : _b.id) || null,
tech: ((_c = rawResponse.contactTech) === null || _c === void 0 ? void 0 : _c.id) || null,
billing: ((_d = rawResponse.contactBilling) === null || _d === void 0 ? void 0 : _d.id) || null,
};
let contactId = null;
if (contactType === 'owner' && contactFields.owner) {
contactId = contactFields.owner;
contactInfo.contactId = contactFields.owner;
}
else if (contactType === 'admin' && contactFields.admin) {
contactId = contactFields.admin;
contactInfo.contactId = contactFields.admin;
}
else if (contactType === 'tech' && contactFields.tech) {
contactId = contactFields.tech;
contactInfo.contactId = contactFields.tech;
}
else if (contactType === 'billing' && contactFields.billing) {
contactId = contactFields.billing;
contactInfo.contactId = contactFields.billing;
}
else {
contactInfo.ownerContact = contactFields.owner;
contactInfo.adminContact = contactFields.admin;
contactInfo.techContact = contactFields.tech;
contactInfo.billingContact = contactFields.billing;
}
contactInfo.domainState = rawResponse.state;
contactInfo.transferLockStatus = rawResponse.transferLockStatus;
contactInfo.expirationDate = rawResponse.expirationDate;
contactInfo.whoisOwner = rawResponse.whoisOwner;
if (contactId) {
try {
const contactPath = `/me/contact/${contactId}`;
const contactUrl = `${endpoint}${contactPath}`;
const contactTimestamp = Math.round(Date.now() / 1000);
const contactSignatureElements = [
applicationSecret,
consumerKey,
'GET',
contactUrl,
'',
contactTimestamp.toString(),
];
const contactSignature = crypto
.createHash('sha1')
.update(`$1$${contactSignatureElements.join('+')}`)
.digest('hex');
const contactOptions = {
method: 'GET',
url: contactUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': `$1$${contactSignature}`,
'X-Ovh-Timestamp': contactTimestamp.toString(),
},
};
const contactDetails = await this.helpers.request(contactOptions);
let parsedContactDetails = contactDetails;
if (typeof contactDetails === 'string') {
try {
parsedContactDetails = JSON.parse(contactDetails);
}
catch (error) {
}
}
if (parsedContactDetails && typeof parsedContactDetails === 'object') {
const details = parsedContactDetails;
contactInfo.contactDetails = {
id: details.id,
firstName: details.firstName,
lastName: details.lastName,
email: details.email,
phone: details.phone,
cellPhone: details.cellPhone,
fax: details.fax,
address: details.address,
city: details.city,
zip: details.zip,
country: details.country,
language: details.language,
legalForm: details.legalForm,
organisationName: details.organisationName,
organisationType: details.organisationType,
nationalIdentificationNumber: details.nationalIdentificationNumber,
vat: details.vat,
birthDay: details.birthDay,
birthCity: details.birthCity,
birthCountry: details.birthCountry,
gender: details.gender,
};
}
}
catch (error) {
contactInfo.contactDetailsError = error.message || 'Failed to fetch contact details';
}
}
responseData = contactInfo;
}
if (operation === 'getAll' &&
resource === 'nameserver' &&
responseData &&
typeof responseData === 'object' &&
responseData.nameServers) {
const nameServers = responseData.nameServers;
responseData = nameServers;
}
if (operation === 'getAllDetailed' &&
resource === 'record' &&
Array.isArray(responseData)) {
const zoneName = this.getNodeParameter('zoneName', i);
const zoneNameTrimmed = zoneName.trim();
const detailedRecords = [];
for (const recordId of responseData) {
try {
const detailPath = `/domain/zone/${zoneNameTrimmed}/record/${recordId}`;
const detailUrl = `${endpoint}${detailPath}`;
const detailTimestamp = Math.round(Date.now() / 1000);
const detailSignatureElements = [
applicationSecret,
consumerKey,
'GET',
detailUrl,
'',
detailTimestamp,
];
const detailSignature = '$1$' + crypto.createHash('sha1').update(detailSignatureElements.join('+')).digest('hex');
const detailOptions = {
method: 'GET',
url: detailUrl,
headers: {
'X-Ovh-Application': applicationKey,
'X-Ovh-Consumer': consumerKey,
'X-Ovh-Signature': detailSignature,
'X-Ovh-Timestamp': detailTimestamp.toString(),
},
};
let detailResponse = await this.helpers.request(detailOptions);
if (typeof detailResponse === 'string') {
try {
detailResponse = JSON.parse(detailResponse);
}
catch (error) {
}
}
detailedRecords.push(detailResponse);
}
catch (error) {
detailedRecords.push({
id: recordId,
error: 'Failed to fetch details',
message: error.message || 'Unknown error',
});
}
}
responseData = detailedRecords;
}
if (Array.isArray(responseData)) {
if (operation === 'getAll' && resource === 'domain') {
responseData.forEach((domainName) => {
returnData.push({ json: { domain: domainName } });
});
}
else if (operation === 'getAll' && resource === 'nameserver') {
responseData.forEach((nameserver) => {
returnData.push({
json: {
nameserver: nameserver.nameServer,
id: nameserver.id,
nameServerType: nameserver.nameServerType,
},
});
});
}
else {
responseData.forEach((item) => {
if (typeof item === 'string' || typeof item === 'number') {
returnData.push({ json: { value: item } });
}
else {
returnData.push({ json: item });
}
});
}
}
else {
if (operation === 'export' && resource === 'zone' && typeof responseData === 'string') {
returnData.push({ json: { zoneContent: responseData } });
}
else {
returnData.push(responseData);
}
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
}
else {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
itemIndex: i,
});
}
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}
exports.OvhDomain = OvhDomain;
//# sourceMappingURL=OvhDomain.node.js.map