UNPKG

n8n-node-crypto-js

Version:
154 lines 5.68 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Base64 = void 0; const set_1 = __importDefault(require("lodash/set")); const n8n_workflow_1 = require("n8n-workflow"); class Base64 { constructor() { this.description = { displayName: 'Base64', name: 'base64', icon: 'file:base64.png', group: ['transform'], version: 1, subtitle: '={{$parameter["action"]}}', description: 'Base64 encode and decode a string', defaults: { name: 'Base64', }, inputs: ['main'], outputs: ['main'], properties: [ { displayName: 'Action', name: 'action', type: 'options', options: [ { name: 'Base64 Encode', description: 'Base64 encode a string', value: 'base64Encode', action: 'Base64 encode a string', }, { name: 'Base64 Decode', description: 'Base64 decode a string', value: 'base64Decode', action: 'Base64 decode a string', }, ], default: 'base64Decode', }, { displayName: 'Value', name: 'value', type: 'string', typeOptions: { editor: 'htmlEditor', rows: 10, }, default: '', description: 'The value that should be encoded or decoded', required: true, }, { displayName: 'Output Property Name', name: 'outputPropertyName', type: 'string', default: 'data', required: true, description: 'Name of the property to which to write the encoded or decoded value', }, { displayName: 'Options', name: 'options', type: 'collection', placeholder: 'Add option', default: {}, options: [ { displayName: 'JSON Parse', name: 'jsonParse', type: 'boolean', default: false, description: 'Whether to parse the value as JSON', }, ], displayOptions: { show: { action: ['base64Decode'], }, }, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const length = items.length; const action = this.getNodeParameter('action', 0); let item; for (let i = 0; i < length; i++) { try { item = items[i]; const outputPropertyName = this.getNodeParameter('outputPropertyName', i); const value = this.getNodeParameter('value', i, ''); const { jsonParse } = this.getNodeParameter('options', i, {}); let newValue; let binaryProcessed = false; if (action === 'base64Encode') { newValue = Buffer.from(value).toString('base64'); } if (action === 'base64Decode') { newValue = Buffer.from(value, 'base64').toString(); if (jsonParse) { newValue = JSON.parse(newValue); } } let newItem; if (outputPropertyName.includes('.')) { newItem = { json: (0, n8n_workflow_1.deepCopy)(item.json), pairedItem: { item: i, }, }; } else { newItem = { json: { ...item.json }, pairedItem: { item: i, }, }; } if (item.binary !== undefined && !binaryProcessed) { newItem.binary = item.binary; } (0, set_1.default)(newItem, ['json', outputPropertyName], newValue); returnData.push(newItem); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, pairedItem: { item: i, }, }); continue; } throw error; } } return [returnData]; } } exports.Base64 = Base64; //# sourceMappingURL=Base64.node.js.map