dotsec 2.0.0-alpha.1 → 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 +120 -20
- package/dist/cli/index.js.map +1 -7
- package/dist/cli/index.mjs +120 -20
- 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 -8
- package/src/templates/dotsec.config.ts +1 -13
- package/dist/index.d.ts +0 -148
package/dist/cli/index.mjs
CHANGED
|
@@ -1,29 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
The default file name is derived from the name of the encrypted file.
|
|
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:
|
|
3
2
|
|
|
4
|
-
See the --manifest-file option for more information.
|
|
5
|
-
`],env:"DOTSEC_ENCRYPTION_CREATE_MANIFEST"},manifestFile:{option:["--manifest-file <manifestFile>",`Specify the name of the manifest file to create.
|
|
6
|
-
This option is only used if the --create-manifest option is set to true.
|
|
7
3
|
|
|
8
|
-
|
|
4
|
+
Decrypt .sec file to .env file
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
`],env:"DOTSEC_ENCRYPTION_MANIFEST_FILE"},yes:S}}},le=Me;var Je={init:{options:{verbose:["--verbose","Verbose output",!1],configFile:["-c, --config-file, --configFile <configFile>","Config file",L],envFile:b,secFile:$,yes:S}}},me=Je;var Be={pull:{inheritsFrom:["dotsec"],options:{withEnv:q,withSec:K,envFile:b,secFile:$,yes:S}}},J=Be;var Ye={runEnvOnly:{inheritsFrom:["dotsec"],usage:"[commandArgs...]",options:{envFile:b,yes:S},description:"Run a command in a separate process and populate env with contents of a dotenv file.",helpText:`Examples:
|
|
6
|
+
$ npx dotsec decrypt
|
|
12
7
|
|
|
13
|
-
Run a command with a .env file
|
|
14
8
|
|
|
15
|
-
|
|
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)"
|
|
16
93
|
|
|
17
94
|
|
|
18
95
|
Run a command with a specific .env file
|
|
19
96
|
|
|
20
|
-
$ dotsec run --env-file .env
|
|
97
|
+
$ npx dotsec run --using env --env-file .env node -e "console.log(process.env)"
|
|
98
|
+
|
|
21
99
|
|
|
22
100
|
Run a command with a specific ENV_FILE variable
|
|
23
101
|
|
|
24
|
-
$ ENV_FILE=.env.dev dotsec run
|
|
102
|
+
$ ENV_FILE=.env.dev npx dotsec run --using env node -e "console.log(process.env)"
|
|
103
|
+
|
|
25
104
|
|
|
26
|
-
|
|
105
|
+
You can also specify 'using' as an environment variable
|
|
106
|
+
|
|
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
|
|
27
109
|
- contents of a dotenv file
|
|
28
110
|
- decrypted values of a dotsec file.
|
|
29
111
|
|
|
@@ -47,21 +129,39 @@ $ dotsec run --with-sec echo "hello world"
|
|
|
47
129
|
Run a command with a specific .sec file
|
|
48
130
|
|
|
49
131
|
$ dotsec run --with-sec --sec-file .sec.dev echo "hello world"
|
|
50
|
-
`}
|
|
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
|
|
51
149
|
|
|
52
150
|
## Overview
|
|
53
151
|
|
|
54
|
-
- plaintext source: ${
|
|
152
|
+
- plaintext source: ${r}
|
|
55
153
|
- ciphertext target: ${f}
|
|
56
154
|
- created: ${new Date().toUTCString()}
|
|
57
|
-
- encryption engine: ${
|
|
58
|
-
- encryption engine options: ${JSON.stringify(
|
|
155
|
+
- encryption engine: ${g.encryptionEngineName||g.triggerOptionValue}
|
|
156
|
+
- encryption engine options: ${JSON.stringify(v)}
|
|
59
157
|
|
|
60
158
|
## Variables
|
|
61
159
|
|
|
62
160
|
| Key |
|
|
63
161
|
| --- |
|
|
64
|
-
${Object.keys(
|
|
162
|
+
${Object.keys(y).map(le=>`| \`${le} \`| `).join(`
|
|
65
163
|
`)}
|
|
66
|
-
`,
|
|
67
|
-
|
|
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
|