@fluid-app/fluid-cli 0.1.727 → 0.1.729
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/bin/fluid.mjs +37 -7
- package/dist/bin/fluid.mjs.map +1 -1
- package/dist/client-DR4F01_p.mjs +2 -0
- package/dist/{hook-BOhhK8ae.mjs → hook-CGb_NRuW.mjs} +4 -4
- package/dist/{hook-BOhhK8ae.mjs.map → hook-CGb_NRuW.mjs.map} +1 -1
- package/dist/index.mjs +3 -3
- package/dist/{profiles-CpG6O9Zi.mjs → profiles-CUTsnD_9.mjs} +126 -126
- package/dist/profiles-CUTsnD_9.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/client-DU__lstz.mjs +0 -2
- package/dist/profiles-CpG6O9Zi.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
3
2
|
import { dirname, join } from "node:path";
|
|
3
|
+
import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { execFile } from "node:child_process";
|
|
6
6
|
import { createServer } from "node:http";
|
|
@@ -22,6 +22,129 @@ function createDefaultConfig() {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
+
//#region src/config/paths.ts
|
|
26
|
+
/**
|
|
27
|
+
* XDG-compliant config directory resolution
|
|
28
|
+
*
|
|
29
|
+
* Priority:
|
|
30
|
+
* 1. FLUID_CONFIG_DIR env var (explicit override)
|
|
31
|
+
* 2. ~/.fluid/ on macOS (convention for CLI tools)
|
|
32
|
+
* 3. %APPDATA%/fluid/ on Windows
|
|
33
|
+
* 4. $XDG_CONFIG_HOME/fluid/ on Linux (XDG spec)
|
|
34
|
+
* 5. ~/.config/fluid/ fallback on Linux
|
|
35
|
+
*/
|
|
36
|
+
function getConfigDir() {
|
|
37
|
+
const envOverride = process.env["FLUID_CONFIG_DIR"];
|
|
38
|
+
if (envOverride) return envOverride;
|
|
39
|
+
if (process.platform === "darwin") return join(homedir(), ".fluid");
|
|
40
|
+
if (process.platform === "win32") return join(process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming"), "fluid");
|
|
41
|
+
const xdgConfig = process.env["XDG_CONFIG_HOME"];
|
|
42
|
+
if (xdgConfig) return join(xdgConfig, "fluid");
|
|
43
|
+
return join(homedir(), ".config", "fluid");
|
|
44
|
+
}
|
|
45
|
+
function getConfigFilePath() {
|
|
46
|
+
return join(getConfigDir(), "config.json");
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/config/strict.ts
|
|
50
|
+
/**
|
|
51
|
+
* Whether this process runs under a host that supplies the base URL and
|
|
52
|
+
* credential through the environment alone. The host sets
|
|
53
|
+
* FLUID_RUNTIME_STRICT_CONFIG=1 on its CLI children; setting it only removes
|
|
54
|
+
* the CLI's config-file authentication, it never adds any.
|
|
55
|
+
*/
|
|
56
|
+
function isStrictConfig() {
|
|
57
|
+
return process.env["FLUID_RUNTIME_STRICT_CONFIG"] === "1";
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/config/config.ts
|
|
61
|
+
/**
|
|
62
|
+
* Read/write config.json with atomic writes and safe defaults
|
|
63
|
+
*/
|
|
64
|
+
/** Under strict config (see {@link isStrictConfig}) stored profiles are dropped; `updateConfig` still sees the stored file. */
|
|
65
|
+
function readConfig() {
|
|
66
|
+
const config = readStoredConfig();
|
|
67
|
+
return isStrictConfig() ? {
|
|
68
|
+
...config,
|
|
69
|
+
activeProfile: null,
|
|
70
|
+
profiles: {}
|
|
71
|
+
} : config;
|
|
72
|
+
}
|
|
73
|
+
/** The config file as stored, including the profiles strict config hides from `readConfig`. */
|
|
74
|
+
function readStoredConfig() {
|
|
75
|
+
const configPath = getConfigFilePath();
|
|
76
|
+
if (!existsSync(configPath)) return createDefaultConfig();
|
|
77
|
+
const raw = readFileSync(configPath, "utf8");
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
parsed = JSON.parse(raw);
|
|
81
|
+
} catch {
|
|
82
|
+
return createDefaultConfig();
|
|
83
|
+
}
|
|
84
|
+
return withDurableWorkspaceAliases({
|
|
85
|
+
...createDefaultConfig(),
|
|
86
|
+
...parsed
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function writeConfig(config) {
|
|
90
|
+
const configPath = getConfigFilePath();
|
|
91
|
+
const dir = dirname(configPath);
|
|
92
|
+
mkdirSync(dir, {
|
|
93
|
+
recursive: true,
|
|
94
|
+
mode: 448
|
|
95
|
+
});
|
|
96
|
+
const tmpPath = join(dir, `.fluid-config-${randomBytes(6).toString("hex")}.tmp`);
|
|
97
|
+
try {
|
|
98
|
+
writeFileSync(tmpPath, JSON.stringify(withDurableWorkspaceAliases(config), null, 2) + "\n", {
|
|
99
|
+
encoding: "utf8",
|
|
100
|
+
mode: 384
|
|
101
|
+
});
|
|
102
|
+
renameSync(tmpPath, configPath);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
try {
|
|
105
|
+
unlinkSync(tmpPath);
|
|
106
|
+
} catch {}
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function workspaceSlug(value) {
|
|
111
|
+
return value.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
112
|
+
}
|
|
113
|
+
function storefrontSlug(value) {
|
|
114
|
+
return workspaceSlug((value.trim().replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").split(/[/?#]/, 1)[0]?.replace(/:\d+$/, "") ?? "").replace(/\.fluid\.app$/i, ""));
|
|
115
|
+
}
|
|
116
|
+
/** Preserve rename history even when `fluid logout` clears the profiles that
|
|
117
|
+
* originally carried it. Derivation on read migrates existing config files;
|
|
118
|
+
* normalization on every write makes the migration durable before profiles
|
|
119
|
+
* are removed. */
|
|
120
|
+
function withDurableWorkspaceAliases(config) {
|
|
121
|
+
const aliases = {};
|
|
122
|
+
const add = (storefront, candidates) => {
|
|
123
|
+
const key = storefrontSlug(storefront);
|
|
124
|
+
if (!key) return;
|
|
125
|
+
const values = new Set(aliases[key] ?? []);
|
|
126
|
+
for (const candidate of candidates) {
|
|
127
|
+
const slug = workspaceSlug(candidate);
|
|
128
|
+
if (slug) values.add(slug);
|
|
129
|
+
}
|
|
130
|
+
if (values.size > 0) aliases[key] = [...values];
|
|
131
|
+
};
|
|
132
|
+
for (const [storefront, candidates] of Object.entries(config.workspaceAliasesByFluidShop ?? {})) {
|
|
133
|
+
if (!Array.isArray(candidates)) continue;
|
|
134
|
+
add(storefront, candidates.filter((candidate) => typeof candidate === "string"));
|
|
135
|
+
}
|
|
136
|
+
for (const profile of Object.values(config.profiles)) if (profile.fluidShop) add(profile.fluidShop, [profile.name, profile.companyName]);
|
|
137
|
+
return Object.keys(aliases).length > 0 || config.workspaceAliasesByFluidShop !== void 0 ? {
|
|
138
|
+
...config,
|
|
139
|
+
workspaceAliasesByFluidShop: aliases
|
|
140
|
+
} : config;
|
|
141
|
+
}
|
|
142
|
+
function updateConfig(updater) {
|
|
143
|
+
const updated = updater(readStoredConfig());
|
|
144
|
+
writeConfig(updated);
|
|
145
|
+
return updated;
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
25
148
|
//#region ../../platform/api-client-core/src/api-error-shape.ts
|
|
26
149
|
/**
|
|
27
150
|
* Narrows a parsed JSON error payload to the envelope contract. Arrays and
|
|
@@ -2039,129 +2162,6 @@ function createKeyringSecureStorage(options) {
|
|
|
2039
2162
|
};
|
|
2040
2163
|
}
|
|
2041
2164
|
//#endregion
|
|
2042
|
-
//#region src/config/paths.ts
|
|
2043
|
-
/**
|
|
2044
|
-
* XDG-compliant config directory resolution
|
|
2045
|
-
*
|
|
2046
|
-
* Priority:
|
|
2047
|
-
* 1. FLUID_CONFIG_DIR env var (explicit override)
|
|
2048
|
-
* 2. ~/.fluid/ on macOS (convention for CLI tools)
|
|
2049
|
-
* 3. %APPDATA%/fluid/ on Windows
|
|
2050
|
-
* 4. $XDG_CONFIG_HOME/fluid/ on Linux (XDG spec)
|
|
2051
|
-
* 5. ~/.config/fluid/ fallback on Linux
|
|
2052
|
-
*/
|
|
2053
|
-
function getConfigDir() {
|
|
2054
|
-
const envOverride = process.env["FLUID_CONFIG_DIR"];
|
|
2055
|
-
if (envOverride) return envOverride;
|
|
2056
|
-
if (process.platform === "darwin") return join(homedir(), ".fluid");
|
|
2057
|
-
if (process.platform === "win32") return join(process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming"), "fluid");
|
|
2058
|
-
const xdgConfig = process.env["XDG_CONFIG_HOME"];
|
|
2059
|
-
if (xdgConfig) return join(xdgConfig, "fluid");
|
|
2060
|
-
return join(homedir(), ".config", "fluid");
|
|
2061
|
-
}
|
|
2062
|
-
function getConfigFilePath() {
|
|
2063
|
-
return join(getConfigDir(), "config.json");
|
|
2064
|
-
}
|
|
2065
|
-
//#endregion
|
|
2066
|
-
//#region src/config/strict.ts
|
|
2067
|
-
/**
|
|
2068
|
-
* Whether this process runs under a host that supplies the base URL and
|
|
2069
|
-
* credential through the environment alone. The host sets
|
|
2070
|
-
* FLUID_RUNTIME_STRICT_CONFIG=1 on its CLI children; setting it only removes
|
|
2071
|
-
* the CLI's config-file authentication, it never adds any.
|
|
2072
|
-
*/
|
|
2073
|
-
function isStrictConfig() {
|
|
2074
|
-
return process.env["FLUID_RUNTIME_STRICT_CONFIG"] === "1";
|
|
2075
|
-
}
|
|
2076
|
-
//#endregion
|
|
2077
|
-
//#region src/config/config.ts
|
|
2078
|
-
/**
|
|
2079
|
-
* Read/write config.json with atomic writes and safe defaults
|
|
2080
|
-
*/
|
|
2081
|
-
/** Under strict config (see {@link isStrictConfig}) stored profiles are dropped; `updateConfig` still sees the stored file. */
|
|
2082
|
-
function readConfig() {
|
|
2083
|
-
const config = readStoredConfig();
|
|
2084
|
-
return isStrictConfig() ? {
|
|
2085
|
-
...config,
|
|
2086
|
-
activeProfile: null,
|
|
2087
|
-
profiles: {}
|
|
2088
|
-
} : config;
|
|
2089
|
-
}
|
|
2090
|
-
/** The config file as stored, including the profiles strict config hides from `readConfig`. */
|
|
2091
|
-
function readStoredConfig() {
|
|
2092
|
-
const configPath = getConfigFilePath();
|
|
2093
|
-
if (!existsSync(configPath)) return createDefaultConfig();
|
|
2094
|
-
const raw = readFileSync(configPath, "utf8");
|
|
2095
|
-
let parsed;
|
|
2096
|
-
try {
|
|
2097
|
-
parsed = JSON.parse(raw);
|
|
2098
|
-
} catch {
|
|
2099
|
-
return createDefaultConfig();
|
|
2100
|
-
}
|
|
2101
|
-
return withDurableWorkspaceAliases({
|
|
2102
|
-
...createDefaultConfig(),
|
|
2103
|
-
...parsed
|
|
2104
|
-
});
|
|
2105
|
-
}
|
|
2106
|
-
function writeConfig(config) {
|
|
2107
|
-
const configPath = getConfigFilePath();
|
|
2108
|
-
const dir = dirname(configPath);
|
|
2109
|
-
mkdirSync(dir, {
|
|
2110
|
-
recursive: true,
|
|
2111
|
-
mode: 448
|
|
2112
|
-
});
|
|
2113
|
-
const tmpPath = join(dir, `.fluid-config-${randomBytes(6).toString("hex")}.tmp`);
|
|
2114
|
-
try {
|
|
2115
|
-
writeFileSync(tmpPath, JSON.stringify(withDurableWorkspaceAliases(config), null, 2) + "\n", {
|
|
2116
|
-
encoding: "utf8",
|
|
2117
|
-
mode: 384
|
|
2118
|
-
});
|
|
2119
|
-
renameSync(tmpPath, configPath);
|
|
2120
|
-
} catch (err) {
|
|
2121
|
-
try {
|
|
2122
|
-
unlinkSync(tmpPath);
|
|
2123
|
-
} catch {}
|
|
2124
|
-
throw err;
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
function workspaceSlug(value) {
|
|
2128
|
-
return value.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
2129
|
-
}
|
|
2130
|
-
function storefrontSlug(value) {
|
|
2131
|
-
return workspaceSlug((value.trim().replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").split(/[/?#]/, 1)[0]?.replace(/:\d+$/, "") ?? "").replace(/\.fluid\.app$/i, ""));
|
|
2132
|
-
}
|
|
2133
|
-
/** Preserve rename history even when `fluid logout` clears the profiles that
|
|
2134
|
-
* originally carried it. Derivation on read migrates existing config files;
|
|
2135
|
-
* normalization on every write makes the migration durable before profiles
|
|
2136
|
-
* are removed. */
|
|
2137
|
-
function withDurableWorkspaceAliases(config) {
|
|
2138
|
-
const aliases = {};
|
|
2139
|
-
const add = (storefront, candidates) => {
|
|
2140
|
-
const key = storefrontSlug(storefront);
|
|
2141
|
-
if (!key) return;
|
|
2142
|
-
const values = new Set(aliases[key] ?? []);
|
|
2143
|
-
for (const candidate of candidates) {
|
|
2144
|
-
const slug = workspaceSlug(candidate);
|
|
2145
|
-
if (slug) values.add(slug);
|
|
2146
|
-
}
|
|
2147
|
-
if (values.size > 0) aliases[key] = [...values];
|
|
2148
|
-
};
|
|
2149
|
-
for (const [storefront, candidates] of Object.entries(config.workspaceAliasesByFluidShop ?? {})) {
|
|
2150
|
-
if (!Array.isArray(candidates)) continue;
|
|
2151
|
-
add(storefront, candidates.filter((candidate) => typeof candidate === "string"));
|
|
2152
|
-
}
|
|
2153
|
-
for (const profile of Object.values(config.profiles)) if (profile.fluidShop) add(profile.fluidShop, [profile.name, profile.companyName]);
|
|
2154
|
-
return Object.keys(aliases).length > 0 || config.workspaceAliasesByFluidShop !== void 0 ? {
|
|
2155
|
-
...config,
|
|
2156
|
-
workspaceAliasesByFluidShop: aliases
|
|
2157
|
-
} : config;
|
|
2158
|
-
}
|
|
2159
|
-
function updateConfig(updater) {
|
|
2160
|
-
const updated = updater(readStoredConfig());
|
|
2161
|
-
writeConfig(updated);
|
|
2162
|
-
return updated;
|
|
2163
|
-
}
|
|
2164
|
-
//#endregion
|
|
2165
2165
|
//#region src/auth/identity/environment.ts
|
|
2166
2166
|
/**
|
|
2167
2167
|
* Which identity service the CLI signs in with, following the API base the
|
|
@@ -2925,6 +2925,6 @@ async function endUnusedSessions(before, after) {
|
|
|
2925
2925
|
return problems;
|
|
2926
2926
|
}
|
|
2927
2927
|
//#endregion
|
|
2928
|
-
export { isClientProfile as A,
|
|
2928
|
+
export { isClientProfile as A, readStoredConfig as C, getConfigDir as D, isStrictConfig as E, getConfigFilePath as O, readConfig as S, writeConfig as T, primeClientProfile as _, peekIdentityToken as a, ApiError as b, sessionFacts as c, OrphanedClientSecretError as d, ProfileExistsError as f, peekClientToken as g, invalidateClientToken as h, isRoleNotGrantedError as i, isIdentityProfile as j, createDefaultConfig as k, signInWithBrowser as l, deleteClientSecret as m, describeIdentityError as n, primeIdentityProfile as o, clientAccessToken as p, identityToken as r, profileAccessToken as s, endUnusedSessions as t, signOutIdentity as u, saveClientProfile as v, updateConfig as w, createFetchClient as x, resolveIdentityUrl as y };
|
|
2929
2929
|
|
|
2930
|
-
//# sourceMappingURL=profiles-
|
|
2930
|
+
//# sourceMappingURL=profiles-CUTsnD_9.mjs.map
|