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,OAFA,EAAS,KAAK,KAAK,+BAEZ,CAAe,IAEvB,MAAK,KACJ,EAAS,UAAU,IAEpB,OAAO,IACN,EAAS,MAAM,EAAM,GACrB,GAER","file":"/npm/@runforest/encrypt@2.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@runforest/encrypt@2.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const path = require('path');\nconst fs = require('fs-extra');\nconst chalk = require('chalk');\nconst { execSync } = require('child_process');\n\nconst Observable = require('@runforest/run/utils/observable');\n\n/**\n@typedef {{\n  encryptDir: string;\n  publicKey: string;\n  extension: string;\n  mode: 'build';\n}} ValidatedConfig\n@typedef {Partial<Omit<ValidatedConfig, 'mode'>> & { mode: string; }} Config\n */\n\n/**\n * Validate the inbound config and throw errors if required configs are missing\n *\n * @param {Config} config\n * @returns {Promise<ValidatedConfig>}\n */\nasync function validate(config) {\n  let { encryptDir } = config;\n\n  const { publicKey, extension, mode = 'build' } = config;\n  const projectRoot = path.resolve(process.cwd());\n\n  if (!encryptDir) {\n    throw new Error('This cannot be run without a directory');\n  }\n\n  encryptDir = path.resolve(projectRoot, encryptDir);\n\n  if (encryptDir === projectRoot) {\n    throw new Error(\"Don't encrypt the root dir\");\n  }\n\n  if (!fs.existsSync(encryptDir)) {\n    throw new Error('Encryption directory does not exist');\n  }\n\n  if (!publicKey) {\n    throw new Error('No Public Key provided');\n  }\n\n  if (!fs.existsSync(publicKey)) {\n    throw new Error('Public key not found');\n  }\n\n  if (!extension) {\n    throw new Error('Provide a type of file to encrypt. Typical .pem');\n  }\n\n  if (mode !== 'build') {\n    throw new Error('This package supports only build mode.');\n  }\n\n  return {\n    encryptDir,\n    publicKey,\n    extension,\n    mode: 'build',\n  };\n}\n\n/**\n * @param {Config} config\n * @returns\n */\nmodule.exports = function runEncrypt(config) {\n  return new Observable((observer) => {\n    validate(config)\n      .then(async (validatedConfig) => {\n        const files = await fs.readdir(validatedConfig.encryptDir);\n        const filtered = files.filter((file) => path.extname(file).toLowerCase() === validatedConfig.extension);\n\n        /* eslint-disable no-await-in-loop */\n        for (let i = 0; i < filtered.length; i += 1) {\n          const file = filtered[i];\n\n          // Make one pass and make the file complete\n          const filePath = path.join(validatedConfig.encryptDir, file);\n\n          // Throws an error file does not exist\n          await fs.stat(filePath);\n\n          observer.next(chalk`{green encrypting ${file}}`);\n          execSync(`openssl rand -base64 128 -out ${filePath}.bin`);\n          execSync(`openssl enc -aes-256-cbc -salt -in ${filePath} -out ${filePath}.enc -pass file:${filePath}.bin`);\n          execSync(\n            `openssl rsautl -encrypt -inkey ${validatedConfig.publicKey} -pubin -in ${filePath}.bin -out ${filePath}.bin.enc`\n          );\n\n          await fs.unlink(`${filePath}.bin`);\n          await fs.unlink(`${filePath}`);\n        }\n        /* eslint-enable no-await-in-loop */\n\n        observer.next(chalk`{green Encryption Complete}`);\n\n        return validatedConfig;\n      })\n      .then(() => {\n        observer.complete();\n      })\n      .catch((error) => {\n        observer.error(error);\n      });\n  });\n};\n"]}