secure-flow
Advanced tools
Comparing version 1.0.6-beta-2 to 1.0.6-beta-3
@@ -13,3 +13,3 @@ import fs from 'fs'; | ||
const isTsFile = path.resolve(__dirName, 'tsconfig.json'); | ||
// console.log("isTsFile", isTsFile); | ||
console.log(isTsFile); | ||
let configPath; | ||
@@ -24,3 +24,3 @@ if (fs.existsSync(isTsFile)) { | ||
if (fs.existsSync(configPath)) { | ||
console.error(fs.existsSync(isTsFile) ? 'secureflow.config.ts already exists in the root directory.' : 'secureflow.config.cjs already exists in the root directory.'); | ||
console.log(fs.existsSync(isTsFile) ? 'secureflow.config.ts already exists in the root directory.' : 'secureflow.config.cjs already exists in the root directory.'); | ||
process.exit(1); | ||
@@ -27,0 +27,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export declare function encrypt(text: string): string | undefined; | ||
export declare function encrypt(text: string): Promise<string>; | ||
export declare function decrypt(text: string): string | undefined; |
import { loadConfig } from './loadConfig.js'; | ||
import { createCipheriv, createDecipheriv } from 'node:crypto'; | ||
const config = loadConfig(); | ||
export function encrypt(text) { | ||
const config = await loadConfig(); | ||
export async function encrypt(text) { | ||
try { | ||
@@ -6,0 +6,0 @@ const cipher = createCipheriv(config.encryptionAlgorithm, Buffer.from(config.encryptionKey), config.iv); |
import { Config } from './config.js'; | ||
export declare function loadConfig(): Config; | ||
export declare function loadConfig(): Promise<Config>; |
import { defaultConfig } from './config.js'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
export function loadConfig() { | ||
export async function loadConfig() { | ||
let customConfigPath; | ||
@@ -15,3 +15,11 @@ // const args = process.argv.slice(2); | ||
if (fs.existsSync(customConfigPath)) { | ||
const customConfig = require(customConfigPath).default || require(customConfigPath); | ||
let customConfig; | ||
// if (customConfigPath.endsWith('.ts')) { | ||
// For TypeScript file | ||
const module = await import(customConfigPath); | ||
customConfig = module.default || module; | ||
// } else { | ||
// // For CommonJS file | ||
// customConfig = require(customConfigPath).default || require(customConfigPath); | ||
// } | ||
return { ...defaultConfig, ...customConfig }; | ||
@@ -18,0 +26,0 @@ } |
{ | ||
"name": "secure-flow", | ||
"version": "1.0.6-beta-2", | ||
"version": "1.0.6-beta-3", | ||
"description": "Secure Flow is a lightweight TypeScript utility package for encryption and decryption using the AES-256-CBC algorithm. This package simplifies the process of securely encrypting and decrypting text, making it easy to integrate strong encryption into your Node.js applications.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -14,2 +14,3 @@ ## SecureFlow | ||
## Usage | ||
A file named secureflow.config.ts or secureflow.config.cjs is created with the following content: | ||
@@ -34,9 +35,9 @@ | ||
```typescript | ||
app.get("/encrypt", (req, res) => { | ||
const data = JSON.stringify({ data: "Hello, World!" }); | ||
app.get("/encrypt", async (req, res) => { | ||
const data = await JSON.stringify({ data: "Hello, World!" }); | ||
res.status(200).json(encrypt(data)); | ||
}); | ||
app.get("/decrypt", (req, res) => { | ||
const data = req.body; | ||
app.get("/decrypt", async (req, res) => { | ||
const data = await req.body; | ||
res.status(200).json(decrypt(data)); | ||
@@ -43,0 +44,0 @@ }); |
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { dirname } from 'path'; | ||
@@ -18,3 +16,2 @@ const __dirName = process.env.INIT_CWD; | ||
const isTsFile = path.resolve(__dirName, 'tsconfig.json'); | ||
// console.log("isTsFile", isTsFile); | ||
@@ -31,3 +28,3 @@ let configPath: string; | ||
if (fs.existsSync(configPath)) { | ||
console.error(fs.existsSync(isTsFile) ? 'secureflow.config.ts already exists in the root directory.' : 'secureflow.config.cjs already exists in the root directory.'); | ||
console.log(fs.existsSync(isTsFile) ? 'secureflow.config.ts already exists in the root directory.' : 'secureflow.config.cjs already exists in the root directory.'); | ||
process.exit(1); | ||
@@ -34,0 +31,0 @@ } else { |
@@ -5,5 +5,5 @@ import { loadConfig } from './loadConfig.js'; | ||
const config: Config = loadConfig(); | ||
const config: Config = await loadConfig(); | ||
export function encrypt(text: string): string | undefined { | ||
export async function encrypt(text: string): Promise<string> { | ||
try { | ||
@@ -24,3 +24,3 @@ const cipher = createCipheriv( | ||
export function decrypt(text: string): string | undefined { | ||
export async function decrypt(text: string): Promise<string> { | ||
try { | ||
@@ -27,0 +27,0 @@ const decipher = createDecipheriv( |
@@ -5,5 +5,4 @@ import { Config, defaultConfig } from './config.js'; | ||
export function loadConfig(): Config { | ||
export async function loadConfig(): Promise<Config> { | ||
let customConfigPath: string; | ||
// const args = process.argv.slice(2); | ||
let configPath = path.resolve(process.cwd(), 'tsconfig.json'); | ||
@@ -18,4 +17,5 @@ | ||
if (fs.existsSync(customConfigPath)) { | ||
const customConfig = require(customConfigPath).default || require(customConfigPath); | ||
return { ...defaultConfig, ...customConfig }; | ||
const module = await import(customConfigPath); | ||
let customConfig = module.default || module; | ||
return { ...defaultConfig, ...customConfig } as Config; | ||
} else { | ||
@@ -22,0 +22,0 @@ throw new Error(`No config file found at ${customConfigPath}`); |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
13268
278
67
3