@settlemint/dalp-cli 3.1.32-main.42194559254 → 3.1.32-main.42209626311

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/src/main.ts ADDED
@@ -0,0 +1,99 @@
1
+ import { Cli } from "incur";
2
+ import { configCommand } from "./commands/config.ts";
3
+ import { loginCommand } from "./commands/login.ts";
4
+ import { logoutCommand } from "./commands/logout.ts";
5
+ import { orgCommand } from "./commands/org.ts";
6
+ import { whoamiCommand } from "./commands/whoami.ts";
7
+ import { makeCliClient } from "./lib/api-client.ts";
8
+ import { resolveConfig } from "./lib/cli-config.ts";
9
+ import { loadCredentials } from "./lib/credential-store.ts";
10
+ import { registerGeneratedOperations } from "./lib/register-operations.ts";
11
+ import { runCommand } from "./lib/run-command.ts";
12
+ import { CLI_VERSION, cliVars } from "./lib/vars.ts";
13
+
14
+ const SKIP_AUTH_COMMANDS = new Set(["login", "logout", "config", "mcp", "skills"]);
15
+
16
+ export const topLevelCommandName = (command: string | undefined): string => command?.split(/[ _]/u)[0] ?? "";
17
+
18
+ export const makeCli = (): Cli.Cli<Record<string, never>, typeof cliVars> => {
19
+ const cli: Cli.Cli<Record<string, never>, typeof cliVars> = Cli.create("dalp", {
20
+ version: CLI_VERSION,
21
+ description: "DALP — Digital Asset Lifecycle Platform CLI",
22
+ vars: cliVars,
23
+ sync: {
24
+ depth: 1,
25
+ include: ["_root"],
26
+ suggestions: ["login to your DALP instance", "list all tokens", "switch active organization", "check whoami"],
27
+ },
28
+ });
29
+
30
+ cli.use(async (c, next) => {
31
+ const commandName = topLevelCommandName(c.command);
32
+
33
+ if (commandName === "login") {
34
+ const config = await resolveConfig();
35
+ if (config.apiUrl !== undefined && config.apiUrl !== "") {
36
+ c.set("apiUrl", config.apiUrl);
37
+ }
38
+ return next();
39
+ }
40
+
41
+ if (SKIP_AUTH_COMMANDS.has(commandName)) {
42
+ return next();
43
+ }
44
+
45
+ let authenticated = false;
46
+
47
+ await runCommand(
48
+ c,
49
+ (async () => {
50
+ const credentials = await loadCredentials();
51
+ if (credentials === undefined) {
52
+ return c.error({
53
+ code: "NOT_AUTHENTICATED",
54
+ message: "Not logged in. Run 'dalp login' to authenticate.",
55
+ retryable: true,
56
+ cta: {
57
+ description:
58
+ "Why: No stored DALP credentials were found for this CLI command.\nFix: Run 'dalp login' against the DALP instance you want to manage, then retry the command.",
59
+ commands: [{ command: "login", description: "Log in via browser" }],
60
+ },
61
+ });
62
+ }
63
+
64
+ const config = await resolveConfig();
65
+ const client = makeCliClient(credentials.apiUrl, credentials, {
66
+ defaultOrg: config.defaultOrg,
67
+ });
68
+ c.set("apiUrl", credentials.apiUrl);
69
+ c.set("credentials", credentials);
70
+ c.set("client", client);
71
+ authenticated = true;
72
+ })(),
73
+ {
74
+ code: "NOT_AUTHENTICATED",
75
+ fallbackMessage: "Not logged in. Run 'dalp login' to authenticate.",
76
+ fallbackWhy: "No stored DALP credentials were found for this CLI command.",
77
+ fallbackFix: "Run 'dalp login' against the DALP instance you want to manage, then retry the command.",
78
+ }
79
+ );
80
+
81
+ if (!authenticated) {
82
+ return;
83
+ }
84
+
85
+ return next();
86
+ });
87
+
88
+ cli.command(loginCommand).command(logoutCommand).command(configCommand).command(whoamiCommand).command(orgCommand);
89
+
90
+ registerGeneratedOperations(cli);
91
+
92
+ return cli;
93
+ };
94
+
95
+ export const cli: Cli.Cli<Record<string, never>, typeof cliVars> = makeCli();
96
+
97
+ if (import.meta.main) {
98
+ await cli.serve();
99
+ }