morphix-env 0.4.1 → 0.5.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/cli.js +15 -9
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -78,7 +78,11 @@ function getInfisicalConfig() {
|
|
|
78
78
|
siteUrl: process.env.INFISICAL_SITE_URL
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
function applyPrefix(key, prefix) {
|
|
82
|
+
if (!prefix) return key;
|
|
83
|
+
return key.startsWith(prefix) ? key : prefix + key;
|
|
84
|
+
}
|
|
85
|
+
async function fetchInfisicalSecrets(config, envPrefix) {
|
|
82
86
|
const client = new import_sdk.InfisicalSDK({
|
|
83
87
|
...config.siteUrl ? { siteUrl: config.siteUrl } : {}
|
|
84
88
|
});
|
|
@@ -96,7 +100,8 @@ async function fetchInfisicalSecrets(config) {
|
|
|
96
100
|
viewSecretValue: true
|
|
97
101
|
});
|
|
98
102
|
for (const secret of result.secrets) {
|
|
99
|
-
|
|
103
|
+
const key = applyPrefix(secret.secretKey, envPrefix);
|
|
104
|
+
process.env[key] = secret.secretValue;
|
|
100
105
|
count++;
|
|
101
106
|
}
|
|
102
107
|
}
|
|
@@ -119,7 +124,7 @@ function readInfisicalJson() {
|
|
|
119
124
|
return {};
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
|
-
function fetchSecretsViaCLI(environment, paths) {
|
|
127
|
+
function fetchSecretsViaCLI(environment, paths, envPrefix) {
|
|
123
128
|
let count = 0;
|
|
124
129
|
for (const secretPath of paths) {
|
|
125
130
|
try {
|
|
@@ -129,7 +134,7 @@ function fetchSecretsViaCLI(environment, paths) {
|
|
|
129
134
|
);
|
|
130
135
|
const vars = (0, import_dotenv2.parse)(output);
|
|
131
136
|
for (const [key, value] of Object.entries(vars)) {
|
|
132
|
-
process.env[key] = value;
|
|
137
|
+
process.env[applyPrefix(key, envPrefix)] = value;
|
|
133
138
|
count++;
|
|
134
139
|
}
|
|
135
140
|
} catch {
|
|
@@ -157,7 +162,7 @@ function loadConfig() {
|
|
|
157
162
|
var import_cross_spawn = __toESM(require("cross-spawn"));
|
|
158
163
|
var import_fs4 = require("fs");
|
|
159
164
|
var import_path4 = require("path");
|
|
160
|
-
var VERSION = "0.
|
|
165
|
+
var VERSION = "0.5.0";
|
|
161
166
|
var DEFAULT_ENV_FILE = ".env.local";
|
|
162
167
|
function parseArgs(argv) {
|
|
163
168
|
const args = {
|
|
@@ -232,18 +237,19 @@ async function loadAllEnv(args, config) {
|
|
|
232
237
|
paths,
|
|
233
238
|
siteUrl: config.infisical.siteUrl
|
|
234
239
|
} : getInfisicalConfig();
|
|
240
|
+
const envPrefix = config.infisical?.envPrefix;
|
|
235
241
|
if (infisicalConfig && infisicalConfig.clientId && infisicalConfig.clientSecret) {
|
|
236
242
|
try {
|
|
237
|
-
const count = await fetchInfisicalSecrets(infisicalConfig);
|
|
238
|
-
console.log(`[morphix-env] Infisical SDK: loaded ${count} secrets (${env}: ${paths.join(", ")})`);
|
|
243
|
+
const count = await fetchInfisicalSecrets(infisicalConfig, envPrefix);
|
|
244
|
+
console.log(`[morphix-env] Infisical SDK: loaded ${count} secrets (${env}: ${paths.join(", ")})${envPrefix ? ` [prefix: ${envPrefix}]` : ""}`);
|
|
239
245
|
} catch (e) {
|
|
240
246
|
console.warn(`[morphix-env] Infisical SDK: failed - ${e.message}`);
|
|
241
247
|
}
|
|
242
248
|
} else if (hasInfisicalCLI()) {
|
|
243
249
|
try {
|
|
244
|
-
const count = fetchSecretsViaCLI(env, paths);
|
|
250
|
+
const count = fetchSecretsViaCLI(env, paths, envPrefix);
|
|
245
251
|
if (count > 0) {
|
|
246
|
-
console.log(`[morphix-env] Infisical CLI: loaded ${count} secrets (${env}: ${paths.join(", ")})`);
|
|
252
|
+
console.log(`[morphix-env] Infisical CLI: loaded ${count} secrets (${env}: ${paths.join(", ")})${envPrefix ? ` [prefix: ${envPrefix}]` : ""}`);
|
|
247
253
|
} else {
|
|
248
254
|
console.log(`[morphix-env] Infisical CLI: no secrets found (run 'infisical login' first?)`);
|
|
249
255
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "morphix-env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Environment variable toolkit — Infisical integration, local overrides, and client-side runtime injection for Next.js / Vite / Express.",
|
|
5
5
|
"author": "MorphixAI <dev@morphixai.com>",
|
|
6
6
|
"homepage": "https://github.com/Morphicai/morphix-env#readme",
|