@dotenvx/primitives 0.8.0 → 0.10.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/index.cjs +108 -56
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6031,9 +6031,9 @@ var require_evaluate = __commonJS({
|
|
|
6031
6031
|
function chomp(value) {
|
|
6032
6032
|
return value.replace(/[\r\n]+$/, "");
|
|
6033
6033
|
}
|
|
6034
|
-
function evaluate2(value,
|
|
6035
|
-
const processEnv =
|
|
6036
|
-
const runningParsed =
|
|
6034
|
+
function evaluate2(value, options) {
|
|
6035
|
+
const processEnv = options.processEnv || process.env;
|
|
6036
|
+
const runningParsed = options.runningParsed || {};
|
|
6037
6037
|
const matches = value.match(/\$\(([^)]+(?:\)[^(]*)*)\)/g) || [];
|
|
6038
6038
|
return matches.reduce((newValue, match) => {
|
|
6039
6039
|
const command = match.slice(2, -1);
|
|
@@ -6054,11 +6054,11 @@ var require_evaluate = __commonJS({
|
|
|
6054
6054
|
// src/expand.js
|
|
6055
6055
|
var require_expand = __commonJS({
|
|
6056
6056
|
"src/expand.js"(exports2, module2) {
|
|
6057
|
-
function expand2(value,
|
|
6058
|
-
const overload =
|
|
6059
|
-
const processEnv =
|
|
6060
|
-
const runningParsed =
|
|
6061
|
-
const literals =
|
|
6057
|
+
function expand2(value, options) {
|
|
6058
|
+
const overload = options.overload;
|
|
6059
|
+
const processEnv = options.processEnv || process.env;
|
|
6060
|
+
const runningParsed = options.runningParsed || {};
|
|
6061
|
+
const literals = options.literals || {};
|
|
6062
6062
|
let env = { ...runningParsed, ...processEnv };
|
|
6063
6063
|
if (overload) {
|
|
6064
6064
|
env = { ...processEnv, ...runningParsed };
|
|
@@ -6146,25 +6146,25 @@ var require_scan = __commonJS({
|
|
|
6146
6146
|
}
|
|
6147
6147
|
return q;
|
|
6148
6148
|
}
|
|
6149
|
-
function clean(value, quote,
|
|
6149
|
+
function clean(value, quote, options) {
|
|
6150
6150
|
let v = trimmer(value);
|
|
6151
6151
|
v = v.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
6152
|
-
if (quote === '"' &&
|
|
6152
|
+
if (quote === '"' && options.expandDoubleQuotedNewlines !== false) {
|
|
6153
6153
|
v = v.replace(/\\n/g, "\n");
|
|
6154
6154
|
v = v.replace(/\\r/g, "\r");
|
|
6155
6155
|
v = v.replace(/\\t/g, " ");
|
|
6156
6156
|
}
|
|
6157
6157
|
return v;
|
|
6158
6158
|
}
|
|
6159
|
-
function scan2(src,
|
|
6160
|
-
if (typeof
|
|
6161
|
-
transform =
|
|
6162
|
-
|
|
6159
|
+
function scan2(src, options = {}, transform) {
|
|
6160
|
+
if (typeof options === "function") {
|
|
6161
|
+
transform = options;
|
|
6162
|
+
options = {};
|
|
6163
6163
|
}
|
|
6164
6164
|
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
6165
6165
|
const parsed = {};
|
|
6166
6166
|
let lines = (src || "").toString();
|
|
6167
|
-
if (
|
|
6167
|
+
if (options.convertWindowsNewlines !== false) {
|
|
6168
6168
|
lines = lines.replace(/\r\n?/mg, "\n");
|
|
6169
6169
|
}
|
|
6170
6170
|
let match;
|
|
@@ -6172,7 +6172,7 @@ var require_scan = __commonJS({
|
|
|
6172
6172
|
const name = match[1];
|
|
6173
6173
|
const raw = match[2];
|
|
6174
6174
|
const quote = getQuote(raw);
|
|
6175
|
-
const value = clean(raw, quote,
|
|
6175
|
+
const value = clean(raw, quote, options);
|
|
6176
6176
|
let parsedValue = value;
|
|
6177
6177
|
if (typeof transform === "function") {
|
|
6178
6178
|
parsedValue = transform({
|
|
@@ -6202,40 +6202,72 @@ var require_keyring = __commonJS({
|
|
|
6202
6202
|
try {
|
|
6203
6203
|
const src = fs.readFileSync(filepath, "utf8");
|
|
6204
6204
|
const { parsed } = scan2(src);
|
|
6205
|
-
const result =
|
|
6205
|
+
const result = [];
|
|
6206
6206
|
for (const name in parsed) {
|
|
6207
|
-
|
|
6207
|
+
if (name.startsWith("DOTENV_PRIVATE_KEY")) {
|
|
6208
|
+
result.push(parsed[name][parsed[name].length - 1]);
|
|
6209
|
+
}
|
|
6208
6210
|
}
|
|
6209
6211
|
return result;
|
|
6210
6212
|
} catch (_e) {
|
|
6211
|
-
return
|
|
6212
|
-
}
|
|
6213
|
-
}
|
|
6214
|
-
function keyring2() {
|
|
6215
|
-
const
|
|
6216
|
-
const
|
|
6217
|
-
const
|
|
6218
|
-
const
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
for (const name in sources) {
|
|
6213
|
+
return [];
|
|
6214
|
+
}
|
|
6215
|
+
}
|
|
6216
|
+
function keyring2(options = {}) {
|
|
6217
|
+
const ring = options.ring || {};
|
|
6218
|
+
const provider = options.provider;
|
|
6219
|
+
const processEnv = options.processEnv || process.env;
|
|
6220
|
+
const keysFilepaths = Array.isArray(options.fk) ? options.fk : [options.fk || ".env.keys"];
|
|
6221
|
+
const privateKeyValues = keysFilepaths.reduce((acc, filepath) => {
|
|
6222
|
+
return acc.concat(keysFromFile(filepath));
|
|
6223
|
+
}, []);
|
|
6224
|
+
for (const name in processEnv) {
|
|
6224
6225
|
if (name.startsWith("DOTENV_PRIVATE_KEY")) {
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6226
|
+
privateKeyValues.push(processEnv[name]);
|
|
6227
|
+
}
|
|
6228
|
+
}
|
|
6229
|
+
for (const privateKeyHex of privateKeyValues) {
|
|
6230
|
+
try {
|
|
6231
|
+
const publicKeyHex = derive2(privateKeyHex);
|
|
6232
|
+
ring[publicKeyHex] = privateKeyHex;
|
|
6233
|
+
} catch (_e) {
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
if (typeof provider === "function") {
|
|
6237
|
+
for (const publicKeyHex in ring) {
|
|
6238
|
+
if (ring[publicKeyHex]) {
|
|
6239
|
+
continue;
|
|
6240
|
+
}
|
|
6241
|
+
const privateKeyHex = provider(publicKeyHex);
|
|
6242
|
+
if (privateKeyHex) {
|
|
6243
|
+
ring[publicKeyHex] = privateKeyHex;
|
|
6230
6244
|
}
|
|
6231
6245
|
}
|
|
6232
6246
|
}
|
|
6233
|
-
return
|
|
6247
|
+
return ring;
|
|
6234
6248
|
}
|
|
6235
6249
|
module2.exports = keyring2;
|
|
6236
6250
|
}
|
|
6237
6251
|
});
|
|
6238
6252
|
|
|
6253
|
+
// src/publickeys.js
|
|
6254
|
+
var require_publickeys = __commonJS({
|
|
6255
|
+
"src/publickeys.js"(exports2, module2) {
|
|
6256
|
+
var scan2 = require_scan();
|
|
6257
|
+
function publickeys2(src) {
|
|
6258
|
+
const { parsed } = scan2(src);
|
|
6259
|
+
const result = [];
|
|
6260
|
+
for (const name in parsed) {
|
|
6261
|
+
if (name.startsWith("DOTENV_PUBLIC_KEY")) {
|
|
6262
|
+
result.push(parsed[name][parsed[name].length - 1]);
|
|
6263
|
+
}
|
|
6264
|
+
}
|
|
6265
|
+
return result;
|
|
6266
|
+
}
|
|
6267
|
+
module2.exports = publickeys2;
|
|
6268
|
+
}
|
|
6269
|
+
});
|
|
6270
|
+
|
|
6239
6271
|
// src/parse.js
|
|
6240
6272
|
var require_parse = __commonJS({
|
|
6241
6273
|
"src/parse.js"(exports2, module2) {
|
|
@@ -6244,39 +6276,56 @@ var require_parse = __commonJS({
|
|
|
6244
6276
|
var encrypted2 = require_encrypted();
|
|
6245
6277
|
var evaluate2 = require_evaluate();
|
|
6246
6278
|
var expand2 = require_expand();
|
|
6279
|
+
var publickeys2 = require_publickeys();
|
|
6247
6280
|
var scan2 = require_scan();
|
|
6248
6281
|
function resolveEscapeSequences(value) {
|
|
6249
6282
|
return value.replace(/\\\$/g, "$");
|
|
6250
6283
|
}
|
|
6251
|
-
function
|
|
6252
|
-
const
|
|
6253
|
-
for (const
|
|
6254
|
-
|
|
6284
|
+
function decryptWithKeyring(ring, value, publicKeyHexes) {
|
|
6285
|
+
const tried = {};
|
|
6286
|
+
for (const publicKeyHex of publicKeyHexes) {
|
|
6287
|
+
const privateKeyHex = ring[publicKeyHex];
|
|
6288
|
+
if (!privateKeyHex) {
|
|
6289
|
+
continue;
|
|
6290
|
+
}
|
|
6291
|
+
tried[privateKeyHex] = true;
|
|
6292
|
+
try {
|
|
6293
|
+
return decrypt2(privateKeyHex, value);
|
|
6294
|
+
} catch (_e) {
|
|
6295
|
+
}
|
|
6255
6296
|
}
|
|
6256
|
-
|
|
6297
|
+
for (const privateKeyHex of Object.values(ring)) {
|
|
6298
|
+
if (!privateKeyHex || tried[privateKeyHex]) {
|
|
6299
|
+
continue;
|
|
6300
|
+
}
|
|
6301
|
+
try {
|
|
6302
|
+
return decrypt2(privateKeyHex, value);
|
|
6303
|
+
} catch (_e) {
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
6306
|
+
return value;
|
|
6257
6307
|
}
|
|
6258
|
-
function parse2(src,
|
|
6259
|
-
const overload =
|
|
6260
|
-
const processEnv =
|
|
6261
|
-
const
|
|
6308
|
+
function parse2(src, options = {}) {
|
|
6309
|
+
const overload = options.overload;
|
|
6310
|
+
const processEnv = options.processEnv || process.env;
|
|
6311
|
+
const publicKeyHexes = publickeys2(src);
|
|
6312
|
+
let ring = {};
|
|
6313
|
+
for (const publicKeyHex of publicKeyHexes) {
|
|
6314
|
+
ring[publicKeyHex] = "";
|
|
6315
|
+
}
|
|
6316
|
+
ring = keyring2({ processEnv, ring });
|
|
6262
6317
|
function inProcessEnv(name) {
|
|
6263
6318
|
return Object.prototype.hasOwnProperty.call(processEnv, name);
|
|
6264
6319
|
}
|
|
6265
|
-
let publicKeyHex;
|
|
6266
6320
|
const runningParsed = {};
|
|
6267
6321
|
const literals = {};
|
|
6268
|
-
const
|
|
6322
|
+
const parsed = {};
|
|
6323
|
+
scan2(src, ({ name, value, quote }) => {
|
|
6269
6324
|
let parsedValue = value;
|
|
6270
|
-
if (name.startsWith("DOTENV_PUBLIC_KEY")) {
|
|
6271
|
-
publicKeyHex = parsedValue;
|
|
6272
|
-
}
|
|
6273
6325
|
if (!overload && inProcessEnv(name)) {
|
|
6274
6326
|
parsedValue = processEnv[name];
|
|
6275
6327
|
}
|
|
6276
|
-
|
|
6277
|
-
parsedValue = decrypt2(ring[publicKeyHex], parsedValue);
|
|
6278
|
-
} catch (_e) {
|
|
6279
|
-
}
|
|
6328
|
+
parsedValue = decryptWithKeyring(ring, parsedValue, publicKeyHexes);
|
|
6280
6329
|
const encryptedPrefixed = encrypted2(parsedValue);
|
|
6281
6330
|
let evaled = false;
|
|
6282
6331
|
if (!encryptedPrefixed && quote !== "'" && (!inProcessEnv(name) || processEnv[name] === parsedValue)) {
|
|
@@ -6296,13 +6345,14 @@ var require_parse = __commonJS({
|
|
|
6296
6345
|
literals[name] = parsedValue;
|
|
6297
6346
|
}
|
|
6298
6347
|
runningParsed[name] = parsedValue;
|
|
6348
|
+
parsed[name] = parsedValue;
|
|
6299
6349
|
if (Object.prototype.hasOwnProperty.call(processEnv, name) && !overload) {
|
|
6300
6350
|
} else {
|
|
6301
6351
|
}
|
|
6302
6352
|
return parsedValue;
|
|
6303
6353
|
});
|
|
6304
6354
|
return {
|
|
6305
|
-
parsed
|
|
6355
|
+
parsed
|
|
6306
6356
|
};
|
|
6307
6357
|
}
|
|
6308
6358
|
module2.exports = parse2;
|
|
@@ -6342,6 +6392,7 @@ var expand = require_expand();
|
|
|
6342
6392
|
var keypair = require_keypair();
|
|
6343
6393
|
var keyring = require_keyring();
|
|
6344
6394
|
var parse = require_parse();
|
|
6395
|
+
var publickeys = require_publickeys();
|
|
6345
6396
|
var scan = require_scan();
|
|
6346
6397
|
var sealed = require_sealed();
|
|
6347
6398
|
module.exports = {
|
|
@@ -6354,6 +6405,7 @@ module.exports = {
|
|
|
6354
6405
|
keypair,
|
|
6355
6406
|
keyring,
|
|
6356
6407
|
parse,
|
|
6408
|
+
publickeys,
|
|
6357
6409
|
scan,
|
|
6358
6410
|
sealed
|
|
6359
6411
|
};
|
package/package.json
CHANGED