n8n-nodes-dataforseo
Version:
DataForSEO is an SEO and marketing data provider, empowering businesses with invaluable insights via APIs and databases.
111 lines • 4.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataForSeoMerchantApi = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const google_shopping_1 = require("./resources/google_shopping");
const amazon_1 = require("./execute/amazon");
const google_shopping_2 = require("./execute/google_shopping");
const amazon_2 = require("./resources/amazon");
class DataForSeoMerchantApi {
constructor() {
this.description = {
displayName: 'DataForSEO Merchant API',
name: 'dataForSeoMerchantApi',
icon: 'file:dataforseo.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'DataForSEO',
defaults: {
name: 'DataForSeo Merchant API',
},
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: 'dataForSeoApi',
required: true,
},
],
requestDefaults: {
method: 'POST',
baseURL: 'https://api.dataforseo.com/v3',
headers: {
'Content-Type': 'application/json',
},
},
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Google Shopping',
value: 'google_shopping',
},
{
name: 'Amazon',
value: 'amazon',
}
],
default: 'google_shopping',
},
...google_shopping_1.GoogleShoppingOperations,
...amazon_2.AmazonOperations
],
};
}
async execute() {
let responseData = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const mapping = {
'google_shopping': {
'get-products-advanced': google_shopping_2.getProductsAdvnced,
'get-products-html': google_shopping_2.getProductsHTML,
'get-sellers-advanced': google_shopping_2.getSellersAdvnced,
'get-product-info': google_shopping_2.getProductInfo,
'get-product-reviews': google_shopping_2.getProductReviews
},
'amazon': {
'get-amazon-products-advanced': amazon_1.getAmazonProductsAdvnced,
'get-amazon-products-html': amazon_1.getAmazonProductsHtml,
'get-amazon-product-asins-advanced': amazon_1.getAmazonProductAsinsAdvnced,
'get-amazon-product-asins-html': amazon_1.getAmazonProductAsinsHtml,
'get-amazon-sellers-advanced': amazon_1.getAmazonSellersAdvnced,
'get-amazon-sellers-html': amazon_1.getAmazonSellersHtml
}
};
if (resource == 'google_shopping'
&& (operation == 'get-sellers-html' || operation == 'get-product-specification-advanced' || operation == 'get-product-specification-html')) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "This function is no longer available");
}
const fn = mapping[resource][operation];
if (!fn) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Something went wrong");
}
try {
const items = this.getInputData();
for (let i = 0; i < items.length; i++) {
const result = await fn(this, i);
responseData.push({
json: result,
pairedItem: { item: i }
});
}
}
catch (e) {
if (e instanceof n8n_workflow_1.NodeOperationError) {
throw e;
}
else {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Something went wrong");
}
}
return [this.helpers.returnJsonArray(responseData)];
}
}
exports.DataForSeoMerchantApi = DataForSeoMerchantApi;
//# sourceMappingURL=DataForSeoMerchantApi.node.js.map