@dotenvx/primitives 0.11.0 → 1.0.1
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 +86 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6198,7 +6198,22 @@ var require_keyring = __commonJS({
|
|
|
6198
6198
|
var fs = require("fs");
|
|
6199
6199
|
var derive2 = require_derive();
|
|
6200
6200
|
var scan2 = require_scan();
|
|
6201
|
-
function keysFromFile(filepath = ".env.keys") {
|
|
6201
|
+
async function keysFromFile(filepath = ".env.keys") {
|
|
6202
|
+
try {
|
|
6203
|
+
const src = await fs.promises.readFile(filepath, "utf8");
|
|
6204
|
+
const { parsed } = scan2(src);
|
|
6205
|
+
const result = [];
|
|
6206
|
+
for (const name in parsed) {
|
|
6207
|
+
if (name.startsWith("DOTENV_PRIVATE_KEY")) {
|
|
6208
|
+
result.push(parsed[name][parsed[name].length - 1]);
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
return result;
|
|
6212
|
+
} catch (_e) {
|
|
6213
|
+
return [];
|
|
6214
|
+
}
|
|
6215
|
+
}
|
|
6216
|
+
function keysFromFileSync(filepath = ".env.keys") {
|
|
6202
6217
|
try {
|
|
6203
6218
|
const src = fs.readFileSync(filepath, "utf8");
|
|
6204
6219
|
const { parsed } = scan2(src);
|
|
@@ -6213,13 +6228,47 @@ var require_keyring = __commonJS({
|
|
|
6213
6228
|
return [];
|
|
6214
6229
|
}
|
|
6215
6230
|
}
|
|
6216
|
-
function keyring2(options = {}) {
|
|
6231
|
+
async function keyring2(options = {}) {
|
|
6232
|
+
const ring = options.ring || {};
|
|
6233
|
+
const provider = options.provider;
|
|
6234
|
+
const processEnv = options.processEnv || process.env;
|
|
6235
|
+
const keysFilepaths = Array.isArray(options.fk) ? options.fk : [options.fk || ".env.keys"];
|
|
6236
|
+
const privateKeyValues = [];
|
|
6237
|
+
for (const filepath of keysFilepaths) {
|
|
6238
|
+
privateKeyValues.push(...await keysFromFile(filepath));
|
|
6239
|
+
}
|
|
6240
|
+
for (const name in processEnv) {
|
|
6241
|
+
if (name.startsWith("DOTENV_PRIVATE_KEY")) {
|
|
6242
|
+
privateKeyValues.push(processEnv[name]);
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
for (const privateKeyHex of privateKeyValues) {
|
|
6246
|
+
try {
|
|
6247
|
+
const publicKeyHex = derive2(privateKeyHex);
|
|
6248
|
+
ring[publicKeyHex] = privateKeyHex;
|
|
6249
|
+
} catch (_e) {
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
if (typeof provider === "function") {
|
|
6253
|
+
for (const publicKeyHex in ring) {
|
|
6254
|
+
if (ring[publicKeyHex]) {
|
|
6255
|
+
continue;
|
|
6256
|
+
}
|
|
6257
|
+
const privateKeyHex = await provider(publicKeyHex);
|
|
6258
|
+
if (privateKeyHex) {
|
|
6259
|
+
ring[publicKeyHex] = privateKeyHex;
|
|
6260
|
+
}
|
|
6261
|
+
}
|
|
6262
|
+
}
|
|
6263
|
+
return ring;
|
|
6264
|
+
}
|
|
6265
|
+
function keyringSync2(options = {}) {
|
|
6217
6266
|
const ring = options.ring || {};
|
|
6218
6267
|
const provider = options.provider;
|
|
6219
6268
|
const processEnv = options.processEnv || process.env;
|
|
6220
6269
|
const keysFilepaths = Array.isArray(options.fk) ? options.fk : [options.fk || ".env.keys"];
|
|
6221
6270
|
const privateKeyValues = keysFilepaths.reduce((acc, filepath) => {
|
|
6222
|
-
return acc.concat(
|
|
6271
|
+
return acc.concat(keysFromFileSync(filepath));
|
|
6223
6272
|
}, []);
|
|
6224
6273
|
for (const name in processEnv) {
|
|
6225
6274
|
if (name.startsWith("DOTENV_PRIVATE_KEY")) {
|
|
@@ -6247,6 +6296,7 @@ var require_keyring = __commonJS({
|
|
|
6247
6296
|
return ring;
|
|
6248
6297
|
}
|
|
6249
6298
|
module2.exports = keyring2;
|
|
6299
|
+
module2.exports.sync = keyringSync2;
|
|
6250
6300
|
}
|
|
6251
6301
|
});
|
|
6252
6302
|
|
|
@@ -6273,6 +6323,7 @@ var require_parse = __commonJS({
|
|
|
6273
6323
|
"src/parse.js"(exports2, module2) {
|
|
6274
6324
|
var decrypt2 = require_decrypt();
|
|
6275
6325
|
var keyring2 = require_keyring();
|
|
6326
|
+
var keyringSync2 = require_keyring().sync;
|
|
6276
6327
|
var encrypted2 = require_encrypted();
|
|
6277
6328
|
var evaluate2 = require_evaluate();
|
|
6278
6329
|
var expand2 = require_expand();
|
|
@@ -6305,23 +6356,41 @@ var require_parse = __commonJS({
|
|
|
6305
6356
|
}
|
|
6306
6357
|
return value;
|
|
6307
6358
|
}
|
|
6308
|
-
function parse2(src, options = {}) {
|
|
6359
|
+
async function parse2(src, options = {}) {
|
|
6360
|
+
const { overload, processEnv, fk, provider, publicKeyHexes, ring: initialRing } = keyringOptions(src, options);
|
|
6361
|
+
const ring = await keyring2({ processEnv, ring: initialRing, fk, provider });
|
|
6362
|
+
return parseWithRing(src, { overload, processEnv, ring, publicKeyHexes });
|
|
6363
|
+
}
|
|
6364
|
+
function parseSync2(src, options = {}) {
|
|
6365
|
+
const { overload, processEnv, fk, provider, publicKeyHexes, ring: initialRing } = keyringOptions(src, options);
|
|
6366
|
+
const ring = keyringSync2({ processEnv, ring: initialRing, fk, provider });
|
|
6367
|
+
return parseWithRing(src, { overload, processEnv, ring, publicKeyHexes });
|
|
6368
|
+
}
|
|
6369
|
+
function keyringOptions(src, options = {}) {
|
|
6309
6370
|
const overload = options.overload;
|
|
6310
6371
|
const processEnv = options.processEnv || process.env;
|
|
6311
6372
|
const fk = options.fk;
|
|
6312
6373
|
const provider = options.provider;
|
|
6313
6374
|
const publicKeyHexes = publickeys2(src);
|
|
6314
|
-
|
|
6375
|
+
const ring = {};
|
|
6315
6376
|
for (const publicKeyHex of publicKeyHexes) {
|
|
6316
6377
|
ring[publicKeyHex] = "";
|
|
6317
6378
|
}
|
|
6318
|
-
|
|
6379
|
+
return { overload, processEnv, fk, provider, publicKeyHexes, ring };
|
|
6380
|
+
}
|
|
6381
|
+
function parseWithRing(src, options = {}) {
|
|
6382
|
+
const overload = options.overload;
|
|
6383
|
+
const processEnv = options.processEnv || process.env;
|
|
6384
|
+
const ring = options.ring || {};
|
|
6385
|
+
const publicKeyHexes = options.publicKeyHexes || [];
|
|
6319
6386
|
function inProcessEnv(name) {
|
|
6320
6387
|
return Object.prototype.hasOwnProperty.call(processEnv, name);
|
|
6321
6388
|
}
|
|
6322
6389
|
const runningParsed = {};
|
|
6323
6390
|
const literals = {};
|
|
6324
6391
|
const parsed = {};
|
|
6392
|
+
const injected = {};
|
|
6393
|
+
const existed = {};
|
|
6325
6394
|
scan2(src, ({ name, value, quote }) => {
|
|
6326
6395
|
let parsedValue = value;
|
|
6327
6396
|
if (!overload && inProcessEnv(name)) {
|
|
@@ -6341,7 +6410,7 @@ var require_parse = __commonJS({
|
|
|
6341
6410
|
}
|
|
6342
6411
|
}
|
|
6343
6412
|
if (!encryptedPrefixed && !evaled && quote !== "'" && (!processEnv[name] || overload)) {
|
|
6344
|
-
parsedValue = resolveEscapeSequences(expand2(parsedValue, { processEnv, runningParsed, literals }));
|
|
6413
|
+
parsedValue = resolveEscapeSequences(expand2(parsedValue, { overload, processEnv, runningParsed, literals }));
|
|
6345
6414
|
}
|
|
6346
6415
|
if (quote === "'") {
|
|
6347
6416
|
literals[name] = parsedValue;
|
|
@@ -6349,15 +6418,20 @@ var require_parse = __commonJS({
|
|
|
6349
6418
|
runningParsed[name] = parsedValue;
|
|
6350
6419
|
parsed[name] = parsedValue;
|
|
6351
6420
|
if (Object.prototype.hasOwnProperty.call(processEnv, name) && !overload) {
|
|
6421
|
+
existed[name] = processEnv[name];
|
|
6352
6422
|
} else {
|
|
6423
|
+
injected[name] = parsed[name];
|
|
6353
6424
|
}
|
|
6354
6425
|
return parsedValue;
|
|
6355
6426
|
});
|
|
6356
6427
|
return {
|
|
6357
|
-
parsed
|
|
6428
|
+
parsed,
|
|
6429
|
+
injected,
|
|
6430
|
+
existed
|
|
6358
6431
|
};
|
|
6359
6432
|
}
|
|
6360
6433
|
module2.exports = parse2;
|
|
6434
|
+
module2.exports.sync = parseSync2;
|
|
6361
6435
|
}
|
|
6362
6436
|
});
|
|
6363
6437
|
|
|
@@ -6393,7 +6467,9 @@ var evaluate = require_evaluate();
|
|
|
6393
6467
|
var expand = require_expand();
|
|
6394
6468
|
var keypair = require_keypair();
|
|
6395
6469
|
var keyring = require_keyring();
|
|
6470
|
+
var keyringSync = require_keyring().sync;
|
|
6396
6471
|
var parse = require_parse();
|
|
6472
|
+
var parseSync = require_parse().sync;
|
|
6397
6473
|
var publickeys = require_publickeys();
|
|
6398
6474
|
var scan = require_scan();
|
|
6399
6475
|
var sealed = require_sealed();
|
|
@@ -6406,7 +6482,9 @@ module.exports = {
|
|
|
6406
6482
|
expand,
|
|
6407
6483
|
keypair,
|
|
6408
6484
|
keyring,
|
|
6485
|
+
keyringSync,
|
|
6409
6486
|
parse,
|
|
6487
|
+
parseSync,
|
|
6410
6488
|
publickeys,
|
|
6411
6489
|
scan,
|
|
6412
6490
|
sealed
|
package/package.json
CHANGED