dotsec 2.0.0-alpha.0 → 4.0.0-alpha.0
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.
- package/dist/cli/index.js +134 -8
- package/dist/cli/index.js.map +1 -7
- package/dist/cli/index.mjs +134 -8
- package/dist/cli/index.mjs.map +1 -7
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -7
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -7
- package/package.json +4 -7
- package/src/templates/dotsec.config.ts +1 -13
- package/dist/index.d.ts +0 -148
package/dist/cli/index.mjs
CHANGED
|
@@ -1,19 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
import{Command as Ke}from"commander";var de="dotsec.config.ts",G=[de],R=".sec",M=".env",T={defaults:{}};import fe from"fs";import me from"node:path";function ge(t){try{return new Function(`return ${t.trim()}`)()}catch{return{}}}var W=async t=>{try{return ge(await fe.promises.readFile(t,"utf8"))}catch(i){throw i instanceof Error?new Error(`Failed to parse ${me.relative(process.cwd(),t)}: ${i.message}`):i}};import{bundleRequire as ue}from"bundle-require";import ye from"joycon";import Oe from"path";var U=async t=>{let i=process.cwd(),n=await new ye().resolve({files:t?[t]:[...G,"package.json"],cwd:i,stopDir:Oe.parse(i).root,packageKey:"dotsec"});if(t&&n===null)throw new Error(`Could not find config file ${t}`);if(n){if(n.endsWith(".json")){let e=await W(n),o;return n.endsWith("package.json")&&e.dotsec!==void 0?o=e.dotsec:o=e,{source:"json",contents:{...T,...o,defaults:{...o?.defaults,...T.defaults,plugins:{...o?.defaults?.plugins,...T.defaults?.plugins}},push:{...o?.push}}}}else if(n.endsWith(".ts")){let e=await ue({filepath:n}),o=e.mod.dotsec||e.mod.default||e.mod;return{source:"ts",contents:{...T,...o,defaults:{...o?.defaults,...T.defaults,plugins:{...o?.defaults?.plugins,...T.defaults?.plugins}},push:{...o?.push}}}}}return{source:"defaultConfig",contents:T}};var q=async t=>import(t.name).then(i=>i.default);import{Option as Ce}from"commander";var F=(t,i,p)=>{t&&Object.values(t).map(n=>{let e;if(Array.isArray(n)){let[o,a,l]=n;e={flags:o,description:a,defaultValue:l}}else{let{flags:o,description:a,defaultValue:l,choices:s,env:r,fn:f}=n;e={flags:o,description:a,defaultValue:l,choices:s,env:r,fn:f}}if(e){let o=new Ce(e.flags,e.description);e.fn&&o.argParser(e.fn),e.defaultValue&&o.default(e.defaultValue),e.env&&o.env(e.env),p&&o.makeOptionMandatory(!0),e.choices&&o.choices(e.choices),i.addOption(o)}})};import K,{stat as he}from"node:fs/promises";import ve from"node:path";import Ee from"prompts";var j=async t=>await K.readFile(t,"utf-8"),_=async(t,i)=>await K.writeFile(t,i,"utf-8"),we=async t=>{try{return await he(t),!0}catch{return!1}},V=async({filePath:t,skip:i})=>{let p;return await we(t)&&i!==!0?p=await Ee({type:"confirm",name:"overwrite",message:()=>`Overwrite './${ve.relative(process.cwd(),t)}' ?`}):p=void 0,p};import De from"chalk";import On from"cli-table";var C=t=>De.yellow.bold(t);import{Option as Te}from"commander";var b={option:["--env-file <envFile>",`Path to .env file. If not provided, will look for value in 'ENV_FILE' environment variable. If not provided, will look for '${M}' file in current directory.`,M],env:"ENV_FILE"},I={option:["--sec-file, <secFile>",`Path to .sec file. If not provided, will look for value in 'SEC_FILE' environment variable. If not provided, will look for '${R}' file in current directory.`,R],env:"SEC_FILE"},k={flags:"--using <using>",description:"Wether to use a dot env file or a dot sec file",choices:["env","sec"],env:"DOTSEC_USING"},J={flags:"--using <using>",description:"Wether to use a dot env file or a dot sec file",choices:["env"],env:"DOTSEC_USING"},P={option:["--yes","Skip confirmation prompts"]};var D={option:["-c, --config-file, --configFile <configFile>","Config file"],env:"DOTSEC_CONFIG_FILE"},B={option:["--plugin <plugin>","Comma-separated list of plugins to use"],env:"DOTSEC_PLUGIN"},Y={option:["--engine <engine>","Encryption engine to use"],env:"DOTSEC_ENGINE"},H={option:["--create-manifest","Create a markdown manifest file. See the --manifest-file option for more information."],env:"CREATE_MANIFEST"},L={option:["--manifest-file <manifestFile>","Specify the name of the manifest file to create."],env:"ENCRYPTION_MANIFEST_FILE"};var Fe={decrypt:{options:{configFile:D,envFile:b,secFile:I,createManifest:H,manifestFile:L,yes:P},description:"Decrypt a sec file",helpText:`Examples:
|
|
2
2
|
|
|
3
|
-
Run a command with a .env file
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
Decrypt .sec file to .env file
|
|
5
|
+
|
|
6
|
+
$ npx dotsec decrypt
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Specify a different .sec file
|
|
10
|
+
|
|
11
|
+
$ npx dotsec decrypt --sec-file .sec.dev
|
|
12
|
+
$ SEC_FILE=.sec.dev npx dotsec decrypt
|
|
13
|
+
|
|
14
|
+
Specify a different .env file
|
|
15
|
+
|
|
16
|
+
$ npx dotsec decrypt --env-file .env.dev
|
|
17
|
+
$ ENV_FILE=.env.dev npx dotsec decrypt
|
|
18
|
+
|
|
19
|
+
Write a manifest file
|
|
20
|
+
|
|
21
|
+
$ npx dotsec decrypt --create-manifest
|
|
22
|
+
$ CREATE_MANIFEST=true npx dotsec decrypt
|
|
23
|
+
|
|
24
|
+
Specify a different manifest file
|
|
25
|
+
|
|
26
|
+
$ npx dotsec decrypt --manifest-file .manifest.dev
|
|
27
|
+
$ MANIFEST_FILE=.manifest.dev npx dotsec decrypt
|
|
28
|
+
`}},z=Fe;var xe={dotsec:{options:{configFile:D,plugin:B}}},Q=xe;var Pe={encrypt:{options:{configFile:D,envFile:b,secFile:I,createManifest:H,manifestFile:L,yes:P},description:"Encrypt an env file",helpText:`Examples:
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Encrypt .env file to .sec file
|
|
32
|
+
|
|
33
|
+
$ npx dotsec encrypt
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Specify a different .env file
|
|
37
|
+
|
|
38
|
+
$ npx dotsec encrypt --env-file .env.dev
|
|
39
|
+
$ ENV_FILE=.env.dev npx dotsec encrypt
|
|
40
|
+
|
|
41
|
+
Specify a different .sec file
|
|
42
|
+
|
|
43
|
+
$ npx dotsec encrypt --sec-file .sec.dev
|
|
44
|
+
$ SEC_FILE=.sec.dev npx dotsec encrypt
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Write a manifest file
|
|
48
|
+
|
|
49
|
+
$ npx dotsec encrypt --create-manifest
|
|
50
|
+
$ CREATE_MANIFEST=true npx dotsec encrypt
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Specify a different manifest file
|
|
54
|
+
|
|
55
|
+
$ npx dotsec encrypt --manifest-file .manifest.dev
|
|
56
|
+
$ MANIFEST_FILE=.manifest.dev npx dotsec encrypt
|
|
57
|
+
`}},X=Pe;var $e={init:{options:{configFile:D,yes:P},description:"Initialize a dotsec project by creating a dotsec.config.ts file.",helpText:`Examples:
|
|
58
|
+
|
|
59
|
+
Create a dotsec.config.ts file in the current directory
|
|
60
|
+
|
|
61
|
+
$ npx dotsec init
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
Overwrite an existing dotsec.config.ts file in the current directory
|
|
65
|
+
|
|
66
|
+
$ npx dotsec init --yes
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Create a dotsec config file in the current directory with a specific config file name
|
|
70
|
+
|
|
71
|
+
By specifying the --config-file option, you can create a dotsec config file with a specific name.
|
|
72
|
+
|
|
73
|
+
$ npx dotsec init --config-file dotsec.config.ts
|
|
74
|
+
|
|
75
|
+
$ DOTSEC_CONFIG_FILE=my.config.ts npx dotsec init
|
|
76
|
+
`}},Z=$e;var be={push:{options:{configFile:D,envFile:b,secFile:I,yes:P},requiredOptions:{using:k},description:"Push variables from env or sec file to a remote",helpText:`Examples:
|
|
77
|
+
|
|
78
|
+
Push variables from .env file to remote
|
|
79
|
+
|
|
80
|
+
$ npx dotsec push --using env
|
|
81
|
+
$ DOTSEC_USING=env npx dotsec push
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
Push variables from .sec file to remote
|
|
85
|
+
|
|
86
|
+
$ npx dotsec push --using sec
|
|
87
|
+
$ DOTSEC_USING=sec npx dotsec push
|
|
88
|
+
`}},ee=be;var Se={runEnvOnly:{usage:"--using env [commandArgs...]",options:{configFile:D,envFile:b,yes:P,engine:Y},requiredOptions:{using:J},description:"Run a command in a separate process and populate env with contents of a dotenv file.",helpText:`Examples:
|
|
89
|
+
|
|
90
|
+
Run a command with a .env file
|
|
91
|
+
|
|
92
|
+
$ npx dotsec run --using env node -e "console.log(process.env)"
|
|
6
93
|
|
|
7
94
|
|
|
8
95
|
Run a command with a specific .env file
|
|
9
96
|
|
|
10
|
-
$ dotsec run --env-file .env
|
|
97
|
+
$ npx dotsec run --using env --env-file .env node -e "console.log(process.env)"
|
|
98
|
+
|
|
11
99
|
|
|
12
100
|
Run a command with a specific ENV_FILE variable
|
|
13
101
|
|
|
14
|
-
$ ENV_FILE=.env.dev dotsec run
|
|
102
|
+
$ ENV_FILE=.env.dev npx dotsec run --using env node -e "console.log(process.env)"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
You can also specify 'using' as an environment variable
|
|
15
106
|
|
|
16
|
-
|
|
107
|
+
$ DOTSEC_USING=env npx dotsec run node -e "console.log(process.env)"
|
|
108
|
+
`},run:{options:{configFile:D,envFile:b,secFile:I,yes:P},requiredOptions:{using:k},usage:"[--using env] [--using sec] [commandArgs...]",description:`Run a command in a separate process and populate env with either
|
|
17
109
|
- contents of a dotenv file
|
|
18
110
|
- decrypted values of a dotsec file.
|
|
19
111
|
|
|
@@ -37,5 +129,39 @@ $ dotsec run --with-sec echo "hello world"
|
|
|
37
129
|
Run a command with a specific .sec file
|
|
38
130
|
|
|
39
131
|
$ dotsec run --with-sec --sec-file .sec.dev echo "hello world"
|
|
40
|
-
`},push:{options:E(c({},K.dotsec.options),{withEnv:L,withSec:q,envFile:b,secFile:j,yes:S}),requiredOptions:c({},K.dotsec.requiredOptions)}},de=ze;var Xe=c(c(c(c(c(c(c({},K),me),le),pe),de),U),U);var Ye=e=>Array.isArray(e)?{option:e}:e,fe=(e,t)=>{var p,i,m;let r=Ye(e),[o,n,a]=r.option,l=(m=(i=(p=t==null?void 0:t.dotsecConfig)==null?void 0:p.defaults)==null?void 0:i.options)==null?void 0:m[t==null?void 0:t.optionKey],s=new Qe(o,n+(l?". Default from config.":""));return a&&s.default(l||a),r.env&&s.env(r.env),(t==null?void 0:t.required)&&s.makeOptionMandatory(!0),s},T=e=>{let{program:t,commandName:r,dotsecConfig:o}=e,n=Xe[r||t.name()];if(n){let{options:a,requiredOptions:l,description:s,usage:p,helpText:i}=n;a&&Object.keys(a).forEach(m=>{let d=a[m],C=fe(d,{dotsecConfig:o,optionKey:m});t.addOption(C)}),l&&Object.keys(l).forEach(m=>{let d=l[m],C=fe(d,{required:!0,dotsecConfig:o,optionKey:m});t.addOption(C)}),s&&t.description(s),p&&t.description(p),i&&t.description(i)}};var Ze=async(e,t)=>{let{dotsecConfig:r,decryptHandlers:o}=t,n=e.enablePositionalOptions().passThroughOptions().command("decrypt").action(async(l,s)=>{var p;try{let{envFile:i,secFile:m,engine:d,yes:C}=s.optsWithGlobals(),D=d||((p=r==null?void 0:r.defaults)==null?void 0:p.encryptionEngine),v=(o||[]).find(w=>w.triggerOptionValue===D);if(!v)throw new Error(`No decryption plugin found, available decryption engine(s): ${t.decryptHandlers.map(w=>`--${w.triggerOptionValue}`).join(", ")}`);console.log("Decrypting with",F(v.encryptionEngineName||v.triggerOptionValue),"engine");let f=[...Object.keys(v.options||{}),...Object.keys(v.requiredOptions||{})],u=Object.fromEntries(f.map(w=>[w,l[w]])),g=await G(m),h=await v.handler(c({ciphertext:g},u)),y=await I({filePath:i,skip:C});(y===void 0||y.overwrite===!0)&&(await H(i,h),console.log(`Wrote plaintext contents of ${F(m)} file to ${F(i)}`))}catch(i){console.error(F(i.message)),s.help()}});t.decryptHandlers.map(l=>{let{options:s,requiredOptions:p}=l;$(s,n),$(p,n,!0)});let a=t.decryptHandlers.map(l=>l.triggerOptionValue);return n.option("--engine <engine>",`Encryption engine${a.length>0?"s":""} to use: ${a.length===1?a[0]:a.join(", ")}`,a.length===1?a[0]:void 0),T({program:n,dotsecConfig:r}),n},ue=Ze;var et=async(e,t)=>{let{encryptHandlers:r,dotsecConfig:o}=t,n=e.enablePositionalOptions().passThroughOptions().command("encrypt").action(async(s,p)=>{var i;try{let{envFile:m,secFile:d,engine:C,yes:D}=p.optsWithGlobals(),v=C||((i=o==null?void 0:o.defaults)==null?void 0:i.encryptionEngine),f=(r||[]).find(O=>O.triggerOptionValue===v);if(!f)throw new Error(`No encryption plugin found, available encryption engine(s): ${t.encryptHandlers.map(O=>O.triggerOptionValue).join(", ")}`);console.log("Encrypting with",F(f.encryptionEngineName||f.triggerOptionValue),"engine");let u=[...Object.keys(f.options||{}),...Object.keys(f.requiredOptions||{})],g=Object.fromEntries(u.map(O=>[O,s[O]])),h=await G(m),y=await f.handler(c({plaintext:h},g)),w=await I({filePath:d,skip:D});(w===void 0||w.overwrite===!0)&&(await H(d,y),console.log(`Wrote encrypted contents of ${F(m)} file to ${F(d)}`))}catch(m){console.error(F(m.message)),p.help()}});t.encryptHandlers.map(s=>{let{options:p,requiredOptions:i}=s;$(p,n),$(i,n,!0)});let a=t.encryptHandlers.map(s=>s.triggerOptionValue),l=t.encryptHandlers.map(s=>s.encryptionEngineName);return n.option("--engine <engine>",`Encryption engine${a.length>0?"s":""}: ${a.length===1?a[0]:a.join(", ")}`),T({program:n,dotsecConfig:o}),n.description(`Encrypt .env file using ${l.join(", ")}`),n},ge=et;import tt from"node:fs";import{ScriptKind as ct,ScriptTarget as at,SyntaxKind as it,createPrinter as ot,createSourceFile as st,createStringLiteral as he,transform as pt,visitEachChild as nt,visitNode as rt}from"typescript";var ye=e=>{let t=ot(),r=tt.readFileSync(e.configFile,"utf8"),o=p=>i=>{function m(d){var C,D,v,f,u,g,h,y,w,O,P,x,N,Q,X,Y,Z,ee;if(d=nt(d,m,p),d.kind===it.StringLiteral){let V=(D=(C=d==null?void 0:d.parent)==null?void 0:C.parent)==null?void 0:D.parent;if(((u=(f=(v=e.config)==null?void 0:v.aws)==null?void 0:f.kms)==null?void 0:u.keyAlias)&&((g=V==null?void 0:V.getChildAt(0))==null?void 0:g.getText())==="kms"){let A=(h=V==null?void 0:V.parent)==null?void 0:h.parent;if((A==null?void 0:A.getChildAt(0).getText())==="aws")return he((O=(w=(y=e.config)==null?void 0:y.aws)==null?void 0:w.kms)==null?void 0:O.keyAlias)}if(((x=(P=e.config)==null?void 0:P.aws)==null?void 0:x.region)&&((Q=(N=d==null?void 0:d.parent)==null?void 0:N.getChildAt(0))==null?void 0:Q.getText())==="region"){let A=(Y=(X=d==null?void 0:d.parent)==null?void 0:X.parent)==null?void 0:Y.parent;if((A==null?void 0:A.getChildAt(0).getText())==="aws")return he((ee=(Z=e.config)==null?void 0:Z.aws)==null?void 0:ee.region)}}return d}return rt(i,m)},n=st("test.ts",r,at.ES2015,!0,ct.TS),a=pt(n,[o]),l=a.transformed[0],s=t.printFile(l);return a.dispose(),s};import lt from"node:path";var mt=async(e,t)=>{let{dotsecConfig:r}=t,o=e.enablePositionalOptions().passThroughOptions().command("init").action(async(n,a)=>{let{configFile:l,yes:s}=a.optsWithGlobals();try{let p=ye({configFile:lt.resolve(__dirname,"../../src/templates/dotsec.config.ts")}),i=await I({filePath:l,skip:s});(i===void 0||i.overwrite===!0)&&(await H(l,p),console.log(`Wrote config file to ${F(l)}`))}catch(p){a.error(p)}});return T({program:o,dotsecConfig:r}),o},Ce=mt;import{parse as dt}from"dotenv";import{expand as ft}from"dotenv-expand";import Oe from"node:fs";var ut=async(e,t)=>{let{dotsecConfig:r,handlers:o}=t,n=e.enablePositionalOptions().passThroughOptions().command("push").action(async(a,l)=>{var s,p,i;try{let{envFile:m,secFile:d,withEnv:C,withSec:D,engine:v,yes:f}=l.optsWithGlobals(),u=v||((s=r==null?void 0:r.defaults)==null?void 0:s.encryptionEngine),g=(p=(o||[]).find(P=>{var x;return((x=P.decrypt)==null?void 0:x.triggerOptionValue)===u}))==null?void 0:p.decrypt,h=(i=(o||[]).find(P=>{var x;return((x=P.push)==null?void 0:x.triggerOptionValue)===u}))==null?void 0:i.push;if(!h)throw new Error("No push plugin found!");let y=[...Object.keys((g==null?void 0:g.options)||{}),...Object.keys((g==null?void 0:g.requiredOptions)||{}),...Object.keys((h==null?void 0:h.options)||{}),...Object.keys((h==null?void 0:h.requiredOptions)||{})],w=Object.fromEntries(y.map(P=>[P,a[P]]));if(C&&D)throw new Error("Cannot use both --with-env and --with-sec");let O;if(C||!(C||D)){if(!m)throw new Error("No dotenv file specified in --env-file option");O=Oe.readFileSync(m,"utf8")}else if(D){if(!d)throw new Error("No dotsec file specified in --sec-file option");if(!g)throw new Error(`No decryption plugin found, available decryption engine(s): ${o.map(x=>{var N;return`--${(N=x.decrypt)==null?void 0:N.triggerOptionValue}`}).join(", ")}`);let P=Oe.readFileSync(d,"utf8");O=await g.handler(c({ciphertext:P},w))}if(O){let P=dt(O),x=ft({ignoreProcessEnv:!0,parsed:c(c({},process.env),P)});x.parsed&&await h.handler(c({push:x.parsed,yes:f},w))}else throw new Error("No .env or .sec file provided")}catch(m){console.error(m),process.exit(1)}});return T({program:n,dotsecConfig:r}),n},we=ut;import ve from"node:fs";import{parse as gt}from"dotenv";import{expand as yt}from"dotenv-expand";import{spawnSync as ht}from"node:child_process";var Ct=(e,t)=>{let{dotsecConfig:r,decryptHandlers:o}=t||{},n=o!==void 0&&o.length>0,a=e.command("run <command...>").allowUnknownOption(!0).enablePositionalOptions().passThroughOptions().showHelpAfterError(!0).action(async(l,s,p)=>{var i;try{let{envFile:m,secFile:d,withEnv:C,withSec:D,engine:v}=p.optsWithGlobals();if(C&&D)throw new Error("Cannot use both --with-env and --with-sec");let f;if(C||!(C||D)||n===!1){if(!m)throw new Error("No dotenv file specified in --env-file option");f=ve.readFileSync(m,"utf8")}else if(D){if(!d)throw new Error("No dotsec file specified in --sec-file option");let u=v||((i=r==null?void 0:r.defaults)==null?void 0:i.encryptionEngine),g=(o||[]).find(O=>O.triggerOptionValue===u);if(!g)throw new Error(`No decryption plugin found, available decryption engine(s): ${(o||[]).map(O=>`--${O.triggerOptionValue}`).join(", ")}`);let h=[...Object.keys(g.options||{}),...Object.keys(g.requiredOptions||{})],y=Object.fromEntries(h.map(O=>[O,s[O]])),w=ve.readFileSync(d,"utf8");f=await g.handler(c({ciphertext:w},y))}if(f){let u=gt(f),g=yt({ignoreProcessEnv:!0,parsed:c(c({},process.env),u)}),[h,...y]=l,w=ht(h,[...y],{stdio:"inherit",shell:!1,encoding:"utf-8",env:E(c(c({},g.parsed),process.env),{__DOTSEC_ENV__:JSON.stringify(Object.keys(u))})});w.status!==0&&process.exit(w.status||1)}else throw new Error("No .env or .sec file provided")}catch(m){console.error(F(m.message)),p.help()}});if(T({program:a,commandName:n?"run":"runEnvOnly",dotsecConfig:r}),n){o==null||o.map(s=>{let{options:p,requiredOptions:i}=s;$(p,a),$(i,a,!0)});let l=o==null?void 0:o.map(s=>s.triggerOptionValue);a.option("--engine <engine>",`Encryption engine${l.length>0?"s":""}: ${l.join(", "),l.length===1?l[0]:void 0}`)}return a},De=Ct;import wt from"ajv";import vt from"yargs-parser";var Dt={keyword:"separator",type:"string",metaSchema:{type:"string",description:"value separator"},modifying:!0,valid:!0,errors:!1,compile:e=>(t,r)=>{if(r){let{parentData:o,parentDataProperty:n}=r;return o[n]=t===""?[]:t.split(e),!0}else return!1}},k=new Ot;(async()=>{var d,C,D,v;let e=vt(process.argv),t=[];e.plugin&&(Array.isArray(e.plugin)?t.push(...e.plugin):t.push(e.plugin));let r=[...Array.isArray(e.config)?e.config:[e.config],...Array.isArray(e.c)?e.c:[e.c]][0],{contents:o={}}=await ae(r),{defaults:n,push:a}=o;k.name("dotsec").description(".env, but secure").version("1.0.0").enablePositionalOptions().action((f,u)=>{u.help()}),T({program:k,dotsecConfig:o});let l=new wt({allErrors:!0,removeAdditional:!0,useDefaults:!0,coerceTypes:!0,allowUnionTypes:!0,addUsedSchema:!1,keywords:[Dt]}),s={};if(t.length>0)for(let f of t){let g=await(await z({name:f}))({dotsecConfig:o,ajv:l,configFile:r});s[g.name]=f,t.length===1&&(o.defaults=E(c({},o.defaults),{encryptionEngine:String(g.name),plugins:E(c({},(d=o.defaults)==null?void 0:d.plugins),{[g.name]:c({},(D=(C=o.defaults)==null?void 0:C.plugins)==null?void 0:D[g.name])})}))}(n==null?void 0:n.encryptionEngine)&&(((v=n==null?void 0:n.plugins)==null?void 0:v[n.encryptionEngine])||(n.plugins=E(c({},n.plugins),{[n.encryptionEngine]:{}}))),(n==null?void 0:n.plugins)&&Object.entries(n==null?void 0:n.plugins).forEach(([f,u])=>{(u==null?void 0:u.module)?s[f]=u==null?void 0:u.module:s[f]=`@dotsec/plugin-${f}`}),Object.values(a||{}).forEach(f=>{Object.keys(f).forEach(u=>{s[u]||(s[u]=`@dotsec/plugin-${u}`)})});let p=[],i=[],m=[];for(let f of Object.keys(s)){let u=s[f],g=await z({name:u}),{addCliCommand:h,cliHandlers:y}=await g({ajv:l,dotsecConfig:o,configFile:r});(y==null?void 0:y.encrypt)&&p.push(y.encrypt),(y==null?void 0:y.decrypt)&&(i.push(y.decrypt),(y==null?void 0:y.push)&&m.push({push:y.push,decrypt:y.decrypt})),h&&h({program:k})}p.length&&await ge(k,{dotsecConfig:o,encryptHandlers:p}),i.length&&await ue(k,{dotsecConfig:o,decryptHandlers:i}),m.length&&await we(k,{dotsecConfig:o,handlers:m}),await Ce(k,{dotsecConfig:o}),await De(k,{dotsecConfig:o,decryptHandlers:i}),await k.parse()})();
|
|
41
|
-
|
|
132
|
+
`}},ne=Se;var _e={...Q,...Z,...X,...z,...ne,...ee},Ie=t=>{if(Array.isArray(t)){let[i,p,n]=t;return{flags:i,description:p,defaultValue:n}}else{if("option"in t){let[i,p,n]=t.option;return{flags:i,description:p,defaultValue:n,env:t.env}}return t}},te=(t,i)=>{let p=i?.dotsecConfig?.defaults?.options?.[i?.optionKey],n=Ie(t),e=new Te(n.flags,n.description);return n.fn&&e.argParser(n.fn),n.defaultValue&&e.default(p||n.defaultValue),n.env&&e.env(n.env),i.required&&e.makeOptionMandatory(!0),n.choices&&e.choices(n.choices),e},x=t=>{let{program:i,commandName:p,dotsecConfig:n}=t,e=_e[p||i.name()];if(e){let{options:o,requiredOptions:a,description:l,usage:s,helpText:r}=e;o&&Object.keys(o).forEach(f=>{let m=o[f],d=te(m,{dotsecConfig:n,optionKey:f});i.addOption(d)}),a&&Object.keys(a).forEach(f=>{let m=a[f],d=te(m,{required:!0,dotsecConfig:n,optionKey:f});i.addOption(d)}),l&&i.description(l),s&&i.usage(s),r&&i.description(r)}};import{parse as Ne}from"dotenv";var je=async(t,i)=>{let{dotsecConfig:p,decryptHandlers:n}=i,e=t.enablePositionalOptions().passThroughOptions().command("decrypt").action(async(a,l)=>{try{let{envFile:s,secFile:r,engine:f,createManifest:m,manifestFile:d,yes:c}=l.optsWithGlobals(),O=f||p?.defaults?.encryptionEngine,u=(n||[]).find(h=>h.triggerOptionValue===O);if(!u)throw new Error(`No decryption plugin found, available decryption engine(s): ${i.decryptHandlers.map(h=>`--${h.triggerOptionValue}`).join(", ")}`);console.log("Decrypting with",C(u.encryptionEngineName||u.triggerOptionValue),"engine");let g=[...Object.keys(u.options||{}),...Object.keys(u.requiredOptions||{})],w=Object.fromEntries(g.map(h=>[h,a[h]])),v=await j(r),E=await u.handler({ciphertext:v,...w}),N=await V({filePath:s,skip:c});if((N===void 0||N.overwrite===!0)&&(await _(s,E),console.log(`Wrote plaintext contents of ${C(r)} file to ${C(s)}`)),m){let h=Ne(E),y=`# Dotsec decryption manifest
|
|
133
|
+
|
|
134
|
+
## Overview
|
|
135
|
+
|
|
136
|
+
- plaintext source: ${s}
|
|
137
|
+
- ciphertext target: ${r}
|
|
138
|
+
- created: ${new Date().toUTCString()}
|
|
139
|
+
- Decryption engine: ${u.encryptionEngineName||u.triggerOptionValue}
|
|
140
|
+
- Decryption engine options: ${JSON.stringify(w)}
|
|
141
|
+
|
|
142
|
+
## Variables
|
|
143
|
+
|
|
144
|
+
| Key |
|
|
145
|
+
| --- |
|
|
146
|
+
${Object.keys(h).map(A=>`| \`${A} \`| `).join(`
|
|
147
|
+
`)}
|
|
148
|
+
`,$=d||`${s}.decryption-manifest.md`;await _($,y),console.log(`Wrote manifest of ${C(s)} file to ${C($)}`)}}catch(s){console.error(C(s.message)),l.help()}});i.decryptHandlers.map(a=>{let{options:l,requiredOptions:s}=a;F(l,e),F(s,e,!0)});let o=i.decryptHandlers.map(a=>a.triggerOptionValue);return e.option("--engine <engine>",`Encryption engine${o.length>0?"s":""} to use: ${o.length===1?o[0]:o.join(", ")}`,o.length===1?o[0]:void 0),x({program:e,dotsecConfig:p}),e},oe=je;import{parse as Ve}from"dotenv";var Ae=async(t,i)=>{let{encryptHandlers:p,dotsecConfig:n}=i,e=t.enablePositionalOptions().passThroughOptions().command("encrypt").action(async(l,s)=>{try{let{envFile:r,secFile:f,engine:m,createManifest:d,manifestFile:c,yes:O}=s.optsWithGlobals(),u=m||n?.defaults?.encryptionEngine,g=(p||[]).find(y=>y.triggerOptionValue===u);if(!g)throw new Error(`No encryption plugin found, available encryption engine(s): ${i.encryptHandlers.map(y=>y.triggerOptionValue).join(", ")}`);let w=[...Object.keys(g.options||{}),...Object.keys(g.requiredOptions||{})],v=Object.fromEntries(w.map(y=>[y,l[y]])),E=await j(r),N=await g.handler({plaintext:E,...v}),h=await V({filePath:f,skip:O});if((h===void 0||h.overwrite===!0)&&(await _(f,N),console.log(`Wrote encrypted contents of ${C(r)} file to ${C(f)}`),d)){let y=Ve(E),$=`# Dotsec encryption manifest
|
|
149
|
+
|
|
150
|
+
## Overview
|
|
151
|
+
|
|
152
|
+
- plaintext source: ${r}
|
|
153
|
+
- ciphertext target: ${f}
|
|
154
|
+
- created: ${new Date().toUTCString()}
|
|
155
|
+
- encryption engine: ${g.encryptionEngineName||g.triggerOptionValue}
|
|
156
|
+
- encryption engine options: ${JSON.stringify(v)}
|
|
157
|
+
|
|
158
|
+
## Variables
|
|
159
|
+
|
|
160
|
+
| Key |
|
|
161
|
+
| --- |
|
|
162
|
+
${Object.keys(y).map(le=>`| \`${le} \`| `).join(`
|
|
163
|
+
`)}
|
|
164
|
+
`,A=c||`${f}.encryption-manifest.md`;await _(A,$),console.log(`Wrote manifest of ${C(r)} file to ${C(A)}`)}}catch(r){console.error(C(r.message)),s.help()}});i.encryptHandlers.map(l=>{let{options:s,requiredOptions:r}=l;F(s,e),F(r,e,!0)});let o=i.encryptHandlers.map(l=>l.triggerOptionValue),a=i.encryptHandlers.map(l=>l.encryptionEngineName);return e.option("--engine <engine>",`Encryption engine${o.length>0?"s":""}: ${o.length===1?o[0]:o.join(", ")}`,o.length===1?o[0]:void 0),x({program:e,dotsecConfig:n}),e.description(`Encrypt .env file using ${a.join(", ")}`),e},ie=Ae;import ke from"node:path";var He=async(t,i)=>{let{dotsecConfig:p}=i,n=t.enablePositionalOptions().passThroughOptions().command("init").action(async(e,o)=>{let{configFile:a="dotsec.config.ts",yes:l}=o.optsWithGlobals();try{let s=await j(ke.resolve(__dirname,"../../src/templates/dotsec.config.ts")),r=await V({filePath:a,skip:l});(r===void 0||r.overwrite===!0)&&(await _(a,s),console.log(`Wrote config file to ${C(a)}`))}catch(s){o.error(s)}});return x({program:n,dotsecConfig:p}),n},re=He;import{parse as Le}from"dotenv";import{expand as Re}from"dotenv-expand";import se from"node:fs";var Me=async(t,i)=>{let{dotsecConfig:p,handlers:n}=i,e=t.enablePositionalOptions().passThroughOptions().command("push").action(async(r,f)=>{try{let{using:m,envFile:d,secFile:c,engine:O,yes:u}=f.optsWithGlobals(),g=O||p?.defaults?.encryptionEngine,w=(n||[]).find(y=>y.decrypt?.triggerOptionValue===g)?.decrypt,v=(n||[]).find(y=>y.push?.triggerOptionValue===g)?.push;if(!v)throw new Error("No push plugin found!");let E=[...Object.keys(w?.options||{}),...Object.keys(w?.requiredOptions||{}),...Object.keys(v?.options||{}),...Object.keys(v?.requiredOptions||{})],N=Object.fromEntries(E.map(y=>[y,r[y]])),h;if(m==="env"){if(!d)throw new Error("No dotenv file specified in --env-file option");h=se.readFileSync(d,"utf8")}else{if(!c)throw new Error("No dotsec file specified in --sec-file option");if(!w)throw new Error(`No decryption plugin found, available decryption engine(s): ${n.map($=>`--${$.decrypt?.triggerOptionValue}`).join(", ")}`);let y=se.readFileSync(c,"utf8");h=await w.handler({ciphertext:y,...N})}if(h){let y=Le(h),$=Re({ignoreProcessEnv:!0,parsed:{...process.env,...y}});$.parsed&&await v.handler({push:$.parsed,yes:u,...N})}else throw new Error("No .env or .sec file provided")}catch(m){console.error(m),process.exit(1)}});x({program:e,dotsecConfig:p});let o=i.handlers.map(({decrypt:r})=>r.triggerOptionValue);e.option("--engine <engine>",`Encryption engine${o.length>0?"s":""} to use: ${o.length===1?o[0]:o.join(", ")}`,o.length===1?o[0]:void 0);let a={};i.handlers.forEach(r=>{Object.keys(r).map(f=>{let{options:m,requiredOptions:d}=r[f];Object.keys(m||{}).forEach(c=>{a[c]=Array.isArray(m[c])?m[c]:{...a[c],...m[c]}}),Object.keys(d||{}).forEach(c=>{a[c]=Array.isArray(d[c])?d[c]:{...a[c],...d[c],required:!0}})})});let l=[],s=[];return n.forEach(r=>{r.push?.description&&s.push(r.push.description),r.push?.usage&&l.push(r.push.usage)}),s.length>0&&e.description(s.join(`
|
|
165
|
+
`)),l.length>0&&e.usage(l.join(`
|
|
166
|
+
`)),F(Object.fromEntries(Object.entries(a).filter(([r,f])=>f.required!==!0)),e),F(Object.fromEntries(Object.entries(a).filter(([r,f])=>f.required===!0)),e,!0),e},ae=Me;import ce from"node:fs";import{parse as qe}from"dotenv";import{expand as Ge}from"dotenv-expand";import{spawnSync as We}from"node:child_process";var Ue=(t,i)=>{let{dotsecConfig:p,decryptHandlers:n}=i||{},e=n!==void 0&&n.length>0,o=t.command("run <command...>").allowUnknownOption(!0).enablePositionalOptions().passThroughOptions().showHelpAfterError(!0).action(async(a,l,s)=>{try{let{envFile:r,using:f,secFile:m,engine:d}=s.optsWithGlobals(),c;if(f==="env"||e===!1){if(!r)throw new Error("No dotenv file specified in --env-file option");c=ce.readFileSync(r,"utf8")}else if(f==="sec"){if(!m)throw new Error("No dotsec file specified in --sec-file option");let O=d||p?.defaults?.encryptionEngine,u=(n||[]).find(E=>E.triggerOptionValue===O);if(!u)throw new Error(`No decryption plugin found, available decryption engine(s): ${(n||[]).map(E=>`--${E.triggerOptionValue}`).join(", ")}`);let g=[...Object.keys(u.options||{}),...Object.keys(u.requiredOptions||{})],w=Object.fromEntries(g.map(E=>[E,l[E]])),v=ce.readFileSync(m,"utf8");c=await u.handler({ciphertext:v,...w})}if(c){let O=qe(c),u=Ge({ignoreProcessEnv:!0,parsed:{...process.env,...O}}),[g,...w]=a,v=We(g,[...w],{stdio:"inherit",shell:!1,encoding:"utf-8",env:{...u.parsed,...process.env,__DOTSEC_ENV__:JSON.stringify(Object.keys(O))}});v.status!==0&&process.exit(v.status||1)}else throw new Error("No .env or .sec file provided")}catch(r){console.error(C(r.message)),s.help()}});if(x({program:o,commandName:e?"run":"runEnvOnly",dotsecConfig:p}),e){n?.map(l=>{let{options:s,requiredOptions:r}=l;F(s,o),F(r,o,!0)});let a=n?.map(l=>l.triggerOptionValue);o.option("--engine <engine>",`Encryption engine${a.length>0?"s":""}: ${a.join(", "),a.length===1?a[0]:void 0}`)}return o},pe=Ue;import Je from"ajv";import Be from"yargs-parser";var Ye={keyword:"separator",type:"string",metaSchema:{type:"string",description:"value separator"},modifying:!0,valid:!0,errors:!1,compile:t=>(i,p)=>{if(p){let{parentData:n,parentDataProperty:e}=p;return n[e]=i===""?[]:i.split(t),!0}else return!1}},S=new Ke;(async()=>{let t=Be(process.argv),i=[];t.plugin&&(Array.isArray(t.plugin)?i.push(...t.plugin):i.push(t.plugin));let p=[...Array.isArray(t.configFile)?t.configFile:[t.configFile],...Array.isArray(t.c)?t.c:[t.c]][0]||process.env.DOTSEC_CONFIG_FILE,{contents:n={}}=await U(p),{defaults:e={},push:o,plugins:a}=n;S.name("dotsec").description(".env, but secure").version("1.0.0").enablePositionalOptions().action((d,c)=>{c.help()}),x({program:S,dotsecConfig:n});let l=new Je({allErrors:!0,removeAdditional:!0,useDefaults:!0,coerceTypes:!0,allowUnionTypes:!0,addUsedSchema:!1,keywords:[Ye]}),s={};if(a)for(let d of a)e?.plugins?.[d]||(e.plugins={...e.plugins,[d]:{}});if(i.length>0)for(let d of i){let O=await(await q({name:d}))({dotsecConfig:n,ajv:l,configFile:p});s[O.name]=d,i.length===1&&(n.defaults={...n.defaults,encryptionEngine:String(O.name),plugins:{...n.defaults?.plugins,[O.name]:{...n.defaults?.plugins?.[O.name]}}})}e?.encryptionEngine&&(e?.plugins?.[e.encryptionEngine]||(e.plugins={...e.plugins,[e.encryptionEngine]:{}})),e?.plugins&&Object.entries(e?.plugins).forEach(([d,c])=>{c?.name?s[d]=c?.name:s[d]=`@dotsec/plugin-${d}`}),Object.values(o||{}).forEach(d=>{Object.keys(d).forEach(c=>{s[c]||(s[c]=`@dotsec/plugin-${c}`)})});let r=[],f=[],m=[];for(let d of Object.keys(s)){let c=s[d],O=await q({name:c}),{addCliCommand:u,cliHandlers:g}=await O({ajv:l,dotsecConfig:n,configFile:p});g?.encrypt&&r.push(g.encrypt),g?.decrypt&&(f.push(g.decrypt),g?.push&&m.push({push:g.push,decrypt:g.decrypt})),u&&u({program:S})}r.length&&await ie(S,{dotsecConfig:n,encryptHandlers:r}),f.length&&await oe(S,{dotsecConfig:n,decryptHandlers:f}),m.length&&await ae(S,{dotsecConfig:n,handlers:m}),await re(S,{dotsecConfig:n}),await pe(S,{dotsecConfig:n,decryptHandlers:f}),await S.parse()})();
|
|
167
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/cli/index.mjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/cli/index.ts", "../../src/constants.ts", "../../src/lib/json.ts", "../../src/lib/getConfig.ts", "../../src/lib/loadDotsecPlugin.ts", "../../src/lib/addPluginOptions.ts", "../../src/lib/io.ts", "../../src/utils/logging.ts", "../../src/cli/options/index.ts", "../../src/cli/options/sharedOptions.ts", "../../src/cli/options/decrypt.ts", "../../src/cli/options/dotsec.ts", "../../src/cli/options/encrypt.ts", "../../src/cli/options/init.ts", "../../src/cli/options/push.ts", "../../src/cli/options/run.ts", "../../src/cli/commands/decrypt.ts", "../../src/cli/commands/encrypt.ts", "../../src/lib/transformer.ts", "../../src/cli/commands/init.ts", "../../src/cli/commands/push.ts", "../../src/cli/commands/run.ts"],
|
|
4
|
-
"sourcesContent": ["import { Command } from \"commander\";\n\nimport { getMagicalConfig } from \"../lib/getConfig\";\nimport { loadDotsecPlugin } from \"../lib/loadDotsecPlugin\";\nimport {\n\tDotsecCliPluginDecryptHandler,\n\tDotsecCliPluginEncryptHandler,\n\tDotsecCliPluginPushHandler,\n\tDotsecPluginConfig,\n} from \"../types/plugin\";\nimport addDecryptProgram from \"./commands/decrypt\";\nimport addEncryptProgram from \"./commands/encrypt\";\nimport addInitCommand from \"./commands/init\";\nimport addPushProgram from \"./commands/push\";\nimport addRunCommand from \"./commands/run\";\nimport { setProgramOptions } from \"./options\";\nimport Ajv, { KeywordDefinition } from \"ajv\";\nimport yargsParser from \"yargs-parser\";\n\nconst separator: KeywordDefinition = {\n\tkeyword: \"separator\",\n\ttype: \"string\",\n\tmetaSchema: {\n\t\ttype: \"string\",\n\t\tdescription: \"value separator\",\n\t},\n\tmodifying: true,\n\tvalid: true,\n\terrors: false,\n\tcompile: (schema) => (data, ctx) => {\n\t\tif (ctx) {\n\t\t\tconst { parentData, parentDataProperty } = ctx;\n\t\t\tparentData[parentDataProperty] = data === \"\" ? [] : data.split(schema);\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t},\n};\n\nconst program = new Command();\n\n(async () => {\n\tconst parsedOptions = yargsParser(process.argv);\n\tconst argvPluginModules: string[] = [];\n\tif (parsedOptions.plugin) {\n\t\tif (Array.isArray(parsedOptions.plugin)) {\n\t\t\targvPluginModules.push(...parsedOptions.plugin);\n\t\t} else {\n\t\t\targvPluginModules.push(parsedOptions.plugin);\n\t\t}\n\t}\n\t// if (parsedOptions.p) {\n\t// \tif (Array.isArray(parsedOptions.p)) {\n\t// \t\targvPluginModules.push(...parsedOptions.p);\n\t// \t} else {\n\t// \t\targvPluginModules.push(parsedOptions.p);\n\t// \t}\n\t// }\n\tconst configFile = [\n\t\t...(Array.isArray(parsedOptions.config)\n\t\t\t? parsedOptions.config\n\t\t\t: [parsedOptions.config]),\n\t\t...(Array.isArray(parsedOptions.c) ? parsedOptions.c : [parsedOptions.c]),\n\t]?.[0];\n\n\tconst { contents: dotsecConfig = {} } = await getMagicalConfig(configFile);\n\tconst { defaults, push: pushVariables } = dotsecConfig;\n\n\tprogram\n\t\t.name(\"dotsec\")\n\t\t.description(\".env, but secure\")\n\t\t.version(\"1.0.0\")\n\t\t.enablePositionalOptions()\n\t\t.action((_options, other: Command) => {\n\t\t\tother.help();\n\t\t});\n\tsetProgramOptions({ program, dotsecConfig: dotsecConfig });\n\tconst ajv = new Ajv({\n\t\tallErrors: true,\n\t\tremoveAdditional: true,\n\t\tuseDefaults: true,\n\t\tcoerceTypes: true,\n\t\tallowUnionTypes: true,\n\t\taddUsedSchema: false,\n\t\tkeywords: [separator],\n\t});\n\t// if we have plugins in the cli, we need to define them in pluginModules\n\tconst pluginModules: { [key: string]: string } = {};\n\tif (argvPluginModules.length > 0) {\n\t\tfor (const pluginModule of argvPluginModules) {\n\t\t\t// let's load em up\n\t\t\tconst plugin = await loadDotsecPlugin({ name: pluginModule });\n\n\t\t\t// good, let's fire 'em up\n\t\t\tconst loadedPlugin = await plugin({\n\t\t\t\tdotsecConfig: dotsecConfig,\n\t\t\t\tajv,\n\t\t\t\tconfigFile,\n\t\t\t});\n\t\t\tpluginModules[loadedPlugin.name] = pluginModule;\n\n\t\t\tif (argvPluginModules.length === 1) {\n\t\t\t\t// if we only have one plugin, let's set it as the default\n\t\t\t\tdotsecConfig.defaults = {\n\t\t\t\t\t...dotsecConfig.defaults,\n\t\t\t\t\tencryptionEngine: String(loadedPlugin.name),\n\t\t\t\t\tplugins: {\n\t\t\t\t\t\t...dotsecConfig.defaults?.plugins,\n\t\t\t\t\t\t[loadedPlugin.name]: {\n\t\t\t\t\t\t\t...dotsecConfig.defaults?.plugins?.[loadedPlugin.name],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tif (defaults?.encryptionEngine) {\n\t\tif (!defaults?.plugins?.[defaults.encryptionEngine]) {\n\t\t\tdefaults.plugins = {\n\t\t\t\t...defaults.plugins,\n\t\t\t\t[defaults.encryptionEngine]: {},\n\t\t\t};\n\t\t}\n\t}\n\tif (defaults?.plugins) {\n\t\tObject.entries(defaults?.plugins).forEach(\n\t\t\t([pluginName, pluginModule]: [string, DotsecPluginConfig]) => {\n\t\t\t\tif (pluginModule?.module) {\n\t\t\t\t\tpluginModules[pluginName] = pluginModule?.module;\n\t\t\t\t} else {\n\t\t\t\t\tpluginModules[pluginName] = `@dotsec/plugin-${pluginName}`;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tObject.values(pushVariables || {}).forEach((pushVariable) => {\n\t\tObject.keys(pushVariable).forEach((pluginName) => {\n\t\t\tif (!pluginModules[pluginName]) {\n\t\t\t\tpluginModules[pluginName] = `@dotsec/plugin-${pluginName}`;\n\t\t\t}\n\t\t});\n\t});\n\n\t// configure encryption command\n\tconst cliPluginEncryptHandlers: DotsecCliPluginEncryptHandler[] = [];\n\tconst cliPluginDecryptHandlers: DotsecCliPluginDecryptHandler[] = [];\n\tconst cliPluginPushHandlers: {\n\t\tpush: DotsecCliPluginPushHandler;\n\t\tdecrypt: DotsecCliPluginDecryptHandler;\n\t}[] = [];\n\n\tfor (const pluginName of Object.keys(pluginModules)) {\n\t\tconst pluginModule = pluginModules[pluginName];\n\t\tconst initDotsecPlugin = await loadDotsecPlugin({ name: pluginModule });\n\t\tconst { addCliCommand, cliHandlers: cli } = await initDotsecPlugin({\n\t\t\tajv,\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\tconfigFile,\n\t\t});\n\n\t\tif (cli?.encrypt) {\n\t\t\tcliPluginEncryptHandlers.push(cli.encrypt);\n\t\t}\n\t\tif (cli?.decrypt) {\n\t\t\tcliPluginDecryptHandlers.push(cli.decrypt);\n\t\t\tif (cli?.push) {\n\t\t\t\tcliPluginPushHandlers.push({ push: cli.push, decrypt: cli.decrypt });\n\t\t\t}\n\t\t}\n\n\t\tif (addCliCommand) {\n\t\t\taddCliCommand({ program });\n\t\t}\n\t}\n\tif (cliPluginEncryptHandlers.length) {\n\t\tawait addEncryptProgram(program, {\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\tencryptHandlers: cliPluginEncryptHandlers,\n\t\t});\n\t}\n\tif (cliPluginDecryptHandlers.length) {\n\t\tawait addDecryptProgram(program, {\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\tdecryptHandlers: cliPluginDecryptHandlers,\n\t\t});\n\t}\n\tif (cliPluginPushHandlers.length) {\n\t\tawait addPushProgram(program, {\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\thandlers: cliPluginPushHandlers,\n\t\t});\n\t}\n\n\t// add other commands\n\tawait addInitCommand(program, { dotsecConfig: dotsecConfig });\n\tawait addRunCommand(program, {\n\t\tdotsecConfig: dotsecConfig,\n\t\tdecryptHandlers: cliPluginDecryptHandlers,\n\t});\n\tawait program.parse();\n})();\n", "import { DotsecConfig } from \"./types/config\";\n\nexport const DOTSEC_DEFAULT_CONFIG_FILE = \"dotsec.config.ts\";\nexport const DOTSEC_CONFIG_FILES = [DOTSEC_DEFAULT_CONFIG_FILE];\nexport const DOTSEC_DEFAULT_DOTSEC_FILENAME = \".sec\";\nexport const DOTSEC_DEFAULT_DOTENV_FILENAME = \".env\";\nexport const defaultConfig: DotsecConfig = {};\n", "import fs from \"fs\";\nimport path from \"node:path\";\n\n/**\n * Parse JSONC\n * @date 12/7/2022 - 12:48:45 PM\n *\n * @export\n * @param {string} data\n * @returns {*}\n */\nexport function jsoncParse(data: string) {\n\ttry {\n\t\treturn new Function(`return ${data.trim()}`)();\n\t} catch {\n\t\t// Silently ignore any error\n\t\t// That's what tsc/jsonc-parser did after all\n\t\treturn {};\n\t}\n}\n\n/**\n * Load JSON\n * @date 12/7/2022 - 12:48:57 PM\n *\n * @async\n * @param {string} filepath\n * @returns {unknown}\n */\nexport const loadJson = async (filepath: string) => {\n\ttry {\n\t\treturn jsoncParse(await fs.promises.readFile(filepath, \"utf8\"));\n\t} catch (error) {\n\t\tif (error instanceof Error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to parse ${path.relative(process.cwd(), filepath)}: ${\n\t\t\t\t\terror.message\n\t\t\t\t}`,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow error;\n\t\t}\n\t}\n};\n", "import { DOTSEC_CONFIG_FILES, defaultConfig } from \"../constants\";\nimport { DotsecConfig } from \"../types/config\";\nimport { DotsecConfigAndSource } from \"../types/plugin\";\nimport { loadJson } from \"./json\";\nimport { bundleRequire } from \"bundle-require\";\nimport JoyCon from \"joycon\";\nimport path from \"path\";\n\nexport const getMagicalConfig = async (\n\tfilename?: string,\n): Promise<DotsecConfigAndSource> => {\n\tconst cwd = process.cwd();\n\tconst configJoycon = new JoyCon();\n\tconst configPath = await configJoycon.resolve({\n\t\tfiles: filename ? [filename] : [...DOTSEC_CONFIG_FILES, \"package.json\"],\n\t\tcwd,\n\t\tstopDir: path.parse(cwd).root,\n\t\tpackageKey: \"dotsec\",\n\t});\n\tif (filename && configPath === null) {\n\t\tthrow new Error(`Could not find config file ${filename}`);\n\t}\n\tif (configPath) {\n\t\tif (configPath.endsWith(\".json\")) {\n\t\t\tconst rawData = (await loadJson(configPath)) as Partial<DotsecConfig>;\n\n\t\t\tlet data: Partial<DotsecConfig>;\n\n\t\t\tif (\n\t\t\t\tconfigPath.endsWith(\"package.json\") &&\n\t\t\t\t(rawData as { dotsec: Partial<DotsecConfig> }).dotsec !== undefined\n\t\t\t) {\n\t\t\t\tdata = (rawData as { dotsec: Partial<DotsecConfig> }).dotsec;\n\t\t\t} else {\n\t\t\t\tdata = rawData as Partial<DotsecConfig>;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tsource: \"json\",\n\t\t\t\tcontents: {\n\t\t\t\t\t...defaultConfig,\n\t\t\t\t\t...data,\n\t\t\t\t\tdefaults: {\n\t\t\t\t\t\t...data?.defaults,\n\t\t\t\t\t\t...defaultConfig.defaults,\n\t\t\t\t\t\tplugins: {\n\t\t\t\t\t\t\t...data?.defaults?.plugins,\n\t\t\t\t\t\t\t...defaultConfig.defaults?.plugins,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tpush: {\n\t\t\t\t\t\t...data?.push,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t} else if (configPath.endsWith(\".ts\")) {\n\t\t\tconst bundleRequireResult = await bundleRequire({\n\t\t\t\tfilepath: configPath,\n\t\t\t});\n\t\t\tconst data = (bundleRequireResult.mod.dotsec ||\n\t\t\t\tbundleRequireResult.mod.default ||\n\t\t\t\tbundleRequireResult.mod) as Partial<DotsecConfig>;\n\n\t\t\treturn {\n\t\t\t\tsource: \"ts\",\n\t\t\t\tcontents: {\n\t\t\t\t\t...defaultConfig,\n\t\t\t\t\t...data,\n\t\t\t\t\tdefaults: {\n\t\t\t\t\t\t...data?.defaults,\n\t\t\t\t\t\t...defaultConfig.defaults,\n\t\t\t\t\t\tplugins: {\n\t\t\t\t\t\t\t...data?.defaults?.plugins,\n\t\t\t\t\t\t\t...defaultConfig.defaults?.plugins,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tpush: {\n\t\t\t\t\t\t...data?.push,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\n\treturn { source: \"defaultConfig\", contents: defaultConfig };\n};\n", "import { DotsecPluginModule } from \"../types/plugin\";\n\nexport const loadDotsecPlugin = async (options: {\n\tname: string;\n}): Promise<DotsecPluginModule> => {\n\treturn import(options.name).then((imported) => {\n\t\treturn imported.default;\n\t});\n};\n", "import { DotsecCliOption } from \"../types/plugin\";\nimport { Command, Option } from \"commander\";\n\nexport const addPluginOptions = (\n\toptions:\n\t\t| {\n\t\t\t\t[x: string]: DotsecCliOption;\n\t\t }\n\t\t| undefined,\n\tcommand: Command,\n\tmandatory?: boolean,\n) => {\n\tif (options) {\n\t\tObject.values(options).map((option) => {\n\t\t\tlet optionProps:\n\t\t\t\t| {\n\t\t\t\t\t\tflags: string;\n\t\t\t\t\t\tdescription?: string;\n\t\t\t\t\t\tdefaultValue?: string | boolean | string[];\n\t\t\t\t\t\tfn?: (value: string, previous: unknown) => unknown;\n\t\t\t\t\t\tregexp?: RegExp;\n\t\t\t\t\t\tenv?: string;\n\t\t\t\t }\n\t\t\t\t| undefined;\n\t\t\tif (Array.isArray(option)) {\n\t\t\t\tconst [flags, description, defaultValue] = option;\n\t\t\t\toptionProps = {\n\t\t\t\t\tflags,\n\t\t\t\t\tdescription,\n\t\t\t\t\tdefaultValue,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tconst { flags, description, defaultValue, env, fn } = option;\n\t\t\t\toptionProps = {\n\t\t\t\t\tflags,\n\t\t\t\t\tdescription,\n\t\t\t\t\tdefaultValue,\n\t\t\t\t\tenv,\n\t\t\t\t\tfn,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (optionProps) {\n\t\t\t\tconst newOption = new Option(\n\t\t\t\t\toptionProps.flags,\n\t\t\t\t\toptionProps.description,\n\t\t\t\t);\n\t\t\t\tif (optionProps.fn) {\n\t\t\t\t\tnewOption.argParser(optionProps.fn);\n\t\t\t\t}\n\t\t\t\tif (optionProps.defaultValue) {\n\t\t\t\t\tnewOption.default(optionProps.defaultValue);\n\t\t\t\t}\n\t\t\t\tif (optionProps.env) {\n\t\t\t\t\tnewOption.env(optionProps.env);\n\t\t\t\t}\n\t\t\t\tif (mandatory) {\n\t\t\t\t\tnewOption.makeOptionMandatory(true);\n\t\t\t\t}\n\t\t\t\tcommand.addOption(newOption);\n\t\t\t}\n\t\t});\n\t}\n};\n", "import fs, { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport prompts from \"prompts\";\n\nexport const readContentsFromFile = async (\n\tfilePath: string,\n): Promise<string> => {\n\treturn await fs.readFile(filePath, \"utf-8\");\n};\n\nexport const writeContentsToFile = async (\n\tfilePath: string,\n\tcontents: string,\n): Promise<void> => {\n\treturn await fs.writeFile(filePath, contents, \"utf-8\");\n};\n\nexport const fileExists = async (source: string): Promise<boolean> => {\n\ttry {\n\t\tawait stat(source);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const promptOverwriteIfFileExists = async ({\n\tfilePath,\n\tskip,\n}: {\n\tfilePath: string;\n\tskip?: boolean;\n}) => {\n\tlet overwriteResponse: prompts.Answers<\"overwrite\"> | undefined;\n\n\tif ((await fileExists(filePath)) && skip !== true) {\n\t\toverwriteResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"overwrite\",\n\t\t\tmessage: () => {\n\t\t\t\treturn `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;\n\t\t\t},\n\t\t});\n\t} else {\n\t\toverwriteResponse = undefined;\n\t}\n\treturn overwriteResponse;\n};\n", "import chalk from \"chalk\"\nimport Table = require(\"cli-table\")\nexport { Table }\n\nlet _logger: Pick<Console, \"info\" | \"error\" | \"table\">\nexport const getLogger = () => {\n\tif (!_logger) {\n\t\t_logger = console\n\t}\n\n\treturn _logger\n}\nexport const writeLine = (str: string) => {\n\tprocess.stdout.write(str)\n}\nexport const emphasis = (str: string): string => chalk.yellowBright(str)\nexport const strong = (str: string): string => chalk.yellow.bold(str)\n\nexport const clientLogger = {\n\tdebug(content: object) {\n\t\tconsole.log(content)\n\t},\n\tinfo(content: object) {\n\t\tconsole.log(content)\n\t},\n\twarn(content: object) {\n\t\tconsole.log(content)\n\t},\n\terror(content: object) {\n\t\tconsole.error(content)\n\t},\n}\n", "import { DotsecConfig } from \"../../types/index\";\nimport { Command, Option } from \"commander\";\n\nimport decryptCommandDefaults from \"./decrypt\";\nimport dotsecCommandDefaults from \"./dotsec\";\nimport encryptCommandDefaults from \"./encrypt\";\nimport initCommandDefaults from \"./init\";\nimport pullCommandDefaults from \"./push\";\nimport pushCommandDefaults from \"./push\";\nimport runCommandDefaults from \"./run\";\nimport {\n\tCommandOption,\n\tDotSecCommandDefaults,\n\tDotSecCommandOptions,\n\tDotSecCommandsDefaults,\n\tExpandedCommandOption,\n} from \"./types\";\n\nexport const commandOptions: DotSecCommandsDefaults = {\n\t...dotsecCommandDefaults,\n\t...initCommandDefaults,\n\t...encryptCommandDefaults,\n\t...decryptCommandDefaults,\n\t...runCommandDefaults,\n\t...pushCommandDefaults,\n\t...pullCommandDefaults,\n};\n\nconst getInheritedOptions = (\n\tcopts: DotSecCommandsDefaults,\n\tcommandName: string,\n\tresult: {\n\t\toptions?: DotSecCommandOptions;\n\t\trequiredOptions?: DotSecCommandOptions;\n\t} = {},\n): DotSecCommandDefaults | undefined => {\n\tconst command = copts[commandName];\n\tif (command) {\n\t\tif (command.inheritsFrom) {\n\t\t\treturn command?.inheritsFrom.reduce(\n\t\t\t\t(acc, inheritedCommandName) => {\n\t\t\t\t\treturn getInheritedOptions(copts, inheritedCommandName, acc);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t...command,\n\t\t\t\t\toptions: { ...result.options, ...command.options },\n\t\t\t\t\trequiredOptions: {\n\t\t\t\t\t\t...result.requiredOptions,\n\t\t\t\t\t\t...command.requiredOptions,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t} else {\n\t\t\treturn {\n\t\t\t\t...command,\n\t\t\t\toptions: { ...result.options, ...command.options },\n\t\t\t\trequiredOptions: {\n\t\t\t\t\t...result.requiredOptions,\n\t\t\t\t\t...command.requiredOptions,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n};\n\nconst expandCommandOption = (\n\tcommandOption: CommandOption | ExpandedCommandOption,\n): ExpandedCommandOption => {\n\tif (Array.isArray(commandOption)) {\n\t\treturn {\n\t\t\toption: commandOption,\n\t\t};\n\t} else {\n\t\treturn commandOption;\n\t}\n};\n\nconst createOption = (\n\tcommandOption: CommandOption | ExpandedCommandOption,\n\toptions: {\n\t\trequired?: boolean;\n\t\tdotsecConfig?: DotsecConfig;\n\t\toptionKey: string;\n\t},\n): Option => {\n\tconst expandedCommandOption = expandCommandOption(commandOption);\n\tconst [option, description, defaultValue] = expandedCommandOption.option;\n\tconst defaultOptionValueFromConfig =\n\t\toptions?.dotsecConfig?.defaults?.options?.[options?.optionKey];\n\n\tconst newOption = new Option(\n\t\toption,\n\t\tdescription +\n\t\t\t(defaultOptionValueFromConfig ? \". Default from config.\" : \"\"),\n\t);\n\tif (defaultValue) {\n\t\tnewOption.default(defaultOptionValueFromConfig || defaultValue);\n\t}\n\tif (expandedCommandOption.env) {\n\t\tnewOption.env(expandedCommandOption.env);\n\t}\n\tif (options?.required) {\n\t\tnewOption.makeOptionMandatory(true);\n\t}\n\treturn newOption;\n};\nexport const setProgramOptions = (params: {\n\tprogram: Command;\n\tcommandName?: string;\n\tdotsecConfig: DotsecConfig;\n}) => {\n\tconst { program, commandName, dotsecConfig } = params;\n\tconst programOptions = commandOptions[commandName || program.name()];\n\n\tif (programOptions) {\n\t\tconst { options, requiredOptions, description, usage, helpText } =\n\t\t\tprogramOptions;\n\t\tif (options) {\n\t\t\tObject.keys(options).forEach((optionKey) => {\n\t\t\t\tconst commandOption = options[optionKey];\n\t\t\t\tconst newOption = createOption(commandOption, {\n\t\t\t\t\tdotsecConfig,\n\t\t\t\t\toptionKey,\n\t\t\t\t});\n\n\t\t\t\tprogram.addOption(newOption);\n\t\t\t});\n\t\t}\n\t\tif (requiredOptions) {\n\t\t\tObject.keys(requiredOptions).forEach((requiredOptionKey) => {\n\t\t\t\tconst requiredOption = requiredOptions[requiredOptionKey];\n\t\t\t\tconst newOption = createOption(requiredOption, {\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdotsecConfig,\n\t\t\t\t\toptionKey: requiredOptionKey,\n\t\t\t\t});\n\n\t\t\t\tprogram.addOption(newOption);\n\t\t\t});\n\t\t}\n\t\tif (description) {\n\t\t\tprogram.description(description);\n\t\t}\n\t\tif (usage) {\n\t\t\tprogram.description(usage);\n\t\t}\n\t\tif (helpText) {\n\t\t\tprogram.description(helpText);\n\t\t}\n\t}\n};\n", "import {\n\tDOTSEC_DEFAULT_DOTENV_FILENAME,\n\tDOTSEC_DEFAULT_DOTSEC_FILENAME,\n} from \"../../constants\";\nimport { ExpandedCommandOption } from \"./types\";\n\nexport const envFileOption: ExpandedCommandOption = {\n\toption: [\n\t\t\"--env-file <envFile>\",\n\t\t`Path to .env file. If not provided, will look for value in 'ENV_FILE' environment variable. If not provided, will look for '${DOTSEC_DEFAULT_DOTENV_FILENAME}' file in current directory.`,\n\t\tDOTSEC_DEFAULT_DOTENV_FILENAME,\n\t],\n\tenv: \"ENV_FILE\",\n};\nexport const secFileOption: ExpandedCommandOption = {\n\toption: [\n\t\t\"--sec-file, <secFile>\",\n\t\t`Path to .sec file. If not provided, will look for value in 'SEC_FILE' environment variable. If not provided, will look for '${DOTSEC_DEFAULT_DOTSEC_FILENAME}' file in current directory.`,\n\t\tDOTSEC_DEFAULT_DOTSEC_FILENAME,\n\t],\n\tenv: \"SEC_FILE\",\n};\n\nexport const withEnvOption: ExpandedCommandOption = {\n\toption: [\"--with-env, --withEnv\", \"Run command using a dot env file\"],\n};\n\nexport const withSecOption: ExpandedCommandOption = {\n\toption: [\"--with-sec, --withSec\", \"Run command with a dotsec file\"],\n};\n\nexport const yesOption: ExpandedCommandOption = {\n\toption: [\"--yes\", \"Skip confirmation prompts\"],\n};\n", "import { envFileOption, secFileOption, yesOption } from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst decryptCommandDefaults: DotSecCommandsDefaults = {\n\tdecrypt: {\n\t\tinheritsFrom: [\"dotsec\"],\n\t\toptions: {\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t},\n};\n\nexport default decryptCommandDefaults;\n", "import { DOTSEC_DEFAULT_CONFIG_FILE } from \"../../constants\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst dotsecCommandDefaults: DotSecCommandsDefaults = {\n\tdotsec: {\n\t\toptions: {\n\t\t\tverbose: [\"--verbose\", \"Verbose output\", false],\n\t\t\tconfigFile: [\n\t\t\t\t\"-c, --config-file, --configFile <configFile>\",\n\t\t\t\t\"Config file\",\n\t\t\t\tDOTSEC_DEFAULT_CONFIG_FILE,\n\t\t\t],\n\t\t\tplugin: [\"--plugin <plugin>\", \"Comma-separated list of plugins to use\"],\n\t\t},\n\t},\n};\n\nexport default dotsecCommandDefaults;\n", "import { envFileOption, secFileOption, yesOption } from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst encryptCommandDefaults: DotSecCommandsDefaults = {\n\tencrypt: {\n\t\tinheritsFrom: [\"dotsec\"],\n\t\toptions: {\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t},\n};\n\nexport default encryptCommandDefaults;\n", "import { DOTSEC_DEFAULT_CONFIG_FILE } from \"../../constants\";\nimport { envFileOption, secFileOption, yesOption } from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst initCommandDefaults: DotSecCommandsDefaults = {\n\tinit: {\n\t\toptions: {\n\t\t\tverbose: [\"--verbose\", \"Verbose output\", false],\n\t\t\tconfigFile: [\n\t\t\t\t\"-c, --config-file, --configFile <configFile>\",\n\t\t\t\t\"Config file\",\n\t\t\t\tDOTSEC_DEFAULT_CONFIG_FILE,\n\t\t\t],\n\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t},\n};\n\nexport default initCommandDefaults;\n", "import {\n\tenvFileOption,\n\tsecFileOption,\n\twithEnvOption,\n\twithSecOption,\n\tyesOption,\n} from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst pullCommandDefaults: DotSecCommandsDefaults = {\n\tpull: {\n\t\tinheritsFrom: [\"dotsec\"],\n\t\toptions: {\n\t\t\twithEnv: withEnvOption,\n\t\t\twithSec: withSecOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t},\n};\n\nexport default pullCommandDefaults;\n", "import dotsecCommandDefaults from \"./dotsec\";\nimport {\n\tenvFileOption,\n\tsecFileOption,\n\twithEnvOption,\n\twithSecOption,\n\tyesOption,\n} from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst runCommandDefaults: DotSecCommandsDefaults = {\n\trunEnvOnly: {\n\t\tinheritsFrom: [\"dotsec\"],\n\t\tusage: \"[commandArgs...]\",\n\t\toptions: {\n\t\t\tenvFile: envFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\n\t\tdescription:\n\t\t\t\"Run a command in a separate process and populate env with contents of a dotenv file.\",\n\t\thelpText: `${\"Examples:\"}\n\n${\"Run a command with a .env file\"}\n\n$ dotsec run echo \"hello world\"\n\n\n${\"Run a command with a specific .env file\"}\n\n$ dotsec run --env-file .env.dev echo \"hello world\"\n\n${\"Run a command with a specific ENV_FILE variable\"}\n\n$ ENV_FILE=.env.dev dotsec run echo \"hello world\"\n\n`,\n\t},\n\trun: {\n\t\tinheritsFrom: [\"dotsec\"],\n\n\t\toptions: {\n\t\t\twithEnv: withEnvOption,\n\t\t\twithSec: withSecOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\n\t\tusage:\n\t\t\t\"[--with-env --env-file .env] [--with-sec --sec-file .sec] [commandArgs...]\",\n\t\tdescription: `Run a command in a separate process and populate env with either \n\t\t\t- contents of a dotenv file\n\t\t\t- decrypted values of a dotsec file.\n\nThe --withEnv option will take precedence over the --withSec option. If neither are specified, the --withEnv option will be used by default.`,\n\t\thelpText: `${\"Examples:\"}\n\n${\"Run a command with a .env file\"}\n\n$ dotsec run echo \"hello world\"\n\n\n${\"Run a command with a specific .env file\"}\n\n$ dotsec run --with-env --env-file .env.dev echo \"hello world\"\n\n\n${\"Run a command with a .sec file\"}\n\n$ dotsec run --with-sec echo \"hello world\"\n\n\n${\"Run a command with a specific .sec file\"}\n\n$ dotsec run --with-sec --sec-file .sec.dev echo \"hello world\"\n`,\n\t},\n\tpush: {\n\t\toptions: {\n\t\t\t...dotsecCommandDefaults.dotsec.options,\n\t\t\twithEnv: withEnvOption,\n\t\t\twithSec: withSecOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t\trequiredOptions: {\n\t\t\t...dotsecCommandDefaults.dotsec.requiredOptions,\n\t\t},\n\t},\n};\n\nexport default runCommandDefaults;\n", "import { addPluginOptions } from \"../../lib/addPluginOptions\";\nimport {\n\tpromptOverwriteIfFileExists,\n\treadContentsFromFile,\n\twriteContentsToFile,\n} from \"../../lib/io\";\nimport { DecryptCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport { DotsecCliPluginDecryptHandler } from \"../../types/plugin\";\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport { Command } from \"commander\";\n\ntype Formats = {\n\tenv?: string;\n\tawsKeyAlias?: string;\n} & Record<string, unknown>;\n\nconst addEncryptProgram = async (\n\tprogram: Command,\n\toptions: {\n\t\tdotsecConfig: DotsecConfig;\n\t\tdecryptHandlers: DotsecCliPluginDecryptHandler[];\n\t},\n) => {\n\tconst { dotsecConfig, decryptHandlers } = options;\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"decrypt\")\n\t\t.action(async (_options: Formats, command: Command) => {\n\t\t\ttry {\n\t\t\t\tconst {\n\t\t\t\t\t// verbose,\n\t\t\t\t\tenvFile,\n\t\t\t\t\tsecFile,\n\t\t\t\t\tengine,\n\t\t\t\t\tyes,\n\t\t\t\t} = command.optsWithGlobals<DecryptCommandOptions>();\n\n\t\t\t\tconst encryptionEngine =\n\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\n\t\t\t\tconst pluginCliDecrypt = (decryptHandlers || []).find((handler) => {\n\t\t\t\t\treturn handler.triggerOptionValue === encryptionEngine;\n\t\t\t\t});\n\n\t\t\t\tif (!pluginCliDecrypt) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No decryption plugin found, available decryption engine(s): ${options.decryptHandlers\n\t\t\t\t\t\t\t.map((e) => `--${e.triggerOptionValue}`)\n\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"Decrypting with\",\n\t\t\t\t\tstrong(\n\t\t\t\t\t\tpluginCliDecrypt.encryptionEngineName ||\n\t\t\t\t\t\t\tpluginCliDecrypt.triggerOptionValue,\n\t\t\t\t\t),\n\t\t\t\t\t\"engine\",\n\t\t\t\t);\n\n\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t...Object.keys(pluginCliDecrypt.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliDecrypt.requiredOptions || {}),\n\t\t\t\t];\n\n\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\t// get current dot env file\n\t\t\t\tconst dotsecString = await readContentsFromFile(secFile);\n\n\t\t\t\tconst plaintext = await pluginCliDecrypt.handler({\n\t\t\t\t\tciphertext: dotsecString,\n\t\t\t\t\t...allOptionsValues,\n\t\t\t\t});\n\n\t\t\t\tconst dotenvOverwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\tfilePath: envFile,\n\t\t\t\t\tskip: yes,\n\t\t\t\t});\n\t\t\t\tif (\n\t\t\t\t\tdotenvOverwriteResponse === undefined ||\n\t\t\t\t\tdotenvOverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tawait writeContentsToFile(envFile, plaintext);\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`Wrote plaintext contents of ${strong(secFile)} file to ${strong(\n\t\t\t\t\t\t\tenvFile,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(strong(e.message));\n\t\t\t\tcommand.help();\n\t\t\t}\n\t\t});\n\n\toptions.decryptHandlers.map((decryption) => {\n\t\tconst { options, requiredOptions } = decryption;\n\t\taddPluginOptions(options, subProgram);\n\t\taddPluginOptions(requiredOptions, subProgram, true);\n\t});\n\n\tconst engines = options.decryptHandlers.map((e) => e.triggerOptionValue);\n\tsubProgram.option(\n\t\t\"--engine <engine>\",\n\t\t`Encryption engine${engines.length > 0 ? \"s\" : \"\"} to use: ${\n\t\t\tengines.length === 1 ? engines[0] : engines.join(\", \")\n\t\t}`,\n\t\tengines.length === 1 ? engines[0] : undefined,\n\t);\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\n\treturn subProgram;\n};\n\nexport default addEncryptProgram;\n", "import { addPluginOptions } from \"../../lib/addPluginOptions\";\nimport {\n\tpromptOverwriteIfFileExists,\n\treadContentsFromFile,\n\twriteContentsToFile,\n} from \"../../lib/io\";\nimport { EncryptCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport { DotsecCliPluginEncryptHandler } from \"../../types/plugin\";\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport { Command } from \"commander\";\n\ntype Formats = {\n\tenv?: string;\n\tawsKeyAlias?: string;\n} & Record<string, unknown>;\n\nconst addEncryptProgram = async (\n\tprogram: Command,\n\toptions: {\n\t\tencryptHandlers: DotsecCliPluginEncryptHandler[];\n\t\tdotsecConfig: DotsecConfig;\n\t},\n) => {\n\tconst { encryptHandlers, dotsecConfig } = options;\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"encrypt\")\n\t\t.action(async (_options: Formats, command: Command) => {\n\t\t\ttry {\n\t\t\t\tconst {\n\t\t\t\t\t// verbose,\n\t\t\t\t\tenvFile,\n\t\t\t\t\tsecFile,\n\t\t\t\t\tengine,\n\t\t\t\t\tyes,\n\t\t\t\t} = command.optsWithGlobals<EncryptCommandOptions>();\n\n\t\t\t\tconst encryptionEngine =\n\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\t\t\t\tconst pluginCliEncrypt = (encryptHandlers || []).find((handler) => {\n\t\t\t\t\treturn handler.triggerOptionValue === encryptionEngine;\n\t\t\t\t});\n\n\t\t\t\tif (!pluginCliEncrypt) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No encryption plugin found, available encryption engine(s): ${options.encryptHandlers\n\t\t\t\t\t\t\t.map((e) => e.triggerOptionValue)\n\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"Encrypting with\",\n\t\t\t\t\tstrong(\n\t\t\t\t\t\tpluginCliEncrypt.encryptionEngineName ||\n\t\t\t\t\t\t\tpluginCliEncrypt.triggerOptionValue,\n\t\t\t\t\t),\n\t\t\t\t\t\"engine\",\n\t\t\t\t);\n\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t...Object.keys(pluginCliEncrypt.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliEncrypt.requiredOptions || {}),\n\t\t\t\t];\n\n\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst dotenvString = await readContentsFromFile(envFile);\n\n\t\t\t\tconst cipherText = await pluginCliEncrypt.handler({\n\t\t\t\t\tplaintext: dotenvString,\n\t\t\t\t\t...allOptionsValues,\n\t\t\t\t});\n\n\t\t\t\tconst dotsecOverwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\tfilePath: secFile,\n\t\t\t\t\tskip: yes,\n\t\t\t\t});\n\t\t\t\tif (\n\t\t\t\t\tdotsecOverwriteResponse === undefined ||\n\t\t\t\t\tdotsecOverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tawait writeContentsToFile(secFile, cipherText);\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`Wrote encrypted contents of ${strong(envFile)} file to ${strong(\n\t\t\t\t\t\t\tsecFile,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(strong(e.message));\n\t\t\t\tcommand.help();\n\t\t\t}\n\t\t});\n\n\toptions.encryptHandlers.map((encryptionHandler) => {\n\t\tconst { options, requiredOptions } = encryptionHandler;\n\t\taddPluginOptions(options, subProgram);\n\t\taddPluginOptions(requiredOptions, subProgram, true);\n\t});\n\tconst engines = options.encryptHandlers.map((e) => e.triggerOptionValue);\n\tconst encryptionEngineNames = options.encryptHandlers.map(\n\t\t(e) => e.encryptionEngineName,\n\t);\n\n\tsubProgram.option(\n\t\t\"--engine <engine>\",\n\t\t`Encryption engine${engines.length > 0 ? \"s\" : \"\"}: ${\n\t\t\tengines.length === 1 ? engines[0] : engines.join(\", \")\n\t\t}`,\n\t);\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\tsubProgram.description(\n\t\t`Encrypt .env file using ${encryptionEngineNames.join(\", \")}`,\n\t);\n\treturn subProgram;\n};\n\nexport default addEncryptProgram;\n", "import fs from \"node:fs\";\nimport * as ts from \"typescript\";\n\nexport const patchConfigFile = (options: {\n\tconfigFile: string;\n\tconfig?: {\n\t\taws?: {\n\t\t\tregion?: string;\n\t\t\tkms?: {\n\t\t\t\tkeyAlias?: string;\n\t\t\t};\n\t\t};\n\t};\n}) => {\n\tconst printer: ts.Printer = ts.createPrinter();\n\tconst source = fs.readFileSync(options.configFile, \"utf8\");\n\n\tconst transformer =\n\t\t<T extends ts.Node>(context: ts.TransformationContext) =>\n\t\t(rootNode: T) => {\n\t\t\tfunction visit(node: ts.Node): ts.Node {\n\t\t\t\tnode = ts.visitEachChild(node, visit, context);\n\t\t\t\tif (node.kind === ts.SyntaxKind.StringLiteral) {\n\t\t\t\t\tconst kmsNode = node?.parent?.parent?.parent;\n\t\t\t\t\tif (options.config?.aws?.kms?.keyAlias) {\n\t\t\t\t\t\tif (kmsNode?.getChildAt(0)?.getText() === \"kms\") {\n\t\t\t\t\t\t\tconst awsNode = kmsNode?.parent?.parent;\n\t\t\t\t\t\t\tif (awsNode?.getChildAt(0).getText() === \"aws\") {\n\t\t\t\t\t\t\t\treturn ts.createStringLiteral(\n\t\t\t\t\t\t\t\t\toptions.config?.aws?.kms?.keyAlias,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (options.config?.aws?.region) {\n\t\t\t\t\t\tif (node?.parent?.getChildAt(0)?.getText() === \"region\") {\n\t\t\t\t\t\t\tconst awsNode = node?.parent?.parent?.parent;\n\n\t\t\t\t\t\t\t// const awsNode = kmsNode?.parent?.parent;\n\t\t\t\t\t\t\tif (awsNode?.getChildAt(0).getText() === \"aws\") {\n\t\t\t\t\t\t\t\treturn ts.createStringLiteral(options.config?.aws?.region);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn node;\n\t\t\t}\n\t\t\treturn ts.visitNode(rootNode, visit);\n\t\t};\n\n\tconst sourceFile: ts.SourceFile = ts.createSourceFile(\n\t\t\"test.ts\",\n\t\tsource,\n\t\tts.ScriptTarget.ES2015,\n\t\ttrue,\n\t\tts.ScriptKind.TS,\n\t);\n\n\t// Options may be passed to transform\n\tconst result: ts.TransformationResult<ts.SourceFile> =\n\t\tts.transform<ts.SourceFile>(sourceFile, [transformer]);\n\n\tconst transformedSourceFile: ts.SourceFile = result.transformed[0];\n\n\tconst transformedSource = printer.printFile(transformedSourceFile);\n\tresult.dispose();\n\n\treturn transformedSource;\n};\n", "import { promptOverwriteIfFileExists, writeContentsToFile } from \"../../lib/io\";\nimport { DotsecConfig, InitCommandOptions } from \"../../types\";\nimport { Command } from \"commander\";\n\nimport { patchConfigFile } from \"../../lib/transformer\";\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport path from \"node:path\";\ntype Formats = {\n\tenv?: string;\n\tawsKeyAlias?: string;\n};\n\nconst addInitProgram = async (\n\tprogram: Command,\n\toptions: { dotsecConfig: DotsecConfig },\n) => {\n\tconst { dotsecConfig } = options;\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"init\")\n\t\t.action(async (_options: Formats, command: Command) => {\n\t\t\tconst { configFile, yes } = command.optsWithGlobals<InitCommandOptions>();\n\n\t\t\ttry {\n\t\t\t\tconst patchedConfigTemplate = patchConfigFile({\n\t\t\t\t\tconfigFile: path.resolve(\n\t\t\t\t\t\t__dirname,\n\t\t\t\t\t\t\"../../src/templates/dotsec.config.ts\",\n\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t\tconst dotsecConfigOverwriteResponse = await promptOverwriteIfFileExists(\n\t\t\t\t\t{\n\t\t\t\t\t\tfilePath: configFile,\n\t\t\t\t\t\tskip: yes,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tdotsecConfigOverwriteResponse === undefined ||\n\t\t\t\t\tdotsecConfigOverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tawait writeContentsToFile(configFile, patchedConfigTemplate);\n\t\t\t\t\tconsole.log(`Wrote config file to ${strong(configFile)}`);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tcommand.error(e);\n\t\t\t}\n\t\t});\n\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\n\treturn subProgram;\n};\n\nexport default addInitProgram;\n", "import { PushCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport {\n\tDotsecCliPluginDecryptHandler,\n\tDotsecCliPluginPushHandler,\n} from \"../../types/plugin\";\nimport { setProgramOptions } from \"../options\";\nimport { Command } from \"commander\";\nimport { parse } from \"dotenv\";\nimport { expand } from \"dotenv-expand\";\nimport fs from \"node:fs\";\n\n/**\n * Decrypts, and pushes the contents of a .env file to AWS SSM, AWS Secrets Manager or GitHub Actions Secrets\n * @date 12/7/2022 - 9:16:48 AM\n *\n * @async\n * @param {Command} program\n * @returns {unknown}\n */\nconst addPushProgram = async (\n\tprogram: Command,\n\toptions: {\n\t\tdotsecConfig: DotsecConfig;\n\t\thandlers: {\n\t\t\tpush: DotsecCliPluginPushHandler;\n\t\t\tdecrypt: DotsecCliPluginDecryptHandler;\n\t\t}[];\n\t},\n) => {\n\tconst { dotsecConfig, handlers } = options;\n\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"push\")\n\t\t.action(async (_options: Record<string, string>, command: Command) => {\n\t\t\ttry {\n\t\t\t\tconst {\n\t\t\t\t\t// verbose,\n\t\t\t\t\tenvFile,\n\t\t\t\t\tsecFile,\n\t\t\t\t\twithEnv,\n\t\t\t\t\twithSec,\n\t\t\t\t\tengine,\n\t\t\t\t\tyes,\n\t\t\t\t} = command.optsWithGlobals<PushCommandOptions>();\n\n\t\t\t\tconst encryptionEngine =\n\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\n\t\t\t\tconst pluginCliDecrypt = (handlers || []).find((handler) => {\n\t\t\t\t\treturn handler.decrypt?.triggerOptionValue === encryptionEngine;\n\t\t\t\t})?.decrypt;\n\n\t\t\t\tconst pluginCliPush = (handlers || []).find((handler) => {\n\t\t\t\t\treturn handler.push?.triggerOptionValue === encryptionEngine;\n\t\t\t\t})?.push;\n\n\t\t\t\tif (!pluginCliPush) {\n\t\t\t\t\tthrow new Error(\"No push plugin found!\");\n\t\t\t\t}\n\n\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t...Object.keys(pluginCliDecrypt?.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliDecrypt?.requiredOptions || {}),\n\t\t\t\t\t...Object.keys(pluginCliPush?.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliPush?.requiredOptions || {}),\n\t\t\t\t];\n\n\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tif (withEnv && withSec) {\n\t\t\t\t\tthrow new Error(\"Cannot use both --with-env and --with-sec\");\n\t\t\t\t}\n\n\t\t\t\tlet envContents: string | undefined;\n\n\t\t\t\tif (withEnv || !(withEnv || withSec)) {\n\t\t\t\t\tif (!envFile) {\n\t\t\t\t\t\tthrow new Error(\"No dotenv file specified in --env-file option\");\n\t\t\t\t\t}\n\t\t\t\t\tenvContents = fs.readFileSync(envFile, \"utf8\");\n\t\t\t\t} else if (withSec) {\n\t\t\t\t\tif (!secFile) {\n\t\t\t\t\t\tthrow new Error(\"No dotsec file specified in --sec-file option\");\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!pluginCliDecrypt) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`No decryption plugin found, available decryption engine(s): ${handlers\n\t\t\t\t\t\t\t\t.map((e) => `--${e.decrypt?.triggerOptionValue}`)\n\t\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst dotSecContents = fs.readFileSync(secFile, \"utf8\");\n\t\t\t\t\tenvContents = await pluginCliDecrypt.handler({\n\t\t\t\t\t\tciphertext: dotSecContents,\n\t\t\t\t\t\t...allOptionsValues,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (envContents) {\n\t\t\t\t\t// convert to object\n\t\t\t\t\tconst dotenvVars = parse(envContents);\n\t\t\t\t\t// expand env vars\n\t\t\t\t\tconst expandedEnvVars = expand({\n\t\t\t\t\t\tignoreProcessEnv: true,\n\t\t\t\t\t\tparsed: {\n\t\t\t\t\t\t\t// add standard env variables\n\t\t\t\t\t\t\t...(process.env as Record<string, string>),\n\t\t\t\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t\t\t\t...dotenvVars,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\n\t\t\t\t\tif (expandedEnvVars.parsed) {\n\t\t\t\t\t\tawait pluginCliPush.handler({\n\t\t\t\t\t\t\tpush: expandedEnvVars.parsed,\n\t\t\t\t\t\t\tyes,\n\t\t\t\t\t\t\t...allOptionsValues,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"No .env or .sec file provided\");\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t});\n\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\n\treturn subProgram;\n};\n\nexport default addPushProgram;\n", "import fs from \"node:fs\";\n\nimport { Command } from \"commander\";\nimport { parse } from \"dotenv\";\nimport { expand } from \"dotenv-expand\";\n\nimport { addPluginOptions } from \"../../lib/addPluginOptions\";\nimport { RunCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport { DotsecCliPluginDecryptHandler } from \"../../types/plugin\";\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport { spawnSync } from \"node:child_process\";\nconst addRunProgam = (\n\tprogram: Command,\n\toptions: {\n\t\tdotsecConfig: DotsecConfig;\n\t\tdecryptHandlers?: DotsecCliPluginDecryptHandler[];\n\t},\n) => {\n\tconst { dotsecConfig, decryptHandlers } = options || {};\n\n\t// is there an encryption engine?\n\tconst hasDecryptEngine =\n\t\tdecryptHandlers !== undefined && decryptHandlers.length > 0;\n\n\tconst subProgram = program\n\t\t.command(\"run <command...>\")\n\t\t.allowUnknownOption(true)\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.showHelpAfterError(true)\n\t\t.action(\n\t\t\tasync (\n\t\t\t\tcommands: string[],\n\t\t\t\t_options: Record<string, string>,\n\t\t\t\tcommand: Command,\n\t\t\t) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst { envFile, secFile, withEnv, withSec, engine } =\n\t\t\t\t\t\tcommand.optsWithGlobals<RunCommandOptions>();\n\t\t\t\t\tif (withEnv && withSec) {\n\t\t\t\t\t\tthrow new Error(\"Cannot use both --with-env and --with-sec\");\n\t\t\t\t\t}\n\n\t\t\t\t\tlet envContents: string | undefined;\n\n\t\t\t\t\tif (withEnv || !(withEnv || withSec) || hasDecryptEngine === false) {\n\t\t\t\t\t\tif (!envFile) {\n\t\t\t\t\t\t\tthrow new Error(\"No dotenv file specified in --env-file option\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tenvContents = fs.readFileSync(envFile, \"utf8\");\n\t\t\t\t\t} else if (withSec) {\n\t\t\t\t\t\tif (!secFile) {\n\t\t\t\t\t\t\tthrow new Error(\"No dotsec file specified in --sec-file option\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst encryptionEngine =\n\t\t\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\n\t\t\t\t\t\tconst pluginCliDecrypt = (decryptHandlers || []).find((handler) => {\n\t\t\t\t\t\t\treturn handler.triggerOptionValue === encryptionEngine;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!pluginCliDecrypt) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`No decryption plugin found, available decryption engine(s): ${(\n\t\t\t\t\t\t\t\t\tdecryptHandlers || []\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.map((e) => `--${e.triggerOptionValue}`)\n\t\t\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t\t\t...Object.keys(pluginCliDecrypt.options || {}),\n\t\t\t\t\t\t\t...Object.keys(pluginCliDecrypt.requiredOptions || {}),\n\t\t\t\t\t\t];\n\n\t\t\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst dotSecContents = fs.readFileSync(secFile, \"utf8\");\n\t\t\t\t\t\tenvContents = await pluginCliDecrypt.handler({\n\t\t\t\t\t\t\tciphertext: dotSecContents,\n\t\t\t\t\t\t\t...allOptionsValues,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tif (envContents) {\n\t\t\t\t\t\tconst dotenvVars = parse(envContents);\n\t\t\t\t\t\t// expand env vars\n\t\t\t\t\t\tconst expandedEnvVars = expand({\n\t\t\t\t\t\t\tignoreProcessEnv: true,\n\t\t\t\t\t\t\tparsed: {\n\t\t\t\t\t\t\t\t// add standard env variables\n\t\t\t\t\t\t\t\t...(process.env as Record<string, string>),\n\t\t\t\t\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t\t\t\t\t...dotenvVars,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tconst [userCommand, ...userCommandArgs] = commands;\n\t\t\t\t\t\tconst spawn = spawnSync(userCommand, [...userCommandArgs], {\n\t\t\t\t\t\t\tstdio: \"inherit\",\n\t\t\t\t\t\t\tshell: false,\n\t\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t\t\tenv: {\n\t\t\t\t\t\t\t\t...expandedEnvVars.parsed,\n\t\t\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t\t\t__DOTSEC_ENV__: JSON.stringify(Object.keys(dotenvVars)),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (spawn.status !== 0) {\n\t\t\t\t\t\t\tprocess.exit(spawn.status || 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\"No .env or .sec file provided\");\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(strong(e.message));\n\t\t\t\t\tcommand.help();\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\tsetProgramOptions({\n\t\tprogram: subProgram,\n\t\tcommandName: hasDecryptEngine ? \"run\" : \"runEnvOnly\",\n\t\tdotsecConfig,\n\t});\n\n\tif (hasDecryptEngine) {\n\t\tdecryptHandlers?.map((run) => {\n\t\t\tconst { options, requiredOptions } = run;\n\t\t\taddPluginOptions(options, subProgram);\n\t\t\taddPluginOptions(requiredOptions, subProgram, true);\n\t\t});\n\t\tconst engines = decryptHandlers?.map((e) => e.triggerOptionValue);\n\n\t\tsubProgram.option(\n\t\t\t\"--engine <engine>\",\n\t\t\t`Encryption engine${engines.length > 0 ? \"s\" : \"\"}: ${\n\t\t\t\t(engines.join(\", \"), engines.length === 1 ? engines[0] : undefined)\n\t\t\t}`,\n\t\t\t// engines.length === 1 ? engines[0] : undefined,\n\t\t);\n\t}\n\treturn subProgram;\n};\n\nexport default addRunProgam;\n"],
|
|
5
|
-
"mappings": "oqCAAA,qCCEO,GAAM,GAA6B,mBAC7B,GAAsB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IAAe,EAAS,CAC7B,aAAc,EACd,SAAU,IAKZ,KAAM,IAAe,EAAS,CAAE,aAAc,IAC9C,KAAM,IAAc,EAAS,CAC5B,aAAc,EACd,gBAAiB,IAElB,KAAM,GAAQ",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/index.ts","../../src/constants.ts","../../src/lib/json.ts","../../src/lib/getConfig.ts","../../src/lib/loadDotsecPlugin.ts","../../src/lib/addPluginOptions.ts","../../src/lib/io.ts","../../src/utils/logging.ts","../../src/cli/options/index.ts","../../src/cli/options/sharedOptions.ts","../../src/cli/options/decrypt.ts","../../src/cli/options/dotsec.ts","../../src/cli/options/encrypt.ts","../../src/cli/options/init.ts","../../src/cli/options/push.ts","../../src/cli/options/run.ts","../../src/cli/commands/decrypt.ts","../../src/cli/commands/encrypt.ts","../../src/cli/commands/init.ts","../../src/cli/commands/push.ts","../../src/cli/commands/run.ts"],"sourcesContent":["import { Command } from \"commander\";\n\nimport { getMagicalConfig } from \"../lib/getConfig\";\nimport { loadDotsecPlugin } from \"../lib/loadDotsecPlugin\";\nimport {\n\tDotsecCliPluginDecryptHandler,\n\tDotsecCliPluginEncryptHandler,\n\tDotsecCliPluginPushHandler,\n\tDotsecPluginConfig,\n} from \"../types/plugin\";\nimport addDecryptProgram from \"./commands/decrypt\";\nimport addEncryptProgram from \"./commands/encrypt\";\nimport addInitCommand from \"./commands/init\";\nimport addPushProgram from \"./commands/push\";\nimport addRunCommand from \"./commands/run\";\nimport { setProgramOptions } from \"./options\";\nimport Ajv, { KeywordDefinition } from \"ajv\";\nimport yargsParser from \"yargs-parser\";\n\nconst separator: KeywordDefinition = {\n\tkeyword: \"separator\",\n\ttype: \"string\",\n\tmetaSchema: {\n\t\ttype: \"string\",\n\t\tdescription: \"value separator\",\n\t},\n\tmodifying: true,\n\tvalid: true,\n\terrors: false,\n\tcompile: (schema) => (data, ctx) => {\n\t\tif (ctx) {\n\t\t\tconst { parentData, parentDataProperty } = ctx;\n\t\t\tparentData[parentDataProperty] = data === \"\" ? [] : data.split(schema);\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t},\n};\n\nconst program = new Command();\n\n(async () => {\n\tconst parsedOptions = yargsParser(process.argv);\n\tconst argvPluginModules: string[] = [];\n\tif (parsedOptions.plugin) {\n\t\tif (Array.isArray(parsedOptions.plugin)) {\n\t\t\targvPluginModules.push(...parsedOptions.plugin);\n\t\t} else {\n\t\t\targvPluginModules.push(parsedOptions.plugin);\n\t\t}\n\t}\n\tconst configFile =\n\t\t[\n\t\t\t...(Array.isArray(parsedOptions.configFile)\n\t\t\t\t? parsedOptions.configFile\n\t\t\t\t: [parsedOptions.configFile]),\n\t\t\t...(Array.isArray(parsedOptions.c) ? parsedOptions.c : [parsedOptions.c]),\n\t\t]?.[0] || process.env.DOTSEC_CONFIG_FILE;\n\n\tconst { contents: dotsecConfig = {} } = await getMagicalConfig(configFile);\n\tconst { defaults = {}, push: pushVariables, plugins } = dotsecConfig;\n\tprogram\n\t\t.name(\"dotsec\")\n\t\t.description(\".env, but secure\")\n\t\t.version(\"1.0.0\")\n\t\t.enablePositionalOptions()\n\t\t.action((_options, other: Command) => {\n\t\t\tother.help();\n\t\t});\n\tsetProgramOptions({ program, dotsecConfig: dotsecConfig });\n\tconst ajv = new Ajv({\n\t\tallErrors: true,\n\t\tremoveAdditional: true,\n\t\tuseDefaults: true,\n\t\tcoerceTypes: true,\n\t\tallowUnionTypes: true,\n\t\taddUsedSchema: false,\n\t\tkeywords: [separator],\n\t});\n\t// if we have plugins in the cli, we need to define them in pluginModules\n\tconst pluginModules: { [key: string]: string } = {};\n\n\t// check plugins\n\tif (plugins) {\n\t\tfor (const pluginName of plugins) {\n\t\t\tif (!defaults?.plugins?.[pluginName]) {\n\t\t\t\tdefaults.plugins = {\n\t\t\t\t\t...defaults.plugins,\n\t\t\t\t\t[pluginName]: {},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\t// check argv\n\tif (argvPluginModules.length > 0) {\n\t\tfor (const pluginModule of argvPluginModules) {\n\t\t\t// let's load em up\n\t\t\tconst plugin = await loadDotsecPlugin({ name: pluginModule });\n\n\t\t\t// good, let's fire 'em up\n\t\t\tconst loadedPlugin = await plugin({\n\t\t\t\tdotsecConfig: dotsecConfig,\n\t\t\t\tajv,\n\t\t\t\tconfigFile,\n\t\t\t});\n\t\t\tpluginModules[loadedPlugin.name] = pluginModule;\n\n\t\t\tif (argvPluginModules.length === 1) {\n\t\t\t\t// if we only have one plugin, let's set it as the default\n\t\t\t\tdotsecConfig.defaults = {\n\t\t\t\t\t...dotsecConfig.defaults,\n\t\t\t\t\tencryptionEngine: String(loadedPlugin.name),\n\t\t\t\t\tplugins: {\n\t\t\t\t\t\t...dotsecConfig.defaults?.plugins,\n\t\t\t\t\t\t[loadedPlugin.name]: {\n\t\t\t\t\t\t\t...dotsecConfig.defaults?.plugins?.[loadedPlugin.name],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tif (defaults?.encryptionEngine) {\n\t\tif (!defaults?.plugins?.[defaults.encryptionEngine]) {\n\t\t\tdefaults.plugins = {\n\t\t\t\t...defaults.plugins,\n\t\t\t\t[defaults.encryptionEngine]: {},\n\t\t\t};\n\t\t}\n\t}\n\tif (defaults?.plugins) {\n\t\tObject.entries(defaults?.plugins).forEach(\n\t\t\t([pluginName, pluginModule]: [string, DotsecPluginConfig]) => {\n\t\t\t\tif (pluginModule?.name) {\n\t\t\t\t\tpluginModules[pluginName] = pluginModule?.name;\n\t\t\t\t} else {\n\t\t\t\t\tpluginModules[pluginName] = `@dotsec/plugin-${pluginName}`;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tObject.values(pushVariables || {}).forEach((pushVariable) => {\n\t\tObject.keys(pushVariable).forEach((pluginName) => {\n\t\t\tif (!pluginModules[pluginName]) {\n\t\t\t\tpluginModules[pluginName] = `@dotsec/plugin-${pluginName}`;\n\t\t\t}\n\t\t});\n\t});\n\n\t// configure encryption command\n\tconst cliPluginEncryptHandlers: DotsecCliPluginEncryptHandler[] = [];\n\tconst cliPluginDecryptHandlers: DotsecCliPluginDecryptHandler[] = [];\n\tconst cliPluginPushHandlers: {\n\t\tpush: DotsecCliPluginPushHandler;\n\t\tdecrypt: DotsecCliPluginDecryptHandler;\n\t}[] = [];\n\n\tfor (const pluginName of Object.keys(pluginModules)) {\n\t\tconst pluginModule = pluginModules[pluginName];\n\t\tconst initDotsecPlugin = await loadDotsecPlugin({ name: pluginModule });\n\t\tconst { addCliCommand, cliHandlers: cli } = await initDotsecPlugin({\n\t\t\tajv,\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\tconfigFile,\n\t\t});\n\n\t\tif (cli?.encrypt) {\n\t\t\tcliPluginEncryptHandlers.push(cli.encrypt);\n\t\t}\n\t\tif (cli?.decrypt) {\n\t\t\tcliPluginDecryptHandlers.push(cli.decrypt);\n\t\t\tif (cli?.push) {\n\t\t\t\tcliPluginPushHandlers.push({ push: cli.push, decrypt: cli.decrypt });\n\t\t\t}\n\t\t}\n\n\t\tif (addCliCommand) {\n\t\t\taddCliCommand({ program });\n\t\t}\n\t}\n\tif (cliPluginEncryptHandlers.length) {\n\t\tawait addEncryptProgram(program, {\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\tencryptHandlers: cliPluginEncryptHandlers,\n\t\t});\n\t}\n\tif (cliPluginDecryptHandlers.length) {\n\t\tawait addDecryptProgram(program, {\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\tdecryptHandlers: cliPluginDecryptHandlers,\n\t\t});\n\t}\n\tif (cliPluginPushHandlers.length) {\n\t\tawait addPushProgram(program, {\n\t\t\tdotsecConfig: dotsecConfig,\n\t\t\thandlers: cliPluginPushHandlers,\n\t\t});\n\t}\n\n\t// add other commands\n\tawait addInitCommand(program, { dotsecConfig: dotsecConfig });\n\tawait addRunCommand(program, {\n\t\tdotsecConfig: dotsecConfig,\n\t\tdecryptHandlers: cliPluginDecryptHandlers,\n\t});\n\tawait program.parse();\n})();\n","import { DotsecConfig } from \"./types/config\";\n\nexport const DOTSEC_DEFAULT_CONFIG_FILE = \"dotsec.config.ts\";\nexport const DOTSEC_CONFIG_FILES = [DOTSEC_DEFAULT_CONFIG_FILE];\nexport const DOTSEC_DEFAULT_DOTSEC_FILENAME = \".sec\";\nexport const DOTSEC_DEFAULT_DOTENV_FILENAME = \".env\";\nexport const defaultConfig: DotsecConfig = {\n\tdefaults: {\n\t\t// encryptionEngine: \"pke\",\n\t\t// plugins: {\n\t\t// \tpke: {},\n\t\t// },\n\t},\n};\n","import fs from \"fs\";\nimport path from \"node:path\";\n\n/**\n * Parse JSONC\n * @date 12/7/2022 - 12:48:45 PM\n *\n * @export\n * @param {string} data\n * @returns {*}\n */\nexport function jsoncParse(data: string) {\n\ttry {\n\t\treturn new Function(`return ${data.trim()}`)();\n\t} catch {\n\t\t// Silently ignore any error\n\t\t// That's what tsc/jsonc-parser did after all\n\t\treturn {};\n\t}\n}\n\n/**\n * Load JSON\n * @date 12/7/2022 - 12:48:57 PM\n *\n * @async\n * @param {string} filepath\n * @returns {unknown}\n */\nexport const loadJson = async (filepath: string) => {\n\ttry {\n\t\treturn jsoncParse(await fs.promises.readFile(filepath, \"utf8\"));\n\t} catch (error) {\n\t\tif (error instanceof Error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to parse ${path.relative(process.cwd(), filepath)}: ${\n\t\t\t\t\terror.message\n\t\t\t\t}`,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow error;\n\t\t}\n\t}\n};\n","import { DOTSEC_CONFIG_FILES, defaultConfig } from \"../constants\";\nimport { DotsecConfig } from \"../types/config\";\nimport { DotsecConfigAndSource } from \"../types/plugin\";\nimport { loadJson } from \"./json\";\nimport { bundleRequire } from \"bundle-require\";\nimport JoyCon from \"joycon\";\nimport path from \"path\";\n\nexport const getMagicalConfig = async (\n\tfilename?: string,\n): Promise<DotsecConfigAndSource> => {\n\tconst cwd = process.cwd();\n\tconst configJoycon = new JoyCon();\n\tconst configPath = await configJoycon.resolve({\n\t\tfiles: filename ? [filename] : [...DOTSEC_CONFIG_FILES, \"package.json\"],\n\t\tcwd,\n\t\tstopDir: path.parse(cwd).root,\n\t\tpackageKey: \"dotsec\",\n\t});\n\tif (filename && configPath === null) {\n\t\tthrow new Error(`Could not find config file ${filename}`);\n\t}\n\tif (configPath) {\n\t\tif (configPath.endsWith(\".json\")) {\n\t\t\tconst rawData = (await loadJson(configPath)) as Partial<DotsecConfig>;\n\n\t\t\tlet data: Partial<DotsecConfig>;\n\n\t\t\tif (\n\t\t\t\tconfigPath.endsWith(\"package.json\") &&\n\t\t\t\t(rawData as { dotsec: Partial<DotsecConfig> }).dotsec !== undefined\n\t\t\t) {\n\t\t\t\tdata = (rawData as { dotsec: Partial<DotsecConfig> }).dotsec;\n\t\t\t} else {\n\t\t\t\tdata = rawData as Partial<DotsecConfig>;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tsource: \"json\",\n\t\t\t\tcontents: {\n\t\t\t\t\t...defaultConfig,\n\t\t\t\t\t...data,\n\t\t\t\t\tdefaults: {\n\t\t\t\t\t\t...data?.defaults,\n\t\t\t\t\t\t...defaultConfig.defaults,\n\t\t\t\t\t\tplugins: {\n\t\t\t\t\t\t\t...data?.defaults?.plugins,\n\t\t\t\t\t\t\t...defaultConfig.defaults?.plugins,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tpush: {\n\t\t\t\t\t\t...data?.push,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t} else if (configPath.endsWith(\".ts\")) {\n\t\t\tconst bundleRequireResult = await bundleRequire({\n\t\t\t\tfilepath: configPath,\n\t\t\t});\n\t\t\tconst data = (bundleRequireResult.mod.dotsec ||\n\t\t\t\tbundleRequireResult.mod.default ||\n\t\t\t\tbundleRequireResult.mod) as Partial<DotsecConfig>;\n\n\t\t\treturn {\n\t\t\t\tsource: \"ts\",\n\t\t\t\tcontents: {\n\t\t\t\t\t...defaultConfig,\n\t\t\t\t\t...data,\n\t\t\t\t\tdefaults: {\n\t\t\t\t\t\t...data?.defaults,\n\t\t\t\t\t\t...defaultConfig.defaults,\n\t\t\t\t\t\tplugins: {\n\t\t\t\t\t\t\t...data?.defaults?.plugins,\n\t\t\t\t\t\t\t...defaultConfig.defaults?.plugins,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tpush: {\n\t\t\t\t\t\t...data?.push,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\n\treturn { source: \"defaultConfig\", contents: defaultConfig };\n};\n","import { DotsecPluginModule } from \"../types/plugin\";\n\nexport const loadDotsecPlugin = async (options: {\n\tname: string;\n}): Promise<DotsecPluginModule> => {\n\treturn import(options.name).then((imported) => {\n\t\treturn imported.default;\n\t});\n};\n","import { DotsecCliOption } from \"../types/plugin\";\nimport { Command, Option } from \"commander\";\n\nexport const addPluginOptions = (\n\toptions:\n\t\t| {\n\t\t\t\t[x: string]: DotsecCliOption;\n\t\t }\n\t\t| undefined,\n\tcommand: Command,\n\tmandatory?: boolean,\n) => {\n\tif (options) {\n\t\tObject.values(options).map((option) => {\n\t\t\tlet optionProps:\n\t\t\t\t| {\n\t\t\t\t\t\tflags: string;\n\t\t\t\t\t\tdescription?: string;\n\t\t\t\t\t\tdefaultValue?: string | boolean | string[];\n\t\t\t\t\t\tchoices?: string[];\n\t\t\t\t\t\tfn?: (value: string, previous: unknown) => unknown;\n\t\t\t\t\t\tregexp?: RegExp;\n\t\t\t\t\t\tenv?: string;\n\t\t\t\t }\n\t\t\t\t| undefined;\n\t\t\tif (Array.isArray(option)) {\n\t\t\t\tconst [flags, description, defaultValue] = option;\n\t\t\t\toptionProps = {\n\t\t\t\t\tflags,\n\t\t\t\t\tdescription,\n\t\t\t\t\tdefaultValue,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tconst { flags, description, defaultValue, choices, env, fn } = option;\n\t\t\t\toptionProps = {\n\t\t\t\t\tflags,\n\t\t\t\t\tdescription,\n\t\t\t\t\tdefaultValue,\n\t\t\t\t\tchoices,\n\t\t\t\t\tenv,\n\t\t\t\t\tfn,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (optionProps) {\n\t\t\t\tconst newOption = new Option(\n\t\t\t\t\toptionProps.flags,\n\t\t\t\t\toptionProps.description,\n\t\t\t\t);\n\t\t\t\tif (optionProps.fn) {\n\t\t\t\t\tnewOption.argParser(optionProps.fn);\n\t\t\t\t}\n\t\t\t\tif (optionProps.defaultValue) {\n\t\t\t\t\tnewOption.default(optionProps.defaultValue);\n\t\t\t\t}\n\t\t\t\tif (optionProps.env) {\n\t\t\t\t\tnewOption.env(optionProps.env);\n\t\t\t\t}\n\t\t\t\tif (mandatory) {\n\t\t\t\t\tnewOption.makeOptionMandatory(true);\n\t\t\t\t}\n\t\t\t\tif (optionProps.choices) {\n\t\t\t\t\tnewOption.choices(optionProps.choices);\n\t\t\t\t}\n\t\t\t\tcommand.addOption(newOption);\n\t\t\t}\n\t\t});\n\t}\n};\n","import fs, { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport prompts from \"prompts\";\n\nexport const readContentsFromFile = async (\n\tfilePath: string,\n): Promise<string> => {\n\treturn await fs.readFile(filePath, \"utf-8\");\n};\n\nexport const writeContentsToFile = async (\n\tfilePath: string,\n\tcontents: string,\n): Promise<void> => {\n\treturn await fs.writeFile(filePath, contents, \"utf-8\");\n};\n\nexport const fileExists = async (source: string): Promise<boolean> => {\n\ttry {\n\t\tawait stat(source);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const promptOverwriteIfFileExists = async ({\n\tfilePath,\n\tskip,\n}: {\n\tfilePath: string;\n\tskip?: boolean;\n}) => {\n\tlet overwriteResponse: prompts.Answers<\"overwrite\"> | undefined;\n\n\tif ((await fileExists(filePath)) && skip !== true) {\n\t\toverwriteResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"overwrite\",\n\t\t\tmessage: () => {\n\t\t\t\treturn `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;\n\t\t\t},\n\t\t});\n\t} else {\n\t\toverwriteResponse = undefined;\n\t}\n\treturn overwriteResponse;\n};\n","import chalk from \"chalk\";\nimport Table from \"cli-table\";\nexport { Table };\n\nlet _logger: Pick<Console, \"info\" | \"error\" | \"table\">;\nexport const getLogger = () => {\n\tif (!_logger) {\n\t\t_logger = console;\n\t}\n\n\treturn _logger;\n};\nexport const writeLine = (str: string) => {\n\tprocess.stdout.write(str);\n};\nexport const emphasis = (str: string): string => chalk.yellowBright(str);\nexport const strong = (str: string): string => chalk.yellow.bold(str);\n\nexport const clientLogger = {\n\tdebug(content: object) {\n\t\tconsole.log(content);\n\t},\n\tinfo(content: object) {\n\t\tconsole.log(content);\n\t},\n\twarn(content: object) {\n\t\tconsole.log(content);\n\t},\n\terror(content: object) {\n\t\tconsole.error(content);\n\t},\n};\n","import { DotsecConfig } from \"../../types/index\";\nimport { Command, Option } from \"commander\";\n\nimport decryptCommandDefaults from \"./decrypt\";\nimport dotsecCommandDefaults from \"./dotsec\";\nimport encryptCommandDefaults from \"./encrypt\";\nimport initCommandDefaults from \"./init\";\nimport pushCommandDefaults from \"./push\";\nimport runCommandDefaults from \"./run\";\nimport {\n\tCommandOption,\n\tDeepExpandedCommandOption,\n\tDotSecCommandsDefaults,\n\tExpandedCommandOption,\n} from \"./types\";\n\nexport const commandOptions: DotSecCommandsDefaults = {\n\t...dotsecCommandDefaults,\n\t...initCommandDefaults,\n\t...encryptCommandDefaults,\n\t...decryptCommandDefaults,\n\t...runCommandDefaults,\n\t...pushCommandDefaults,\n};\n\nconst expandCommandOption = (\n\tcommandOption: CommandOption | ExpandedCommandOption,\n): DeepExpandedCommandOption => {\n\tif (Array.isArray(commandOption)) {\n\t\tconst [flags, description, defaultValue] = commandOption;\n\t\tconst optionProps = {\n\t\t\tflags,\n\t\t\tdescription,\n\t\t\tdefaultValue,\n\t\t};\n\t\treturn optionProps;\n\t} else {\n\t\tif (\"option\" in commandOption) {\n\t\t\tconst [flags, description, defaultValue] = commandOption.option;\n\t\t\tconst optionProps = {\n\t\t\t\tflags,\n\t\t\t\tdescription,\n\t\t\t\tdefaultValue,\n\t\t\t\tenv: commandOption.env,\n\t\t\t};\n\t\t\treturn optionProps;\n\t\t}\n\t\treturn commandOption;\n\t}\n};\n\nconst createOption = (\n\tcommandOption: CommandOption | ExpandedCommandOption,\n\toptions: {\n\t\trequired?: boolean;\n\t\tdotsecConfig?: DotsecConfig;\n\t\toptionKey: string;\n\t},\n): Option => {\n\tconst defaultOptionValueFromConfig =\n\t\toptions?.dotsecConfig?.defaults?.options?.[options?.optionKey];\n\tconst optionProps = expandCommandOption(commandOption);\n\n\tconst newOption = new Option(optionProps.flags, optionProps.description);\n\tif (optionProps.fn) {\n\t\tnewOption.argParser(optionProps.fn);\n\t}\n\tif (optionProps.defaultValue) {\n\t\tnewOption.default(defaultOptionValueFromConfig || optionProps.defaultValue);\n\t}\n\tif (optionProps.env) {\n\t\tnewOption.env(optionProps.env);\n\t}\n\tif (options.required) {\n\t\tnewOption.makeOptionMandatory(true);\n\t}\n\tif (optionProps.choices) {\n\t\tnewOption.choices(optionProps.choices);\n\t}\n\n\treturn newOption;\n};\n\nexport const setProgramOptions = (params: {\n\tprogram: Command;\n\tcommandName?: string;\n\tdotsecConfig: DotsecConfig;\n}) => {\n\tconst { program, commandName, dotsecConfig } = params;\n\tconst programOptions = commandOptions[commandName || program.name()];\n\n\tif (programOptions) {\n\t\tconst { options, requiredOptions, description, usage, helpText } =\n\t\t\tprogramOptions;\n\t\tif (options) {\n\t\t\tObject.keys(options).forEach((optionKey) => {\n\t\t\t\tconst commandOption = options[optionKey];\n\t\t\t\tconst newOption = createOption(commandOption, {\n\t\t\t\t\tdotsecConfig,\n\t\t\t\t\toptionKey,\n\t\t\t\t});\n\n\t\t\t\tprogram.addOption(newOption);\n\t\t\t});\n\t\t}\n\t\tif (requiredOptions) {\n\t\t\tObject.keys(requiredOptions).forEach((requiredOptionKey) => {\n\t\t\t\tconst requiredOption = requiredOptions[requiredOptionKey];\n\t\t\t\tconst newOption = createOption(requiredOption, {\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdotsecConfig,\n\t\t\t\t\toptionKey: requiredOptionKey,\n\t\t\t\t});\n\n\t\t\t\tprogram.addOption(newOption);\n\t\t\t});\n\t\t}\n\t\tif (description) {\n\t\t\tprogram.description(description);\n\t\t}\n\t\tif (usage) {\n\t\t\tprogram.usage(usage);\n\t\t}\n\t\tif (helpText) {\n\t\t\tprogram.description(helpText);\n\t\t}\n\t}\n};\n","import {\n\tDOTSEC_DEFAULT_DOTENV_FILENAME,\n\tDOTSEC_DEFAULT_DOTSEC_FILENAME,\n} from \"../../constants\";\nimport { ExpandedCommandOption } from \"./types\";\n\nexport const envFileOption: ExpandedCommandOption = {\n\toption: [\n\t\t\"--env-file <envFile>\",\n\t\t`Path to .env file. If not provided, will look for value in 'ENV_FILE' environment variable. If not provided, will look for '${DOTSEC_DEFAULT_DOTENV_FILENAME}' file in current directory.`,\n\t\tDOTSEC_DEFAULT_DOTENV_FILENAME,\n\t],\n\tenv: \"ENV_FILE\",\n};\nexport const secFileOption: ExpandedCommandOption = {\n\toption: [\n\t\t\"--sec-file, <secFile>\",\n\t\t`Path to .sec file. If not provided, will look for value in 'SEC_FILE' environment variable. If not provided, will look for '${DOTSEC_DEFAULT_DOTSEC_FILENAME}' file in current directory.`,\n\t\tDOTSEC_DEFAULT_DOTSEC_FILENAME,\n\t],\n\tenv: \"SEC_FILE\",\n};\n\nexport const usingOption: ExpandedCommandOption = {\n\tflags: \"--using <using>\",\n\tdescription: \"Wether to use a dot env file or a dot sec file\",\n\tchoices: [\"env\", \"sec\"],\n\tenv: \"DOTSEC_USING\",\n};\n\nexport const usingNoEncryptionEngineOption: ExpandedCommandOption = {\n\tflags: \"--using <using>\",\n\tdescription: \"Wether to use a dot env file or a dot sec file\",\n\tchoices: [\"env\"],\n\tenv: \"DOTSEC_USING\",\n};\n\nexport const yesOption: ExpandedCommandOption = {\n\toption: [\"--yes\", \"Skip confirmation prompts\"],\n};\n\nexport const verboseOption: ExpandedCommandOption = {\n\toption: [\"--verbose\", \"Verbose output\"],\n};\n\nexport const configFileOption: ExpandedCommandOption = {\n\toption: [\"-c, --config-file, --configFile <configFile>\", \"Config file\"],\n\tenv: \"DOTSEC_CONFIG_FILE\",\n};\n\nexport const pluginOption: ExpandedCommandOption = {\n\toption: [\"--plugin <plugin>\", \"Comma-separated list of plugins to use\"],\n\tenv: \"DOTSEC_PLUGIN\",\n};\n\nexport const engineOption: ExpandedCommandOption = {\n\toption: [\"--engine <engine>\", \"Encryption engine to use\"],\n\tenv: \"DOTSEC_ENGINE\",\n};\n\nexport const createManifestOption: ExpandedCommandOption = {\n\toption: [\n\t\t\"--create-manifest\",\n\t\t\"Create a markdown manifest file. See the --manifest-file option for more information.\",\n\t],\n\tenv: \"CREATE_MANIFEST\",\n};\n\nexport const manifestFileOption: ExpandedCommandOption = {\n\toption: [\n\t\t\"--manifest-file <manifestFile>\",\n\t\t\"Specify the name of the manifest file to create.\",\n\t],\n\tenv: \"ENCRYPTION_MANIFEST_FILE\",\n};\n","import {\n\tconfigFileOption,\n\tcreateManifestOption,\n\tenvFileOption,\n\tmanifestFileOption,\n\tsecFileOption,\n\tyesOption,\n} from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst decryptCommandDefaults: DotSecCommandsDefaults = {\n\tdecrypt: {\n\t\toptions: {\n\t\t\tconfigFile: configFileOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tcreateManifest: createManifestOption,\n\t\t\tmanifestFile: manifestFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t\tdescription: \"Decrypt a sec file\",\n\t\thelpText: `Examples:\n\n\nDecrypt .sec file to .env file\n\n$ npx dotsec decrypt\n\n\nSpecify a different .sec file\n\n$ npx dotsec decrypt --sec-file .sec.dev\n$ SEC_FILE=.sec.dev npx dotsec decrypt\n\nSpecify a different .env file\n\n$ npx dotsec decrypt --env-file .env.dev\n$ ENV_FILE=.env.dev npx dotsec decrypt\n\nWrite a manifest file\n\n$ npx dotsec decrypt --create-manifest\n$ CREATE_MANIFEST=true npx dotsec decrypt\n\nSpecify a different manifest file\n\n$ npx dotsec decrypt --manifest-file .manifest.dev\n$ MANIFEST_FILE=.manifest.dev npx dotsec decrypt\n`,\n\t},\n};\n\nexport default decryptCommandDefaults;\n","import { configFileOption, pluginOption } from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst dotsecCommandDefaults: DotSecCommandsDefaults = {\n\tdotsec: {\n\t\toptions: {\n\t\t\tconfigFile: configFileOption,\n\t\t\tplugin: pluginOption,\n\t\t},\n\t},\n};\n\nexport default dotsecCommandDefaults;\n","import {\n\tconfigFileOption,\n\tcreateManifestOption,\n\tenvFileOption,\n\tmanifestFileOption,\n\tsecFileOption,\n\tyesOption,\n} from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst encryptCommandDefaults: DotSecCommandsDefaults = {\n\tencrypt: {\n\t\toptions: {\n\t\t\tconfigFile: configFileOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tcreateManifest: createManifestOption,\n\t\t\tmanifestFile: manifestFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t\tdescription: \"Encrypt an env file\",\n\t\thelpText: `Examples:\n\n\nEncrypt .env file to .sec file\n\n$ npx dotsec encrypt\n\n\nSpecify a different .env file\n\n$ npx dotsec encrypt --env-file .env.dev\n$ ENV_FILE=.env.dev npx dotsec encrypt\n\nSpecify a different .sec file\n\n$ npx dotsec encrypt --sec-file .sec.dev\n$ SEC_FILE=.sec.dev npx dotsec encrypt\n\n\nWrite a manifest file\n\n$ npx dotsec encrypt --create-manifest\n$ CREATE_MANIFEST=true npx dotsec encrypt\n\n\nSpecify a different manifest file\n\n$ npx dotsec encrypt --manifest-file .manifest.dev\n$ MANIFEST_FILE=.manifest.dev npx dotsec encrypt\n`,\n\t},\n};\n\nexport default encryptCommandDefaults;\n","import { configFileOption, yesOption } from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst initCommandDefaults: DotSecCommandsDefaults = {\n\tinit: {\n\t\toptions: {\n\t\t\tconfigFile: configFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t\tdescription:\n\t\t\t\"Initialize a dotsec project by creating a dotsec.config.ts file.\",\n\t\thelpText: `Examples:\n\nCreate a dotsec.config.ts file in the current directory\n\n$ npx dotsec init\n\n\nOverwrite an existing dotsec.config.ts file in the current directory\n\n$ npx dotsec init --yes\n\n\nCreate a dotsec config file in the current directory with a specific config file name\n\nBy specifying the --config-file option, you can create a dotsec config file with a specific name.\n\n$ npx dotsec init --config-file dotsec.config.ts\n\n$ DOTSEC_CONFIG_FILE=my.config.ts npx dotsec init\n`,\n\t},\n};\n\nexport default initCommandDefaults;\n","import {\n\tconfigFileOption,\n\tenvFileOption,\n\tsecFileOption,\n\tusingOption,\n\tyesOption,\n} from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n\nconst pushCommandDefaults: DotSecCommandsDefaults = {\n\tpush: {\n\t\toptions: {\n\t\t\tconfigFile: configFileOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t\trequiredOptions: {\n\t\t\tusing: usingOption,\n\t\t},\n\t\tdescription: \"Push variables from env or sec file to a remote\",\n\t\thelpText: `Examples:\n\nPush variables from .env file to remote\n\n$ npx dotsec push --using env\n$ DOTSEC_USING=env npx dotsec push\n\n\nPush variables from .sec file to remote\n\n$ npx dotsec push --using sec\n$ DOTSEC_USING=sec npx dotsec push\n`,\n\t},\n};\n\nexport default pushCommandDefaults;\n","import {\n\tconfigFileOption,\n\tengineOption,\n\tenvFileOption,\n\tsecFileOption,\n\tusingNoEncryptionEngineOption,\n\tusingOption,\n\tyesOption,\n} from \"./sharedOptions\";\nimport { DotSecCommandsDefaults } from \"./types\";\n/*\n\nrun --env-file=.env --sec-file=.sec --with=env-file\n\n*/\nconst runCommandDefaults: DotSecCommandsDefaults = {\n\trunEnvOnly: {\n\t\tusage: \"--using env [commandArgs...]\",\n\n\t\toptions: {\n\t\t\tconfigFile: configFileOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tyes: yesOption,\n\t\t\tengine: engineOption,\n\t\t},\n\t\trequiredOptions: {\n\t\t\tusing: usingNoEncryptionEngineOption,\n\t\t},\n\n\t\tdescription:\n\t\t\t\"Run a command in a separate process and populate env with contents of a dotenv file.\",\n\t\thelpText: `Examples:\n\t\t\nRun a command with a .env file\n\t\t\n$ npx dotsec run --using env node -e \\\"console.log(process.env)\\\"\n\n\nRun a command with a specific .env file\n\n$ npx dotsec run --using env --env-file .env node -e \\\"console.log(process.env)\\\"\n\n\nRun a command with a specific ENV_FILE variable\n\n$ ENV_FILE=.env.dev npx dotsec run --using env node -e \\\"console.log(process.env)\\\"\n\n\nYou can also specify 'using' as an environment variable\n\n$ DOTSEC_USING=env npx dotsec run node -e \\\"console.log(process.env)\\\"\n\t\t`,\n\t},\n\trun: {\n\t\toptions: {\n\t\t\tconfigFile: configFileOption,\n\t\t\tenvFile: envFileOption,\n\t\t\tsecFile: secFileOption,\n\t\t\tyes: yesOption,\n\t\t},\n\t\trequiredOptions: {\n\t\t\tusing: usingOption,\n\t\t},\n\n\t\tusage: \"[--using env] [--using sec] [commandArgs...]\",\n\t\tdescription: `Run a command in a separate process and populate env with either \n\t\t\t- contents of a dotenv file\n\t\t\t- decrypted values of a dotsec file.\n\nThe --withEnv option will take precedence over the --withSec option. If neither are specified, the --withEnv option will be used by default.`,\n\t\thelpText: `${\"Examples:\"}\n\n${\"Run a command with a .env file\"}\n\n$ dotsec run echo \"hello world\"\n\n\n${\"Run a command with a specific .env file\"}\n\n$ dotsec run --with-env --env-file .env.dev echo \"hello world\"\n\n\n${\"Run a command with a .sec file\"}\n\n$ dotsec run --with-sec echo \"hello world\"\n\n\n${\"Run a command with a specific .sec file\"}\n\n$ dotsec run --with-sec --sec-file .sec.dev echo \"hello world\"\n`,\n\t},\n\t// push: {\n\t// \toptions: {\n\t// \t\t...dotsecCommandDefaults.dotsec.options,\n\t// \t\twithEnv: withEnvOption,\n\t// \t\twithSec: withSecOption,\n\t// \t\tenvFile: envFileOption,\n\t// \t\tsecFile: secFileOption,\n\t// \t\tyes: yesOption,\n\t// \t},\n\t// \trequiredOptions: {\n\t// \t\t...dotsecCommandDefaults.dotsec.requiredOptions,\n\t// \t},\n\t// },\n};\n\nexport default runCommandDefaults;\n","import { addPluginOptions } from \"../../lib/addPluginOptions\";\nimport {\n\tpromptOverwriteIfFileExists,\n\treadContentsFromFile,\n\twriteContentsToFile,\n} from \"../../lib/io\";\nimport { DecryptCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport { DotsecCliPluginDecryptHandler } from \"../../types/plugin\";\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport { Command } from \"commander\";\nimport { parse } from \"dotenv\";\n\ntype Formats = {\n\tenv?: string;\n\tawsKeyAlias?: string;\n} & Record<string, unknown>;\n\nconst addEncryptProgram = async (\n\tprogram: Command,\n\toptions: {\n\t\tdotsecConfig: DotsecConfig;\n\t\tdecryptHandlers: DotsecCliPluginDecryptHandler[];\n\t},\n) => {\n\tconst { dotsecConfig, decryptHandlers } = options;\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"decrypt\")\n\t\t.action(async (_options: Formats, command: Command) => {\n\t\t\ttry {\n\t\t\t\tconst {\n\t\t\t\t\t// verbose,\n\t\t\t\t\tenvFile,\n\t\t\t\t\tsecFile,\n\t\t\t\t\tengine,\n\t\t\t\t\tcreateManifest,\n\t\t\t\t\tmanifestFile,\n\t\t\t\t\tyes,\n\t\t\t\t} = command.optsWithGlobals<DecryptCommandOptions>();\n\t\t\t\tconst encryptionEngine =\n\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\n\t\t\t\tconst pluginCliDecrypt = (decryptHandlers || []).find((handler) => {\n\t\t\t\t\treturn handler.triggerOptionValue === encryptionEngine;\n\t\t\t\t});\n\n\t\t\t\tif (!pluginCliDecrypt) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No decryption plugin found, available decryption engine(s): ${options.decryptHandlers\n\t\t\t\t\t\t\t.map((e) => `--${e.triggerOptionValue}`)\n\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"Decrypting with\",\n\t\t\t\t\tstrong(\n\t\t\t\t\t\tpluginCliDecrypt.encryptionEngineName ||\n\t\t\t\t\t\t\tpluginCliDecrypt.triggerOptionValue,\n\t\t\t\t\t),\n\t\t\t\t\t\"engine\",\n\t\t\t\t);\n\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t...Object.keys(pluginCliDecrypt.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliDecrypt.requiredOptions || {}),\n\t\t\t\t];\n\n\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\t// get current dot env file\n\t\t\t\tconst dotsecString = await readContentsFromFile(secFile);\n\n\t\t\t\tconst plaintext = await pluginCliDecrypt.handler({\n\t\t\t\t\tciphertext: dotsecString,\n\t\t\t\t\t...allOptionsValues,\n\t\t\t\t});\n\n\t\t\t\tconst dotenvOverwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\tfilePath: envFile,\n\t\t\t\t\tskip: yes,\n\t\t\t\t});\n\t\t\t\tif (\n\t\t\t\t\tdotenvOverwriteResponse === undefined ||\n\t\t\t\t\tdotenvOverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tawait writeContentsToFile(envFile, plaintext);\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`Wrote plaintext contents of ${strong(secFile)} file to ${strong(\n\t\t\t\t\t\t\tenvFile,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (createManifest) {\n\t\t\t\t\t// parse raw env contents into key value pairs using the dotenv package\n\t\t\t\t\tconst dotenvVars = parse(plaintext);\n\t\t\t\t\t// expand env vars\n\t\t\t\t\tconst markdownManifest = `# Dotsec decryption manifest \n\n## Overview\n\n- plaintext source: ${envFile}\n- ciphertext target: ${secFile}\n- created: ${new Date().toUTCString()}\n- Decryption engine: ${\n\t\t\t\t\t\tpluginCliDecrypt.encryptionEngineName ||\n\t\t\t\t\t\tpluginCliDecrypt.triggerOptionValue\n\t\t\t\t\t}\n- Decryption engine options: ${JSON.stringify(allOptionsValues)}\n\n## Variables\n\n| Key | \n| --- | \n${Object.keys(dotenvVars)\n\t.map((key) => {\n\t\treturn `| \\`${key} \\`| `;\n\t})\n\t.join(\"\\n\")}\n`;\n\n\t\t\t\t\t// write manifest file, don't prompt to overwrite\n\t\t\t\t\tconst manifestTargetFile =\n\t\t\t\t\t\tmanifestFile || `${envFile}.decryption-manifest.md`;\n\t\t\t\t\tawait writeContentsToFile(manifestTargetFile, markdownManifest);\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`Wrote manifest of ${strong(envFile)} file to ${strong(\n\t\t\t\t\t\t\tmanifestTargetFile,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(strong(e.message));\n\t\t\t\tcommand.help();\n\t\t\t}\n\t\t});\n\n\toptions.decryptHandlers.map((decryption) => {\n\t\tconst { options, requiredOptions } = decryption;\n\t\taddPluginOptions(options, subProgram);\n\t\taddPluginOptions(requiredOptions, subProgram, true);\n\t});\n\n\tconst engines = options.decryptHandlers.map((e) => e.triggerOptionValue);\n\tsubProgram.option(\n\t\t\"--engine <engine>\",\n\t\t`Encryption engine${engines.length > 0 ? \"s\" : \"\"} to use: ${\n\t\t\tengines.length === 1 ? engines[0] : engines.join(\", \")\n\t\t}`,\n\t\tengines.length === 1 ? engines[0] : undefined,\n\t);\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\n\treturn subProgram;\n};\n\nexport default addEncryptProgram;\n","import { addPluginOptions } from \"../../lib/addPluginOptions\";\nimport {\n\tpromptOverwriteIfFileExists,\n\treadContentsFromFile,\n\twriteContentsToFile,\n} from \"../../lib/io\";\nimport { EncryptCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport { DotsecCliPluginEncryptHandler } from \"../../types/plugin\";\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport { Command } from \"commander\";\nimport { parse } from \"dotenv\";\n\ntype Formats = {\n\tenv?: string;\n\tawsKeyAlias?: string;\n} & Record<string, unknown>;\n\nconst addEncryptProgram = async (\n\tprogram: Command,\n\toptions: {\n\t\tencryptHandlers: DotsecCliPluginEncryptHandler[];\n\t\tdotsecConfig: DotsecConfig;\n\t},\n) => {\n\tconst { encryptHandlers, dotsecConfig } = options;\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"encrypt\")\n\t\t.action(async (_options: Formats, command: Command) => {\n\t\t\ttry {\n\t\t\t\tconst {\n\t\t\t\t\t// verbose,\n\t\t\t\t\tenvFile,\n\t\t\t\t\tsecFile,\n\t\t\t\t\tengine,\n\t\t\t\t\tcreateManifest,\n\t\t\t\t\tmanifestFile,\n\t\t\t\t\tyes,\n\t\t\t\t} = command.optsWithGlobals<EncryptCommandOptions>();\n\n\t\t\t\tconst encryptionEngine =\n\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\t\t\t\tconst pluginCliEncrypt = (encryptHandlers || []).find((handler) => {\n\t\t\t\t\treturn handler.triggerOptionValue === encryptionEngine;\n\t\t\t\t});\n\n\t\t\t\tif (!pluginCliEncrypt) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No encryption plugin found, available encryption engine(s): ${options.encryptHandlers\n\t\t\t\t\t\t\t.map((e) => e.triggerOptionValue)\n\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t...Object.keys(pluginCliEncrypt.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliEncrypt.requiredOptions || {}),\n\t\t\t\t];\n\n\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst dotenvString = await readContentsFromFile(envFile);\n\n\t\t\t\tconst cipherText = await pluginCliEncrypt.handler({\n\t\t\t\t\tplaintext: dotenvString,\n\t\t\t\t\t...allOptionsValues,\n\t\t\t\t});\n\n\t\t\t\tconst dotsecOverwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\tfilePath: secFile,\n\t\t\t\t\tskip: yes,\n\t\t\t\t});\n\t\t\t\tif (\n\t\t\t\t\tdotsecOverwriteResponse === undefined ||\n\t\t\t\t\tdotsecOverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tawait writeContentsToFile(secFile, cipherText);\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`Wrote encrypted contents of ${strong(envFile)} file to ${strong(\n\t\t\t\t\t\t\tsecFile,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (createManifest) {\n\t\t\t\t\t\t// parse raw env contents into key value pairs using the dotenv package\n\t\t\t\t\t\tconst dotenvVars = parse(dotenvString);\n\t\t\t\t\t\t// expand env vars\n\t\t\t\t\t\tconst markdownManifest = `# Dotsec encryption manifest \n\n## Overview\n\n- plaintext source: ${envFile}\n- ciphertext target: ${secFile}\n- created: ${new Date().toUTCString()}\n- encryption engine: ${\n\t\t\t\t\t\t\tpluginCliEncrypt.encryptionEngineName ||\n\t\t\t\t\t\t\tpluginCliEncrypt.triggerOptionValue\n\t\t\t\t\t\t}\n- encryption engine options: ${JSON.stringify(allOptionsValues)}\n\n## Variables\n\n| Key | \n| --- | \n${Object.keys(dotenvVars)\n\t.map((key) => {\n\t\treturn `| \\`${key} \\`| `;\n\t})\n\t.join(\"\\n\")}\n`;\n\n\t\t\t\t\t\t// write manifest file, don't prompt to overwrite\n\t\t\t\t\t\tconst manifestTargetFile =\n\t\t\t\t\t\t\tmanifestFile || `${secFile}.encryption-manifest.md`;\n\t\t\t\t\t\tawait writeContentsToFile(manifestTargetFile, markdownManifest);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t`Wrote manifest of ${strong(envFile)} file to ${strong(\n\t\t\t\t\t\t\t\tmanifestTargetFile,\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(strong(e.message));\n\t\t\t\tcommand.help();\n\t\t\t}\n\t\t});\n\n\toptions.encryptHandlers.map((encryptionHandler) => {\n\t\tconst { options, requiredOptions } = encryptionHandler;\n\t\taddPluginOptions(options, subProgram);\n\t\taddPluginOptions(requiredOptions, subProgram, true);\n\t});\n\tconst engines = options.encryptHandlers.map((e) => e.triggerOptionValue);\n\tconst encryptionEngineNames = options.encryptHandlers.map(\n\t\t(e) => e.encryptionEngineName,\n\t);\n\n\tsubProgram.option(\n\t\t\"--engine <engine>\",\n\t\t`Encryption engine${engines.length > 0 ? \"s\" : \"\"}: ${\n\t\t\tengines.length === 1 ? engines[0] : engines.join(\", \")\n\t\t}`,\n\t\tengines.length === 1 ? engines[0] : undefined,\n\t);\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\tsubProgram.description(\n\t\t`Encrypt .env file using ${encryptionEngineNames.join(\", \")}`,\n\t);\n\treturn subProgram;\n};\n\nexport default addEncryptProgram;\n","import {\n\tpromptOverwriteIfFileExists,\n\treadContentsFromFile,\n\twriteContentsToFile,\n} from \"../../lib/io\";\nimport { DotsecConfig, InitCommandOptions } from \"../../types\";\nimport { Command } from \"commander\";\n\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport path from \"node:path\";\ntype Formats = {\n\tenv?: string;\n\tawsKeyAlias?: string;\n};\n\nconst addInitProgram = async (\n\tprogram: Command,\n\toptions: { dotsecConfig: DotsecConfig },\n) => {\n\tconst { dotsecConfig } = options;\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"init\")\n\t\t.action(async (_options: Formats, command: Command) => {\n\t\t\tconst { configFile = \"dotsec.config.ts\", yes } =\n\t\t\t\tcommand.optsWithGlobals<InitCommandOptions>();\n\t\t\ttry {\n\t\t\t\tconst configTemplate = await readContentsFromFile(\n\t\t\t\t\tpath.resolve(__dirname, \"../../src/templates/dotsec.config.ts\"),\n\t\t\t\t);\n\n\t\t\t\tconst dotsecConfigOverwriteResponse = await promptOverwriteIfFileExists(\n\t\t\t\t\t{\n\t\t\t\t\t\tfilePath: configFile,\n\t\t\t\t\t\tskip: yes,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tdotsecConfigOverwriteResponse === undefined ||\n\t\t\t\t\tdotsecConfigOverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tawait writeContentsToFile(configFile, configTemplate);\n\t\t\t\t\tconsole.log(`Wrote config file to ${strong(configFile)}`);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tcommand.error(e);\n\t\t\t}\n\t\t});\n\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\n\treturn subProgram;\n};\n\nexport default addInitProgram;\n","import { addPluginOptions } from \"../../lib/addPluginOptions\";\nimport { PushCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport {\n\tDotsecCliOption,\n\tDotsecCliPluginDecryptHandler,\n\tDotsecCliPluginPushHandler,\n} from \"../../types/plugin\";\nimport { setProgramOptions } from \"../options/index\";\nimport { Command } from \"commander\";\nimport { parse } from \"dotenv\";\nimport { expand } from \"dotenv-expand\";\nimport fs from \"node:fs\";\n\n/**\n * Decrypts, and pushes the contents of a .env file to AWS SSM, AWS Secrets Manager or GitHub Actions Secrets\n * @date 12/7/2022 - 9:16:48 AM\n *\n * @async\n * @param {Command} program\n * @returns {unknown}\n */\nconst addPushProgram = async (\n\tprogram: Command,\n\toptions: {\n\t\tdotsecConfig: DotsecConfig;\n\t\thandlers: {\n\t\t\tpush: DotsecCliPluginPushHandler;\n\t\t\tdecrypt: DotsecCliPluginDecryptHandler;\n\t\t}[];\n\t},\n) => {\n\tconst { dotsecConfig, handlers } = options;\n\n\tconst subProgram = program\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.command(\"push\")\n\t\t.action(async (_options: Record<string, string>, command: Command) => {\n\t\t\ttry {\n\t\t\t\tconst {\n\t\t\t\t\t// verbose,\n\t\t\t\t\tusing,\n\t\t\t\t\tenvFile,\n\t\t\t\t\tsecFile,\n\t\t\t\t\tengine,\n\n\t\t\t\t\tyes,\n\t\t\t\t} = command.optsWithGlobals<PushCommandOptions>();\n\n\t\t\t\tconst encryptionEngine =\n\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\n\t\t\t\tconst pluginCliDecrypt = (handlers || []).find((handler) => {\n\t\t\t\t\treturn handler.decrypt?.triggerOptionValue === encryptionEngine;\n\t\t\t\t})?.decrypt;\n\n\t\t\t\tconst pluginCliPush = (handlers || []).find((handler) => {\n\t\t\t\t\treturn handler.push?.triggerOptionValue === encryptionEngine;\n\t\t\t\t})?.push;\n\n\t\t\t\tif (!pluginCliPush) {\n\t\t\t\t\tthrow new Error(\"No push plugin found!\");\n\t\t\t\t}\n\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t...Object.keys(pluginCliDecrypt?.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliDecrypt?.requiredOptions || {}),\n\t\t\t\t\t...Object.keys(pluginCliPush?.options || {}),\n\t\t\t\t\t...Object.keys(pluginCliPush?.requiredOptions || {}),\n\t\t\t\t];\n\n\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tlet envContents: string | undefined;\n\n\t\t\t\tif (using === \"env\") {\n\t\t\t\t\tif (!envFile) {\n\t\t\t\t\t\tthrow new Error(\"No dotenv file specified in --env-file option\");\n\t\t\t\t\t}\n\t\t\t\t\tenvContents = fs.readFileSync(envFile, \"utf8\");\n\t\t\t\t} else {\n\t\t\t\t\tif (!secFile) {\n\t\t\t\t\t\tthrow new Error(\"No dotsec file specified in --sec-file option\");\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!pluginCliDecrypt) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`No decryption plugin found, available decryption engine(s): ${handlers\n\t\t\t\t\t\t\t\t.map((e) => `--${e.decrypt?.triggerOptionValue}`)\n\t\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst dotSecContents = fs.readFileSync(secFile, \"utf8\");\n\t\t\t\t\tenvContents = await pluginCliDecrypt.handler({\n\t\t\t\t\t\tciphertext: dotSecContents,\n\t\t\t\t\t\t...allOptionsValues,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (envContents) {\n\t\t\t\t\t// convert to object\n\t\t\t\t\tconst dotenvVars = parse(envContents);\n\t\t\t\t\t// expand env vars\n\t\t\t\t\tconst expandedEnvVars = expand({\n\t\t\t\t\t\tignoreProcessEnv: true,\n\t\t\t\t\t\tparsed: {\n\t\t\t\t\t\t\t// add standard env variables\n\t\t\t\t\t\t\t...(process.env as Record<string, string>),\n\t\t\t\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t\t\t\t...dotenvVars,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\n\t\t\t\t\tif (expandedEnvVars.parsed) {\n\t\t\t\t\t\tawait pluginCliPush.handler({\n\t\t\t\t\t\t\tpush: expandedEnvVars.parsed,\n\t\t\t\t\t\t\tyes,\n\t\t\t\t\t\t\t...allOptionsValues,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"No .env or .sec file provided\");\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t});\n\n\tsetProgramOptions({ program: subProgram, dotsecConfig });\n\tconst engines = options.handlers.map(\n\t\t({ decrypt }) => decrypt.triggerOptionValue,\n\t);\n\tsubProgram.option(\n\t\t\"--engine <engine>\",\n\t\t`Encryption engine${engines.length > 0 ? \"s\" : \"\"} to use: ${\n\t\t\tengines.length === 1 ? engines[0] : engines.join(\", \")\n\t\t}`,\n\t\tengines.length === 1 ? engines[0] : undefined,\n\t);\n\tconst allOptions: {\n\t\t[x: string]: DotsecCliOption & { required?: boolean };\n\t} = {};\n\toptions.handlers.forEach((handlers) => {\n\t\tObject.keys(handlers).map((handlerName) => {\n\t\t\tconst { options: cliOptions, requiredOptions } = handlers[handlerName];\n\t\t\tObject.keys(cliOptions || {}).forEach((key) => {\n\t\t\t\tallOptions[key] = Array.isArray(cliOptions[key])\n\t\t\t\t\t? cliOptions[key]\n\t\t\t\t\t: { ...allOptions[key], ...cliOptions[key] };\n\t\t\t});\n\t\t\tObject.keys(requiredOptions || {}).forEach((key) => {\n\t\t\t\tallOptions[key] = Array.isArray(requiredOptions[key])\n\t\t\t\t\t? requiredOptions[key]\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t...allOptions[key],\n\t\t\t\t\t\t\t...requiredOptions[key],\n\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t };\n\t\t\t});\n\t\t});\n\t});\n\n\tconst usage: string[] = [];\n\tconst descriptions: string[] = [];\n\n\thandlers.forEach((handler) => {\n\t\tif (handler.push?.description) {\n\t\t\tdescriptions.push(handler.push.description);\n\t\t}\n\n\t\tif (handler.push?.usage) {\n\t\t\tusage.push(handler.push.usage);\n\t\t}\n\t});\n\n\tif (descriptions.length > 0) {\n\t\tsubProgram.description(descriptions.join(\"\\n\"));\n\t}\n\n\tif (usage.length > 0) {\n\t\tsubProgram.usage(usage.join(\"\\n\"));\n\t}\n\n\taddPluginOptions(\n\t\tObject.fromEntries(\n\t\t\tObject.entries(allOptions).filter(\n\t\t\t\t([_key, value]) => value.required !== true,\n\t\t\t),\n\t\t),\n\t\tsubProgram,\n\t);\n\taddPluginOptions(\n\t\tObject.fromEntries(\n\t\t\tObject.entries(allOptions).filter(\n\t\t\t\t([_key, value]) => value.required === true,\n\t\t\t),\n\t\t),\n\t\tsubProgram,\n\t\ttrue,\n\t);\n\n\treturn subProgram;\n};\n\nexport default addPushProgram;\n","import fs from \"node:fs\";\n\nimport { Command } from \"commander\";\nimport { parse } from \"dotenv\";\nimport { expand } from \"dotenv-expand\";\n\nimport { addPluginOptions } from \"../../lib/addPluginOptions\";\nimport { RunCommandOptions } from \"../../types\";\nimport { DotsecConfig } from \"../../types/config\";\nimport { DotsecCliPluginDecryptHandler } from \"../../types/plugin\";\nimport { strong } from \"../../utils/logging\";\nimport { setProgramOptions } from \"../options\";\nimport { spawnSync } from \"node:child_process\";\nconst addRunProgam = (\n\tprogram: Command,\n\toptions: {\n\t\tdotsecConfig: DotsecConfig;\n\t\tdecryptHandlers?: DotsecCliPluginDecryptHandler[];\n\t},\n) => {\n\tconst { dotsecConfig, decryptHandlers } = options || {};\n\n\t// is there an encryption engine?\n\tconst hasDecryptEngine =\n\t\tdecryptHandlers !== undefined && decryptHandlers.length > 0;\n\n\tconst subProgram = program\n\t\t.command(\"run <command...>\")\n\t\t.allowUnknownOption(true)\n\t\t.enablePositionalOptions()\n\t\t.passThroughOptions()\n\t\t.showHelpAfterError(true)\n\t\t.action(\n\t\t\tasync (\n\t\t\t\tcommands: string[],\n\t\t\t\t_options: Record<string, string>,\n\t\t\t\tcommand: Command,\n\t\t\t) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst { envFile, using, secFile, engine } =\n\t\t\t\t\t\tcommand.optsWithGlobals<RunCommandOptions>();\n\n\t\t\t\t\tlet envContents: string | undefined;\n\n\t\t\t\t\tif (using === \"env\" || hasDecryptEngine === false) {\n\t\t\t\t\t\tif (!envFile) {\n\t\t\t\t\t\t\tthrow new Error(\"No dotenv file specified in --env-file option\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tenvContents = fs.readFileSync(envFile, \"utf8\");\n\t\t\t\t\t} else if (using === \"sec\") {\n\t\t\t\t\t\tif (!secFile) {\n\t\t\t\t\t\t\tthrow new Error(\"No dotsec file specified in --sec-file option\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst encryptionEngine =\n\t\t\t\t\t\t\tengine || dotsecConfig?.defaults?.encryptionEngine;\n\n\t\t\t\t\t\tconst pluginCliDecrypt = (decryptHandlers || []).find((handler) => {\n\t\t\t\t\t\t\treturn handler.triggerOptionValue === encryptionEngine;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!pluginCliDecrypt) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`No decryption plugin found, available decryption engine(s): ${(\n\t\t\t\t\t\t\t\t\tdecryptHandlers || []\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.map((e) => `--${e.triggerOptionValue}`)\n\t\t\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst allOptionKeys = [\n\t\t\t\t\t\t\t...Object.keys(pluginCliDecrypt.options || {}),\n\t\t\t\t\t\t\t...Object.keys(pluginCliDecrypt.requiredOptions || {}),\n\t\t\t\t\t\t];\n\n\t\t\t\t\t\tconst allOptionsValues = Object.fromEntries(\n\t\t\t\t\t\t\tallOptionKeys.map((key) => {\n\t\t\t\t\t\t\t\treturn [key, _options[key]];\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst dotSecContents = fs.readFileSync(secFile, \"utf8\");\n\t\t\t\t\t\tenvContents = await pluginCliDecrypt.handler({\n\t\t\t\t\t\t\tciphertext: dotSecContents,\n\t\t\t\t\t\t\t...allOptionsValues,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tif (envContents) {\n\t\t\t\t\t\tconst dotenvVars = parse(envContents);\n\t\t\t\t\t\t// expand env vars\n\t\t\t\t\t\tconst expandedEnvVars = expand({\n\t\t\t\t\t\t\tignoreProcessEnv: true,\n\t\t\t\t\t\t\tparsed: {\n\t\t\t\t\t\t\t\t// add standard env variables\n\t\t\t\t\t\t\t\t...(process.env as Record<string, string>),\n\t\t\t\t\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t\t\t\t\t...dotenvVars,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tconst [userCommand, ...userCommandArgs] = commands;\n\t\t\t\t\t\tconst spawn = spawnSync(userCommand, [...userCommandArgs], {\n\t\t\t\t\t\t\tstdio: \"inherit\",\n\t\t\t\t\t\t\tshell: false,\n\t\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t\t\tenv: {\n\t\t\t\t\t\t\t\t...expandedEnvVars.parsed,\n\t\t\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t\t\t__DOTSEC_ENV__: JSON.stringify(Object.keys(dotenvVars)),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (spawn.status !== 0) {\n\t\t\t\t\t\t\tprocess.exit(spawn.status || 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\"No .env or .sec file provided\");\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(strong(e.message));\n\t\t\t\t\tcommand.help();\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\tsetProgramOptions({\n\t\tprogram: subProgram,\n\t\tcommandName: hasDecryptEngine ? \"run\" : \"runEnvOnly\",\n\t\tdotsecConfig,\n\t});\n\n\tif (hasDecryptEngine) {\n\t\tdecryptHandlers?.map((run) => {\n\t\t\tconst { options, requiredOptions } = run;\n\t\t\taddPluginOptions(options, subProgram);\n\t\t\taddPluginOptions(requiredOptions, subProgram, true);\n\t\t});\n\t\tconst engines = decryptHandlers?.map((e) => e.triggerOptionValue);\n\n\t\tsubProgram.option(\n\t\t\t\"--engine <engine>\",\n\t\t\t`Encryption engine${engines.length > 0 ? \"s\" : \"\"}: ${\n\t\t\t\t(engines.join(\", \"), engines.length === 1 ? engines[0] : undefined)\n\t\t\t}`,\n\t\t\t// engines.length === 1 ? engines[0] : undefined,\n\t\t);\n\t}\n\treturn subProgram;\n};\n\nexport default addRunProgam;\n"],"mappings":"AAAA,OAAS,WAAAA,OAAe,YCEjB,IAAMC,GAA6B,mBAC7BC,EAAsB,CAACD,EAA0B,EACjDE,EAAiC,OACjCC,EAAiC,OACjCC,EAA8B,CAC1C,SAAU,CAKV,CACD,ECbA,OAAOC,OAAQ,KACf,OAAOC,OAAU,YAUV,SAASC,GAAWC,EAAc,CACxC,GAAI,CACH,OAAO,IAAI,SAAS,UAAUA,EAAK,KAAK,GAAG,EAAE,CAC9C,MAAE,CAGD,MAAO,CAAC,CACT,CACD,CAUO,IAAMC,EAAW,MAAOC,GAAqB,CACnD,GAAI,CACH,OAAOH,GAAW,M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AAV,EACA,aAAcR,EACd,WAAAD,CACD,CAAC,EAEGqB,GAAK,SACRL,EAAyB,KAAKK,EAAI,OAAO,EAEtCA,GAAK,UACRJ,EAAyB,KAAKI,EAAI,OAAO,EACrCA,GAAK,MACRH,EAAsB,KAAK,CAAE,KAAMG,EAAI,KAAM,QAASA,EAAI,OAAQ,CAAC,GAIjED,GACHA,EAAc,CAAE,QAAAxB,CAAQ,CAAC,EAGvBoB,EAAyB,QAC5B,MAAMM,GAAkB1B,EAAS,CAChC,aAAcK,EACd,gBAAiBe,CAClB,CAAC,EAEEC,EAAyB,QAC5B,MAAMM,GAAkB3B,EAAS,CAChC,aAAcK,EACd,gBAAiBgB,CAClB,CAAC,EAEEC,EAAsB,QACzB,MAAMM,GAAe5B,EAAS,CAC7B,aAAcK,EACd,SAAUiB,CACX,CAAC,EAIF,MAAMO,GAAe7B,EAAS,CAAE,aAAcK,CAAa,CAAC,EAC5D,MAAMyB,GAAc9B,EAAS,CAC5B,aAAcK,EACd,gBAAiBgB,CAClB,CAAC,EACD,MAAMrB,EAAQ,MAAM,CACrB,GAAG","names":["Command","DOTSEC_DEFAULT_CONFIG_FILE","DOTSEC_CONFIG_FILES","DOTSEC_DEFAULT_DOTSEC_FILENAME","DOTSEC_DEFAULT_DOTENV_FILENAME","defaultConfig","fs","path","jsoncParse","data","loadJson","filepath","error","bundleRequire","JoyCon","path","getMagicalConfig","filename","cwd","configPath","DOTSEC_CONFIG_FILES","rawData","loadJson","data","defaultConfig","bundleRequireResult","loadDotsecPlugin","options","imported","Option","addPluginOptions","options","command","mandatory","option","optionProps","flags","description","defaultValue","choices","env","fn","newOption","fs","stat","path","prompts","readContentsFromFile","filePath","writeContentsToFile","contents","fileExists","source","promptOverwriteIfFileExists","skip","overwriteResponse","chalk","Table","strong","str","chalk","Option","envFileOption","DOTSEC_DEFAULT_DOTENV_FILENAME","secFileOption","DOTSEC_DEFAULT_DOTSEC_FILENAME","usingOption","usingNoEncryptionEngineOption","yesOption","configFileOption","pluginOption","engineOption","createManifestOption","manifestFileOption","decryptCommandDefaults","configFileOption","envFileOption","secFileOption","createManifestOption","manifestFileOption","yesOption","decrypt_default","dotsecCommandDefaults","configFileOption","pluginOption","dotsec_default","encryptCommandDefaults","configFileOption","envFileOption","secFileOption","createManifestOption","manifestFileOption","yesOption","encrypt_default","initCommandDefaults","configFileOption","yesOption","init_default","pushCommandDefaults","configFileOption","envFileOption","secFileOption","yesOption","usingOption","push_default","runCommandDefaults","configFileOption","envFileOption","yesOption","engineOption","usingNoEncryptionEngineOption","secFileOption","usingOption","run_default","commandOptions","dotsec_default","init_default","encrypt_default","decrypt_default","run_default","push_default","expandCommandOption","commandOption","flags","description","defaultValue","createOption","options","defaultOptionValueFromConfig","optionProps","newOption","Option","setProgramOptions","params","program","commandName","dotsecConfig","programOptions","requiredOptions","usage","helpText","optionKey","requiredOptionKey","requiredOption","parse","addEncryptProgram","program","options","dotsecConfig","decryptHandlers","subProgram","_options","command","envFile","secFile","engine","createManifest","manifestFile","yes","encryptionEngine","pluginCliDecrypt","handler","e","strong","allOptionKeys","allOptionsValues","key","dotsecString","readContentsFromFile","plaintext","dotenvOverwriteResponse","promptOverwriteIfFileExists","writeContentsToFile","dotenvVars","markdownManifest","manifestTargetFile","decryption","requiredOptions","addPluginOptions","engines","setProgramOptions","decrypt_default","parse","addEncryptProgram","program","options","encryptHandlers","dotsecConfig","subProgram","_options","command","envFile","secFile","engine","createManifest","manifestFile","yes","encryptionEngine","pluginCliEncrypt","handler","e","allOptionKeys","allOptionsValues","key","dotenvString","readContentsFromFile","cipherText","dotsecOverwriteResponse","promptOverwriteIfFileExists","writeContentsToFile","strong","dotenvVars","markdownManifest","manifestTargetFile","encryptionHandler","requiredOptions","addPluginOptions","engines","encryptionEngineNames","setProgramOptions","encrypt_default","path","addInitProgram","program","options","dotsecConfig","subProgram","_options","command","configFile","yes","configTemplate","readContentsFromFile","dotsecConfigOverwriteResponse","promptOverwriteIfFileExists","writeContentsToFile","strong","e","setProgramOptions","init_default","parse","expand","fs","addPushProgram","program","options","dotsecConfig","handlers","subProgram","_options","command","using","envFile","secFile","engine","yes","encryptionEngine","pluginCliDecrypt","handler","pluginCliPush","allOptionKeys","allOptionsValues","key","envContents","e","dotSecContents","dotenvVars","expandedEnvVars","setProgramOptions","engines","decrypt","allOptions","handlerName","cliOptions","requiredOptions","usage","descriptions","addPluginOptions","_key","value","push_default","fs","parse","expand","spawnSync","addRunProgam","program","options","dotsecConfig","decryptHandlers","hasDecryptEngine","subProgram","commands","_options","command","envFile","using","secFile","engine","envContents","fs","encryptionEngine","pluginCliDecrypt","handler","e","allOptionKeys","allOptionsValues","key","dotSecContents","dotenvVars","parse","expandedEnvVars","expand","userCommand","userCommandArgs","spawn","strong","setProgramOptions","run","requiredOptions","addPluginOptions","engines","run_default","Ajv","yargsParser","separator","schema","data","ctx","parentData","parentDataProperty","program","Command","parsedOptions","argvPluginModules","configFile","dotsecConfig","getMagicalConfig","defaults","pushVariables","plugins","_options","other","setProgramOptions","ajv","pluginModules","pluginName","pluginModule","loadedPlugin","loadDotsecPlugin","pushVariable","cliPluginEncryptHandlers","cliPluginDecryptHandlers","cliPluginPushHandlers","initDotsecPlugin","addCliCommand","cli","encrypt_default","decrypt_default","push_default","init_default","run_default"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
var P=Object.create;var a=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var k=(e,r)=>{for(var o in r)a(e,o,{get:r[o],enumerable:!0})},l=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of R(r))!C.call(e,n)&&n!==o&&a(e,n,{get:()=>r[n],enumerable:!(t=D(r,n))||t.enumerable});return e};var s=(e,r,o)=>(o=e!=null?P(h(e)):{},l(r||!e||!e.__esModule?a(o,"default",{value:e,enumerable:!0}):o,e)),L=e=>l(a({},"__esModule",{value:!0}),e);var V={};k(V,{Table:()=>p.default,emphasis:()=>b,promptExecute:()=>u,promptOverwriteIfFileExists:()=>v,readContentsFromFile:()=>d,resolveFromEnv:()=>g,strong:()=>F,writeContentsToFile:()=>E,writeLine:()=>y});module.exports=L(V);var m=s(require("prompts"));var u=async({skip:e,message:r,execute:o})=>{let t=!1;(e||(await(0,m.default)({type:"confirm",name:"confirm",message:r})).confirm===!0)&&(t=!0),t&&await o()};var f=require("dotenv-expand"),g=e=>{let{fromEnvValue:r,env:o,variables:t}=e;return r?(0,f.expand)({ignoreProcessEnv:!0,parsed:{...o,...t,RESOLVED:r||""}}).parsed?.RESOLVED:""};var i=s(require("fs/promises")),w=s(require("path")),x=s(require("prompts")),d=async e=>await i.default.readFile(e,"utf-8"),E=async(e,r)=>await i.default.writeFile(e,r,"utf-8"),O=async e=>{try{return await(0,i.stat)(e),!0}catch{return!1}},v=async({filePath:e,skip:r})=>{let o;return await O(e)&&r!==!0?o=await(0,x.default)({type:"confirm",name:"overwrite",message:()=>`Overwrite './${w.default.relative(process.cwd(),e)}' ?`}):o=void 0,o};var c=s(require("chalk")),p=s(require("cli-table"));var y=e=>{process.stdout.write(e)},b=e=>c.default.yellowBright(e),F=e=>c.default.yellow.bold(e);0&&(module.exports={Table,emphasis,promptExecute,promptOverwriteIfFileExists,readContentsFromFile,resolveFromEnv,strong,writeContentsToFile,writeLine});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|