@dotenvx/primitives 0.10.0 → 1.0.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 +87 -7
- 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,21 +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;
|
|
6372
|
+
const fk = options.fk;
|
|
6373
|
+
const provider = options.provider;
|
|
6311
6374
|
const publicKeyHexes = publickeys2(src);
|
|
6312
|
-
|
|
6375
|
+
const ring = {};
|
|
6313
6376
|
for (const publicKeyHex of publicKeyHexes) {
|
|
6314
6377
|
ring[publicKeyHex] = "";
|
|
6315
6378
|
}
|
|
6316
|
-
|
|
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 || [];
|
|
6317
6386
|
function inProcessEnv(name) {
|
|
6318
6387
|
return Object.prototype.hasOwnProperty.call(processEnv, name);
|
|
6319
6388
|
}
|
|
6320
6389
|
const runningParsed = {};
|
|
6321
6390
|
const literals = {};
|
|
6322
6391
|
const parsed = {};
|
|
6392
|
+
const injected = {};
|
|
6393
|
+
const existed = {};
|
|
6323
6394
|
scan2(src, ({ name, value, quote }) => {
|
|
6324
6395
|
let parsedValue = value;
|
|
6325
6396
|
if (!overload && inProcessEnv(name)) {
|
|
@@ -6347,15 +6418,20 @@ var require_parse = __commonJS({
|
|
|
6347
6418
|
runningParsed[name] = parsedValue;
|
|
6348
6419
|
parsed[name] = parsedValue;
|
|
6349
6420
|
if (Object.prototype.hasOwnProperty.call(processEnv, name) && !overload) {
|
|
6421
|
+
existed[name] = processEnv[name];
|
|
6350
6422
|
} else {
|
|
6423
|
+
injected[name] = parsed[name];
|
|
6351
6424
|
}
|
|
6352
6425
|
return parsedValue;
|
|
6353
6426
|
});
|
|
6354
6427
|
return {
|
|
6355
|
-
parsed
|
|
6428
|
+
parsed,
|
|
6429
|
+
injected,
|
|
6430
|
+
existed
|
|
6356
6431
|
};
|
|
6357
6432
|
}
|
|
6358
6433
|
module2.exports = parse2;
|
|
6434
|
+
module2.exports.sync = parseSync2;
|
|
6359
6435
|
}
|
|
6360
6436
|
});
|
|
6361
6437
|
|
|
@@ -6391,7 +6467,9 @@ var evaluate = require_evaluate();
|
|
|
6391
6467
|
var expand = require_expand();
|
|
6392
6468
|
var keypair = require_keypair();
|
|
6393
6469
|
var keyring = require_keyring();
|
|
6470
|
+
var keyringSync = require_keyring().sync;
|
|
6394
6471
|
var parse = require_parse();
|
|
6472
|
+
var parseSync = require_parse().sync;
|
|
6395
6473
|
var publickeys = require_publickeys();
|
|
6396
6474
|
var scan = require_scan();
|
|
6397
6475
|
var sealed = require_sealed();
|
|
@@ -6404,7 +6482,9 @@ module.exports = {
|
|
|
6404
6482
|
expand,
|
|
6405
6483
|
keypair,
|
|
6406
6484
|
keyring,
|
|
6485
|
+
keyringSync,
|
|
6407
6486
|
parse,
|
|
6487
|
+
parseSync,
|
|
6408
6488
|
publickeys,
|
|
6409
6489
|
scan,
|
|
6410
6490
|
sealed
|
package/package.json
CHANGED