amp-ext
Advanced tools
Comparing version 1.0.4 to 1.0.5
38
index.js
@@ -43,7 +43,8 @@ #! /usr/bin/env node | ||
verbose = true, | ||
cleanup = true, | ||
region = "US", | ||
time_unit = 'day', | ||
tempDir = './tmp', | ||
destDir = './amplitude-data', | ||
logFile = `./amplitude-export-log.txt` | ||
destDir = './exports', | ||
logFile = `./logs/amplitude-export-log-${Date.now()}.txt` | ||
} = config; | ||
@@ -85,3 +86,3 @@ const l = log(verbose); | ||
const url = region === 'US' ? 'https://amplitude.com/api/2/export' : 'https://analytics.eu.amplitude.com/api/2/export'; | ||
l(`\n\n\tDOWNLOAD\n\n`) | ||
l(`\n\n\tDOWNLOAD\n\n`); | ||
consumeData: for (const dates of datePairs) { | ||
@@ -143,5 +144,5 @@ const logPair = `${dayjs.utc(dates.start).format(logFormat)} → ${dayjs.utc(dates.end).format(logFormat)}`; | ||
const downloadedFiles = (await u.ls(TEMP_DIR)).filter(path => path.endsWith('.zip')); | ||
l(`\n\n\tUNZIP\n\n`) | ||
l(`\n\n\tUNZIP\n\n`); | ||
unzip: for (const zipFile of downloadedFiles) { | ||
@@ -153,3 +154,3 @@ l(`unzipping ${path.basename(zipFile)}`); | ||
execSync(`unzip -j ${escapeForShell(zipFile)} -d ${escapeForShell(dir)}`); | ||
await u.rm(zipFile); | ||
if (cleanup) await u.rm(zipFile); | ||
continue unzip; | ||
@@ -162,3 +163,3 @@ } catch (e) { | ||
}); | ||
await u.rm(zipFile); | ||
if (cleanup) await u.rm(zipFile); | ||
continue unzip; | ||
@@ -185,3 +186,3 @@ } | ||
l(`\n\n\tGUNZIP\n\n`) | ||
l(`\n\n\tGUNZIP\n\n`); | ||
@@ -198,3 +199,3 @@ ungzip: for (const file of gunzipped.flat()) { | ||
eventCount += Number(numLines.toString().split('/').map(x => x.trim())[0]); | ||
await u.rm(file); | ||
if (cleanup) await u.rm(file); | ||
continue ungzip; | ||
@@ -211,3 +212,3 @@ | ||
await u.touch(dest, rawData); | ||
await u.rm(file); | ||
if (cleanup) await u.rm(file); | ||
continue ungzip; | ||
@@ -218,9 +219,12 @@ } | ||
for (const folder of folders) { | ||
await u.rm(folder); | ||
if (cleanup) await u.rm(folder); | ||
} | ||
const extracted = (await u.ls(DESTINATION_DIR)).filter(f => f.endsWith('.json')); | ||
l(`\nextracted ${u.comma(extracted.length)} files for ${u.comma(eventCount)} events\n`); | ||
if (LOG_FILE) await u.touch(path.resolve(LOG_FILE), logText); | ||
await u.rm(TEMP_DIR); | ||
l('\n\nfinish!\n\n') | ||
if (LOG_FILE) { | ||
if (LOG_FILE.includes("/logs/")) await u.mkdir(path.resolve('./logs')); | ||
await u.touch(path.resolve(LOG_FILE), logText); | ||
} | ||
if (cleanup) await u.rm(TEMP_DIR); | ||
l('\n\nfinish!\n\n'); | ||
@@ -287,3 +291,3 @@ return extracted; | ||
demandOption: false, | ||
default: "./amplitude-data", | ||
default: "./exports", | ||
describe: 'where to write files', | ||
@@ -330,3 +334,3 @@ type: 'string' | ||
} | ||
if (verbose) console.log(data); | ||
@@ -333,0 +337,0 @@ }; |
{ | ||
"name": "amp-ext", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "pull data out of amplitude", | ||
"main": "index.js", | ||
"scripts": { | ||
"scratch": "nodemon --inspect -i ./tmp -i ./amplitude-data scratch.js", | ||
"prune": "rm -rf ./tmp/* && rm -rf ./amplitude-data/*", | ||
"post": "npm publish" | ||
"scratch": "nodemon --inspect -i ./tmp -i ./exports -i ./logs scratch.js", | ||
"prune": "rm -rf ./tmp/* && rm -rf ./exports/* && rm -rf ./logs/*", | ||
"post": "npm publish", | ||
"test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js" | ||
}, | ||
@@ -15,2 +16,3 @@ "bin": { | ||
"type": "module", | ||
"types": "./types.d.ts", | ||
"keywords": [], | ||
@@ -29,4 +31,6 @@ "author": "", | ||
"devDependencies": { | ||
"dotenv": "^16.0.3", | ||
"jest": "^29.5.0", | ||
"nodemon": "^2.0.22" | ||
} | ||
} |
@@ -21,24 +21,28 @@ interface Config { | ||
*/ | ||
region: "US" | "EU"; | ||
region?: "US" | "EU"; | ||
/** | ||
* unit of time to chunk | ||
*/ | ||
time_unit: "day" | "hour" | "month"; | ||
time_unit?: "day" | "hour" | "month"; | ||
/** | ||
* where to put temporary data; must be a valid file path .... default is ./tmp | ||
*/ | ||
tempDir: string; | ||
tempDir?: string; | ||
/** | ||
* where to put extracted data; must be a valid file path .... default is ./amplitude-data | ||
*/ | ||
destDir: string; | ||
destDir?: string; | ||
/** | ||
* file to write logs; must be a valid file path .... default is ./amplitude-data | ||
*/ | ||
logFile: string | false; | ||
logFile?: string | false; | ||
/** | ||
* log console output messages | ||
*/ | ||
verbose: boolean | ||
verbose?: boolean | ||
/** | ||
* remove all temporary + intermediate files | ||
*/ | ||
cleanup?: boolean | ||
} |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
13119
9
441
3
5
3