autho 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/bin.js +141 -10
  2. package/package.json +14 -14
package/build/bin.js CHANGED
@@ -54924,7 +54924,7 @@ var {
54924
54924
  } = import_index.default;
54925
54925
 
54926
54926
  // packages/cli/bin.js
54927
- var import_path = __toESM(require("path"), 1);
54927
+ var import_path2 = __toESM(require("path"), 1);
54928
54928
 
54929
54929
  // node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js
54930
54930
  var ANSI_BACKGROUND_OFFSET = 10;
@@ -57258,6 +57258,8 @@ var createSecretSchema = import_joi.default.object({
57258
57258
  // packages/sdk/cipher.js
57259
57259
  var import_crypto = __toESM(require("crypto"), 1);
57260
57260
  var import_fs = __toESM(require("fs"), 1);
57261
+ var import_path = __toESM(require("path"), 1);
57262
+ var import_zlib = __toESM(require("zlib"), 1);
57261
57263
 
57262
57264
  // packages/shared/config.js
57263
57265
  var import_dotenv = __toESM(require_main2(), 1);
@@ -57384,6 +57386,84 @@ var Cipher = class _Cipher {
57384
57386
  const decryptedData = _Cipher.decrypt(params);
57385
57387
  import_fs.default.writeFileSync(outputFilePath, decryptedData);
57386
57388
  }
57389
+ static encryptFolder({ inputFolderPath, outputFilePath, encryptionKey, algorithm = config_default.encryptionALgo, encoding = "hex" }) {
57390
+ const outputStream = import_fs.default.createWriteStream(outputFilePath);
57391
+ const gzip = import_zlib.default.createGzip();
57392
+ gzip.pipe(outputStream);
57393
+ const baseFolder = import_path.default.basename(inputFolderPath);
57394
+ function traverseFolder(folderPath) {
57395
+ const items = import_fs.default.readdirSync(folderPath);
57396
+ for (const item of items) {
57397
+ const itemPath = import_path.default.join(baseFolder, import_path.default.relative(inputFolderPath, import_path.default.join(folderPath, item)));
57398
+ if (import_fs.default.statSync(itemPath).isDirectory()) {
57399
+ traverseFolder(itemPath);
57400
+ } else {
57401
+ const fileContent = import_fs.default.readFileSync(itemPath);
57402
+ const params = {
57403
+ value: fileContent,
57404
+ encryptionKey,
57405
+ algorithm,
57406
+ encoding
57407
+ };
57408
+ const encryptedData = _Cipher.encrypt(params);
57409
+ const encrypted = encryptedData.encrypted;
57410
+ delete encryptedData.encrypted;
57411
+ const encryptionMeta = Buffer.from(JSON.stringify(encryptedData)).toString("base64");
57412
+ gzip.write(`${itemPath}
57413
+ ---
57414
+ ${encrypted}
57415
+ ---
57416
+ ${encryptionMeta}
57417
+ :::
57418
+ `);
57419
+ }
57420
+ }
57421
+ }
57422
+ traverseFolder(inputFolderPath);
57423
+ gzip.end();
57424
+ return new Promise((resolve, reject) => {
57425
+ outputStream.on("finish", resolve);
57426
+ outputStream.on("error", reject);
57427
+ });
57428
+ }
57429
+ static decryptFolder({ inputFilePath, outputFolderPath, encryptionKey }) {
57430
+ const inputStream = import_fs.default.createReadStream(inputFilePath);
57431
+ const gunzip = import_zlib.default.createGunzip();
57432
+ inputStream.pipe(gunzip);
57433
+ let buff = "";
57434
+ const compileFile = (data) => {
57435
+ buff += data;
57436
+ if (buff.includes(":::")) {
57437
+ const [file, next] = buff.split("\n:::\n");
57438
+ let [filePath, encrypted, encryptionMeta] = file.split("\n---\n");
57439
+ filePath = import_path.default.join(outputFolderPath, filePath);
57440
+ try {
57441
+ import_fs.default.mkdirSync(import_path.default.dirname(filePath), { recursive: true });
57442
+ } catch (error) {
57443
+ }
57444
+ const decoded = Buffer.from(
57445
+ encryptionMeta,
57446
+ "base64"
57447
+ ).toString("utf-8");
57448
+ const metaData = JSON.parse(decoded);
57449
+ const params = {
57450
+ ...metaData,
57451
+ value: encrypted,
57452
+ encryptionKey
57453
+ };
57454
+ const decryptedData = _Cipher.decrypt(params);
57455
+ import_fs.default.writeFileSync(filePath, decryptedData);
57456
+ buff = next;
57457
+ }
57458
+ };
57459
+ gunzip.on("data", (data) => {
57460
+ compileFile(data.toString("utf8"));
57461
+ });
57462
+ return new Promise((resolve, reject) => {
57463
+ gunzip.on("end", resolve);
57464
+ gunzip.on("error", reject);
57465
+ });
57466
+ }
57387
57467
  };
57388
57468
 
57389
57469
  // packages/sdk/secrets.js
@@ -58033,14 +58113,14 @@ var Temp = {
58033
58113
  }
58034
58114
  },
