@wlfi-agent/cli 1.4.18 → 1.4.19
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.cjs +93 -4
- package/dist/cli.cjs.map +1 -1
- package/package.json +1 -1
- package/src/lib/admin-reset.ts +86 -3
- package/src/lib/admin-setup.ts +39 -0
package/dist/cli.cjs
CHANGED
|
@@ -23941,6 +23941,17 @@ var sudoSession = createSudoSession({
|
|
|
23941
23941
|
"macOS admin password for sudo"
|
|
23942
23942
|
)
|
|
23943
23943
|
});
|
|
23944
|
+
function isSudoWrappedInvocation() {
|
|
23945
|
+
return typeof process.geteuid === "function" && process.geteuid() === 0 && typeof process.env.SUDO_UID === "string" && process.env.SUDO_UID.trim().length > 0;
|
|
23946
|
+
}
|
|
23947
|
+
function assertNotInvokedViaSudo(commandName) {
|
|
23948
|
+
if (!isSudoWrappedInvocation()) {
|
|
23949
|
+
return;
|
|
23950
|
+
}
|
|
23951
|
+
throw new Error(
|
|
23952
|
+
`run \`wlfi-agent ${commandName}\` as your normal macOS user, not with sudo; the CLI prompts for sudo internally and running it as root can target the wrong local WLFI home`
|
|
23953
|
+
);
|
|
23954
|
+
}
|
|
23944
23955
|
function createProgress(message, enabled = true) {
|
|
23945
23956
|
if (!enabled) {
|
|
23946
23957
|
return {
|
|
@@ -23998,6 +24009,43 @@ function print(payload, asJson) {
|
|
|
23998
24009
|
}
|
|
23999
24010
|
console.dir(payload, { depth: null, colors: process.stdout.isTTY });
|
|
24000
24011
|
}
|
|
24012
|
+
async function managedPathExists(targetPath) {
|
|
24013
|
+
const result = await sudoSession.run(["/bin/test", "-e", targetPath]);
|
|
24014
|
+
if (result.code === 0) {
|
|
24015
|
+
return true;
|
|
24016
|
+
}
|
|
24017
|
+
if (result.code === 1 && !/password is required|try again|authentication failed|sorry/iu.test(result.stderr)) {
|
|
24018
|
+
return false;
|
|
24019
|
+
}
|
|
24020
|
+
throw new Error(
|
|
24021
|
+
result.stderr.trim() || result.stdout.trim() || `failed to inspect managed path '${targetPath}' (exit code ${result.code})`
|
|
24022
|
+
);
|
|
24023
|
+
}
|
|
24024
|
+
async function assertManagedUninstallArtifactsRemoved(targetPaths) {
|
|
24025
|
+
const remaining = [];
|
|
24026
|
+
for (const targetPath of targetPaths) {
|
|
24027
|
+
if (await managedPathExists(targetPath)) {
|
|
24028
|
+
remaining.push(targetPath);
|
|
24029
|
+
}
|
|
24030
|
+
}
|
|
24031
|
+
if (remaining.length > 0) {
|
|
24032
|
+
throw new Error(
|
|
24033
|
+
`admin uninstall left managed root-owned files behind: ${remaining.join(", ")}`
|
|
24034
|
+
);
|
|
24035
|
+
}
|
|
24036
|
+
}
|
|
24037
|
+
function assertLocalUninstallArtifactsRemoved(result) {
|
|
24038
|
+
const remaining = [];
|
|
24039
|
+
if (result.config.existed && import_node_fs6.default.existsSync(result.config.path)) {
|
|
24040
|
+
remaining.push(result.config.path);
|
|
24041
|
+
}
|
|
24042
|
+
if (result.wlfiHome.existed && import_node_fs6.default.existsSync(result.wlfiHome.path)) {
|
|
24043
|
+
remaining.push(result.wlfiHome.path);
|
|
24044
|
+
}
|
|
24045
|
+
if (remaining.length > 0) {
|
|
24046
|
+
throw new Error(`admin uninstall left local WLFI files behind: ${remaining.join(", ")}`);
|
|
24047
|
+
}
|
|
24048
|
+
}
|
|
24001
24049
|
function printResetSummary(result) {
|
|
24002
24050
|
const lines = [
|
|
24003
24051
|
"reset complete",
|
|
@@ -24192,6 +24240,7 @@ async function confirmReset(options) {
|
|
|
24192
24240
|
}
|
|
24193
24241
|
}
|
|
24194
24242
|
async function runAdminReset(options) {
|
|
24243
|
+
assertNotInvokedViaSudo("admin reset");
|
|
24195
24244
|
await confirmReset(options);
|
|
24196
24245
|
const showProgress = !options.json;
|
|
24197
24246
|
const keychainAccount = import_node_os2.default.userInfo().username;
|
|
@@ -24312,6 +24361,7 @@ function printUninstallSummary(result) {
|
|
|
24312
24361
|
console.log(lines.join("\n"));
|
|
24313
24362
|
}
|
|
24314
24363
|
async function runAdminUninstall(options) {
|
|
24364
|
+
assertNotInvokedViaSudo("admin uninstall");
|
|
24315
24365
|
await confirmUninstall(options);
|
|
24316
24366
|
const showProgress = !options.json;
|
|
24317
24367
|
const keychainAccount = import_node_os2.default.userInfo().username;
|
|
@@ -24366,10 +24416,28 @@ async function runAdminUninstall(options) {
|
|
|
24366
24416
|
deleteRootArtifactsResult.stderr.trim() || deleteRootArtifactsResult.stdout.trim() || `failed to delete managed root-owned files (exit code ${deleteRootArtifactsResult.code})`
|
|
24367
24417
|
);
|
|
24368
24418
|
}
|
|
24369
|
-
|
|
24419
|
+
try {
|
|
24420
|
+
await assertManagedUninstallArtifactsRemoved([
|
|
24421
|
+
DEFAULT_LAUNCH_DAEMON_PLIST,
|
|
24422
|
+
DEFAULT_MANAGED_ROOT_DIR,
|
|
24423
|
+
DEFAULT_MANAGED_STATE_DIR,
|
|
24424
|
+
DEFAULT_MANAGED_LOG_DIR
|
|
24425
|
+
]);
|
|
24426
|
+
rootProgress.succeed("Managed root-owned files removed");
|
|
24427
|
+
} catch (error) {
|
|
24428
|
+
rootProgress.fail();
|
|
24429
|
+
throw error;
|
|
24430
|
+
}
|
|
24370
24431
|
const localProgress = createProgress("Removing local WLFI files and credentials", showProgress);
|
|
24371
|
-
|
|
24372
|
-
|
|
24432
|
+
let local;
|
|
24433
|
+
try {
|
|
24434
|
+
local = cleanupLocalAdminUninstallState();
|
|
24435
|
+
assertLocalUninstallArtifactsRemoved(local);
|
|
24436
|
+
localProgress.succeed("Local WLFI files and credentials removed");
|
|
24437
|
+
} catch (error) {
|
|
24438
|
+
localProgress.fail();
|
|
24439
|
+
throw error;
|
|
24440
|
+
}
|
|
24373
24441
|
const result = {
|
|
24374
24442
|
command: "uninstall",
|
|
24375
24443
|
daemon: {
|
|
@@ -26581,6 +26649,21 @@ function resolveDaemonSocket(optionValue) {
|
|
|
26581
26649
|
function resolveStateFile() {
|
|
26582
26650
|
return import_node_path8.default.resolve(DEFAULT_MANAGED_STATE_FILE2);
|
|
26583
26651
|
}
|
|
26652
|
+
function resolveDefaultActiveChainForFreshSetup(config) {
|
|
26653
|
+
try {
|
|
26654
|
+
const profile = resolveCliNetworkProfile("bsc", config);
|
|
26655
|
+
return {
|
|
26656
|
+
chainId: profile.chainId,
|
|
26657
|
+
chainName: profile.key?.trim() || profile.name.trim().toLowerCase() || "bsc",
|
|
26658
|
+
...profile.rpcUrl?.trim() ? { rpcUrl: profile.rpcUrl.trim() } : {}
|
|
26659
|
+
};
|
|
26660
|
+
} catch {
|
|
26661
|
+
return null;
|
|
26662
|
+
}
|
|
26663
|
+
}
|
|
26664
|
+
function shouldSeedDefaultActiveChain(options, config) {
|
|
26665
|
+
return !options.network && !options.rpcUrl && !options.chainName && config.chainId === void 0 && !config.chainName?.trim() && !config.rpcUrl?.trim();
|
|
26666
|
+
}
|
|
26584
26667
|
function createAdminSetupPlan(options, deps = {}) {
|
|
26585
26668
|
if (options.rpcUrl && !options.network) {
|
|
26586
26669
|
throw new Error("--rpc-url requires --network");
|
|
@@ -27296,6 +27379,7 @@ async function runAdminSetup(options) {
|
|
|
27296
27379
|
const config = readConfig();
|
|
27297
27380
|
const daemonSocket = resolveDaemonSocket(options.daemonSocket);
|
|
27298
27381
|
const stateFile = resolveStateFile();
|
|
27382
|
+
const defaultActiveChain = shouldSeedDefaultActiveChain(options, config) ? resolveDefaultActiveChainForFreshSetup(config) : null;
|
|
27299
27383
|
const reusableWallet = options.reuseExistingWallet ? resolveReusableWalletSetupTarget(config) : null;
|
|
27300
27384
|
assertManagedDaemonInstallPreconditions(config, daemonSocket, stateFile);
|
|
27301
27385
|
await confirmAdminSetupOverwrite(options, config);
|
|
@@ -27559,7 +27643,12 @@ async function runAdminSetup(options) {
|
|
|
27559
27643
|
}
|
|
27560
27644
|
const persistedConfig = writeConfig({
|
|
27561
27645
|
daemonSocket,
|
|
27562
|
-
stateFile
|
|
27646
|
+
stateFile,
|
|
27647
|
+
...defaultActiveChain ? {
|
|
27648
|
+
chainId: defaultActiveChain.chainId,
|
|
27649
|
+
chainName: defaultActiveChain.chainName,
|
|
27650
|
+
...defaultActiveChain.rpcUrl ? { rpcUrl: defaultActiveChain.rpcUrl } : {}
|
|
27651
|
+
} : {}
|
|
27563
27652
|
});
|
|
27564
27653
|
printCliPayload(
|
|
27565
27654
|
{
|