@dotenvx/next-env 2.0.1 → 2.0.3
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 +122 -62
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5350,7 +5350,7 @@ var require_dist = __commonJS({
|
|
|
5350
5350
|
const isAEAD = algorithm === "aes-256-gcm" || algorithm === "chacha20-poly1305";
|
|
5351
5351
|
const authTagLength = isAEAD ? AEAD_TAG_LENGTH : 0;
|
|
5352
5352
|
const options = isAEAD ? { authTagLength } : void 0;
|
|
5353
|
-
const
|
|
5353
|
+
const encrypt2 = (plainText) => {
|
|
5354
5354
|
const cipher = (0, node_crypto_1.createCipheriv)(algorithm, key, nonce, options);
|
|
5355
5355
|
if (isAEAD && AAD !== void 0) {
|
|
5356
5356
|
cipher.setAAD(AAD);
|
|
@@ -5375,7 +5375,7 @@ var require_dist = __commonJS({
|
|
|
5375
5375
|
return (0, utils_1.concatBytes)(updated, finalized);
|
|
5376
5376
|
};
|
|
5377
5377
|
return {
|
|
5378
|
-
encrypt,
|
|
5378
|
+
encrypt: encrypt2,
|
|
5379
5379
|
decrypt: decrypt2
|
|
5380
5380
|
};
|
|
5381
5381
|
};
|
|
@@ -5768,13 +5768,13 @@ var require_dist = __commonJS({
|
|
|
5768
5768
|
"use strict";
|
|
5769
5769
|
Object.defineProperty(exports22, "__esModule", { value: true });
|
|
5770
5770
|
exports22.PublicKey = exports22.PrivateKey = exports22.ECIES_CONFIG = void 0;
|
|
5771
|
-
exports22.encrypt =
|
|
5771
|
+
exports22.encrypt = encrypt2;
|
|
5772
5772
|
exports22.decrypt = decrypt2;
|
|
5773
5773
|
var utils_1 = require_utils();
|
|
5774
5774
|
var config_js_1 = require_config();
|
|
5775
5775
|
var index_js_1 = require_keys();
|
|
5776
5776
|
var index_js_2 = require_utils4();
|
|
5777
|
-
function
|
|
5777
|
+
function encrypt2(receiverRawPK, data, config = config_js_1.ECIES_CONFIG) {
|
|
5778
5778
|
const curve = config.ellipticCurve;
|
|
5779
5779
|
const ephemeralSK = new index_js_1.PrivateKey(void 0, curve);
|
|
5780
5780
|
const receiverPK = receiverRawPK instanceof Uint8Array ? new index_js_1.PublicKey(receiverRawPK, curve) : index_js_1.PublicKey.fromHex(receiverRawPK, curve);
|
|
@@ -5900,8 +5900,9 @@ var require_dist = __commonJS({
|
|
|
5900
5900
|
var { decrypt: eciesDecrypt } = require_dist2();
|
|
5901
5901
|
var Errors = require_errors();
|
|
5902
5902
|
var encrypted2 = require_encrypted();
|
|
5903
|
-
function decrypt2(privateKeyHex, encryptedValue) {
|
|
5904
|
-
|
|
5903
|
+
function decrypt2(privateKeyHex, encryptedValue, options = {}) {
|
|
5904
|
+
const value = options.prefix === false ? `${encrypted2.PREFIX}${encryptedValue}` : encryptedValue;
|
|
5905
|
+
if (!encrypted2(value)) {
|
|
5905
5906
|
return encryptedValue;
|
|
5906
5907
|
}
|
|
5907
5908
|
if (!privateKeyHex || privateKeyHex.length < 1) {
|
|
@@ -5909,7 +5910,7 @@ var require_dist = __commonJS({
|
|
|
5909
5910
|
}
|
|
5910
5911
|
try {
|
|
5911
5912
|
const privateKey = Buffer.from(privateKeyHex, "hex");
|
|
5912
|
-
const ciphertext = Buffer.from(
|
|
5913
|
+
const ciphertext = Buffer.from(value.substring(encrypted2.PREFIX.length), "base64");
|
|
5913
5914
|
return Buffer.from(eciesDecrypt(privateKey, ciphertext)).toString("utf8");
|
|
5914
5915
|
} catch (e) {
|
|
5915
5916
|
if (e.message === "Invalid private key") {
|
|
@@ -5935,6 +5936,21 @@ var require_dist = __commonJS({
|
|
|
5935
5936
|
module22.exports = derive2;
|
|
5936
5937
|
}
|
|
5937
5938
|
});
|
|
5939
|
+
var require_encrypt = __commonJS2({
|
|
5940
|
+
"src/encrypt.js"(exports22, module22) {
|
|
5941
|
+
var { encrypt: eciesEncrypt } = require_dist2();
|
|
5942
|
+
var { PREFIX } = require_encrypted();
|
|
5943
|
+
function encrypt2(publicKeyHex, value, options = {}) {
|
|
5944
|
+
const ciphertext = eciesEncrypt(publicKeyHex, Buffer.from(value));
|
|
5945
|
+
const encoded = Buffer.from(ciphertext, "hex").toString("base64");
|
|
5946
|
+
if (options.prefix === false) {
|
|
5947
|
+
return encoded;
|
|
5948
|
+
}
|
|
5949
|
+
return `${PREFIX}${encoded}`;
|
|
5950
|
+
}
|
|
5951
|
+
module22.exports = encrypt2;
|
|
5952
|
+
}
|
|
5953
|
+
});
|
|
5938
5954
|
var require_evaluate = __commonJS2({
|
|
5939
5955
|
"src/evaluate.js"(exports22, module22) {
|
|
5940
5956
|
var { execSync } = require("child_process");
|
|
@@ -6010,40 +6026,12 @@ var require_dist = __commonJS({
|
|
|
6010
6026
|
module22.exports = expand2;
|
|
6011
6027
|
}
|
|
6012
6028
|
});
|
|
6013
|
-
var
|
|
6014
|
-
"src/
|
|
6015
|
-
var { PrivateKey } = require_dist2();
|
|
6016
|
-
var derive2 = require_derive();
|
|
6017
|
-
function keyring2() {
|
|
6018
|
-
const mem = {};
|
|
6019
|
-
const processEnv2 = process.env;
|
|
6020
|
-
for (const name in processEnv2) {
|
|
6021
|
-
if (name.startsWith("DOTENV_PRIVATE_KEY")) {
|
|
6022
|
-
try {
|
|
6023
|
-
const privateKeyHex = processEnv2[name];
|
|
6024
|
-
const publicKeyHex = derive2(privateKeyHex);
|
|
6025
|
-
mem[publicKeyHex] = privateKeyHex;
|
|
6026
|
-
} catch (_e) {
|
|
6027
|
-
}
|
|
6028
|
-
}
|
|
6029
|
-
}
|
|
6030
|
-
return mem;
|
|
6031
|
-
}
|
|
6032
|
-
module22.exports = keyring2;
|
|
6033
|
-
}
|
|
6034
|
-
});
|
|
6035
|
-
var require_parse = __commonJS2({
|
|
6036
|
-
"src/parse.js"(exports22, module22) {
|
|
6037
|
-
var decrypt2 = require_decrypt();
|
|
6038
|
-
var keyring2 = require_keyring();
|
|
6039
|
-
var encrypted2 = require_encrypted();
|
|
6040
|
-
var evaluate2 = require_evaluate();
|
|
6041
|
-
var expand2 = require_expand();
|
|
6042
|
-
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
6029
|
+
var require_scan = __commonJS2({
|
|
6030
|
+
"src/scan.js"(exports22, module22) {
|
|
6043
6031
|
function trimmer(value) {
|
|
6044
6032
|
return (value || "").trim();
|
|
6045
6033
|
}
|
|
6046
|
-
function
|
|
6034
|
+
function getQuote(value) {
|
|
6047
6035
|
const v = trimmer(value);
|
|
6048
6036
|
const maybeQuote = v[0];
|
|
6049
6037
|
let q = "";
|
|
@@ -6066,16 +6054,89 @@ var require_dist = __commonJS({
|
|
|
6066
6054
|
}
|
|
6067
6055
|
return q;
|
|
6068
6056
|
}
|
|
6069
|
-
function clean(value,
|
|
6057
|
+
function clean(value, quote) {
|
|
6070
6058
|
let v = trimmer(value);
|
|
6071
6059
|
v = v.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
6072
|
-
if (
|
|
6060
|
+
if (quote === '"') {
|
|
6073
6061
|
v = v.replace(/\\n/g, "\n");
|
|
6074
6062
|
v = v.replace(/\\r/g, "\r");
|
|
6075
6063
|
v = v.replace(/\\t/g, " ");
|
|
6076
6064
|
}
|
|
6077
6065
|
return v;
|
|
6078
6066
|
}
|
|
6067
|
+
function scan2(src, transform) {
|
|
6068
|
+
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
6069
|
+
const parsed = {};
|
|
6070
|
+
const lines = (src || "").toString().replace(/\r\n?/mg, "\n");
|
|
6071
|
+
let match;
|
|
6072
|
+
while ((match = LINE.exec(lines)) !== null) {
|
|
6073
|
+
const name = match[1];
|
|
6074
|
+
const raw = match[2];
|
|
6075
|
+
const quote = getQuote(raw);
|
|
6076
|
+
const value = clean(raw, quote);
|
|
6077
|
+
let parsedValue = value;
|
|
6078
|
+
if (typeof transform === "function") {
|
|
6079
|
+
parsedValue = transform({
|
|
6080
|
+
name,
|
|
6081
|
+
value,
|
|
6082
|
+
quote
|
|
6083
|
+
});
|
|
6084
|
+
}
|
|
6085
|
+
parsed[name] = parsedValue;
|
|
6086
|
+
}
|
|
6087
|
+
return {
|
|
6088
|
+
parsed
|
|
6089
|
+
};
|
|
6090
|
+
}
|
|
6091
|
+
module22.exports = scan2;
|
|
6092
|
+
}
|
|
6093
|
+
});
|
|
6094
|
+
var require_keyring = __commonJS2({
|
|
6095
|
+
"src/keyring.js"(exports22, module22) {
|
|
6096
|
+
var fs2 = require("fs");
|
|
6097
|
+
var derive2 = require_derive();
|
|
6098
|
+
var scan2 = require_scan();
|
|
6099
|
+
function keysFromFile(filepath = ".env.keys") {
|
|
6100
|
+
try {
|
|
6101
|
+
const src = fs2.readFileSync(filepath, "utf8");
|
|
6102
|
+
const { parsed } = scan2(src);
|
|
6103
|
+
return parsed;
|
|
6104
|
+
} catch (_e) {
|
|
6105
|
+
return {};
|
|
6106
|
+
}
|
|
6107
|
+
}
|
|
6108
|
+
function keyring2() {
|
|
6109
|
+
const mem = {};
|
|
6110
|
+
const processEnv2 = process.env;
|
|
6111
|
+
const keysFilepath = ".env.keys";
|
|
6112
|
+
const sources = {
|
|
6113
|
+
...keysFromFile(keysFilepath),
|
|
6114
|
+
...processEnv2
|
|
6115
|
+
// process.env wins
|
|
6116
|
+
};
|
|
6117
|
+
for (const name in sources) {
|
|
6118
|
+
if (name.startsWith("DOTENV_PRIVATE_KEY")) {
|
|
6119
|
+
try {
|
|
6120
|
+
const privateKeyHex = sources[name];
|
|
6121
|
+
const publicKeyHex = derive2(privateKeyHex);
|
|
6122
|
+
mem[publicKeyHex] = privateKeyHex;
|
|
6123
|
+
} catch (_e) {
|
|
6124
|
+
}
|
|
6125
|
+
}
|
|
6126
|
+
}
|
|
6127
|
+
return mem;
|
|
6128
|
+
}
|
|
6129
|
+
module22.exports = keyring2;
|
|
6130
|
+
}
|
|
6131
|
+
});
|
|
6132
|
+
var require_parse = __commonJS2({
|
|
6133
|
+
"src/parse.js"(exports22, module22) {
|
|
6134
|
+
var decrypt2 = require_decrypt();
|
|
6135
|
+
var keyring2 = require_keyring();
|
|
6136
|
+
var encrypted2 = require_encrypted();
|
|
6137
|
+
var evaluate2 = require_evaluate();
|
|
6138
|
+
var expand2 = require_expand();
|
|
6139
|
+
var scan2 = require_scan();
|
|
6079
6140
|
function resolveEscapeSequences(value) {
|
|
6080
6141
|
return value.replace(/\\\$/g, "$");
|
|
6081
6142
|
}
|
|
@@ -6086,50 +6147,45 @@ var require_dist = __commonJS({
|
|
|
6086
6147
|
function inProcessEnv(name) {
|
|
6087
6148
|
return Object.prototype.hasOwnProperty.call(processEnv2, name);
|
|
6088
6149
|
}
|
|
6089
|
-
let parsed = {};
|
|
6090
6150
|
let publicKeyHex;
|
|
6091
6151
|
let runningParsed = {};
|
|
6092
6152
|
let literals = {};
|
|
6093
|
-
const
|
|
6094
|
-
|
|
6095
|
-
while ((match = LINE.exec(lines)) !== null) {
|
|
6096
|
-
const name = match[1];
|
|
6097
|
-
const value = match[2];
|
|
6098
|
-
const _quote = quote(value);
|
|
6099
|
-
parsed[name] = clean(value, _quote);
|
|
6153
|
+
const { parsed } = scan2(src, ({ name, value, quote }) => {
|
|
6154
|
+
let parsedValue = value;
|
|
6100
6155
|
if (name.startsWith("DOTENV_PUBLIC_KEY")) {
|
|
6101
|
-
publicKeyHex =
|
|
6156
|
+
publicKeyHex = parsedValue;
|
|
6102
6157
|
}
|
|
6103
6158
|
if (!overload && inProcessEnv(name)) {
|
|
6104
|
-
|
|
6159
|
+
parsedValue = processEnv2[name];
|
|
6105
6160
|
}
|
|
6106
6161
|
try {
|
|
6107
|
-
|
|
6162
|
+
parsedValue = decrypt2(ring[publicKeyHex], parsedValue);
|
|
6108
6163
|
} catch (_e) {
|
|
6109
6164
|
}
|
|
6110
|
-
const encryptedPrefixed = encrypted2(
|
|
6165
|
+
const encryptedPrefixed = encrypted2(parsedValue);
|
|
6111
6166
|
let evaled = false;
|
|
6112
|
-
if (!encryptedPrefixed &&
|
|
6113
|
-
const priorEvaled =
|
|
6167
|
+
if (!encryptedPrefixed && quote !== "'" && (!inProcessEnv(name) || processEnv2[name] === parsedValue)) {
|
|
6168
|
+
const priorEvaled = parsedValue;
|
|
6114
6169
|
try {
|
|
6115
|
-
|
|
6170
|
+
parsedValue = evaluate2(priorEvaled, { processEnv: processEnv2, runningParsed });
|
|
6116
6171
|
} catch (_e) {
|
|
6117
6172
|
}
|
|
6118
|
-
if (priorEvaled !==
|
|
6173
|
+
if (priorEvaled !== parsedValue) {
|
|
6119
6174
|
evaled = true;
|
|
6120
6175
|
}
|
|
6121
6176
|
}
|
|
6122
|
-
if (!encryptedPrefixed && !evaled &&
|
|
6123
|
-
|
|
6177
|
+
if (!encryptedPrefixed && !evaled && quote !== "'" && (!processEnv2[name] || overload)) {
|
|
6178
|
+
parsedValue = resolveEscapeSequences(expand2(parsedValue, { processEnv: processEnv2, runningParsed, literals }));
|
|
6124
6179
|
}
|
|
6125
6180
|
if (quote === "'") {
|
|
6126
|
-
literals[name] =
|
|
6181
|
+
literals[name] = parsedValue;
|
|
6127
6182
|
}
|
|
6128
|
-
runningParsed[name] =
|
|
6183
|
+
runningParsed[name] = parsedValue;
|
|
6129
6184
|
if (Object.prototype.hasOwnProperty.call(processEnv2, name) && !overload) {
|
|
6130
6185
|
} else {
|
|
6131
6186
|
}
|
|
6132
|
-
|
|
6187
|
+
return parsedValue;
|
|
6188
|
+
});
|
|
6133
6189
|
return {
|
|
6134
6190
|
parsed
|
|
6135
6191
|
};
|
|
@@ -6139,19 +6195,23 @@ var require_dist = __commonJS({
|
|
|
6139
6195
|
});
|
|
6140
6196
|
var decrypt = require_decrypt();
|
|
6141
6197
|
var derive = require_derive();
|
|
6198
|
+
var encrypt = require_encrypt();
|
|
6142
6199
|
var encrypted = require_encrypted();
|
|
6143
6200
|
var evaluate = require_evaluate();
|
|
6144
6201
|
var expand = require_expand();
|
|
6145
6202
|
var keyring = require_keyring();
|
|
6146
6203
|
var parse2 = require_parse();
|
|
6204
|
+
var scan = require_scan();
|
|
6147
6205
|
module2.exports = {
|
|
6148
6206
|
decrypt,
|
|
6149
6207
|
derive,
|
|
6208
|
+
encrypt,
|
|
6150
6209
|
encrypted,
|
|
6151
6210
|
evaluate,
|
|
6152
6211
|
expand,
|
|
6153
6212
|
keyring,
|
|
6154
|
-
parse: parse2
|
|
6213
|
+
parse: parse2,
|
|
6214
|
+
scan
|
|
6155
6215
|
};
|
|
6156
6216
|
}
|
|
6157
6217
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotenvx/next-env",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "dotenvx drop-in replacement for @next/env",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"prepublishOnly": "npm pack --dry-run"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@dotenvx/primitives": "0.
|
|
26
|
+
"@dotenvx/primitives": "^0.6.0",
|
|
27
27
|
"esbuild": "^0.28.1"
|
|
28
28
|
}
|
|
29
29
|
}
|