@metamask-previews/wallet-cli 0.0.0-preview-429f86194 → 0.0.0-preview-e82188855
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/CHANGELOG.md +1 -3
- package/README.md +2 -16
- package/dist/commands/daemon/call.cjs +7 -3
- package/dist/commands/daemon/call.cjs.map +1 -1
- package/dist/commands/daemon/call.d.cts.map +1 -1
- package/dist/commands/daemon/call.d.mts.map +1 -1
- package/dist/commands/daemon/call.mjs +8 -4
- package/dist/commands/daemon/call.mjs.map +1 -1
- package/dist/daemon/daemon-entry.cjs +0 -4
- package/dist/daemon/daemon-entry.cjs.map +1 -1
- package/dist/daemon/daemon-entry.mjs +0 -4
- package/dist/daemon/daemon-entry.mjs.map +1 -1
- package/dist/daemon/daemon-spawn.cjs +25 -46
- package/dist/daemon/daemon-spawn.cjs.map +1 -1
- package/dist/daemon/daemon-spawn.d.cts.map +1 -1
- package/dist/daemon/daemon-spawn.d.mts.map +1 -1
- package/dist/daemon/daemon-spawn.mjs +26 -47
- package/dist/daemon/daemon-spawn.mjs.map +1 -1
- package/dist/daemon/socket-line.cjs +4 -8
- package/dist/daemon/socket-line.cjs.map +1 -1
- package/dist/daemon/socket-line.d.cts.map +1 -1
- package/dist/daemon/socket-line.d.mts.map +1 -1
- package/dist/daemon/socket-line.mjs +4 -8
- package/dist/daemon/socket-line.mjs.map +1 -1
- package/dist/daemon/stop-daemon.cjs +9 -23
- package/dist/daemon/stop-daemon.cjs.map +1 -1
- package/dist/daemon/stop-daemon.d.cts +7 -17
- package/dist/daemon/stop-daemon.d.cts.map +1 -1
- package/dist/daemon/stop-daemon.d.mts +7 -17
- package/dist/daemon/stop-daemon.d.mts.map +1 -1
- package/dist/daemon/stop-daemon.mjs +9 -23
- package/dist/daemon/stop-daemon.mjs.map +1 -1
- package/dist/daemon/utils.cjs +1 -52
- package/dist/daemon/utils.cjs.map +1 -1
- package/dist/daemon/utils.d.cts +0 -28
- package/dist/daemon/utils.d.cts.map +1 -1
- package/dist/daemon/utils.d.mts +0 -28
- package/dist/daemon/utils.d.mts.map +1 -1
- package/dist/daemon/utils.mjs +0 -48
- package/dist/daemon/utils.mjs.map +1 -1
- package/package.json +2 -3
- package/dist/commands/daemon/list.cjs +0 -48
- package/dist/commands/daemon/list.cjs.map +0 -1
- package/dist/commands/daemon/list.d.cts +0 -7
- package/dist/commands/daemon/list.d.cts.map +0 -1
- package/dist/commands/daemon/list.d.mts +0 -7
- package/dist/commands/daemon/list.d.mts.map +0 -1
- package/dist/commands/daemon/list.mjs +0 -46
- package/dist/commands/daemon/list.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";;;AAAA,2CAAkE;AAClE,+CAA4C;AAE5C;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,KAAc,EAAE,IAAY;IAC1D,OAAO,IAAA,uBAAY,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACpD,CAAC;AAFD,0CAEC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,WAAW,CAC/B,OAAe;IAEf,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,IAAA,mBAAQ,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,8EAA8E;IAC9E,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5D,CAAC;AAfD,kCAeC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAC,GAAW;IACxC,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAbD,wCAaC;AAED;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAsB;IAC5D,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAVD,gCAUC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,OAAO,CAC3B,KAAuC,EACvC,SAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,0BAYC","sourcesContent":["import { isErrorWithCode as hasErrorCode } from '@metamask/utils';\nimport { readFile } from 'node:fs/promises';\n\n/**\n * Check whether an unknown error is a Node.js system error with the given code.\n *\n * @param error - The error to check.\n * @param code - The expected error code (e.g. 'ENOENT', 'EPERM').\n * @returns True if the error matches the code.\n */\nexport function isErrorWithCode(error: unknown, code: string): boolean {\n return hasErrorCode(error) && error.code === code;\n}\n\n/**\n * Read a PID from a file. The file may contain just the PID, or the PID on\n * the first line followed by additional metadata (e.g. start time written by\n * the daemon).\n *\n * @param pidPath - The PID file path.\n * @returns The PID, or undefined if the file is missing or its first line is\n * not a positive integer.\n */\nexport async function readPidFile(\n pidPath: string,\n): Promise<number | undefined> {\n let contents: string;\n try {\n contents = await readFile(pidPath, 'utf-8');\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ENOENT')) {\n return undefined;\n }\n throw error;\n }\n // String.prototype.split always returns at least one element, so [0] is safe.\n const pid = Number(contents.split('\\n')[0].trim());\n return Number.isInteger(pid) && pid > 0 ? pid : undefined;\n}\n\n/**\n * Check whether a process is alive by sending signal 0.\n *\n * Treats `ESRCH` as \"process is gone\", `EPERM` as \"process exists but we\n * cannot signal it\" (still alive from our perspective), and rethrows\n * anything else so the caller can surface unexpected failures rather than\n * silently assuming the process is dead.\n *\n * @param pid - The process ID to check.\n * @returns True if the process exists.\n */\nexport function isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n if (isErrorWithCode(error, 'EPERM')) {\n return true;\n }\n throw error;\n }\n}\n\n/**\n * Send a signal to a process. Returns true if the signal was sent, false if\n * the process does not exist (ESRCH). Re-throws on permission errors and\n * other failures.\n *\n * @param pid - The process ID.\n * @param signal - The signal to send.\n * @returns True if the signal was delivered, false if the process is gone.\n */\nexport function sendSignal(pid: number, signal: NodeJS.Signals): boolean {\n try {\n process.kill(pid, signal);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n throw error;\n }\n}\n\n/**\n * Poll until a condition is met or the timeout elapses.\n *\n * @param check - A function that returns true when the condition is met.\n * @param timeoutMs - Maximum time to wait in milliseconds.\n * @returns True if the condition was met, false on timeout.\n */\nexport async function waitFor(\n check: () => boolean | Promise<boolean>,\n timeoutMs: number,\n): Promise<boolean> {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n if (await check()) {\n return true;\n }\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n return false;\n}\n"]}
|
package/dist/daemon/utils.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { JsonRpcError } from "@metamask/utils";
|
|
3
2
|
/**
|
|
4
3
|
* Check whether an unknown error is a Node.js system error with the given code.
|
|
5
4
|
*
|
|
@@ -8,33 +7,6 @@ import type { JsonRpcError } from "@metamask/utils";
|
|
|
8
7
|
* @returns True if the error matches the code.
|
|
9
8
|
*/
|
|
10
9
|
export declare function isErrorWithCode(error: unknown, code: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Turn an error thrown while contacting the daemon socket into a user-facing
|
|
13
|
-
* message for `Command.error`, so every command reports the same failure the
|
|
14
|
-
* same way. Distinguishes a stopped daemon (`ENOENT`/`ECONNREFUSED`), a
|
|
15
|
-
* connection dropped mid-request (`ECONNRESET`), and a permission problem
|
|
16
|
-
* (`EACCES`/`EPERM`), falling back to the raw error message.
|
|
17
|
-
*
|
|
18
|
-
* @param error - The value thrown while contacting the daemon.
|
|
19
|
-
* @returns A human-readable explanation of the failure.
|
|
20
|
-
*/
|
|
21
|
-
export declare function makeDaemonConnectionError(error: unknown): string;
|
|
22
|
-
/**
|
|
23
|
-
* Format the error of a JSON-RPC failure response into a user-facing message
|
|
24
|
-
* for `Command.error`, so every command reports RPC failures the same way.
|
|
25
|
-
*
|
|
26
|
-
* @param error - The `error` field of a JSON-RPC failure response.
|
|
27
|
-
* @returns The error message annotated with its numeric code.
|
|
28
|
-
*/
|
|
29
|
-
export declare function formatJsonRpcError(error: JsonRpcError): string;
|
|
30
|
-
/**
|
|
31
|
-
* Check whether a value is an array of strings. Used to validate untyped RPC
|
|
32
|
-
* results (e.g. the daemon's `listActions`) before treating them as `string[]`.
|
|
33
|
-
*
|
|
34
|
-
* @param value - The value to check.
|
|
35
|
-
* @returns True if the value is an array whose every element is a string.
|
|
36
|
-
*/
|
|
37
|
-
export declare function isStringArray(value: unknown): value is string[];
|
|
38
10
|
/**
|
|
39
11
|
* Read a PID from a file. The file may contain just the PID, or the PID on
|
|
40
12
|
* the first line followed by additional metadata (e.g. start time written by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";AAGA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAa7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAanD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAUvE;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EACvC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
package/dist/daemon/utils.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { JsonRpcError } from "@metamask/utils";
|
|
3
2
|
/**
|
|
4
3
|
* Check whether an unknown error is a Node.js system error with the given code.
|
|
5
4
|
*
|
|
@@ -8,33 +7,6 @@ import type { JsonRpcError } from "@metamask/utils";
|
|
|
8
7
|
* @returns True if the error matches the code.
|
|
9
8
|
*/
|
|
10
9
|
export declare function isErrorWithCode(error: unknown, code: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Turn an error thrown while contacting the daemon socket into a user-facing
|
|
13
|
-
* message for `Command.error`, so every command reports the same failure the
|
|
14
|
-
* same way. Distinguishes a stopped daemon (`ENOENT`/`ECONNREFUSED`), a
|
|
15
|
-
* connection dropped mid-request (`ECONNRESET`), and a permission problem
|
|
16
|
-
* (`EACCES`/`EPERM`), falling back to the raw error message.
|
|
17
|
-
*
|
|
18
|
-
* @param error - The value thrown while contacting the daemon.
|
|
19
|
-
* @returns A human-readable explanation of the failure.
|
|
20
|
-
*/
|
|
21
|
-
export declare function makeDaemonConnectionError(error: unknown): string;
|
|
22
|
-
/**
|
|
23
|
-
* Format the error of a JSON-RPC failure response into a user-facing message
|
|
24
|
-
* for `Command.error`, so every command reports RPC failures the same way.
|
|
25
|
-
*
|
|
26
|
-
* @param error - The `error` field of a JSON-RPC failure response.
|
|
27
|
-
* @returns The error message annotated with its numeric code.
|
|
28
|
-
*/
|
|
29
|
-
export declare function formatJsonRpcError(error: JsonRpcError): string;
|
|
30
|
-
/**
|
|
31
|
-
* Check whether a value is an array of strings. Used to validate untyped RPC
|
|
32
|
-
* results (e.g. the daemon's `listActions`) before treating them as `string[]`.
|
|
33
|
-
*
|
|
34
|
-
* @param value - The value to check.
|
|
35
|
-
* @returns True if the value is an array whose every element is a string.
|
|
36
|
-
*/
|
|
37
|
-
export declare function isStringArray(value: unknown): value is string[];
|
|
38
10
|
/**
|
|
39
11
|
* Read a PID from a file. The file may contain just the PID, or the PID on
|
|
40
12
|
* the first line followed by additional metadata (e.g. start time written by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";AAGA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAa7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAanD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAUvE;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EACvC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
package/dist/daemon/utils.mjs
CHANGED
|
@@ -10,54 +10,6 @@ import { readFile } from "node:fs/promises";
|
|
|
10
10
|
export function isErrorWithCode(error, code) {
|
|
11
11
|
return hasErrorCode(error) && error.code === code;
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Turn an error thrown while contacting the daemon socket into a user-facing
|
|
15
|
-
* message for `Command.error`, so every command reports the same failure the
|
|
16
|
-
* same way. Distinguishes a stopped daemon (`ENOENT`/`ECONNREFUSED`), a
|
|
17
|
-
* connection dropped mid-request (`ECONNRESET`), and a permission problem
|
|
18
|
-
* (`EACCES`/`EPERM`), falling back to the raw error message.
|
|
19
|
-
*
|
|
20
|
-
* @param error - The value thrown while contacting the daemon.
|
|
21
|
-
* @returns A human-readable explanation of the failure.
|
|
22
|
-
*/
|
|
23
|
-
export function makeDaemonConnectionError(error) {
|
|
24
|
-
if (isErrorWithCode(error, 'ENOENT') ||
|
|
25
|
-
isErrorWithCode(error, 'ECONNREFUSED')) {
|
|
26
|
-
return 'Daemon is not running. Start it with `mm daemon start`.';
|
|
27
|
-
}
|
|
28
|
-
// A reset drops an already-established connection, so the daemon was running
|
|
29
|
-
// — most likely it crashed mid-request. Don't tell the user to start it.
|
|
30
|
-
if (isErrorWithCode(error, 'ECONNRESET')) {
|
|
31
|
-
return ('Lost the connection to the daemon; it may have crashed while ' +
|
|
32
|
-
'handling the request. Check `mm daemon status` and the daemon log.');
|
|
33
|
-
}
|
|
34
|
-
if (isErrorWithCode(error, 'EACCES') || isErrorWithCode(error, 'EPERM')) {
|
|
35
|
-
return ('Cannot connect to the daemon socket: permission denied. ' +
|
|
36
|
-
'The socket may be owned by another user, or MM_DATA_DIR ' +
|
|
37
|
-
'may point to a directory you cannot access.');
|
|
38
|
-
}
|
|
39
|
-
return error instanceof Error ? error.message : String(error);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Format the error of a JSON-RPC failure response into a user-facing message
|
|
43
|
-
* for `Command.error`, so every command reports RPC failures the same way.
|
|
44
|
-
*
|
|
45
|
-
* @param error - The `error` field of a JSON-RPC failure response.
|
|
46
|
-
* @returns The error message annotated with its numeric code.
|
|
47
|
-
*/
|
|
48
|
-
export function formatJsonRpcError(error) {
|
|
49
|
-
return `${error.message} (code ${String(error.code)})`;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Check whether a value is an array of strings. Used to validate untyped RPC
|
|
53
|
-
* results (e.g. the daemon's `listActions`) before treating them as `string[]`.
|
|
54
|
-
*
|
|
55
|
-
* @param value - The value to check.
|
|
56
|
-
* @returns True if the value is an array whose every element is a string.
|
|
57
|
-
*/
|
|
58
|
-
export function isStringArray(value) {
|
|
59
|
-
return (Array.isArray(value) && value.every((item) => typeof item === 'string'));
|
|
60
|
-
}
|
|
61
13
|
/**
|
|
62
14
|
* Read a PID from a file. The file may contain just the PID, or the PID on
|
|
63
15
|
* the first line followed by additional metadata (e.g. start time written by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,YAAY,EAAE,wBAAwB;AAClE,OAAO,EAAE,QAAQ,EAAE,yBAAyB;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,IAAY;IAC1D,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACpD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAe;IAEf,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,8EAA8E;IAC9E,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,MAAsB;IAC5D,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAAuC,EACvC,SAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { isErrorWithCode as hasErrorCode } from '@metamask/utils';\nimport { readFile } from 'node:fs/promises';\n\n/**\n * Check whether an unknown error is a Node.js system error with the given code.\n *\n * @param error - The error to check.\n * @param code - The expected error code (e.g. 'ENOENT', 'EPERM').\n * @returns True if the error matches the code.\n */\nexport function isErrorWithCode(error: unknown, code: string): boolean {\n return hasErrorCode(error) && error.code === code;\n}\n\n/**\n * Read a PID from a file. The file may contain just the PID, or the PID on\n * the first line followed by additional metadata (e.g. start time written by\n * the daemon).\n *\n * @param pidPath - The PID file path.\n * @returns The PID, or undefined if the file is missing or its first line is\n * not a positive integer.\n */\nexport async function readPidFile(\n pidPath: string,\n): Promise<number | undefined> {\n let contents: string;\n try {\n contents = await readFile(pidPath, 'utf-8');\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ENOENT')) {\n return undefined;\n }\n throw error;\n }\n // String.prototype.split always returns at least one element, so [0] is safe.\n const pid = Number(contents.split('\\n')[0].trim());\n return Number.isInteger(pid) && pid > 0 ? pid : undefined;\n}\n\n/**\n * Check whether a process is alive by sending signal 0.\n *\n * Treats `ESRCH` as \"process is gone\", `EPERM` as \"process exists but we\n * cannot signal it\" (still alive from our perspective), and rethrows\n * anything else so the caller can surface unexpected failures rather than\n * silently assuming the process is dead.\n *\n * @param pid - The process ID to check.\n * @returns True if the process exists.\n */\nexport function isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n if (isErrorWithCode(error, 'EPERM')) {\n return true;\n }\n throw error;\n }\n}\n\n/**\n * Send a signal to a process. Returns true if the signal was sent, false if\n * the process does not exist (ESRCH). Re-throws on permission errors and\n * other failures.\n *\n * @param pid - The process ID.\n * @param signal - The signal to send.\n * @returns True if the signal was delivered, false if the process is gone.\n */\nexport function sendSignal(pid: number, signal: NodeJS.Signals): boolean {\n try {\n process.kill(pid, signal);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n throw error;\n }\n}\n\n/**\n * Poll until a condition is met or the timeout elapses.\n *\n * @param check - A function that returns true when the condition is met.\n * @param timeoutMs - Maximum time to wait in milliseconds.\n * @returns True if the condition was met, false on timeout.\n */\nexport async function waitFor(\n check: () => boolean | Promise<boolean>,\n timeoutMs: number,\n): Promise<boolean> {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n if (await check()) {\n return true;\n }\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n return false;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/wallet-cli",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-e82188855",
|
|
4
4
|
"description": "The CLI of @metamask/wallet",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"test:prepare": "./scripts/install-binaries.sh",
|
|
40
40
|
"test": "yarn test:prepare && NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
41
41
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
42
|
-
"test:e2e": "yarn test:prepare && NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.e2e.js",
|
|
43
42
|
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
44
43
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
45
44
|
},
|
|
@@ -50,7 +49,7 @@
|
|
|
50
49
|
"@metamask/rpc-errors": "^7.0.2",
|
|
51
50
|
"@metamask/storage-service": "^1.0.2",
|
|
52
51
|
"@metamask/utils": "^11.11.0",
|
|
53
|
-
"@metamask/wallet": "^
|
|
52
|
+
"@metamask/wallet": "^5.0.0",
|
|
54
53
|
"@oclif/core": "^4.10.5",
|
|
55
54
|
"better-sqlite3": "^12.9.0",
|
|
56
55
|
"immer": "^9.0.6"
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("@metamask/utils");
|
|
4
|
-
const core_1 = require("@oclif/core");
|
|
5
|
-
const daemon_client_1 = require("../../daemon/daemon-client.cjs");
|
|
6
|
-
const paths_1 = require("../../daemon/paths.cjs");
|
|
7
|
-
const utils_2 = require("../../daemon/utils.cjs");
|
|
8
|
-
class DaemonList extends core_1.Command {
|
|
9
|
-
async run() {
|
|
10
|
-
await this.parse(DaemonList);
|
|
11
|
-
const { socketPath } = (0, paths_1.getDaemonPaths)(this.config.dataDir);
|
|
12
|
-
let response;
|
|
13
|
-
try {
|
|
14
|
-
response = await (0, daemon_client_1.sendCommand)({ socketPath, method: 'listActions' });
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
this.error((0, utils_2.makeDaemonConnectionError)(error));
|
|
18
|
-
}
|
|
19
|
-
if ((0, utils_1.isJsonRpcFailure)(response)) {
|
|
20
|
-
this.error((0, utils_2.formatJsonRpcError)(response.error));
|
|
21
|
-
}
|
|
22
|
-
if (!(0, utils_2.isStringArray)(response.result)) {
|
|
23
|
-
this.error('Daemon returned an unexpected action list.');
|
|
24
|
-
}
|
|
25
|
-
const actions = [...response.result].sort();
|
|
26
|
-
const isTTY = process.stdout.isTTY ?? false;
|
|
27
|
-
if (!isTTY) {
|
|
28
|
-
// Bare output so it pipes cleanly into `grep`/`fzf`.
|
|
29
|
-
if (actions.length > 0) {
|
|
30
|
-
process.stdout.write(`${actions.join('\n')}\n`);
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (actions.length === 0) {
|
|
35
|
-
this.log('The daemon has no callable actions registered.');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this.log(`${actions.length} callable action${actions.length === 1 ? '' : 's'} ` +
|
|
39
|
-
'(dispatch with `mm daemon call <action>`):');
|
|
40
|
-
for (const action of actions) {
|
|
41
|
-
this.log(` ${action}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
DaemonList.description = 'List the messenger actions the running daemon can dispatch via `daemon call`';
|
|
46
|
-
DaemonList.examples = ['<%= config.bin %> daemon list'];
|
|
47
|
-
exports.default = DaemonList;
|
|
48
|
-
//# sourceMappingURL=list.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.cjs","sourceRoot":"","sources":["../../../src/commands/daemon/list.ts"],"names":[],"mappings":";;AAAA,2CAAmD;AACnD,sCAAsC;AAEtC,kEAAyD;AACzD,kDAAoD;AACpD,kDAI4B;AAE5B,MAAqB,UAAW,SAAQ,cAAO;IAMtC,KAAK,CAAC,GAAG;QACd,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC7B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,sBAAc,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE3D,IAAI,QAAQ,CAAC;QACb,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,IAAA,2BAAW,EAAC,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACtE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,IAAA,iCAAyB,EAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,IAAA,wBAAgB,EAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,CAAC,IAAA,0BAAkB,EAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,IAAA,qBAAa,EAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAE5C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,qDAAqD;YACrD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,GAAG,CACN,GAAG,OAAO,CAAC,MAAM,mBAAmB,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;YACpE,4CAA4C,CAC/C,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;;AA/Ce,sBAAW,GACzB,8EAA8E,CAAC;AAEjE,mBAAQ,GAAG,CAAC,+BAA+B,CAAC,CAAC;kBAJ1C,UAAU","sourcesContent":["import { isJsonRpcFailure } from '@metamask/utils';\nimport { Command } from '@oclif/core';\n\nimport { sendCommand } from '../../daemon/daemon-client';\nimport { getDaemonPaths } from '../../daemon/paths';\nimport {\n formatJsonRpcError,\n isStringArray,\n makeDaemonConnectionError,\n} from '../../daemon/utils';\n\nexport default class DaemonList extends Command {\n static override description =\n 'List the messenger actions the running daemon can dispatch via `daemon call`';\n\n static override examples = ['<%= config.bin %> daemon list'];\n\n public async run(): Promise<void> {\n await this.parse(DaemonList);\n const { socketPath } = getDaemonPaths(this.config.dataDir);\n\n let response;\n try {\n response = await sendCommand({ socketPath, method: 'listActions' });\n } catch (error) {\n this.error(makeDaemonConnectionError(error));\n }\n\n if (isJsonRpcFailure(response)) {\n this.error(formatJsonRpcError(response.error));\n }\n\n if (!isStringArray(response.result)) {\n this.error('Daemon returned an unexpected action list.');\n }\n\n const actions = [...response.result].sort();\n\n const isTTY = process.stdout.isTTY ?? false;\n if (!isTTY) {\n // Bare output so it pipes cleanly into `grep`/`fzf`.\n if (actions.length > 0) {\n process.stdout.write(`${actions.join('\\n')}\\n`);\n }\n return;\n }\n\n if (actions.length === 0) {\n this.log('The daemon has no callable actions registered.');\n return;\n }\n\n this.log(\n `${actions.length} callable action${actions.length === 1 ? '' : 's'} ` +\n '(dispatch with `mm daemon call <action>`):',\n );\n for (const action of actions) {\n this.log(` ${action}`);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.cts","sourceRoot":"","sources":["../../../src/commands/daemon/list.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,oBAAoB;AAUtC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IAC7C,OAAgB,WAAW,SACsD;IAEjF,OAAgB,QAAQ,WAAqC;IAEhD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA2ClC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.mts","sourceRoot":"","sources":["../../../src/commands/daemon/list.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,oBAAoB;AAUtC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IAC7C,OAAgB,WAAW,SACsD;IAEjF,OAAgB,QAAQ,WAAqC;IAEhD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA2ClC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { isJsonRpcFailure } from "@metamask/utils";
|
|
2
|
-
import { Command } from "@oclif/core";
|
|
3
|
-
import { sendCommand } from "../../daemon/daemon-client.mjs";
|
|
4
|
-
import { getDaemonPaths } from "../../daemon/paths.mjs";
|
|
5
|
-
import { formatJsonRpcError, isStringArray, makeDaemonConnectionError } from "../../daemon/utils.mjs";
|
|
6
|
-
class DaemonList extends Command {
|
|
7
|
-
async run() {
|
|
8
|
-
await this.parse(DaemonList);
|
|
9
|
-
const { socketPath } = getDaemonPaths(this.config.dataDir);
|
|
10
|
-
let response;
|
|
11
|
-
try {
|
|
12
|
-
response = await sendCommand({ socketPath, method: 'listActions' });
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
this.error(makeDaemonConnectionError(error));
|
|
16
|
-
}
|
|
17
|
-
if (isJsonRpcFailure(response)) {
|
|
18
|
-
this.error(formatJsonRpcError(response.error));
|
|
19
|
-
}
|
|
20
|
-
if (!isStringArray(response.result)) {
|
|
21
|
-
this.error('Daemon returned an unexpected action list.');
|
|
22
|
-
}
|
|
23
|
-
const actions = [...response.result].sort();
|
|
24
|
-
const isTTY = process.stdout.isTTY ?? false;
|
|
25
|
-
if (!isTTY) {
|
|
26
|
-
// Bare output so it pipes cleanly into `grep`/`fzf`.
|
|
27
|
-
if (actions.length > 0) {
|
|
28
|
-
process.stdout.write(`${actions.join('\n')}\n`);
|
|
29
|
-
}
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (actions.length === 0) {
|
|
33
|
-
this.log('The daemon has no callable actions registered.');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.log(`${actions.length} callable action${actions.length === 1 ? '' : 's'} ` +
|
|
37
|
-
'(dispatch with `mm daemon call <action>`):');
|
|
38
|
-
for (const action of actions) {
|
|
39
|
-
this.log(` ${action}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
DaemonList.description = 'List the messenger actions the running daemon can dispatch via `daemon call`';
|
|
44
|
-
DaemonList.examples = ['<%= config.bin %> daemon list'];
|
|
45
|
-
export default DaemonList;
|
|
46
|
-
//# sourceMappingURL=list.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.mjs","sourceRoot":"","sources":["../../../src/commands/daemon/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,wBAAwB;AACnD,OAAO,EAAE,OAAO,EAAE,oBAAoB;AAEtC,OAAO,EAAE,WAAW,EAAE,uCAAmC;AACzD,OAAO,EAAE,cAAc,EAAE,+BAA2B;AACpD,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,yBAAyB,EAC1B,+BAA2B;AAE5B,MAAqB,UAAW,SAAQ,OAAO;IAMtC,KAAK,CAAC,GAAG;QACd,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC7B,MAAM,EAAE,UAAU,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE3D,IAAI,QAAQ,CAAC;QACb,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,WAAW,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACtE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAE5C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,qDAAqD;YACrD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,GAAG,CACN,GAAG,OAAO,CAAC,MAAM,mBAAmB,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;YACpE,4CAA4C,CAC/C,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;;AA/Ce,sBAAW,GACzB,8EAA8E,CAAC;AAEjE,mBAAQ,GAAG,CAAC,+BAA+B,CAAC,CAAC;eAJ1C,UAAU","sourcesContent":["import { isJsonRpcFailure } from '@metamask/utils';\nimport { Command } from '@oclif/core';\n\nimport { sendCommand } from '../../daemon/daemon-client';\nimport { getDaemonPaths } from '../../daemon/paths';\nimport {\n formatJsonRpcError,\n isStringArray,\n makeDaemonConnectionError,\n} from '../../daemon/utils';\n\nexport default class DaemonList extends Command {\n static override description =\n 'List the messenger actions the running daemon can dispatch via `daemon call`';\n\n static override examples = ['<%= config.bin %> daemon list'];\n\n public async run(): Promise<void> {\n await this.parse(DaemonList);\n const { socketPath } = getDaemonPaths(this.config.dataDir);\n\n let response;\n try {\n response = await sendCommand({ socketPath, method: 'listActions' });\n } catch (error) {\n this.error(makeDaemonConnectionError(error));\n }\n\n if (isJsonRpcFailure(response)) {\n this.error(formatJsonRpcError(response.error));\n }\n\n if (!isStringArray(response.result)) {\n this.error('Daemon returned an unexpected action list.');\n }\n\n const actions = [...response.result].sort();\n\n const isTTY = process.stdout.isTTY ?? false;\n if (!isTTY) {\n // Bare output so it pipes cleanly into `grep`/`fzf`.\n if (actions.length > 0) {\n process.stdout.write(`${actions.join('\\n')}\\n`);\n }\n return;\n }\n\n if (actions.length === 0) {\n this.log('The daemon has no callable actions registered.');\n return;\n }\n\n this.log(\n `${actions.length} callable action${actions.length === 1 ? '' : 's'} ` +\n '(dispatch with `mm daemon call <action>`):',\n );\n for (const action of actions) {\n this.log(` ${action}`);\n }\n }\n}\n"]}
|