UNPKG

n8n-nodes-bcryptsalted

Version:

Custom n8n node to generate salted bcrypt hash given a string input

101 lines (100 loc) 3.73 kB
"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.Bcryptsalted = void 0; const n8n_workflow_1 = require("n8n-workflow"); const bcrypt = __importStar(require("bcryptjs")); class Bcryptsalted { constructor() { this.description = { displayName: 'Bcrypt', name: 'bcrypt', group: ['transform'], version: 1, icon: 'file:bcryptsalted.svg', description: 'Generate a salted bcrypt hash from input string', defaults: { name: 'Bcrypt', }, inputs: ["main" /* NodeConnectionType.Main */], outputs: ["main" /* NodeConnectionType.Main */], properties: [ { displayName: 'Input String', name: 'input', type: 'string', default: '', placeholder: 'Enter text to hash...', required: true, description: 'The string to hash', }, { displayName: 'Salt Rounds', name: 'saltRounds', type: 'number', typeOptions: { minValue: 1, maxValue: 20, }, default: 10, description: 'Number of salt rounds to use for bcrypt', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const inputString = this.getNodeParameter('input', i); const saltRounds = this.getNodeParameter('saltRounds', i); const salt = bcrypt.genSaltSync(saltRounds); const hash = bcrypt.hashSync(inputString, salt); returnData.push({ json: { input: inputString, hash, }, }); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message); } } return this.prepareOutputData(returnData); } } exports.Bcryptsalted = Bcryptsalted;