@insforge/cli 0.1.66 → 0.1.68
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.js +59 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1835,6 +1835,15 @@ async function getJwtSecret() {
|
|
|
1835
1835
|
return null;
|
|
1836
1836
|
}
|
|
1837
1837
|
}
|
|
1838
|
+
async function getDatabaseConnectionString() {
|
|
1839
|
+
try {
|
|
1840
|
+
const res = await ossFetch("/api/metadata/database-connection-string");
|
|
1841
|
+
const data = await res.json();
|
|
1842
|
+
return typeof data.connectionURL === "string" && data.connectionURL.length > 0 ? data.connectionURL : null;
|
|
1843
|
+
} catch {
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1838
1847
|
async function ossFetch(path6, options = {}) {
|
|
1839
1848
|
const config = requireProjectConfig();
|
|
1840
1849
|
const headers = {
|
|
@@ -1892,6 +1901,33 @@ function extractEnvKeys(content) {
|
|
|
1892
1901
|
}
|
|
1893
1902
|
return keys;
|
|
1894
1903
|
}
|
|
1904
|
+
function extractEnvPairs(content) {
|
|
1905
|
+
const out = /* @__PURE__ */ new Map();
|
|
1906
|
+
for (const line of content.split("\n")) {
|
|
1907
|
+
const trimmed = line.replace(/^\s*export\s+/, "").trimStart();
|
|
1908
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
1909
|
+
const m = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/);
|
|
1910
|
+
if (m) out.set(m[1], m[2]);
|
|
1911
|
+
}
|
|
1912
|
+
return out;
|
|
1913
|
+
}
|
|
1914
|
+
function refreshStaleEnvDefaults(existing, manifestDefaults, platformValues) {
|
|
1915
|
+
const refreshed = [];
|
|
1916
|
+
const lines = existing.split("\n").map((line) => {
|
|
1917
|
+
const m = line.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/);
|
|
1918
|
+
if (!m) return line;
|
|
1919
|
+
const key = m[1];
|
|
1920
|
+
const userValue = m[2];
|
|
1921
|
+
const def = manifestDefaults.get(key);
|
|
1922
|
+
const real = platformValues.get(key);
|
|
1923
|
+
if (def !== void 0 && real !== void 0 && userValue === def && real !== def) {
|
|
1924
|
+
refreshed.push(key);
|
|
1925
|
+
return `${key}=${real}`;
|
|
1926
|
+
}
|
|
1927
|
+
return line;
|
|
1928
|
+
});
|
|
1929
|
+
return { updated: lines.join("\n"), refreshed };
|
|
1930
|
+
}
|
|
1895
1931
|
function filterCollidingEnvLines(append, existingKeys) {
|
|
1896
1932
|
const dropped = [];
|
|
1897
1933
|
const out = [];
|
|
@@ -1986,6 +2022,7 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
|
|
|
1986
2022
|
envExampleAppended: false,
|
|
1987
2023
|
envLocalWritten: false,
|
|
1988
2024
|
envKeysSkipped: [],
|
|
2025
|
+
envKeysRefreshed: [],
|
|
1989
2026
|
nextSteps: manifest.nextSteps
|
|
1990
2027
|
};
|
|
1991
2028
|
const allFiles = (await walkFiles(providerDir)).filter((rel) => !PROVIDER_META_FILES.has(rel));
|
|
@@ -2032,8 +2069,11 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
|
|
|
2032
2069
|
const envLocalExists = await pathExists(envLocalPath);
|
|
2033
2070
|
const existingLocal = envLocalExists ? await fs.readFile(envLocalPath, "utf-8") : "";
|
|
2034
2071
|
const existingLocalKeys = envLocalExists ? extractEnvKeys(existingLocal) : /* @__PURE__ */ new Set();
|
|
2035
|
-
const anonKey = await
|
|
2036
|
-
|
|
2072
|
+
const [anonKey, jwtSecret, databaseUrl] = await Promise.all([
|
|
2073
|
+
getAnonKey(),
|
|
2074
|
+
getJwtSecret(),
|
|
2075
|
+
getDatabaseConnectionString()
|
|
2076
|
+
]);
|
|
2037
2077
|
const filled = manifest.envExampleAppend.replace(
|
|
2038
2078
|
/^([A-Z][A-Z0-9_]*=)(.*)$/gm,
|
|
2039
2079
|
(_, prefix, value) => {
|
|
@@ -2043,6 +2083,7 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
|
|
|
2043
2083
|
if (key === "NEXT_PUBLIC_APP_URL") return `${prefix}https://${projectConfig.appkey}.insforge.site`;
|
|
2044
2084
|
if (/JWT_SECRET$/.test(key)) return `${prefix}${jwtSecret ?? value}`;
|
|
2045
2085
|
if (key === "BETTER_AUTH_SECRET") return `${prefix}${randomBytes2(32).toString("hex")}`;
|
|
2086
|
+
if (key === "DATABASE_URL") return `${prefix}${databaseUrl ?? value}`;
|
|
2046
2087
|
return `${prefix}${value}`;
|
|
2047
2088
|
}
|
|
2048
2089
|
);
|
|
@@ -2050,13 +2091,20 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
|
|
|
2050
2091
|
await fs.writeFile(envLocalPath, filled + "\n");
|
|
2051
2092
|
result.envLocalWritten = true;
|
|
2052
2093
|
} else {
|
|
2053
|
-
const
|
|
2094
|
+
const manifestDefaults = extractEnvPairs(manifest.envExampleAppend);
|
|
2095
|
+
const platformValues = extractEnvPairs(filled);
|
|
2096
|
+
const { updated, refreshed } = refreshStaleEnvDefaults(existingLocal, manifestDefaults, platformValues);
|
|
2097
|
+
const refreshedSet = new Set(refreshed);
|
|
2098
|
+
const keysAfterRefresh = /* @__PURE__ */ new Set([...existingLocalKeys, ...refreshedSet]);
|
|
2099
|
+
const { filtered, dropped } = filterCollidingEnvLines(filled, keysAfterRefresh);
|
|
2054
2100
|
const hasNewKey = filtered.split("\n").some((l) => /^[A-Z][A-Z0-9_]*=/.test(l));
|
|
2055
|
-
if (hasNewKey) {
|
|
2056
|
-
|
|
2101
|
+
if (refreshed.length > 0 || hasNewKey) {
|
|
2102
|
+
const base = hasNewKey ? updated.replace(/\n*$/, "\n\n") + filtered + "\n" : updated;
|
|
2103
|
+
await fs.writeFile(envLocalPath, base);
|
|
2057
2104
|
result.envLocalWritten = true;
|
|
2058
2105
|
}
|
|
2059
2106
|
result.envKeysSkipped = Array.from(/* @__PURE__ */ new Set([...result.envKeysSkipped, ...dropped]));
|
|
2107
|
+
result.envKeysRefreshed = Array.from(/* @__PURE__ */ new Set([...result.envKeysRefreshed, ...refreshed]));
|
|
2060
2108
|
}
|
|
2061
2109
|
if (!jwtSecret && !json) {
|
|
2062
2110
|
clack9.log.warn("Could not auto-fill JWT_SECRET \u2014 run `npx @insforge/cli secrets get JWT_SECRET` and paste it into .env.local.");
|
|
@@ -2066,6 +2114,11 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
|
|
|
2066
2114
|
`Kept your existing values for: ${result.envKeysSkipped.join(", ")}. If any of these need the auth-provider's defaults, see .env.example for reference.`
|
|
2067
2115
|
);
|
|
2068
2116
|
}
|
|
2117
|
+
if (result.envKeysRefreshed.length > 0 && !json) {
|
|
2118
|
+
clack9.log.info(
|
|
2119
|
+
`Refreshed stale platform defaults: ${result.envKeysRefreshed.join(", ")}. Your value matched the manifest's default, so we replaced it with the live one.`
|
|
2120
|
+
);
|
|
2121
|
+
}
|
|
2069
2122
|
return result;
|
|
2070
2123
|
} finally {
|
|
2071
2124
|
await cleanup();
|
|
@@ -6776,7 +6829,7 @@ function registerDiagnoseCommands(diagnoseCmd2) {
|
|
|
6776
6829
|
const s = !json ? clack14.spinner() : null;
|
|
6777
6830
|
s?.start("Collecting diagnostic data...");
|
|
6778
6831
|
const data2 = await collectDiagnosticData(projectId, ossMode, apiUrl);
|
|
6779
|
-
const cliVersion = "0.1.
|
|
6832
|
+
const cliVersion = "0.1.68";
|
|
6780
6833
|
s?.stop("Data collected");
|
|
6781
6834
|
if (!json) {
|
|
6782
6835
|
console.log(`
|