UNPKG

@papavault/n8n-nodes-papavault

Version:

n8n community node for PapaVault

95 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PapavaultNode = void 0; const n8n_workflow_1 = require("n8n-workflow"); const cli_1 = require("@papavault/cli"); class PapavaultNode { constructor() { this.description = { displayName: 'PapaVault', name: 'papavault', icon: 'file:papavault.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["filename"]}}', description: 'Interact with PapaVault API', defaults: { name: 'PapaVault', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'papaVaultApi', required: true, }, ], properties: [ { displayName: 'Environment', name: 'environment', type: 'string', default: '', required: true, description: 'The environment to use', }, { displayName: 'Filename', name: 'filename', type: 'string', default: '', required: true, description: 'The name of the credential file to retrieve', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const environment = this.getNodeParameter('environment', i); const filename = this.getNodeParameter('filename', i); const credentials = await this.getCredentials('papaVaultApi'); const papaVault = new cli_1.PapaVault({ token: credentials.token, projectId: credentials.projectId, }); const result = await papaVault.getCredentialFiles(environment); const file = result[0]; if (!file) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: `No credential file found with name: ${filename}`, description: 'Please check if the file exists in the specified environment', }); } const fileInfo = await papaVault.getCredentialFile(environment, file.id); const content = await papaVault.downloadCredentialFile(fileInfo.downloadUrl); const outputData = { fileName: file.fileName, filePath: file.filePath, content, createdAt: file.createdAt, updatedAt: file.updatedAt, }; returnData.push(outputData); } catch (error) { if (this.continueOnFail()) { returnData.push({ error: error.message, }); continue; } throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: error.message, description: 'An error occurred while fetching credentials from PapaVault', }); } } return [this.helpers.returnJsonArray(returnData)]; } } exports.PapavaultNode = PapavaultNode; //# sourceMappingURL=Papavault.node.js.map