@powerhousedao/ph-cli 6.0.0-dev.6 → 6.0.0-dev.60
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/scripts/generate-commands-docs.d.ts +2 -0
- package/dist/scripts/generate-commands-docs.d.ts.map +1 -0
- package/dist/scripts/generate-commands-docs.js +41 -0
- package/dist/scripts/generate-commands-docs.js.map +1 -0
- package/dist/scripts/generate-commands-docs.ts +45 -0
- package/dist/src/cli.js +21 -37
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/access-token.d.ts +13 -8
- package/dist/src/commands/access-token.d.ts.map +1 -1
- package/dist/src/commands/access-token.js +100 -79
- package/dist/src/commands/access-token.js.map +1 -1
- package/dist/src/commands/connect.d.ts +248 -18
- package/dist/src/commands/connect.d.ts.map +1 -1
- package/dist/src/commands/connect.js +61 -84
- package/dist/src/commands/connect.js.map +1 -1
- package/dist/src/commands/generate.d.ts +59 -8
- package/dist/src/commands/generate.d.ts.map +1 -1
- package/dist/src/commands/generate.js +24 -40
- package/dist/src/commands/generate.js.map +1 -1
- package/dist/src/commands/index.d.ts +1 -2
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +13 -2
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/inspect.d.ts +11 -5
- package/dist/src/commands/inspect.d.ts.map +1 -1
- package/dist/src/commands/inspect.js +25 -20
- package/dist/src/commands/inspect.js.map +1 -1
- package/dist/src/commands/install.d.ts +21 -14
- package/dist/src/commands/install.d.ts.map +1 -1
- package/dist/src/commands/install.js +74 -123
- package/dist/src/commands/install.js.map +1 -1
- package/dist/src/commands/list.d.ts +9 -8
- package/dist/src/commands/list.d.ts.map +1 -1
- package/dist/src/commands/list.js +37 -32
- package/dist/src/commands/list.js.map +1 -1
- package/dist/src/commands/login.d.ts +23 -11
- package/dist/src/commands/login.d.ts.map +1 -1
- package/dist/src/commands/login.js +105 -118
- package/dist/src/commands/login.js.map +1 -1
- package/dist/src/commands/logout.d.ts +6 -0
- package/dist/src/commands/logout.d.ts.map +1 -0
- package/dist/src/commands/logout.js +13 -0
- package/dist/src/commands/logout.js.map +1 -0
- package/dist/src/commands/migrate.d.ts +11 -9
- package/dist/src/commands/migrate.d.ts.map +1 -1
- package/dist/src/commands/migrate.js +15 -11
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/ph-cli-commands.d.ts +417 -0
- package/dist/src/commands/ph-cli-commands.d.ts.map +1 -0
- package/dist/src/commands/ph-cli-commands.js +27 -0
- package/dist/src/commands/ph-cli-commands.js.map +1 -0
- package/dist/src/commands/ph-cli-help.d.ts +398 -0
- package/dist/src/commands/ph-cli-help.d.ts.map +1 -0
- package/dist/src/commands/ph-cli-help.js +12 -0
- package/dist/src/commands/ph-cli-help.js.map +1 -0
- package/dist/src/commands/ph-cli.d.ts +504 -0
- package/dist/src/commands/ph-cli.d.ts.map +1 -0
- package/dist/src/commands/ph-cli.js +12 -0
- package/dist/src/commands/ph-cli.js.map +1 -0
- package/dist/src/commands/service.d.ts +11 -4
- package/dist/src/commands/service.d.ts.map +1 -1
- package/dist/src/commands/service.js +27 -16
- package/dist/src/commands/service.js.map +1 -1
- package/dist/src/commands/switchboard.d.ts +45 -8
- package/dist/src/commands/switchboard.d.ts.map +1 -1
- package/dist/src/commands/switchboard.js +35 -71
- package/dist/src/commands/switchboard.js.map +1 -1
- package/dist/src/commands/uninstall.d.ts +21 -14
- package/dist/src/commands/uninstall.d.ts.map +1 -1
- package/dist/src/commands/uninstall.js +71 -117
- package/dist/src/commands/uninstall.js.map +1 -1
- package/dist/src/commands/vetra.d.ts +63 -10
- package/dist/src/commands/vetra.d.ts.map +1 -1
- package/dist/src/commands/vetra.js +23 -34
- package/dist/src/commands/vetra.js.map +1 -1
- package/dist/src/get-version.d.ts +2 -0
- package/dist/src/get-version.d.ts.map +1 -0
- package/dist/src/get-version.js +6 -0
- package/dist/src/get-version.js.map +1 -0
- package/dist/src/help.d.ts +3 -3
- package/dist/src/help.d.ts.map +1 -1
- package/dist/src/help.js +7 -7
- package/dist/src/services/auth.d.ts +5 -53
- package/dist/src/services/auth.d.ts.map +1 -1
- package/dist/src/services/auth.js +11 -159
- package/dist/src/services/auth.js.map +1 -1
- package/dist/src/services/connect-build.d.ts +3 -0
- package/dist/src/services/connect-build.d.ts.map +1 -0
- package/dist/src/services/connect-build.js +24 -0
- package/dist/src/services/connect-build.js.map +1 -0
- package/dist/src/services/connect-preview.d.ts +3 -0
- package/dist/src/services/connect-preview.d.ts.map +1 -0
- package/dist/src/services/connect-preview.js +35 -0
- package/dist/src/services/connect-preview.js.map +1 -0
- package/dist/src/services/connect-studio.d.ts +4 -0
- package/dist/src/services/connect-studio.d.ts.map +1 -0
- package/dist/src/services/connect-studio.js +30 -0
- package/dist/src/services/connect-studio.js.map +1 -0
- package/dist/src/services/generate.d.ts +2 -29
- package/dist/src/services/generate.d.ts.map +1 -1
- package/dist/src/services/generate.js +55 -75
- package/dist/src/services/generate.js.map +1 -1
- package/dist/src/services/inspect.d.ts +2 -4
- package/dist/src/services/inspect.d.ts.map +1 -1
- package/dist/src/services/inspect.js +7 -6
- package/dist/src/services/inspect.js.map +1 -1
- package/dist/src/services/migrate.d.ts +2 -6
- package/dist/src/services/migrate.d.ts.map +1 -1
- package/dist/src/services/migrate.js +52 -14
- package/dist/src/services/migrate.js.map +1 -1
- package/dist/src/services/switchboard.d.ts +3 -34
- package/dist/src/services/switchboard.d.ts.map +1 -1
- package/dist/src/services/switchboard.js +7 -7
- package/dist/src/services/switchboard.js.map +1 -1
- package/dist/src/services/vetra.d.ts +2 -14
- package/dist/src/services/vetra.d.ts.map +1 -1
- package/dist/src/services/vetra.js +109 -88
- package/dist/src/services/vetra.js.map +1 -1
- package/dist/src/types.d.ts +26 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/assign-env-vars.d.ts +3 -0
- package/dist/src/utils/assign-env-vars.d.ts.map +1 -0
- package/dist/src/utils/assign-env-vars.js +11 -0
- package/dist/src/utils/assign-env-vars.js.map +1 -0
- package/dist/src/utils/constants.d.ts +2 -0
- package/dist/src/utils/constants.d.ts.map +1 -0
- package/dist/src/utils/constants.js +2 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/resolve-connect-dirs.d.ts +7 -0
- package/dist/src/utils/resolve-connect-dirs.d.ts.map +1 -0
- package/dist/src/utils/resolve-connect-dirs.js +16 -0
- package/dist/src/utils/resolve-connect-dirs.js.map +1 -0
- package/dist/src/utils.d.ts +0 -4
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +39 -29
- package/dist/scripts/generate-commands-md.d.ts +0 -2
- package/dist/scripts/generate-commands-md.d.ts.map +0 -1
- package/dist/scripts/generate-commands-md.js +0 -72
- package/dist/scripts/generate-commands-md.js.map +0 -1
- package/dist/scripts/generate-commands-md.ts +0 -84
- package/dist/src/commands/help.d.ts +0 -3
- package/dist/src/commands/help.d.ts.map +0 -1
- package/dist/src/commands/help.js +0 -9
- package/dist/src/commands/help.js.map +0 -1
- package/dist/src/commands/register-commands.d.ts +0 -5
- package/dist/src/commands/register-commands.d.ts.map +0 -1
- package/dist/src/commands/register-commands.js +0 -32
- package/dist/src/commands/register-commands.js.map +0 -1
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -5
- package/dist/src/index.js.map +0 -1
- package/dist/src/services/connect.d.ts +0 -2
- package/dist/src/services/connect.d.ts.map +0 -1
- package/dist/src/services/connect.js +0 -2
- package/dist/src/services/connect.js.map +0 -1
- package/dist/src/version.d.ts +0 -2
- package/dist/src/version.d.ts.map +0 -1
- package/dist/src/version.js +0 -3
- package/dist/src/version.js.map +0 -1
- package/dist/test/utils.test.d.ts +0 -2
- package/dist/test/utils.test.d.ts.map +0 -1
- package/dist/test/utils.test.js +0 -132
- package/dist/test/utils.test.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-commands-docs.d.ts","sourceRoot":"","sources":["../../scripts/generate-commands-docs.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { writeCliDocsMarkdownFile } from "@powerhousedao/codegen/file-builders";
|
|
2
|
+
import { accessToken } from "../src/commands/access-token.js";
|
|
3
|
+
import { build, connect, preview, studio } from "../src/commands/connect.js";
|
|
4
|
+
import { generate } from "../src/commands/generate.js";
|
|
5
|
+
import { inspect } from "../src/commands/inspect.js";
|
|
6
|
+
import { install } from "../src/commands/install.js";
|
|
7
|
+
import { list } from "../src/commands/list.js";
|
|
8
|
+
import { login } from "../src/commands/login.js";
|
|
9
|
+
import { migrate } from "../src/commands/migrate.js";
|
|
10
|
+
import { phCli } from "../src/commands/ph-cli.js";
|
|
11
|
+
import { switchboard } from "../src/commands/switchboard.js";
|
|
12
|
+
import { uninstall } from "../src/commands/uninstall.js";
|
|
13
|
+
import { vetra } from "../src/commands/vetra.js";
|
|
14
|
+
const commands = [
|
|
15
|
+
{ name: "generate", command: generate },
|
|
16
|
+
{ name: "vetra", command: vetra },
|
|
17
|
+
{ name: "connect", command: connect },
|
|
18
|
+
{ name: "connect studio", command: studio },
|
|
19
|
+
{ name: "connect build", command: build },
|
|
20
|
+
{ name: "connect preview", command: preview },
|
|
21
|
+
{ name: "access token", command: accessToken },
|
|
22
|
+
{ name: "inspect", command: inspect },
|
|
23
|
+
{ name: "list", command: list },
|
|
24
|
+
{ name: "migrate", command: migrate },
|
|
25
|
+
{ name: "switchboard", command: switchboard },
|
|
26
|
+
{ name: "login", command: login },
|
|
27
|
+
{ name: "install", command: install },
|
|
28
|
+
{ name: "uninstall", command: uninstall },
|
|
29
|
+
];
|
|
30
|
+
const cliDescription = phCli.description ?? "";
|
|
31
|
+
async function main() {
|
|
32
|
+
await writeCliDocsMarkdownFile({
|
|
33
|
+
filePath: "COMMANDS.md",
|
|
34
|
+
docsTitle: `Powerhouse CLI Commands (${process.env.WORKSPACE_VERSION || process.env.npm_package_version})`,
|
|
35
|
+
docsIntroduction: "This document provides detailed information about the available commands in the Powerhouse CLI.",
|
|
36
|
+
cliDescription,
|
|
37
|
+
entries: commands,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
await main();
|
|
41
|
+
//# sourceMappingURL=generate-commands-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-commands-docs.js","sourceRoot":"","sources":["../../scripts/generate-commands-docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEjD,MAAM,QAAQ,GAAG;IACf,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE;IACvC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE;IACrC,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE;IAC3C,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE;IACzC,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,EAAE;IAC7C,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE;IAC9C,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE;IACrC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;IAC/B,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE;IACrC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE;IAC7C,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE;IACrC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE;CAC1C,CAAC;AAEF,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC;AAE/C,KAAK,UAAU,IAAI;IACjB,MAAM,wBAAwB,CAAC;QAC7B,QAAQ,EAAE,aAAa;QACvB,SAAS,EAAE,4BAA4B,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG;QAC1G,gBAAgB,EACd,iGAAiG;QACnG,cAAc;QACd,OAAO,EAAE,QAAQ;KAClB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { writeCliDocsMarkdownFile } from "@powerhousedao/codegen/file-builders";
|
|
2
|
+
import { accessToken } from "../src/commands/access-token.js";
|
|
3
|
+
import { build, connect, preview, studio } from "../src/commands/connect.js";
|
|
4
|
+
import { generate } from "../src/commands/generate.js";
|
|
5
|
+
import { inspect } from "../src/commands/inspect.js";
|
|
6
|
+
import { install } from "../src/commands/install.js";
|
|
7
|
+
import { list } from "../src/commands/list.js";
|
|
8
|
+
import { login } from "../src/commands/login.js";
|
|
9
|
+
import { migrate } from "../src/commands/migrate.js";
|
|
10
|
+
import { phCli } from "../src/commands/ph-cli.js";
|
|
11
|
+
import { switchboard } from "../src/commands/switchboard.js";
|
|
12
|
+
import { uninstall } from "../src/commands/uninstall.js";
|
|
13
|
+
import { vetra } from "../src/commands/vetra.js";
|
|
14
|
+
|
|
15
|
+
const commands = [
|
|
16
|
+
{ name: "generate", command: generate },
|
|
17
|
+
{ name: "vetra", command: vetra },
|
|
18
|
+
{ name: "connect", command: connect },
|
|
19
|
+
{ name: "connect studio", command: studio },
|
|
20
|
+
{ name: "connect build", command: build },
|
|
21
|
+
{ name: "connect preview", command: preview },
|
|
22
|
+
{ name: "access token", command: accessToken },
|
|
23
|
+
{ name: "inspect", command: inspect },
|
|
24
|
+
{ name: "list", command: list },
|
|
25
|
+
{ name: "migrate", command: migrate },
|
|
26
|
+
{ name: "switchboard", command: switchboard },
|
|
27
|
+
{ name: "login", command: login },
|
|
28
|
+
{ name: "install", command: install },
|
|
29
|
+
{ name: "uninstall", command: uninstall },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const cliDescription = phCli.description ?? "";
|
|
33
|
+
|
|
34
|
+
async function main() {
|
|
35
|
+
await writeCliDocsMarkdownFile({
|
|
36
|
+
filePath: "COMMANDS.md",
|
|
37
|
+
docsTitle: `Powerhouse CLI Commands (${process.env.WORKSPACE_VERSION || process.env.npm_package_version})`,
|
|
38
|
+
docsIntroduction:
|
|
39
|
+
"This document provides detailed information about the available commands in the Powerhouse CLI.",
|
|
40
|
+
cliDescription,
|
|
41
|
+
entries: commands,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await main();
|
package/dist/src/cli.js
CHANGED
|
@@ -1,42 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { assertNodeVersion } from "@powerhousedao/common/clis";
|
|
3
|
+
import { run } from "cmd-ts";
|
|
4
|
+
import { phCliHelp } from "./commands/ph-cli-help.js";
|
|
5
|
+
import { phCli } from "./commands/ph-cli.js";
|
|
6
|
+
async function main() {
|
|
7
|
+
assertNodeVersion();
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
const hasNoArgs = args.length === 0;
|
|
10
|
+
const isHelp = args.some((arg) => arg === "--help" || arg === "-h");
|
|
11
|
+
const isTopLevelHelp = isHelp && args.length === 1;
|
|
12
|
+
const showTopLevelHelp = hasNoArgs || isTopLevelHelp;
|
|
13
|
+
const cli = showTopLevelHelp ? phCliHelp : phCli;
|
|
14
|
+
const [command, ...restArgs] = args;
|
|
15
|
+
if (command === "connect" &&
|
|
16
|
+
!["studio", "build", "preview"].includes(args[1]) &&
|
|
17
|
+
!isHelp) {
|
|
18
|
+
const argsWithDefaultConnectSubCommand = ["connect", "studio", ...restArgs];
|
|
19
|
+
await run(cli, argsWithDefaultConnectSubCommand);
|
|
8
20
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
process.exit(1);
|
|
21
|
+
else {
|
|
22
|
+
await run(cli, args);
|
|
12
23
|
}
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
ensureNodeVersion("22");
|
|
16
|
-
const program = new Command();
|
|
17
|
-
program
|
|
18
|
-
.name("ph-cli")
|
|
19
|
-
.description("The Powerhouse CLI (ph-cli) is a command-line interface tool that provides essential commands for managing Powerhouse projects. The tool and it's commands are fundamental for creating, building, and running Document Models as a builder in studio mode.")
|
|
20
|
-
.allowUnknownOption(true)
|
|
21
|
-
.option("--verbose, --debug", "Enable debug mode");
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
-
// @ts-ignore build time version file
|
|
24
|
-
import("./version.js")
|
|
25
|
-
.then(({ version }) => program.version(version))
|
|
26
|
-
.catch((error) => console.error("Error loading version", error));
|
|
27
|
-
registerCommands(program);
|
|
28
|
-
// Logs full error only on debug mode. Otherwise logs only error message
|
|
29
|
-
program.parseAsync(process.argv).catch((error) => {
|
|
30
|
-
const isDebug = process.argv.find((arg) => ["--verbose", "--debug"].includes(arg));
|
|
31
|
-
if (isDebug) {
|
|
32
|
-
console.error(error);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const errorMessage = error instanceof Error
|
|
36
|
-
? error.message
|
|
37
|
-
: typeof error === "string"
|
|
38
|
-
? error
|
|
39
|
-
: JSON.stringify(error, null, 2);
|
|
40
|
-
console.error(errorMessage);
|
|
41
|
-
});
|
|
25
|
+
await main();
|
|
42
26
|
//# sourceMappingURL=cli.js.map
|
package/dist/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,KAAK,UAAU,IAAI;IACjB,iBAAiB,EAAE,CAAC;IACpB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC;IACpE,MAAM,cAAc,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;IACnD,MAAM,gBAAgB,GAAG,SAAS,IAAI,cAAc,CAAC;IACrD,MAAM,GAAG,GAAG,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IACjD,MAAM,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC;IACpC,IACE,OAAO,KAAK,SAAS;QACrB,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjD,CAAC,MAAM,EACP,CAAC;QACD,MAAM,gCAAgC,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;QAC5E,MAAM,GAAG,CAAC,GAAG,EAAE,gCAAgC,CAAC,CAAC;IACnD,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED,MAAM,IAAI,EAAE,CAAC"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export declare const accessToken: Partial<import("cmd-ts/dist/cjs/argparser.js").Register> & {
|
|
2
|
+
parse(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<{
|
|
3
|
+
debug: boolean | undefined;
|
|
4
|
+
expiry: string | undefined;
|
|
5
|
+
audience: string | undefined;
|
|
6
|
+
}>>;
|
|
7
|
+
} & import("cmd-ts/dist/cjs/helpdoc.js").PrintHelp & import("cmd-ts/dist/cjs/helpdoc.js").ProvidesHelp & import("cmd-ts/dist/cjs/helpdoc.js").Named & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Versioned> & import("cmd-ts/dist/cjs/argparser.js").Register & import("cmd-ts/dist/cjs/runner.js").Handling<{
|
|
8
|
+
debug: boolean | undefined;
|
|
9
|
+
expiry: string | undefined;
|
|
10
|
+
audience: string | undefined;
|
|
11
|
+
}, Promise<never>> & {
|
|
12
|
+
run(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<Promise<never>>>;
|
|
13
|
+
} & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Versioned & import("cmd-ts/dist/cjs/helpdoc.js").Descriptive & import("cmd-ts/dist/cjs/helpdoc.js").Aliased>;
|
|
9
14
|
//# sourceMappingURL=access-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-token.d.ts","sourceRoot":"","sources":["../../../src/commands/access-token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"access-token.d.ts","sourceRoot":"","sources":["../../../src/commands/access-token.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW;;;;;;;;;;;;6JA2GtB,CAAC"}
|
|
@@ -1,8 +1,103 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { accessTokenArgs, DEFAULT_EXPIRY_SECONDS, SECONDS_IN_DAY, } from "@powerhousedao/common/clis";
|
|
2
|
+
import { command } from "cmd-ts";
|
|
3
|
+
export const accessToken = command({
|
|
4
|
+
name: "access-token",
|
|
5
|
+
description: `
|
|
6
|
+
The access-token command generates a bearer token for API authentication. This token
|
|
7
|
+
can be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).
|
|
8
|
+
|
|
9
|
+
This command:
|
|
10
|
+
1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential
|
|
11
|
+
2. Creates a JWT bearer token with configurable expiration
|
|
12
|
+
3. Outputs the token to stdout (info to stderr) for easy piping
|
|
13
|
+
|
|
14
|
+
Prerequisites:
|
|
15
|
+
You must have a cryptographic identity. Run 'ph login' first to:
|
|
16
|
+
- Generate a keypair (stored in .ph/.keypair.json)
|
|
17
|
+
- Optionally link your Ethereum address (stored in .ph/.renown.json)
|
|
18
|
+
|
|
19
|
+
Token Details:
|
|
20
|
+
The generated token is a JWT (JSON Web Token) containing:
|
|
21
|
+
- Issuer (iss): Your CLI's DID (did:key:...)
|
|
22
|
+
- Subject (sub): Your CLI's DID
|
|
23
|
+
- Credential Subject: Chain ID, network ID, and address (if authenticated)
|
|
24
|
+
- Expiration (exp): Based on --expiry option
|
|
25
|
+
- Audience (aud): If --audience is specified
|
|
26
|
+
|
|
27
|
+
Output:
|
|
28
|
+
- Token information (DID, address, expiry) is printed to stderr
|
|
29
|
+
- The token itself is printed to stdout for easy piping/copying
|
|
30
|
+
|
|
31
|
+
This allows you to use the command in scripts:
|
|
32
|
+
TOKEN=$(ph access-token)
|
|
33
|
+
curl -H "Authorization: Bearer $TOKEN" http://localhost:4001/graphql
|
|
34
|
+
|
|
35
|
+
Usage with APIs:
|
|
36
|
+
Generate token and use with curl
|
|
37
|
+
TOKEN=$(ph access-token --expiry 1d)
|
|
38
|
+
curl -X POST http://localhost:4001/graphql \\
|
|
39
|
+
-H "Content-Type: application/json" \\
|
|
40
|
+
-H "Authorization: Bearer $TOKEN" \\
|
|
41
|
+
-d '{"query": "{ drives { id name } }"}'
|
|
42
|
+
|
|
43
|
+
Export as environment variable
|
|
44
|
+
export PH_ACCESS_TOKEN=$(ph access-token)
|
|
45
|
+
|
|
46
|
+
Notes:
|
|
47
|
+
- Tokens are self-signed using your CLI's private key
|
|
48
|
+
- No network request is made; tokens are generated locally
|
|
49
|
+
- The recipient API must trust your CLI's DID to accept the token
|
|
50
|
+
- For reactor-api, ensure AUTH_ENABLED=true to require authentication
|
|
51
|
+
`,
|
|
52
|
+
args: accessTokenArgs,
|
|
53
|
+
handler: async (args) => {
|
|
54
|
+
if (args.debug) {
|
|
55
|
+
console.log(args);
|
|
56
|
+
}
|
|
57
|
+
const { getRenown } = await import("../services/auth.js");
|
|
58
|
+
const renown = await getRenown();
|
|
59
|
+
const did = renown.did;
|
|
60
|
+
const user = renown.user;
|
|
61
|
+
// Require Renown authentication - user must have done 'ph login'
|
|
62
|
+
if (!user || !user.credential) {
|
|
63
|
+
throw new Error("Not authenticated. Run 'ph login' first to authenticate with Renown. A Renown credential is required to generate valid bearer tokens.");
|
|
64
|
+
}
|
|
65
|
+
const address = user.address;
|
|
66
|
+
// Parse expiry
|
|
67
|
+
let expiresIn = DEFAULT_EXPIRY_SECONDS;
|
|
68
|
+
if (args.expiry)
|
|
69
|
+
expiresIn = parseExpiry(args.expiry);
|
|
70
|
+
// Generate the bearer token;
|
|
71
|
+
const token = await renown.getBearerToken({
|
|
72
|
+
expiresIn,
|
|
73
|
+
aud: args.audience,
|
|
74
|
+
}, true);
|
|
75
|
+
// Calculate human-readable expiry
|
|
76
|
+
const expiryDays = Math.floor(expiresIn / SECONDS_IN_DAY);
|
|
77
|
+
const expiryHours = Math.floor((expiresIn % SECONDS_IN_DAY) / 3600);
|
|
78
|
+
let expiryStr;
|
|
79
|
+
if (expiryDays > 0) {
|
|
80
|
+
expiryStr =
|
|
81
|
+
expiryHours > 0
|
|
82
|
+
? `${expiryDays} day${expiryDays > 1 ? "s" : ""} and ${expiryHours} hour${expiryHours > 1 ? "s" : ""}`
|
|
83
|
+
: `${expiryDays} day${expiryDays > 1 ? "s" : ""}`;
|
|
84
|
+
}
|
|
85
|
+
else if (expiryHours > 0) {
|
|
86
|
+
expiryStr = `${expiryHours} hour${expiryHours > 1 ? "s" : ""}`;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
expiryStr = `${expiresIn} seconds`;
|
|
90
|
+
}
|
|
91
|
+
// Output token info to stderr, token itself to stdout for piping
|
|
92
|
+
console.error(`CLI DID: ${did}`);
|
|
93
|
+
console.error(`ETH Address: ${address}`);
|
|
94
|
+
console.error(`Token expires in: ${expiryStr}`);
|
|
95
|
+
console.error("");
|
|
96
|
+
// Output just the token to stdout (for easy piping/copying)
|
|
97
|
+
console.log(token);
|
|
98
|
+
process.exit(0);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
6
101
|
/**
|
|
7
102
|
* Parse expiry string to seconds
|
|
8
103
|
* Supports formats: "7d" (days), "24h" (hours), "3600" (seconds), "3600s" (seconds)
|
|
@@ -33,78 +128,4 @@ function parseExpiry(expiry) {
|
|
|
33
128
|
}
|
|
34
129
|
return seconds;
|
|
35
130
|
}
|
|
36
|
-
export const accessToken = async (options) => {
|
|
37
|
-
const { getConnectCrypto, getConnectDid, isAuthenticated, loadCredentials } = await import("../services/auth.js");
|
|
38
|
-
// Require Renown authentication - user must have done 'ph login'
|
|
39
|
-
if (!isAuthenticated()) {
|
|
40
|
-
console.error("Not authenticated. Run 'ph login' first to authenticate with Renown.");
|
|
41
|
-
console.error("A Renown credential is required to generate valid bearer tokens.");
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
const creds = loadCredentials();
|
|
45
|
-
if (!creds) {
|
|
46
|
-
console.error("Failed to load credentials.");
|
|
47
|
-
process.exit(1);
|
|
48
|
-
}
|
|
49
|
-
// Get the CLI's DID
|
|
50
|
-
let did;
|
|
51
|
-
try {
|
|
52
|
-
did = await getConnectDid();
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
console.error("Failed to get CLI identity. Run 'ph login' to reinitialize.");
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
const address = creds.address;
|
|
59
|
-
// Parse expiry
|
|
60
|
-
let expiresIn = DEFAULT_EXPIRY_SECONDS;
|
|
61
|
-
if (options.expiry) {
|
|
62
|
-
try {
|
|
63
|
-
expiresIn = parseExpiry(options.expiry);
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
console.error(e.message);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Generate the bearer token
|
|
71
|
-
const crypto = await getConnectCrypto();
|
|
72
|
-
const token = await crypto.getBearerToken(options.audience ?? "", address, true, // Force refresh to ensure we get a new token with the specified expiry
|
|
73
|
-
{
|
|
74
|
-
expiresIn,
|
|
75
|
-
aud: options.audience,
|
|
76
|
-
});
|
|
77
|
-
// Calculate human-readable expiry
|
|
78
|
-
const expiryDays = Math.floor(expiresIn / SECONDS_IN_DAY);
|
|
79
|
-
const expiryHours = Math.floor((expiresIn % SECONDS_IN_DAY) / 3600);
|
|
80
|
-
let expiryStr;
|
|
81
|
-
if (expiryDays > 0) {
|
|
82
|
-
expiryStr =
|
|
83
|
-
expiryHours > 0
|
|
84
|
-
? `${expiryDays} day${expiryDays > 1 ? "s" : ""} and ${expiryHours} hour${expiryHours > 1 ? "s" : ""}`
|
|
85
|
-
: `${expiryDays} day${expiryDays > 1 ? "s" : ""}`;
|
|
86
|
-
}
|
|
87
|
-
else if (expiryHours > 0) {
|
|
88
|
-
expiryStr = `${expiryHours} hour${expiryHours > 1 ? "s" : ""}`;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
expiryStr = `${expiresIn} seconds`;
|
|
92
|
-
}
|
|
93
|
-
// Output token info to stderr, token itself to stdout for piping
|
|
94
|
-
console.error(`CLI DID: ${did}`);
|
|
95
|
-
console.error(`ETH Address: ${address}`);
|
|
96
|
-
console.error(`Token expires in: ${expiryStr}`);
|
|
97
|
-
console.error("");
|
|
98
|
-
// Output just the token to stdout (for easy piping/copying)
|
|
99
|
-
console.log(token);
|
|
100
|
-
};
|
|
101
|
-
export function accessTokenCommand(program) {
|
|
102
|
-
const cmd = program
|
|
103
|
-
.command("access-token")
|
|
104
|
-
.description("Generate a bearer token for API authentication")
|
|
105
|
-
.option("--expiry <duration>", `Token expiry duration. Supports: "7d" (days), "24h" (hours), "3600" or "3600s" (seconds). Default: ${DEFAULT_EXPIRY_DAYS}d`)
|
|
106
|
-
.option("--audience <url>", "Target audience URL for the token (optional)")
|
|
107
|
-
.action(accessToken);
|
|
108
|
-
return setCustomHelp(cmd, accessTokenHelp);
|
|
109
|
-
}
|
|
110
131
|
//# sourceMappingURL=access-token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-token.js","sourceRoot":"","sources":["../../../src/commands/access-token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"access-token.js","sourceRoot":"","sources":["../../../src/commands/access-token.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;IACjC,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Cd;IACC,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACvB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAEzB,iEAAiE;QACjE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACb,uIAAuI,CACxI,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,C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