redact-phi
Advanced tools
Comparing version 0.6.0 to 0.7.0
#!/usr/bin/env node | ||
const crypto = require('crypto'); | ||
const telemetry = require('../telemetry'); | ||
const { Command } = require('commander'); | ||
@@ -7,7 +9,16 @@ const program = new Command(); | ||
const csv = require('csv'); | ||
const process = require('process'); | ||
program.version('1.0.0'); | ||
const runId = crypto.randomBytes(16).toString('hex'); | ||
let metric; | ||
async function main() { | ||
metric = await telemetry.init(); | ||
metric(runId, { | ||
start: true | ||
}); | ||
program | ||
.option('--delimiter <delimiter>', 'sets delimiter type', ',') | ||
.option('-y', 'Skips all prompts') | ||
.option('--strategy <override>', 'Provide the location of your redaction specification') | ||
@@ -19,4 +30,12 @@ .argument('<infile>', 'File to redact') | ||
.action(async (infile, outfile) => { | ||
metric(runId, { | ||
infile: typeof infile === 'string', | ||
outfile: typeof outfile === 'string' | ||
}) | ||
if (infile === 'help') { | ||
metric(runId, { | ||
'help': true | ||
}); | ||
console.log('Please run again with --help flag'); | ||
await telemetry.sendMetrics(); | ||
return process.exit(0); | ||
@@ -27,2 +46,5 @@ } | ||
const fileExtension = path.extname(infile); | ||
metric(runId, { | ||
fileExtension, override | ||
}); | ||
const absolutePath = path.join(process.cwd(), infile); | ||
@@ -34,3 +56,7 @@ if (!outfile) { | ||
if (fileExtension === '.csv') { | ||
handleCsv(engine, absolutePath, outfile); | ||
await handleCsv(engine, absolutePath, outfile); | ||
} else { | ||
console.error(`File type ${fileExtension} is currently unsupported, xslx and JSON are coming soon!`); | ||
await telemetry.sendMetrics(); | ||
process.exit(-1); | ||
} | ||
@@ -43,3 +69,3 @@ }) | ||
function handleCsv(engine, absolutePath, outfile) { | ||
async function handleCsv(engine, absolutePath, outfile) { | ||
console.log('Starting Redaction'); | ||
@@ -51,2 +77,16 @@ let count = 0; | ||
}); | ||
metric(runId, { | ||
delimiter: options.delimiter | ||
}); | ||
try { | ||
fs.statSync(absolutePath) | ||
} catch (err) { | ||
console.error(`Input file '${absolutePath}' does not exist or cannot be read`); | ||
metric(runId, { | ||
name: err.name, | ||
code: err.code | ||
}) | ||
await telemetry.sendMetrics(); | ||
process.exit(-1); | ||
} | ||
const parser = fs.createReadStream(absolutePath).pipe(csv.parse()); | ||
@@ -57,4 +97,3 @@ const outStream = fs.createWriteStream(outfile); | ||
while (row = stringifier.read()) { | ||
outStream.write(row) | ||
outStream.write(row); | ||
} | ||
@@ -71,3 +110,10 @@ }); | ||
parser.on('end', () => { | ||
metric(runId, { | ||
end: true, | ||
count | ||
}); | ||
telemetry.sendMetrics(); | ||
console.log(`Finished Redacting, ${count} records processed`); | ||
console.log(`Created File: ${outfile}`); | ||
}) | ||
@@ -84,5 +130,9 @@ } | ||
} catch (err) { | ||
metric(runId, { | ||
error: err, | ||
code: err.code | ||
}); | ||
} | ||
if (config === false) { | ||
await telemetry.sendMetrics(); | ||
throw new Error('No suitable configuration file found'); | ||
@@ -95,6 +145,31 @@ } | ||
await fs.promises.stat(absolutePath.replace(fileExtension, '.js')); | ||
metric(runId, { | ||
defaultStrategy: false | ||
}); | ||
} catch (err) { | ||
configuration.strategies = {} | ||
metric(runId, { | ||
defaultStrategy: true | ||
}); | ||
configuration.strategies = {}; | ||
} | ||
telemetry.sendMetrics(); | ||
return configuration; | ||
} | ||
} | ||
process.on('beforeExit', async () => { | ||
return await telemetry.sendMetrics(); | ||
}); | ||
process.on('SIGTERM', async () => { | ||
return await telemetry.sendMetrics(); | ||
}); | ||
process.on('uncaughtException', async (err, origin) => { | ||
metric(runId, { | ||
uncaughtException: true, | ||
errorName: err.name, | ||
errorMessage: err.message, | ||
origin | ||
}) | ||
await telemetry.sendMetrics(); | ||
}); |
{ | ||
"name": "redact-phi", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Assists in the redaction of PHI in structured or semi-structured data, supporting excel (XSLX), CSV or JSON.", | ||
@@ -27,2 +27,3 @@ "main": "main.js", | ||
"dependencies": { | ||
"axios": "^0.22.0", | ||
"commander": "^8.2.0", | ||
@@ -29,0 +30,0 @@ "csv": "^5.5.3", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
27324
13
497
5
5
+ Addedaxios@^0.22.0
+ Addedaxios@0.22.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)