58035
58115
  truncate: (filePath) => {
58036
- const basename = import_node_path2.default.basename(filePath);
58037
- if (basename.length <= LIMIT_BASENAME_LENGTH)
58116
+ const basename2 = import_node_path2.default.basename(filePath);
58117
+ if (basename2.length <= LIMIT_BASENAME_LENGTH)
58038
58118
  return filePath;
58039
- const truncable = /^(\.?)(.*?)((?:\.[^.]+)?(?:\.tmp-\d{10}[a-f0-9]{6})?)$/.exec(basename);
58119
+ const truncable = /^(\.?)(.*?)((?:\.[^.]+)?(?:\.tmp-\d{10}[a-f0-9]{6})?)$/.exec(basename2);
58040
58120
  if (!truncable)
58041
58121
  return filePath;
58042
- const truncationLength = basename.length - LIMIT_BASENAME_LENGTH;
58043
- return `${filePath.slice(0, -basename.length)}${truncable[1]}${truncable[2].slice(0, -truncationLength)}${truncable[3]}`;
58122
+ const truncationLength = basename2.length - LIMIT_BASENAME_LENGTH;
58123
+ return `${filePath.slice(0, -basename2.length)}${truncable[1]}${truncable[2].slice(0, -truncationLength)}${truncable[3]}`;
58044
58124
  }
58045
58125
  };
58046
58126
  node_default(Temp.purgeSyncAll);
@@ -59523,10 +59603,22 @@ var Logger = import_baloga.Logger;
59523
59603
  var logger2 = new Logger();
59524
59604
  var program2 = new Command();
59525
59605
  var getAuthoAbsolutePath = (path5) => {
59526
- if (import_path.default.isAbsolute(path5)) {
59527
- return import_path.default.join(path5, ".autho");
59606
+ if (import_path2.default.isAbsolute(path5)) {
59607
+ return import_path2.default.join(path5, ".autho");
59608
+ }
59609
+ return import_path2.default.join(process.cwd(), path5, ".autho");
59610
+ };
59611
+ var toAbsolutePath = (inputPath) => {
59612
+ if (import_path2.default.isAbsolute(inputPath)) {
59613
+ return inputPath;
59614
+ } else {
59615
+ return import_path2.default.join(process.cwd(), inputPath);
59528
59616
  }
59529
- return import_path.default.join(process.cwd(), path5, ".autho");
59617
+ };
59618
+ var basename = (filePath) => {
59619
+ const normalizedPath = import_path2.default.normalize(filePath);
59620
+ const folderName = import_path2.default.basename(normalizedPath);
59621
+ return folderName;
59530
59622
  };
59531
59623
  program2.name("autho").description("Secrets manager").version("0.0.1").option("-p, --password <password>", "Master password").option("-ph, --passwordHash <passwordHash>", "Master password hash").option("-n, --name <name>", "Collection name", "default").option(
59532
59624
  "-data, --dataFolder <folderPath>",
@@ -59604,7 +59696,10 @@ program2.name("autho").description("Secrets manager").version("0.0.1").option("-
59604
59696
  }
59605
59697
  });
