UNPKG

@ai-growth/n8n-nodes-wordpress

Version:

n8n node for WordPress integration with AI GROWTH - SEO WP plugin

58 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CredentialHelper = void 0; const Validator_1 = require("./Validator"); const n8n_workflow_1 = require("n8n-workflow"); /** * Classe auxiliar para gerenciar credenciais do WordPress */ class CredentialHelper { /** * Obtém e valida as credenciais do WordPress * @param execFunctions Funções de execução do n8n * @param itemIndex Índice do item atual (padrão: 0) * @returns Credenciais do WordPress validadas */ static async getCredentials(execFunctions, itemIndex = 0) { try { // Obter credenciais do n8n const credentials = await execFunctions.getCredentials('wordpressApi'); if (!credentials) { throw new n8n_workflow_1.NodeOperationError(execFunctions.getNode(), 'No credentials provided for WordPress API'); } // Converter para o formato esperado const wordpressCredentials = { url: Validator_1.Validator.sanitizeUrl(credentials.url), username: credentials.username, password: credentials.password, }; // Validar credenciais const validationResult = Validator_1.Validator.validateCredentials(wordpressCredentials); if (!validationResult.valid) { throw new n8n_workflow_1.NodeOperationError(execFunctions.getNode(), `Invalid WordPress API credentials: ${validationResult.error}`); } return wordpressCredentials; } catch (error) { if (error instanceof n8n_workflow_1.NodeOperationError) { throw error; } throw new n8n_workflow_1.NodeOperationError(execFunctions.getNode(), `Error retrieving WordPress API credentials: ${error.message}`); } } /** * Cria os cabeçalhos de autenticação para requisições * @param credentials Credenciais do WordPress * @returns Cabeçalhos de autenticação */ static createAuthHeaders(credentials) { // Codificar as credenciais em base64 const token = Buffer.from(`${credentials.username}:${credentials.password}`).toString('base64'); return { 'Authorization': `Basic ${token}`, 'Content-Type': 'application/json', }; } } exports.CredentialHelper = CredentialHelper; //# sourceMappingURL=CredentialHelper.js.map