@fluid-app/fluid-cli 0.1.668 → 0.1.670
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 +62 -40
- package/dist/bin/fluid.mjs.map +1 -1
- package/dist/{hook-C8GwU1TO.mjs → hook-Cy4Rnvl2.mjs} +315 -136
- package/dist/hook-Cy4Rnvl2.mjs.map +1 -0
- package/dist/index.d.mts +15 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +35 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/hook-C8GwU1TO.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { closeSync, constants, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
2
2
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
3
|
-
import { execFile } from "node:child_process";
|
|
4
|
-
import { createServer } from "node:http";
|
|
5
3
|
import { dirname, isAbsolute, join, sep } from "node:path";
|
|
6
4
|
import { homedir } from "node:os";
|
|
5
|
+
import { execFile } from "node:child_process";
|
|
6
|
+
import { createServer } from "node:http";
|
|
7
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
8
|
//#region src/catalog/annotations.ts
|
|
9
9
|
const ANNOTATION = Symbol.for("@fluid-app/fluid-cli.command-annotation");
|
|
@@ -106,7 +106,7 @@ function filterCatalog(entries, root, prefix) {
|
|
|
106
106
|
}
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region package.json
|
|
109
|
-
var version = "0.1.
|
|
109
|
+
var version = "0.1.670";
|
|
110
110
|
//#endregion
|
|
111
111
|
//#region src/auth/client-headers.ts
|
|
112
112
|
const CLIENT_HEADERS = {
|
|
@@ -662,6 +662,10 @@ async function signup(request) {
|
|
|
662
662
|
function isIdentityProfile(profile) {
|
|
663
663
|
return profile?.auth?.mode === "identity";
|
|
664
664
|
}
|
|
665
|
+
/** Whether a profile signs in with stored client credentials. */
|
|
666
|
+
function isClientProfile(profile) {
|
|
667
|
+
return profile?.auth?.mode === "client";
|
|
668
|
+
}
|
|
665
669
|
function createDefaultConfig() {
|
|
666
670
|
return {
|
|
667
671
|
activeProfile: null,
|
|
@@ -2686,33 +2690,126 @@ function createKeyringSecureStorage(options) {
|
|
|
2686
2690
|
};
|
|
2687
2691
|
}
|
|
2688
2692
|
//#endregion
|
|
2689
|
-
//#region src/
|
|
2693
|
+
//#region src/config/paths.ts
|
|
2690
2694
|
/**
|
|
2691
|
-
*
|
|
2692
|
-
*
|
|
2695
|
+
* XDG-compliant config directory resolution
|
|
2696
|
+
*
|
|
2697
|
+
* Priority:
|
|
2698
|
+
* 1. FLUID_CONFIG_DIR env var (explicit override)
|
|
2699
|
+
* 2. ~/.fluid/ on macOS (convention for CLI tools)
|
|
2700
|
+
* 3. %APPDATA%/fluid/ on Windows
|
|
2701
|
+
* 4. $XDG_CONFIG_HOME/fluid/ on Linux (XDG spec)
|
|
2702
|
+
* 5. ~/.config/fluid/ fallback on Linux
|
|
2693
2703
|
*/
|
|
2694
|
-
function
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2704
|
+
function getConfigDir() {
|
|
2705
|
+
const envOverride = process.env["FLUID_CONFIG_DIR"];
|
|
2706
|
+
if (envOverride) return envOverride;
|
|
2707
|
+
if (process.platform === "darwin") return join(homedir(), ".fluid");
|
|
2708
|
+
if (process.platform === "win32") return join(process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming"), "fluid");
|
|
2709
|
+
const xdgConfig = process.env["XDG_CONFIG_HOME"];
|
|
2710
|
+
if (xdgConfig) return join(xdgConfig, "fluid");
|
|
2711
|
+
return join(homedir(), ".config", "fluid");
|
|
2712
|
+
}
|
|
2713
|
+
function getConfigFilePath() {
|
|
2714
|
+
return join(getConfigDir(), "config.json");
|
|
2715
|
+
}
|
|
2716
|
+
//#endregion
|
|
2717
|
+
//#region src/config/strict.ts
|
|
2718
|
+
/**
|
|
2719
|
+
* Whether this process runs under a host that supplies the base URL and
|
|
2720
|
+
* credential through the environment alone. The host sets
|
|
2721
|
+
* FLUID_RUNTIME_STRICT_CONFIG=1 on its CLI children; setting it only removes
|
|
2722
|
+
* the CLI's config-file authentication, it never adds any.
|
|
2723
|
+
*/
|
|
2724
|
+
function isStrictConfig() {
|
|
2725
|
+
return process.env["FLUID_RUNTIME_STRICT_CONFIG"] === "1";
|
|
2726
|
+
}
|
|
2727
|
+
//#endregion
|
|
2728
|
+
//#region src/config/config.ts
|
|
2729
|
+
/**
|
|
2730
|
+
* Read/write config.json with atomic writes and safe defaults
|
|
2731
|
+
*/
|
|
2732
|
+
/** Under strict config (see {@link isStrictConfig}) stored profiles are dropped; `updateConfig` still sees the stored file. */
|
|
2733
|
+
function readConfig() {
|
|
2734
|
+
const config = readStoredConfig();
|
|
2735
|
+
return isStrictConfig() ? {
|
|
2736
|
+
...config,
|
|
2737
|
+
activeProfile: null,
|
|
2738
|
+
profiles: {}
|
|
2739
|
+
} : config;
|
|
2740
|
+
}
|
|
2741
|
+
function readStoredConfig() {
|
|
2742
|
+
const configPath = getConfigFilePath();
|
|
2743
|
+
if (!existsSync(configPath)) return createDefaultConfig();
|
|
2744
|
+
const raw = readFileSync(configPath, "utf8");
|
|
2745
|
+
let parsed;
|
|
2746
|
+
try {
|
|
2747
|
+
parsed = JSON.parse(raw);
|
|
2748
|
+
} catch {
|
|
2749
|
+
return createDefaultConfig();
|
|
2708
2750
|
}
|
|
2751
|
+
return withDurableWorkspaceAliases({
|
|
2752
|
+
...createDefaultConfig(),
|
|
2753
|
+
...parsed
|
|
2754
|
+
});
|
|
2709
2755
|
}
|
|
2710
|
-
function
|
|
2711
|
-
|
|
2712
|
-
const
|
|
2756
|
+
function writeConfig(config) {
|
|
2757
|
+
const configPath = getConfigFilePath();
|
|
2758
|
+
const dir = dirname(configPath);
|
|
2759
|
+
mkdirSync(dir, {
|
|
2760
|
+
recursive: true,
|
|
2761
|
+
mode: 448
|
|
2762
|
+
});
|
|
2763
|
+
const tmpPath = join(dir, `.fluid-config-${randomBytes(6).toString("hex")}.tmp`);
|
|
2713
2764
|
try {
|
|
2714
|
-
|
|
2715
|
-
|
|
2765
|
+
writeFileSync(tmpPath, JSON.stringify(withDurableWorkspaceAliases(config), null, 2) + "\n", {
|
|
2766
|
+
encoding: "utf8",
|
|
2767
|
+
mode: 384
|
|
2768
|
+
});
|
|
2769
|
+
renameSync(tmpPath, configPath);
|
|
2770
|
+
} catch (err) {
|
|
2771
|
+
try {
|
|
2772
|
+
unlinkSync(tmpPath);
|
|
2773
|
+
} catch {}
|
|
2774
|
+
throw err;
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
function workspaceSlug(value) {
|
|
2778
|
+
return value.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
2779
|
+
}
|
|
2780
|
+
function storefrontSlug(value) {
|
|
2781
|
+
return workspaceSlug((value.trim().replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").split(/[/?#]/, 1)[0]?.replace(/:\d+$/, "") ?? "").replace(/\.fluid\.app$/i, ""));
|
|
2782
|
+
}
|
|
2783
|
+
/** Preserve rename history even when `fluid logout` clears the profiles that
|
|
2784
|
+
* originally carried it. Derivation on read migrates existing config files;
|
|
2785
|
+
* normalization on every write makes the migration durable before profiles
|
|
2786
|
+
* are removed. */
|
|
2787
|
+
function withDurableWorkspaceAliases(config) {
|
|
2788
|
+
const aliases = {};
|
|
2789
|
+
const add = (storefront, candidates) => {
|
|
2790
|
+
const key = storefrontSlug(storefront);
|
|
2791
|
+
if (!key) return;
|
|
2792
|
+
const values = new Set(aliases[key] ?? []);
|
|
2793
|
+
for (const candidate of candidates) {
|
|
2794
|
+
const slug = workspaceSlug(candidate);
|
|
2795
|
+
if (slug) values.add(slug);
|
|
2796
|
+
}
|
|
2797
|
+
if (values.size > 0) aliases[key] = [...values];
|
|
2798
|
+
};
|
|
2799
|
+
for (const [storefront, candidates] of Object.entries(config.workspaceAliasesByFluidShop ?? {})) {
|
|
2800
|
+
if (!Array.isArray(candidates)) continue;
|
|
2801
|
+
add(storefront, candidates.filter((candidate) => typeof candidate === "string"));
|
|
2802
|
+
}
|
|
2803
|
+
for (const profile of Object.values(config.profiles)) if (profile.fluidShop) add(profile.fluidShop, [profile.name, profile.companyName]);
|
|
2804
|
+
return Object.keys(aliases).length > 0 || config.workspaceAliasesByFluidShop !== void 0 ? {
|
|
2805
|
+
...config,
|
|
2806
|
+
workspaceAliasesByFluidShop: aliases
|
|
2807
|
+
} : config;
|
|
2808
|
+
}
|
|
2809
|
+
function updateConfig(updater) {
|
|
2810
|
+
const updated = updater(readStoredConfig());
|
|
2811
|
+
writeConfig(updated);
|
|
2812
|
+
return updated;
|
|
2716
2813
|
}
|
|
2717
2814
|
//#endregion
|
|
2718
2815
|
//#region src/auth/identity/environment.ts
|
|
@@ -2783,6 +2880,152 @@ function loadKeyringStorage() {
|
|
|
2783
2880
|
});
|
|
2784
2881
|
return loaded;
|
|
2785
2882
|
}
|
|
2883
|
+
let deps$1 = {
|
|
2884
|
+
storage: loadKeyringStorage,
|
|
2885
|
+
now: Date.now
|
|
2886
|
+
};
|
|
2887
|
+
const EXPIRY_MARGIN_MS$1 = 3e4;
|
|
2888
|
+
const REFRESH_RETRY_MS = 15e3;
|
|
2889
|
+
const held = /* @__PURE__ */ new Map();
|
|
2890
|
+
const pending = /* @__PURE__ */ new Map();
|
|
2891
|
+
const refreshTimers$1 = /* @__PURE__ */ new Map();
|
|
2892
|
+
function cacheKey(auth) {
|
|
2893
|
+
return `${auth.identityUrl} ${auth.storageKey}`;
|
|
2894
|
+
}
|
|
2895
|
+
/**
|
|
2896
|
+
* Drops a profile's held token so the next read asks the identity service
|
|
2897
|
+
* again. With `sent`, only when the held token is that one, so a late 401 for
|
|
2898
|
+
* an older token leaves a newer one alone.
|
|
2899
|
+
*/
|
|
2900
|
+
function invalidateClientToken(profile, sent) {
|
|
2901
|
+
const key = cacheKey(profile.auth);
|
|
2902
|
+
if (sent !== void 0 && held.get(key)?.token !== sent) return;
|
|
2903
|
+
held.delete(key);
|
|
2904
|
+
}
|
|
2905
|
+
async function requestToken(auth) {
|
|
2906
|
+
const secret = await (await deps$1.storage()).get(auth.storageKey);
|
|
2907
|
+
if (!secret) throw new SessionError("not_signed_in", "The client secret for this profile is not in the credential store.");
|
|
2908
|
+
const basic = Buffer.from(`${auth.clientId}:${secret}`).toString("base64");
|
|
2909
|
+
const response = await (deps$1.fetch ?? fetch)(`${auth.identityUrl.replace(/\/$/, "")}/token`, {
|
|
2910
|
+
method: "POST",
|
|
2911
|
+
headers: {
|
|
2912
|
+
Authorization: `Basic ${basic}`,
|
|
2913
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
2914
|
+
Accept: "application/json"
|
|
2915
|
+
},
|
|
2916
|
+
body: new URLSearchParams({
|
|
2917
|
+
grant_type: "client_credentials",
|
|
2918
|
+
resource: auth.org
|
|
2919
|
+
}).toString()
|
|
2920
|
+
}).catch(() => {
|
|
2921
|
+
throw new SessionError("temporarily_unavailable", "The identity service could not be reached.");
|
|
2922
|
+
});
|
|
2923
|
+
if (response.status >= 500 || response.status === 429) throw new SessionError("temporarily_unavailable", "The identity service is unavailable.");
|
|
2924
|
+
if (!response.ok) throw new SessionError("access_denied", "The identity service refused this client's credentials.");
|
|
2925
|
+
const body = await response.json().catch(() => null);
|
|
2926
|
+
if (typeof body?.access_token !== "string" || !body.access_token) throw new SessionError("temporarily_unavailable", "The identity service answered with no access token.");
|
|
2927
|
+
const seconds = typeof body.expires_in === "number" ? body.expires_in : 300;
|
|
2928
|
+
return {
|
|
2929
|
+
token: body.access_token,
|
|
2930
|
+
expiresAt: deps$1.now() + seconds * 1e3
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2933
|
+
async function refresh(profile) {
|
|
2934
|
+
const key = cacheKey(profile.auth);
|
|
2935
|
+
let request = pending.get(key);
|
|
2936
|
+
if (!request) {
|
|
2937
|
+
request = requestToken(profile.auth).finally(() => pending.delete(key));
|
|
2938
|
+
pending.set(key, request);
|
|
2939
|
+
}
|
|
2940
|
+
const fresh = await request;
|
|
2941
|
+
held.set(key, fresh);
|
|
2942
|
+
return fresh;
|
|
2943
|
+
}
|
|
2944
|
+
/** The profile's current access token, requesting a new one when none is held or it is near expiry. */
|
|
2945
|
+
async function clientAccessToken(profile) {
|
|
2946
|
+
const existing = held.get(cacheKey(profile.auth));
|
|
2947
|
+
if (existing && deps$1.now() < existing.expiresAt - EXPIRY_MARGIN_MS$1) return existing.token;
|
|
2948
|
+
return (await refresh(profile)).token;
|
|
2949
|
+
}
|
|
2950
|
+
const REFUSAL_CODES = ["access_denied", "not_signed_in"];
|
|
2951
|
+
function isRefusal(error) {
|
|
2952
|
+
return error instanceof SessionError && REFUSAL_CODES.includes(error.code);
|
|
2953
|
+
}
|
|
2954
|
+
function scheduleRefresh(profile, delay) {
|
|
2955
|
+
const key = cacheKey(profile.auth);
|
|
2956
|
+
clearTimeout(refreshTimers$1.get(key));
|
|
2957
|
+
const timer = setTimeout(() => {
|
|
2958
|
+
refreshTimers$1.delete(key);
|
|
2959
|
+
refresh(profile).then((fresh) => {
|
|
2960
|
+
scheduleRefresh(profile, nextRefreshDelay(fresh.expiresAt));
|
|
2961
|
+
}, (error) => {
|
|
2962
|
+
if (!isRefusal(error)) scheduleRefresh(profile, REFRESH_RETRY_MS);
|
|
2963
|
+
});
|
|
2964
|
+
}, delay);
|
|
2965
|
+
timer.unref();
|
|
2966
|
+
refreshTimers$1.set(key, timer);
|
|
2967
|
+
}
|
|
2968
|
+
function nextRefreshDelay(expiresAt) {
|
|
2969
|
+
return Math.max(expiresAt - deps$1.now() - 2 * EXPIRY_MARGIN_MS$1, 5e3);
|
|
2970
|
+
}
|
|
2971
|
+
/**
|
|
2972
|
+
* Gets a token before a command runs and keeps it current for a long-running
|
|
2973
|
+
* one by asking again shortly before it expires. A failed refresh keeps the
|
|
2974
|
+
* held token until it expires and is retried unless the identity service
|
|
2975
|
+
* refused the credentials or the secret is missing. The timer never keeps the
|
|
2976
|
+
* process alive.
|
|
2977
|
+
*/
|
|
2978
|
+
async function primeClientProfile(profile) {
|
|
2979
|
+
try {
|
|
2980
|
+
await clientAccessToken(profile);
|
|
2981
|
+
} catch (error) {
|
|
2982
|
+
if (!isRefusal(error)) scheduleRefresh(profile, REFRESH_RETRY_MS);
|
|
2983
|
+
throw error;
|
|
2984
|
+
}
|
|
2985
|
+
const current = held.get(cacheKey(profile.auth));
|
|
2986
|
+
if (!current) return;
|
|
2987
|
+
scheduleRefresh(profile, nextRefreshDelay(current.expiresAt));
|
|
2988
|
+
}
|
|
2989
|
+
/** The held token while still current, for synchronous readers. */
|
|
2990
|
+
function peekClientToken(profile) {
|
|
2991
|
+
const existing = held.get(cacheKey(profile.auth));
|
|
2992
|
+
if (!existing || deps$1.now() >= existing.expiresAt - EXPIRY_MARGIN_MS$1) return null;
|
|
2993
|
+
return existing.token;
|
|
2994
|
+
}
|
|
2995
|
+
/** Deletes a client secret from the credential store. */
|
|
2996
|
+
async function deleteClientSecret(auth) {
|
|
2997
|
+
held.delete(cacheKey(auth));
|
|
2998
|
+
await (await deps$1.storage()).delete(auth.storageKey);
|
|
2999
|
+
}
|
|
3000
|
+
//#endregion
|
|
3001
|
+
//#region src/auth/identity/browser.ts
|
|
3002
|
+
/**
|
|
3003
|
+
* Opens a URL in the user's default browser. Best effort: the sign-in URL is
|
|
3004
|
+
* always printed too, for a terminal with no browser to open.
|
|
3005
|
+
*/
|
|
3006
|
+
function opener(url) {
|
|
3007
|
+
switch (process.platform) {
|
|
3008
|
+
case "darwin": return {
|
|
3009
|
+
command: "open",
|
|
3010
|
+
args: [url]
|
|
3011
|
+
};
|
|
3012
|
+
case "win32": return {
|
|
3013
|
+
command: "rundll32",
|
|
3014
|
+
args: ["url.dll,FileProtocolHandler", url]
|
|
3015
|
+
};
|
|
3016
|
+
default: return {
|
|
3017
|
+
command: "xdg-open",
|
|
3018
|
+
args: [url]
|
|
3019
|
+
};
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
function openBrowser(url) {
|
|
3023
|
+
if (process.env["FLUID_NO_BROWSER"]) return;
|
|
3024
|
+
const launch = opener(url);
|
|
3025
|
+
try {
|
|
3026
|
+
execFile(launch.command, launch.args, () => void 0);
|
|
3027
|
+
} catch {}
|
|
3028
|
+
}
|
|
2786
3029
|
//#endregion
|
|
2787
3030
|
//#region src/auth/identity/loopback.ts
|
|
2788
3031
|
/**
|
|
@@ -3202,126 +3445,59 @@ function describeIdentityError(error) {
|
|
|
3202
3445
|
return error instanceof Error ? error.message : String(error);
|
|
3203
3446
|
}
|
|
3204
3447
|
//#endregion
|
|
3205
|
-
//#region src/
|
|
3448
|
+
//#region src/auth/identity/profiles.ts
|
|
3206
3449
|
/**
|
|
3207
|
-
*
|
|
3450
|
+
* Ending identity sessions when the profiles that use them go away.
|
|
3208
3451
|
*
|
|
3209
|
-
*
|
|
3210
|
-
*
|
|
3211
|
-
*
|
|
3212
|
-
* 3. %APPDATA%/fluid/ on Windows
|
|
3213
|
-
* 4. $XDG_CONFIG_HOME/fluid/ on Linux (XDG spec)
|
|
3214
|
-
* 5. ~/.config/fluid/ fallback on Linux
|
|
3452
|
+
* `fluid switch` gives each company its own profile, and in identity mode
|
|
3453
|
+
* those profiles share the session they were switched from. A session is
|
|
3454
|
+
* revoked only once no profile is left that uses it.
|
|
3215
3455
|
*/
|
|
3216
|
-
function
|
|
3217
|
-
const
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
return
|
|
3224
|
-
}
|
|
3225
|
-
function getConfigFilePath() {
|
|
3226
|
-
return join(getConfigDir(), "config.json");
|
|
3456
|
+
function sessionsIn(config) {
|
|
3457
|
+
const found = /* @__PURE__ */ new Map();
|
|
3458
|
+
for (const profile of Object.values(config.profiles)) {
|
|
3459
|
+
if (!isIdentityProfile(profile)) continue;
|
|
3460
|
+
const { auth } = profile;
|
|
3461
|
+
found.set(`${auth.identityUrl} ${auth.storageKey}`, auth);
|
|
3462
|
+
}
|
|
3463
|
+
return found;
|
|
3227
3464
|
}
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
*/
|
|
3236
|
-
function isStrictConfig() {
|
|
3237
|
-
return process.env["FLUID_RUNTIME_STRICT_CONFIG"] === "1";
|
|
3465
|
+
function clientsIn(config) {
|
|
3466
|
+
const found = /* @__PURE__ */ new Map();
|
|
3467
|
+
for (const profile of Object.values(config.profiles)) {
|
|
3468
|
+
if (!isClientProfile(profile)) continue;
|
|
3469
|
+
found.set(profile.auth.storageKey, profile.auth);
|
|
3470
|
+
}
|
|
3471
|
+
return found;
|
|
3238
3472
|
}
|
|
3239
|
-
//#endregion
|
|
3240
|
-
//#region src/config/config.ts
|
|
3241
3473
|
/**
|
|
3242
|
-
*
|
|
3474
|
+
* Revokes every identity session `before` used that `after` no longer does,
|
|
3475
|
+
* and deletes its refresh token from the credential store, and deletes the
|
|
3476
|
+
* secret of every client profile `before` had that `after` no longer does.
|
|
3477
|
+
* Resolves with a
|
|
3478
|
+
* message for each session that could not be ended cleanly; never rejects.
|
|
3243
3479
|
*/
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
const
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
activeProfile: null,
|
|
3250
|
-
profiles: {}
|
|
3251
|
-
} : config;
|
|
3252
|
-
}
|
|
3253
|
-
function readStoredConfig() {
|
|
3254
|
-
const configPath = getConfigFilePath();
|
|
3255
|
-
if (!existsSync(configPath)) return createDefaultConfig();
|
|
3256
|
-
const raw = readFileSync(configPath, "utf8");
|
|
3257
|
-
let parsed;
|
|
3258
|
-
try {
|
|
3259
|
-
parsed = JSON.parse(raw);
|
|
3260
|
-
} catch {
|
|
3261
|
-
return createDefaultConfig();
|
|
3262
|
-
}
|
|
3263
|
-
return withDurableWorkspaceAliases({
|
|
3264
|
-
...createDefaultConfig(),
|
|
3265
|
-
...parsed
|
|
3266
|
-
});
|
|
3267
|
-
}
|
|
3268
|
-
function writeConfig(config) {
|
|
3269
|
-
const configPath = getConfigFilePath();
|
|
3270
|
-
const dir = dirname(configPath);
|
|
3271
|
-
mkdirSync(dir, {
|
|
3272
|
-
recursive: true,
|
|
3273
|
-
mode: 448
|
|
3274
|
-
});
|
|
3275
|
-
const tmpPath = join(dir, `.fluid-config-${randomBytes(6).toString("hex")}.tmp`);
|
|
3276
|
-
try {
|
|
3277
|
-
writeFileSync(tmpPath, JSON.stringify(withDurableWorkspaceAliases(config), null, 2) + "\n", {
|
|
3278
|
-
encoding: "utf8",
|
|
3279
|
-
mode: 384
|
|
3280
|
-
});
|
|
3281
|
-
renameSync(tmpPath, configPath);
|
|
3282
|
-
} catch (err) {
|
|
3480
|
+
async function endUnusedSessions(before, after) {
|
|
3481
|
+
const remaining = sessionsIn(after);
|
|
3482
|
+
const problems = [];
|
|
3483
|
+
for (const [key, auth] of sessionsIn(before)) {
|
|
3484
|
+
if (remaining.has(key)) continue;
|
|
3283
3485
|
try {
|
|
3284
|
-
|
|
3285
|
-
} catch {
|
|
3286
|
-
|
|
3486
|
+
await signOutIdentity(auth);
|
|
3487
|
+
} catch (error) {
|
|
3488
|
+
problems.push(describeIdentityError(error));
|
|
3489
|
+
}
|
|
3287
3490
|
}
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
/** Preserve rename history even when `fluid logout` clears the profiles that
|
|
3296
|
-
* originally carried it. Derivation on read migrates existing config files;
|
|
3297
|
-
* normalization on every write makes the migration durable before profiles
|
|
3298
|
-
* are removed. */
|
|
3299
|
-
function withDurableWorkspaceAliases(config) {
|
|
3300
|
-
const aliases = {};
|
|
3301
|
-
const add = (storefront, candidates) => {
|
|
3302
|
-
const key = storefrontSlug(storefront);
|
|
3303
|
-
if (!key) return;
|
|
3304
|
-
const values = new Set(aliases[key] ?? []);
|
|
3305
|
-
for (const candidate of candidates) {
|
|
3306
|
-
const slug = workspaceSlug(candidate);
|
|
3307
|
-
if (slug) values.add(slug);
|
|
3491
|
+
const remainingClients = clientsIn(after);
|
|
3492
|
+
for (const [key, auth] of clientsIn(before)) {
|
|
3493
|
+
if (remainingClients.has(key)) continue;
|
|
3494
|
+
try {
|
|
3495
|
+
await deleteClientSecret(auth);
|
|
3496
|
+
} catch (error) {
|
|
3497
|
+
problems.push(describeIdentityError(error));
|
|
3308
3498
|
}
|
|
3309
|
-
if (values.size > 0) aliases[key] = [...values];
|
|
3310
|
-
};
|
|
3311
|
-
for (const [storefront, candidates] of Object.entries(config.workspaceAliasesByFluidShop ?? {})) {
|
|
3312
|
-
if (!Array.isArray(candidates)) continue;
|
|
3313
|
-
add(storefront, candidates.filter((candidate) => typeof candidate === "string"));
|
|
3314
3499
|
}
|
|
3315
|
-
|
|
3316
|
-
return Object.keys(aliases).length > 0 || config.workspaceAliasesByFluidShop !== void 0 ? {
|
|
3317
|
-
...config,
|
|
3318
|
-
workspaceAliasesByFluidShop: aliases
|
|
3319
|
-
} : config;
|
|
3320
|
-
}
|
|
3321
|
-
function updateConfig(updater) {
|
|
3322
|
-
const updated = updater(readStoredConfig());
|
|
3323
|
-
writeConfig(updated);
|
|
3324
|
-
return updated;
|
|
3500
|
+
return problems;
|
|
3325
3501
|
}
|
|
3326
3502
|
//#endregion
|
|
3327
3503
|
//#region src/config/project-config.ts
|
|
@@ -3445,6 +3621,7 @@ function getAuthToken(profileName) {
|
|
|
3445
3621
|
if (!source) return null;
|
|
3446
3622
|
if (source.kind === "token") return source.token;
|
|
3447
3623
|
if (isIdentityProfile(source.profile)) return peekIdentityToken(source.profile.name);
|
|
3624
|
+
if (isClientProfile(source.profile)) return peekClientToken(source.profile);
|
|
3448
3625
|
return source.profile.token ?? null;
|
|
3449
3626
|
}
|
|
3450
3627
|
/**
|
|
@@ -3457,6 +3634,7 @@ async function getAuthTokenAsync(profileName) {
|
|
|
3457
3634
|
if (!source) return null;
|
|
3458
3635
|
if (source.kind === "token") return source.token;
|
|
3459
3636
|
if (isIdentityProfile(source.profile)) return profileAccessToken(source.profile);
|
|
3637
|
+
if (isClientProfile(source.profile)) return clientAccessToken(source.profile);
|
|
3460
3638
|
return source.profile.token ?? null;
|
|
3461
3639
|
}
|
|
3462
3640
|
/**
|
|
@@ -3478,6 +3656,7 @@ async function getRoleAuthTokenAsync(roles, profileName) {
|
|
|
3478
3656
|
if (!source) return null;
|
|
3479
3657
|
if (source.kind === "token") return source.token;
|
|
3480
3658
|
if (isIdentityProfile(source.profile)) return profileAccessToken(source.profile, roles);
|
|
3659
|
+
if (isClientProfile(source.profile)) return clientAccessToken(source.profile);
|
|
3481
3660
|
return source.profile.token ?? null;
|
|
3482
3661
|
}
|
|
3483
3662
|
/**
|
|
@@ -3950,6 +4129,6 @@ function exitOnInputsError(error, io = processIo) {
|
|
|
3950
4129
|
io.exit(64);
|
|
3951
4130
|
}
|
|
3952
4131
|
//#endregion
|
|
3953
|
-
export {
|
|
4132
|
+
export { sendMfa as $, signInWithBrowser as A, getConfigDir as B, endUnusedSessions as C, primeIdentityProfile as D, isRoleNotGrantedError as E, resolveIdentityUrl as F, isClientProfile as G, ApiError as H, readConfig as I, SIGNUP_ERROR as J, isIdentityProfile as K, updateConfig as L, clientAccessToken as M, invalidateClientToken as N, profileAccessToken as O, primeClientProfile as P, redeemIdentityLink as Q, writeConfig as R, findProjectConfig as S, identityToken as T, createFetchClient as U, getConfigFilePath as V, createDefaultConfig as W, fetchUserCompanies as X, confirmMfa as Y, getFluidApiBase as Z, getAuthToken as _, rootCommand as _t, INPUTS_UNDECLARED_CODE as a, isError as at, listProfileNames as b, walkCommands as bt, inputsModeActive as c, isSuccess as ct, setActiveSnapshot as d, success as dt, signup as et, inInternalRead as f, tryCatch as ft, getActiveProfile as g, filterCatalog as gt, declareInputs as h, unwrapOr as ht, INPUTS_MODE_ENV as i, getErrorMessage$1 as it, signOutIdentity as j, sessionFacts as k, registerInputsHook as l, mapError as lt, withInternalReadsAsync as m, unwrap as mt, INPUTS_MISMATCH_CODE as n, validateToken as nt, INPUTS_UNDECLARED_EXIT as o, isFailure as ot, withInternalReads as p, tryCatchAsync as pt, FLUID_API_ERROR as q, INPUTS_MISMATCH_EXIT as r, failure as rt, exitOnInputsError as s, isNodeError as st, INPUTS_EXPECT_ENV as t, switchCompany as tt, createInputsReader as u, mapResult as ut, getAuthTokenAsync as v, visibleOptions as vt, describeIdentityError as w, resolveCredentialSource as x, describeCommand as xt, getRoleAuthTokenAsync as y, visibleSubcommands as yt, isStrictConfig as z };
|
|
3954
4133
|
|
|
3955
|
-
//# sourceMappingURL=hook-
|
|
4134
|
+
//# sourceMappingURL=hook-Cy4Rnvl2.mjs.map
|