dotsec 4.0.0-alpha.7 → 4.0.0-alpha.9
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/bin/dotsec.js +1 -1
- package/dist/cli/index.js +107 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +96 -21
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +91 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/bin/dotsec.js
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var commander = require('commander');
|
|
4
|
+
var ce = require('fs');
|
|
5
|
+
var ge = require('path');
|
|
6
|
+
var bundleRequire = require('bundle-require');
|
|
7
|
+
var Oe = require('joycon');
|
|
8
|
+
var J = require('fs/promises');
|
|
9
|
+
var De = require('prompts');
|
|
10
|
+
var Pe = require('chalk');
|
|
11
|
+
require('cli-table');
|
|
12
|
+
var dotenvExpand = require('dotenv-expand');
|
|
13
|
+
var child_process = require('child_process');
|
|
14
|
+
var Ue = require('ajv');
|
|
15
|
+
var Ye = require('yargs-parser');
|
|
16
|
+
|
|
17
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
|
|
19
|
+
var ce__default = /*#__PURE__*/_interopDefault(ce);
|
|
20
|
+
var ge__default = /*#__PURE__*/_interopDefault(ge);
|
|
21
|
+
var Oe__default = /*#__PURE__*/_interopDefault(Oe);
|
|
22
|
+
var J__default = /*#__PURE__*/_interopDefault(J);
|
|
23
|
+
var De__default = /*#__PURE__*/_interopDefault(De);
|
|
24
|
+
var Pe__default = /*#__PURE__*/_interopDefault(Pe);
|
|
25
|
+
var Ue__default = /*#__PURE__*/_interopDefault(Ue);
|
|
26
|
+
var Ye__default = /*#__PURE__*/_interopDefault(Ye);
|
|
27
|
+
|
|
28
|
+
var me="dotsec.config.ts",W=[me],L=".sec",K=".env",I={defaults:{}};function ye(i){try{return new Function(`return ${i.trim()}`)()}catch{return {}}}var U=async i=>{try{return ye(await ce__default.default.promises.readFile(i,"utf8"))}catch(t){throw t instanceof Error?new Error(`Failed to parse ${ge__default.default.relative(process.cwd(),i)}: ${t.message}`):t}};var Y=async i=>{let t=process.cwd(),o=await new Oe__default.default().resolve({files:i?[i]:[...W,"package.json"],cwd:t,stopDir:ge__default.default.parse(t).root,packageKey:"dotsec"});if(i&&o===null)throw new Error(`Could not find config file ${i}`);if(o){if(o.endsWith(".json")){let e=await U(o),n;return o.endsWith("package.json")&&e.dotsec!==void 0?n=e.dotsec:n=e,{source:"json",contents:{...I,...n,defaults:{...n?.defaults,...I.defaults,plugins:{...n?.defaults?.plugins,...I.defaults?.plugins}},push:{...n?.push}}}}else if(o.endsWith(".ts")){let e=await bundleRequire.bundleRequire({filepath:o}),n=e.mod.dotsec||e.mod.default||e.mod;return {source:"ts",contents:{...I,...n,defaults:{...n?.defaults,...I.defaults,plugins:{...n?.defaults?.plugins,...I.defaults?.plugins}},push:{...n?.push}}}}}return {source:"defaultConfig",contents:I}};var q=async i=>import(i.name).then(t=>t.default);var F=(i,t,a)=>{i&&Object.values(i).map(o=>{let e;if(Array.isArray(o)){let[n,s,p]=o;e={flags:n,description:s,defaultValue:p};}else {let{flags:n,description:s,defaultValue:p,choices:l,env:r,fn:d}=o;e={flags:n,description:s,defaultValue:p,choices:l,env:r,fn:d};}if(e){let n=new commander.Option(e.flags,e.description);e.fn&&n.argParser(e.fn),e.defaultValue&&n.default(e.defaultValue),e.env&&n.env(e.env),a&&n.makeOptionMandatory(!0),e.choices&&n.choices(e.choices),t.addOption(n);}});};var k=async i=>await J__default.default.readFile(i,"utf-8"),_=async(i,t)=>await J__default.default.writeFile(i,t,"utf-8"),xe=async i=>{try{return await J.stat(i),!0}catch{return !1}},V=async({filePath:i,skip:t})=>{let a;return await xe(i)&&t!==!0?a=await De__default.default({type:"confirm",name:"overwrite",message:()=>`Overwrite './${ge__default.default.relative(process.cwd(),i)}' ?`}):a=void 0,a};var Fe=/^(#.*)|(\s?\r?\n)|(?:^|^)\s*(?:export\s+)?([\w.-]*)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?(\s*)(#.*)?(?:$|$)/gm,P=i=>{let t={},a=[],o=i.toString();o=o.replace(/\r\n?/gm,`
|
|
29
|
+
`);let e;for(;(e=Fe.exec(o))!=null;){let n=e[3];if(e?.[1]?.[0]==="#")a.push({type:"comment",raw:e[1]});else if(e?.[2])a.push({type:"whitespace",raw:e[2]});else {let s=e[4]||"";s=s.trim();let p=s[0];s=s.replace(/^(['"`])([\s\S]*)\1$/gm,"$2"),p==='"'&&(s=s.replace(/\\n/g,`
|
|
30
|
+
`),s=s.replace(/\\r/g,"\r")),t[n]=s,a.push({type:"value",key:n,value:s,raw:s+(e[5]?e[5]:"")+(e[6]?e[6]:"")});}}return {blocks:a,obj:t}};if(undefined){let{it:i,expect:t}=undefined;i("parse",()=>{let a="KEY=value",o='KEY="value"',e="KEY='value'",n="KEY=value # this is a comment";t(P(a)).toMatchInlineSnapshot(`
|
|
31
|
+
{
|
|
32
|
+
"blocks": [
|
|
33
|
+
{
|
|
34
|
+
"key": "KEY",
|
|
35
|
+
"raw": "value",
|
|
36
|
+
"type": "value",
|
|
37
|
+
"value": "value",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
"obj": {
|
|
41
|
+
"KEY": "value",
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
`),t(P(o)).toMatchInlineSnapshot(`
|
|
45
|
+
{
|
|
46
|
+
"blocks": [
|
|
47
|
+
{
|
|
48
|
+
"key": "KEY",
|
|
49
|
+
"raw": "value",
|
|
50
|
+
"type": "value",
|
|
51
|
+
"value": "value",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
"obj": {
|
|
55
|
+
"KEY": "value",
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
`),t(P(e)).toMatchInlineSnapshot(`
|
|
59
|
+
{
|
|
60
|
+
"blocks": [
|
|
61
|
+
{
|
|
62
|
+
"key": "KEY",
|
|
63
|
+
"raw": "value",
|
|
64
|
+
"type": "value",
|
|
65
|
+
"value": "value",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
"obj": {
|
|
69
|
+
"KEY": "value",
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
`),t(P(n)).toMatchInlineSnapshot(`
|
|
73
|
+
{
|
|
74
|
+
"blocks": [
|
|
75
|
+
{
|
|
76
|
+
"key": "KEY",
|
|
77
|
+
"raw": "value# this is a comment",
|
|
78
|
+
"type": "value",
|
|
79
|
+
"value": "value",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
"obj": {
|
|
83
|
+
"KEY": "value",
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
`);});}var C=i=>Pe__default.default.yellow.bold(i);var S={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 '${K}' file in current directory.`,K],env:"ENV_FILE"},N={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 '${L}' file in current directory.`,L],env:"SEC_FILE"},A={flags:"--using <using>",description:"Wether to use a dot env file or a dot sec file",choices:["env","sec"],env:"DOTSEC_USING"},B={flags:"--using <using>",description:"Wether to use a dot env file or a dot sec file",choices:["env"],env:"DOTSEC_USING"},$={option:["--yes","Skip confirmation prompts"]};var x={option:["-c, --config-file, --configFile <configFile>","Config file"],env:"DOTSEC_CONFIG_FILE"},z={option:["--plugin <plugin>","Comma-separated list of plugins to use"],env:"DOTSEC_PLUGIN"},Q={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"},M={option:["--manifest-file-prefix <manifestFilePrefix>","Mmanifest file prefix"],env:"ENCRYPTION_MANIFEST_FILE"};var be={decrypt:{options:{configFile:x,envFile:S,secFile:N,createManifest:H,manifestFilePrefix:M,yes:$},description:"Decrypt a sec file",helpText:`Examples:
|
|
2
87
|
|
|
3
88
|
|
|
4
89
|
Decrypt .sec file to .env file
|
|
@@ -25,7 +110,7 @@ Specify a different manifest file
|
|
|
25
110
|
|
|
26
111
|
$ npx dotsec decrypt --manifest-file .manifest.dev
|
|
27
112
|
$ MANIFEST_FILE=decryption-manifest.md npx dotsec decrypt
|
|
28
|
-
`}},
|
|
113
|
+
`}},X=be;var $e={dotsec:{options:{configFile:x,plugin:z}}},Z=$e;var Se={encrypt:{options:{configFile:x,envFile:S,secFile:N,createManifest:H,manifestFile:M,yes:$},description:"Encrypt an env file",helpText:`Examples:
|
|
29
114
|
|
|
30
115
|
|
|
31
116
|
Encrypt .env file to .sec file
|
|
@@ -55,7 +140,7 @@ Specify a different manifest file
|
|
|
55
140
|
|
|
56
141
|
$ npx dotsec encrypt --manifest-file manifest.dev
|
|
57
142
|
$ MANIFEST_FILE=encryption-manifest.md npx dotsec encrypt
|
|
58
|
-
`}},
|
|
143
|
+
`}},ee=Se;var je={init:{options:{configFile:x,yes:$},description:"Initialize a dotsec project by creating a dotsec.config.ts file.",helpText:`Examples:
|
|
59
144
|
|
|
60
145
|
Create a dotsec.config.ts file in the current directory
|
|
61
146
|
|
|
@@ -74,7 +159,7 @@ By specifying the --config-file option, you can create a dotsec config file with
|
|
|
74
159
|
$ npx dotsec init --config-file dotsec.config.ts
|
|
75
160
|
|
|
76
161
|
$ DOTSEC_CONFIG_FILE=my.config.ts npx dotsec init
|
|
77
|
-
`}},
|
|
162
|
+
`}},ne=je;var Te={push:{options:{configFile:x,envFile:S,secFile:N,yes:$},requiredOptions:{using:A},description:"Push variables from env or sec file to a remote",helpText:`Examples:
|
|
78
163
|
|
|
79
164
|
Push variables from .env file to remote
|
|
80
165
|
|
|
@@ -86,7 +171,7 @@ Push variables from .sec file to remote
|
|
|
86
171
|
|
|
87
172
|
$ npx dotsec push --using sec
|
|
88
173
|
$ DOTSEC_USING=sec npx dotsec push
|
|
89
|
-
`}},
|
|
174
|
+
`}},te=Te;var Ie={runEnvOnly:{usage:"--using env [commandArgs...]",options:{configFile:x,envFile:S,yes:$,engine:Q},requiredOptions:{using:B},description:"Run a command in a separate process and populate env with contents of a dotenv file.",helpText:`Examples:
|
|
90
175
|
|
|
91
176
|
Run a command with a .env file
|
|
92
177
|
|
|
@@ -106,7 +191,7 @@ $ ENV_FILE=.env.dev npx dotsec run --using env node -e "console.log(process.env)
|
|
|
106
191
|
You can also specify 'using' as an environment variable
|
|
107
192
|
|
|
108
193
|
$ DOTSEC_USING=env npx dotsec run node -e "console.log(process.env)"
|
|
109
|
-
`},run:{options:{configFile:x,envFile:S,secFile:N,yes:$},requiredOptions:{using:
|
|
194
|
+
`},run:{options:{configFile:x,envFile:S,secFile:N,yes:$},requiredOptions:{using:A},usage:"[--using env] [--using sec] [commandArgs...]",description:`Run a command in a separate process and populate env with either
|
|
110
195
|
- contents of a dotenv file
|
|
111
196
|
- decrypted values of a dotsec file.
|
|
112
197
|
|
|
@@ -130,39 +215,40 @@ $ dotsec run --with-sec echo "hello world"
|
|
|
130
215
|
Run a command with a specific .sec file
|
|
131
216
|
|
|
132
217
|
$ dotsec run --with-sec --sec-file .sec.dev echo "hello world"
|
|
133
|
-
`}},
|
|
218
|
+
`}},oe=Ie;var Ne={...Z,...ne,...ee,...X,...oe,...te},ke=i=>{if(Array.isArray(i)){let[t,a,o]=i;return {flags:t,description:a,defaultValue:o}}else {if("option"in i){let[t,a,o]=i.option;return {flags:t,description:a,defaultValue:o,env:i.env}}return i}},ie=(i,t)=>{let a=t?.dotsecConfig?.defaults?.options?.[t?.optionKey],o=ke(i),e=new commander.Option(o.flags,o.description);return o.fn&&e.argParser(o.fn),o.defaultValue&&e.default(a||o.defaultValue),o.env&&e.env(o.env),t.required&&e.makeOptionMandatory(!0),o.choices&&e.choices(o.choices),e},b=i=>{let{program:t,commandName:a,dotsecConfig:o}=i,e=Ne[a||t.name()];if(e){let{options:n,requiredOptions:s,description:p,usage:l,helpText:r}=e;n&&Object.keys(n).forEach(d=>{let m=n[d],g=ie(m,{dotsecConfig:o,optionKey:d});t.addOption(g);}),s&&Object.keys(s).forEach(d=>{let m=s[d],g=ie(m,{required:!0,dotsecConfig:o,optionKey:d});t.addOption(g);}),p&&t.description(p),l&&t.usage(l),r&&t.description(r);}};var Ve=async(i,t)=>{let{dotsecConfig:a,decryptHandlers:o}=t,e=i.enablePositionalOptions().passThroughOptions().command("decrypt").action(async(s,p)=>{try{let{envFile:l,secFile:r,engine:d,createManifest:m,manifestFile:g,yes:c}=p.optsWithGlobals(),u=d||a?.defaults?.encryptionEngine,f=(o||[]).find(v=>v.triggerOptionValue===u);if(!f)throw new Error(`No decryption plugin found, available decryption engine(s): ${t.decryptHandlers.map(v=>`--${v.triggerOptionValue}`).join(", ")}`);console.log("Decrypting with",C(f.encryptionEngineName||f.triggerOptionValue),"engine");let h=[...Object.keys(f.options||{}),...Object.keys(f.requiredOptions||{})],y=Object.fromEntries(h.map(v=>[v,s[v]])),w=await k(r),D=await f.handler({ciphertext:w,...y}),T=await V({filePath:l,skip:c});if((T===void 0||T.overwrite===!0)&&(await _(l,D),console.log(`Wrote plaintext contents of ${C(r)} file to ${C(l)}`)),m||a?.defaults?.options?.createManifest){let v=P(D).obj,E=`# Dotsec decryption manifest
|
|
134
219
|
|
|
135
220
|
## Overview
|
|
136
221
|
|
|
137
|
-
- plaintext source: ${
|
|
222
|
+
- plaintext source: ${l}
|
|
138
223
|
- ciphertext target: ${r}
|
|
139
224
|
- created: ${new Date().toUTCString()}
|
|
140
|
-
- Decryption engine: ${
|
|
141
|
-
- Decryption engine options: ${JSON.stringify(
|
|
225
|
+
- Decryption engine: ${f.encryptionEngineName||f.triggerOptionValue}
|
|
226
|
+
- Decryption engine options: ${JSON.stringify(y)}
|
|
142
227
|
|
|
143
228
|
## Variables
|
|
144
229
|
|
|
145
|
-
| Key |
|
|
146
|
-
| --- |
|
|
147
|
-
${Object.keys(
|
|
230
|
+
| Key |
|
|
231
|
+
| --- |
|
|
232
|
+
${Object.keys(v).map(R=>`| \`${R} \`| `).join(`
|
|
148
233
|
`)}
|
|
149
|
-
`,
|
|
234
|
+
`,O=g||`${l}.decryption-manifest.md`;await _(O,E),console.log(`Wrote manifest of ${C(l)} file to ${C(O)}`);}}catch(l){console.error(C(l.message)),p.help();}});t.decryptHandlers.map(s=>{let{options:p,requiredOptions:l}=s;F(p,e),F(l,e,!0);});let n=t.decryptHandlers.map(s=>s.triggerOptionValue);return e.option("--engine <engine>",`Encryption engine${n.length>0?"s":""} to use: ${n.length===1?n[0]:n.join(", ")}`,n.length===1?n[0]:void 0),b({program:e,dotsecConfig:a}),e},re=Ve;var Ae=async(i,t)=>{let{encryptHandlers:a,dotsecConfig:o}=t,e=i.enablePositionalOptions().passThroughOptions().command("encrypt").action(async(p,l)=>{try{let{envFile:r,secFile:d,engine:m,createManifest:g,manifestFile:c,yes:u}=l.optsWithGlobals(),f=m||o?.defaults?.encryptionEngine,h=(a||[]).find(O=>O.triggerOptionValue===f);if(!h)throw new Error(`No encryption plugin found, available encryption engine(s): ${t.encryptHandlers.map(O=>O.triggerOptionValue).join(", ")}`);let y=[...Object.keys(h.options||{}),...Object.keys(h.requiredOptions||{})],w=Object.fromEntries(y.map(O=>[O,p[O]])),D=await k(r),T;try{T=await k(d);}catch{}let v=await h.handler({plaintext:D,ciphertext:T,...w}),E=await V({filePath:d,skip:u});if((E===void 0||E.overwrite===!0)&&(await _(d,v),console.log(`Wrote encrypted contents of ${C(r)} file to ${C(d)}`),g||o?.defaults?.options?.createManifest)){let O=P(D).obj,R=`# Dotsec encryption manifest
|
|
150
235
|
|
|
151
236
|
## Overview
|
|
152
237
|
|
|
153
238
|
- plaintext source: ${r}
|
|
154
|
-
- ciphertext target: ${
|
|
239
|
+
- ciphertext target: ${d}
|
|
155
240
|
- created: ${new Date().toUTCString()}
|
|
156
|
-
- encryption engine: ${
|
|
157
|
-
- encryption engine options: ${JSON.stringify(
|
|
241
|
+
- encryption engine: ${h.encryptionEngineName||h.triggerOptionValue}
|
|
242
|
+
- encryption engine options: ${JSON.stringify(w)}
|
|
158
243
|
|
|
159
244
|
## Variables
|
|
160
245
|
|
|
161
246
|
| Key |
|
|
162
247
|
| --- |
|
|
163
|
-
${Object.keys(
|
|
248
|
+
${Object.keys(O).map(fe=>`| \`${fe} \`| `).join(`
|
|
164
249
|
`)}
|
|
165
|
-
`,
|
|
166
|
-
`)),
|
|
167
|
-
`)),F(Object.fromEntries(Object.entries(
|
|
250
|
+
`,G=c||`${d}.encryption-manifest.md`;await _(G,R),console.log(`Wrote manifest of ${C(r)} file to ${C(G)}`);}}catch(r){console.error(C(r.message)),l.help();}});t.encryptHandlers.map(p=>{let{options:l,requiredOptions:r}=p;F(l,e),F(r,e,!0);});let n=t.encryptHandlers.map(p=>p.triggerOptionValue),s=t.encryptHandlers.map(p=>p.encryptionEngineName);return e.option("--engine <engine>",`Encryption engine${n.length>0?"s":""}: ${n.length===1?n[0]:n.join(", ")}`,n.length===1?n[0]:void 0),b({program:e,dotsecConfig:o}),e.description(`Encrypt .env file using ${s.join(", ")}`),e},se=Ae;var Me=async(i,t)=>{let{dotsecConfig:a}=t,o=i.enablePositionalOptions().passThroughOptions().command("init").action(async(e,n)=>{let{configFile:s="dotsec.config.ts",yes:p}=n.optsWithGlobals();try{let l=await k(ge__default.default.resolve(__dirname,"../../src/templates/dotsec.config.ts")),r=await V({filePath:s,skip:p});(r===void 0||r.overwrite===!0)&&(await _(s,l),console.log(`Wrote config file to ${C(s)}`));}catch(l){n.error(l);}});return b({program:o,dotsecConfig:a}),o},ae=Me;var Le=async(i,t)=>{let{dotsecConfig:a,handlers:o}=t,e=i.enablePositionalOptions().passThroughOptions().command("push").action(async(r,d)=>{try{let{using:m,envFile:g,secFile:c,engine:u,yes:f}=d.optsWithGlobals(),h=u||a?.defaults?.encryptionEngine,y=(o||[]).find(E=>E.decrypt?.triggerOptionValue===h)?.decrypt,w=(o||[]).find(E=>E.push?.triggerOptionValue===h)?.push;if(!w)throw new Error("No push plugin found!");let D=[...Object.keys(y?.options||{}),...Object.keys(y?.requiredOptions||{}),...Object.keys(w?.options||{}),...Object.keys(w?.requiredOptions||{})],T=Object.fromEntries(D.map(E=>[E,r[E]])),v;if(m==="env"){if(!g)throw new Error("No dotenv file specified in --env-file option");v=ce__default.default.readFileSync(g,"utf8");}else {if(!c)throw new Error("No dotsec file specified in --sec-file option");if(!y)throw new Error(`No decryption plugin found, available decryption engine(s): ${o.map(O=>`--${O.decrypt?.triggerOptionValue}`).join(", ")}`);let E=ce__default.default.readFileSync(c,"utf8");v=await y.handler({ciphertext:E,...T});}if(v){let E=P(v).obj,O=dotenvExpand.expand({ignoreProcessEnv:!0,parsed:{...process.env,...E}});O.parsed&&await w.handler({push:O.parsed,yes:f,...T});}else throw new Error("No .env or .sec file provided")}catch(m){console.error(m),process.exit(1);}});b({program:e,dotsecConfig:a});let n=t.handlers.map(({decrypt:r})=>r.triggerOptionValue);e.option("--engine <engine>",`Encryption engine${n.length>0?"s":""} to use: ${n.length===1?n[0]:n.join(", ")}`,n.length===1?n[0]:void 0);let s={};t.handlers.forEach(r=>{Object.keys(r).map(d=>{let{options:m,requiredOptions:g}=r[d];Object.keys(m||{}).forEach(c=>{s[c]=Array.isArray(m[c])?m[c]:{...s[c],...m[c]};}),Object.keys(g||{}).forEach(c=>{s[c]=Array.isArray(g[c])?g[c]:{...s[c],...g[c],required:!0};});});});let p=[],l=[];return o.forEach(r=>{r.push?.description&&l.push(r.push.description),r.push?.usage&&p.push(r.push.usage);}),l.length>0&&e.description(l.join(`
|
|
251
|
+
`)),p.length>0&&e.usage(p.join(`
|
|
252
|
+
`)),F(Object.fromEntries(Object.entries(s).filter(([r,d])=>d.required!==!0)),e),F(Object.fromEntries(Object.entries(s).filter(([r,d])=>d.required===!0)),e,!0),e},pe=Le;var Ge=(i,t)=>{let{dotsecConfig:a,decryptHandlers:o}=t||{},e=o!==void 0&&o.length>0,n=i.command("run <command...>").allowUnknownOption(!0).enablePositionalOptions().passThroughOptions().showHelpAfterError(!0).action(async(s,p,l)=>{try{let{envFile:r,using:d,secFile:m,engine:g}=l.optsWithGlobals(),c;if(d==="env"||e===!1){if(!r)throw new Error("No dotenv file specified in --env-file option");c=ce__default.default.readFileSync(r,"utf8");}else if(d==="sec"){if(!m)throw new Error("No dotsec file specified in --sec-file option");let u=g||a?.defaults?.encryptionEngine,f=(o||[]).find(D=>D.triggerOptionValue===u);if(!f)throw new Error(`No decryption plugin found, available decryption engine(s): ${(o||[]).map(D=>`--${D.triggerOptionValue}`).join(", ")}`);let h=[...Object.keys(f.options||{}),...Object.keys(f.requiredOptions||{})],y=Object.fromEntries(h.map(D=>[D,p[D]])),w=ce__default.default.readFileSync(m,"utf8");c=await f.handler({ciphertext:w,...y});}if(c){let u=P(c).obj,f=dotenvExpand.expand({ignoreProcessEnv:!0,parsed:{...process.env,...u}}),[h,...y]=s,w=child_process.spawnSync(h,[...y],{stdio:"inherit",shell:!1,encoding:"utf-8",env:{...f.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(r){console.error(C(r.message)),l.help();}});if(b({program:n,commandName:e?"run":"runEnvOnly",dotsecConfig:a}),e){o?.map(p=>{let{options:l,requiredOptions:r}=p;F(l,n),F(r,n,!0);});let s=o?.map(p=>p.triggerOptionValue);n.option("--engine <engine>",`Encryption engine${s.length>0?"s":""}: ${s.join(", "),s.length===1?s[0]:void 0}`);}return n},de=Ge;var Je={keyword:"separator",type:"string",metaSchema:{type:"string",description:"value separator"},modifying:!0,valid:!0,errors:!1,compile:i=>(t,a)=>{if(a){let{parentData:o,parentDataProperty:e}=a;return o[e]=t===""?[]:t.split(i),!0}else return !1}},j=new commander.Command;(async()=>{let i=Ye__default.default(process.argv),t=[];i.plugin&&(Array.isArray(i.plugin)?t.push(...i.plugin):t.push(i.plugin));let a=i.configFile||i.c,o=[...Array.isArray(a)?a:[a]][0]||process.env.DOTSEC_CONFIG_FILE,{contents:e={}}=await Y(o),{defaults:n={},push:s,plugins:p}=e;j.name("dotsec").description(".env, but secure").version("1.0.0").passThroughOptions().action((c,u)=>{u.help();}),b({program:j,dotsecConfig:e});let l=new Ue__default.default({allErrors:!0,removeAdditional:!0,useDefaults:!0,coerceTypes:!0,allowUnionTypes:!0,addUsedSchema:!1,keywords:[Je]}),r={};if(p)for(let c of p)n?.plugins?.[c]||(n.plugins={...n.plugins,[c]:{}});if(t.length>0)for(let c of t){let f=await(await q({name:c}))({dotsecConfig:e,ajv:l,configFile:o});r[f.name]=c,t.length===1&&(e.defaults={...e.defaults,encryptionEngine:String(f.name),plugins:{...e.defaults?.plugins,[f.name]:{...e.defaults?.plugins?.[f.name]}}});}n?.encryptionEngine&&(n?.plugins?.[n.encryptionEngine]||(n.plugins={...n.plugins,[n.encryptionEngine]:{}})),n?.plugins&&Object.entries(n?.plugins).forEach(([c,u])=>{u?.name?r[c]=u?.name:r[c]=`@dotsec/plugin-${c}`;}),Object.values(s||{}).forEach(c=>{Object.keys(c).forEach(u=>{r[u]||(r[u]=`@dotsec/plugin-${u}`);});});let d=[],m=[],g=[];for(let c of Object.keys(r)){let u=r[c],f=await q({name:u}),{addCliCommand:h,cliHandlers:y}=await f({ajv:l,dotsecConfig:e,configFile:o});y?.encrypt&&d.push(y.encrypt),y?.decrypt&&(m.push(y.decrypt),y?.push&&g.push({push:y.push,decrypt:y.decrypt})),h&&h({program:j});}d.length&&await se(j,{dotsecConfig:e,encryptHandlers:d}),m.length&&await re(j,{dotsecConfig:e,decryptHandlers:m}),g.length&&await pe(j,{dotsecConfig:e,handlers:g}),await ae(j,{dotsecConfig:e}),await de(j,{dotsecConfig:e,decryptHandlers:m}),await j.parse();})();
|
|
253
|
+
//# sourceMappingURL=out.js.map
|
|
168
254
|
//# sourceMappingURL=index.js.map
|