59606
59698
  program2.command("file").description("Encrypt/Decrypt file").option("-f, --filePath <filePath>", "File path").option("-en, --encrypt", "Encrypt file", false).option("-de, --decrypt", "Decrypt file", false).option("--override", "Override original file", false).action(async (args) => {
59607
- const { encrypt, decrypt, filePath, override } = args;
59699
+ logger2.debug(`file:`, args);
59700
+ const { encrypt, decrypt, override } = args;
59701
+ let { filePath } = args;
59702
+ filePath = toAbsolutePath(filePath);
59608
59703
  const encryptionKey = await App.masterKey();
59609
59704
  if (!encrypt && !decrypt) {
59610
59705
  console.log("Please provide either --encrypt or --decrypt");
@@ -59624,6 +59719,42 @@ program2.command("file").description("Encrypt/Decrypt file").option("-f, --fileP
59624
59719
  }
59625
59720
  process.exit(0);
59626
59721
  });
59722
+ program2.command("files").description("Encrypt/Decrypt file").option("--input <inputPath>", "Folder path").option("--output <outputPath>", "Folder path", process.cwd()).option("-en, --encrypt", "Encrypt folder", false).option("-de, --decrypt", "Decrypt folder", false).action(async (args) => {
59723
+ try {
59724
+ logger2.debug(`files:`, args);
59725
+ const { encrypt, decrypt } = args;
59726
+ let { input, output } = args;
59727
+ input = toAbsolutePath(input);
59728
+ output = toAbsolutePath(output);
59729
+ const folderName = basename(input);
59730
+ const encryptionKey = await App.masterKey();
59731
+ if (!encrypt && !decrypt) {
59732
+ console.log("Please provide either --encrypt or --decrypt");
59733
+ process.exit(1);
59734
+ } else if (encrypt) {
59735
+ console.log("Encrypting files:", input);
59736
+ const outputFilePath = import_path2.default.join(output, folderName + ".gzip.autho");
59737
+ await Cipher.encryptFolder({
59738
+ inputFolderPath: input,
59739
+ outputFilePath,
59740
+ encryptionKey
59741
+ });
59742
+ console.log("Created:", outputFilePath);
59743
+ } else if (decrypt) {
59744
+ console.log("Decrypting files:", input);
59745
+ await Cipher.decryptFolder({
59746
+ inputFilePath: input,
59747
+ outputFolderPath: output,
59748
+ encryptionKey
59749
+ });
59750
+ }
59751
+ } catch (error) {
59752
+ logger2.error("Something went wrong, Error: ", error.message);
59753
+ console.log(error.stack);
59754
+ process.exit(1);
59755
+ }
59756
+ process.exit(0);
59757
+ });
59627
59758
  program2.parse();
59628
59759
  /*! Bundled license information:
59629
59760
 
package/package.json CHANGED
@@ -1,24 +1,11 @@
1
1
  {
2
2
  "name": "autho",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "main": "build/bin.js",
5
5
  "type": "commonjs",
6
6
  "bin": {
7
7
  "autho": "build/bin.js"
8
8
  },
9
- "scripts": {
10
- "format": "prettier --check .",
11
- "format:write": "prettier --write .",
12
- "lint": "eslint .",
13
- "lint:fix": "eslint --fix .",
14
- "build": "esbuild packages/cli/bin.js --bundle --platform=node --target=node18 --outdir=build",
15
- "pkg": "npm run pkg:linux && npm run pkg:macos && npm run pkg:win",
16
- "pkg:macos-arm64": "pkg build/bin.js --output dist/autho --target node18-macos-arm64",
17
- "pkg:macos": "pkg build/bin.js --output dist/autho-macos --target node18-macos-x64",
18
- "pkg:linux": "pkg build/bin.js --output dist/autho-linux --target node18-linux-x64",
19
- "pkg:win": "pkg build/bin.js --output dist/autho-win --target node18-win-x64",
20
- "release": "gh release create v0.0.8 ./dist"
21
- },
22
9
  "keywords": [
23
10
  "secrets",
24
11
  "otp"
@@ -49,5 +36,18 @@
49
36
  "node18-macos-x64"
50
37
  ],
51
38
  "outputPath": "dist"
39
+ },
40
+ "scripts": {
41
+ "format": "prettier --check .",
42
+ "format:write": "prettier --write .",
43
+ "lint": "eslint .",
44
+ "lint:fix": "eslint --fix .",
45
+ "build": "esbuild packages/cli/bin.js --bundle --platform=node --target=node18 --outdir=build",
46
+ "pkg": "npm run pkg:linux && npm run pkg:macos && npm run pkg:win",
47
+ "pkg:macos-arm64": "pkg build/bin.js --output dist/autho --target node18-macos-arm64",
48
+ "pkg:macos": "pkg build/bin.js --output dist/autho-macos --target node18-macos-x64",
49
+ "pkg:linux": "pkg build/bin.js --output dist/autho-linux --target node18-linux-x64",
50
+ "pkg:win": "pkg build/bin.js --output dist/autho-win --target node18-win-x64",
51
+ "release": "gh release create v0.0.8 ./dist/* --title 'v0.0.8' --generate-notes --prerelease"
52
52
  }
53
53
  }