@podge/cli 0.2.0-beta.0

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/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # Podge CLI
2
+
3
+ Command-line interface for managing Podge workspaces, environments, collections, and search.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install -g @podge/cli
9
+ ```
10
+
11
+ That's it — the `podge` command is now available globally.
12
+
13
+ ## Quick Start
14
+
15
+ ```sh
16
+ # Authenticate with your personal access token
17
+ podge auth login --token pdgu_your_token_here
18
+
19
+ # Set a default workspace and environment
20
+ podge config set --workspace my-workspace --environment production
21
+
22
+ # Start using it
23
+ podge workspaces list
24
+ podge search "my query" -c my-collection
25
+ ```
26
+
27
+ ## Authentication
28
+
29
+ ```sh
30
+ podge auth login --token <token> # Log in (token must start with pdgu_)
31
+ podge auth login --token <token> --api-url https://custom.api.url
32
+ podge auth status # Check auth status
33
+ podge auth logout # Remove stored credentials
34
+ ```
35
+
36
+ Credentials are stored in `~/.podge/credentials.json`.
37
+
38
+ ## Configuration
39
+
40
+ Set defaults so you don't have to pass `-w` and `-e` on every command:
41
+
42
+ ```sh
43
+ podge config set --workspace my-workspace --environment production
44
+ podge config get
45
+ ```
46
+
47
+ ## Commands
48
+
49
+ ### Workspaces
50
+
51
+ ```sh
52
+ podge workspaces list
53
+ podge workspaces get <key>
54
+ ```
55
+
56
+ ### Environments
57
+
58
+ ```sh
59
+ podge environments list
60
+ podge environments get <key>
61
+ ```
62
+
63
+ ### Collections
64
+
65
+ ```sh
66
+ podge collections list
67
+ podge collections get <key>
68
+ podge collections schema <key>
69
+ ```
70
+
71
+ ### Items
72
+
73
+ ```sh
74
+ podge items create -c <collection> -d '{"field": "value"}'
75
+ podge items create -c <collection> -f data.json
76
+ podge items get <documentId> -c <collection>
77
+ podge items import -c <collection> -f items.json
78
+ ```
79
+
80
+ ### Search
81
+
82
+ ```sh
83
+ podge search "my query" -c <collection>
84
+ podge search "my query" -c <collection> --json --no-cache
85
+ ```
86
+
87
+ All commands support `-w <workspace>` and `-e <environment>` flags to override your configured defaults. Add `--json` to list/get commands for machine-readable output.
88
+
89
+ Run `podge <command> --help` for detailed usage on any command.
90
+
91
+ ## Development
92
+
93
+ ```sh
94
+ pnpm install # Install deps + build
95
+ pnpm dev # Watch mode
96
+ pnpm build # One-off build
97
+ ```
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerApiKeyCommands(program: Command): void;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerApiKeyCommands = void 0;
7
+ const client_1 = require("../lib/client");
8
+ const config_1 = require("../lib/config");
9
+ const output_1 = require("../lib/output");
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ function requireWorkspace(opts) {
12
+ const cfg = (0, config_1.getConfig)();
13
+ const ws = opts.workspace || cfg.workspace;
14
+ if (!ws) {
15
+ console.error(chalk_1.default.red("Workspace required. Use -w flag or `podge config set`."));
16
+ process.exit(1);
17
+ }
18
+ return ws;
19
+ }
20
+ function registerApiKeyCommands(program) {
21
+ const apikeys = program
22
+ .command("apikeys")
23
+ .alias("api-keys")
24
+ .description("Manage API keys");
25
+ apikeys
26
+ .command("list")
27
+ .description("List API keys")
28
+ .option("-w, --workspace <slug>", "Workspace slug")
29
+ .option("--json", "Output as JSON")
30
+ .action(async (opts) => {
31
+ try {
32
+ const ws = requireWorkspace(opts);
33
+ const { data } = await (0, client_1.getClient)().get(`/api/v1/workspace/${ws}/api-keys`);
34
+ if (opts.json) {
35
+ (0, output_1.printJson)(data);
36
+ }
37
+ else {
38
+ const keys = Array.isArray(data) ? data : [];
39
+ if (keys.length === 0) {
40
+ console.log("No API keys found.");
41
+ return;
42
+ }
43
+ (0, output_1.printTable)(["ID", "NAME", "PREFIX", "REVOKED", "CREATED"], keys.map((k) => [
44
+ String(k.id),
45
+ k.name,
46
+ k.keyPrefix,
47
+ k.revoked ? "yes" : "no",
48
+ k.createdAt,
49
+ ]));
50
+ }
51
+ }
52
+ catch (err) {
53
+ (0, client_1.handleError)(err);
54
+ }
55
+ });
56
+ apikeys
57
+ .command("create")
58
+ .description("Create an API key")
59
+ .requiredOption("--name <name>", "Key name")
60
+ .option("-e, --environment <slug>", "Scope to environment")
61
+ .option("-w, --workspace <slug>", "Workspace slug")
62
+ .option("--json", "Output as JSON")
63
+ .action(async (opts) => {
64
+ try {
65
+ const ws = requireWorkspace(opts);
66
+ const body = {
67
+ name: opts.name,
68
+ };
69
+ if (opts.environment) {
70
+ body.environmentKey = opts.environment;
71
+ }
72
+ const { data } = await (0, client_1.getClient)().post(`/api/v1/workspace/${ws}/api-keys`, body);
73
+ if (opts.json) {
74
+ (0, output_1.printJson)(data);
75
+ }
76
+ else {
77
+ (0, output_1.printSuccess)(`API key created: ${data.name}`);
78
+ if (data.key) {
79
+ console.log(chalk_1.default.yellow(`\n Key: ${data.key}\n\n Save this key — it will not be shown again.\n`));
80
+ }
81
+ (0, output_1.printJson)(data);
82
+ }
83
+ }
84
+ catch (err) {
85
+ (0, client_1.handleError)(err);
86
+ }
87
+ });
88
+ apikeys
89
+ .command("delete <keyId>")
90
+ .description("Revoke/delete an API key")
91
+ .option("-w, --workspace <slug>", "Workspace slug")
92
+ .action(async (keyId, opts) => {
93
+ try {
94
+ const ws = requireWorkspace(opts);
95
+ await (0, client_1.getClient)().delete(`/api/v1/workspace/${ws}/api-keys/${keyId}`);
96
+ (0, output_1.printSuccess)(`API key ${keyId} revoked`);
97
+ }
98
+ catch (err) {
99
+ (0, client_1.handleError)(err);
100
+ }
101
+ });
102
+ }
103
+ exports.registerApiKeyCommands = registerApiKeyCommands;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerAuthCommands(program: Command): void;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.registerAuthCommands = void 0;
30
+ const crypto = __importStar(require("crypto"));
31
+ const chalk_1 = __importDefault(require("chalk"));
32
+ const config_1 = require("../lib/config");
33
+ const output_1 = require("../lib/output");
34
+ const auth_server_1 = require("../lib/auth-server");
35
+ const open_browser_1 = require("../lib/open-browser");
36
+ function registerAuthCommands(program) {
37
+ const auth = program.command("auth").description("Manage authentication");
38
+ auth
39
+ .command("login", { isDefault: true })
40
+ .description("Authenticate with the browser or a personal access token")
41
+ .option("--token <token>", "Personal access token (pdgu_...)")
42
+ .option("--no-browser", "Print the login URL instead of opening the browser")
43
+ .action(async (opts) => {
44
+ if (opts.token) {
45
+ // Manual token flow
46
+ if (!opts.token.startsWith("pdgu_")) {
47
+ console.error(chalk_1.default.red('Invalid token format. Token must start with "pdgu_".'));
48
+ process.exit(1);
49
+ }
50
+ (0, config_1.saveCredentials)({ token: opts.token, apiUrl: (0, config_1.getApiUrl)() });
51
+ (0, output_1.printSuccess)("Authenticated successfully. Credentials saved to ~/.podge/credentials.json");
52
+ return;
53
+ }
54
+ // Browser auth flow
55
+ const state = crypto.randomBytes(16).toString("hex");
56
+ let port;
57
+ let tokenPromise;
58
+ try {
59
+ const server = await (0, auth_server_1.startAuthServer)(state);
60
+ port = server.port;
61
+ tokenPromise = server.tokenPromise;
62
+ }
63
+ catch (err) {
64
+ console.error(chalk_1.default.red("Failed to start local auth server."));
65
+ process.exit(1);
66
+ }
67
+ const appUrl = (0, config_1.getAppUrl)();
68
+ const loginUrl = `${appUrl}/cli-auth?port=${port}&state=${state}`;
69
+ if (opts.browser) {
70
+ (0, output_1.printInfo)("Opening browser to authenticate...");
71
+ (0, open_browser_1.openBrowser)(loginUrl);
72
+ }
73
+ else {
74
+ (0, output_1.printInfo)("Open this URL in your browser to authenticate:");
75
+ console.log(`\n ${loginUrl}\n`);
76
+ }
77
+ (0, output_1.printInfo)("Waiting for authentication...");
78
+ try {
79
+ const result = await tokenPromise;
80
+ (0, config_1.saveCredentials)({ token: result.token, apiUrl: (0, config_1.getApiUrl)() });
81
+ (0, output_1.printSuccess)("Authenticated successfully. Credentials saved to ~/.podge/credentials.json");
82
+ }
83
+ catch (err) {
84
+ console.error(chalk_1.default.red(err instanceof Error ? err.message : "Authentication failed."));
85
+ process.exit(1);
86
+ }
87
+ });
88
+ auth
89
+ .command("logout")
90
+ .description("Remove stored credentials")
91
+ .action(() => {
92
+ (0, config_1.clearCredentials)();
93
+ (0, output_1.printSuccess)("Logged out. Credentials removed.");
94
+ });
95
+ auth
96
+ .command("status")
97
+ .description("Show current authentication status")
98
+ .action(() => {
99
+ const creds = (0, config_1.getCredentials)();
100
+ if (creds) {
101
+ console.log(chalk_1.default.green("Authenticated"));
102
+ console.log(` API URL: ${creds.apiUrl}`);
103
+ console.log(` Token: ${creds.token.substring(0, 12)}...`);
104
+ }
105
+ else {
106
+ console.log(chalk_1.default.yellow("Not authenticated"));
107
+ }
108
+ });
109
+ }
110
+ exports.registerAuthCommands = registerAuthCommands;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerCollectionCommands(program: Command): void;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerCollectionCommands = void 0;
7
+ const client_1 = require("../lib/client");
8
+ const config_1 = require("../lib/config");
9
+ const output_1 = require("../lib/output");
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ function requireContext(opts) {
12
+ const cfg = (0, config_1.getConfig)();
13
+ const ws = opts.workspace || cfg.workspace;
14
+ const env = opts.environment || cfg.environment;
15
+ if (!ws || !env) {
16
+ console.error(chalk_1.default.red("Workspace and environment required. Use --workspace/--environment or `podge config set`."));
17
+ process.exit(1);
18
+ }
19
+ return { ws, env };
20
+ }
21
+ function registerCollectionCommands(program) {
22
+ const col = program
23
+ .command("collections")
24
+ .alias("col")
25
+ .description("Manage collections");
26
+ col
27
+ .command("list")
28
+ .description("List collections")
29
+ .option("-w, --workspace <key>", "Workspace key")
30
+ .option("-e, --environment <key>", "Environment key")
31
+ .option("--json", "Output as JSON")
32
+ .action(async (opts) => {
33
+ try {
34
+ const { ws, env } = requireContext(opts);
35
+ const { data } = await (0, client_1.getClient)().get(`/api/v1/workspace/${ws}/environment/${env}/collections`);
36
+ if (opts.json) {
37
+ (0, output_1.printJson)(data);
38
+ }
39
+ else {
40
+ const rows = (Array.isArray(data) ? data : []).map((c) => [
41
+ String(c.id),
42
+ c.key,
43
+ c.name,
44
+ ]);
45
+ (0, output_1.printTable)(["ID", "KEY", "NAME"], rows);
46
+ }
47
+ }
48
+ catch (err) {
49
+ (0, client_1.handleError)(err);
50
+ }
51
+ });
52
+ col
53
+ .command("get <key>")
54
+ .description("Get collection details")
55
+ .option("-w, --workspace <key>", "Workspace key")
56
+ .option("-e, --environment <key>", "Environment key")
57
+ .option("--json", "Output as JSON")
58
+ .action(async (key, opts) => {
59
+ try {
60
+ const { ws, env } = requireContext(opts);
61
+ const { data } = await (0, client_1.getClient)().get(`/api/v1/workspace/${ws}/environment/${env}/collection/${key}`);
62
+ if (opts.json) {
63
+ (0, output_1.printJson)(data);
64
+ }
65
+ else {
66
+ console.log(`Name: ${data.name}`);
67
+ console.log(`Key: ${data.key}`);
68
+ }
69
+ }
70
+ catch (err) {
71
+ (0, client_1.handleError)(err);
72
+ }
73
+ });
74
+ col
75
+ .command("schema <key>")
76
+ .description("Get collection schema")
77
+ .option("-w, --workspace <key>", "Workspace key")
78
+ .option("-e, --environment <key>", "Environment key")
79
+ .action(async (key, opts) => {
80
+ try {
81
+ const { ws, env } = requireContext(opts);
82
+ const { data } = await (0, client_1.getClient)().get(`/api/v1/workspace/${ws}/environment/${env}/collection/${key}/schema`);
83
+ (0, output_1.printJson)(data);
84
+ }
85
+ catch (err) {
86
+ (0, client_1.handleError)(err);
87
+ }
88
+ });
89
+ }
90
+ exports.registerCollectionCommands = registerCollectionCommands;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerConfigCommands(program: Command): void;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerConfigCommands = void 0;
4
+ const config_1 = require("../lib/config");
5
+ const output_1 = require("../lib/output");
6
+ function registerConfigCommands(program) {
7
+ const config = program
8
+ .command("config")
9
+ .description("Manage CLI configuration");
10
+ config
11
+ .command("set")
12
+ .description("Set a configuration value")
13
+ .requiredOption("--workspace <key>", "Default workspace key")
14
+ .option("--environment <key>", "Default environment key")
15
+ .action((opts) => {
16
+ const updates = {};
17
+ if (opts.workspace)
18
+ updates.workspace = opts.workspace;
19
+ if (opts.environment)
20
+ updates.environment = opts.environment;
21
+ (0, config_1.saveConfig)(updates);
22
+ (0, output_1.printSuccess)("Configuration updated.");
23
+ });
24
+ config
25
+ .command("get")
26
+ .description("Show current configuration")
27
+ .action(() => {
28
+ const cfg = (0, config_1.getConfig)();
29
+ if (Object.keys(cfg).length === 0) {
30
+ (0, output_1.printInfo)("No configuration set. Use `podge config set` to configure defaults.");
31
+ return;
32
+ }
33
+ for (const [key, value] of Object.entries(cfg)) {
34
+ console.log(` ${key}: ${value}`);
35
+ }
36
+ });
37
+ }
38
+ exports.registerConfigCommands = registerConfigCommands;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerDebugCommands(program: Command): void;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerDebugCommands = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const config_1 = require("../lib/config");
9
+ const output_1 = require("../lib/output");
10
+ function registerDebugCommands(program) {
11
+ const debug = program
12
+ .command("debug")
13
+ .description("Internal commands for Podge developers")
14
+ .addHelpText("before", chalk_1.default.yellow("⚠ These commands are for Podge developers only.\n"));
15
+ debug
16
+ .command("set-api <url>")
17
+ .description("Override the API base URL (e.g. http://localhost:3000/api)")
18
+ .action((url) => {
19
+ (0, config_1.saveConfig)({ apiUrl: url });
20
+ (0, output_1.printSuccess)(`API URL set to ${url}`);
21
+ console.log(chalk_1.default.dim("Run `podge auth login` again to apply the new URL."));
22
+ });
23
+ debug
24
+ .command("reset-api")
25
+ .description("Reset API URL to the default")
26
+ .action(() => {
27
+ const { apiUrl: _, ...rest } = (0, config_1.getConfig)();
28
+ (0, config_1.writeConfig)(rest);
29
+ (0, output_1.printSuccess)("API URL reset to default.");
30
+ });
31
+ debug
32
+ .command("status")
33
+ .description("Show resolved URLs and config")
34
+ .action(() => {
35
+ const config = (0, config_1.getConfig)();
36
+ console.log(` API URL: ${(0, config_1.getApiUrl)()}${config.apiUrl ? " (override)" : ""}`);
37
+ console.log(` App URL: ${(0, config_1.getAppUrl)()}${config.appUrl ? " (override)" : ""}`);
38
+ console.log(` Config: ~/.podge/config.json`);
39
+ });
40
+ }
41
+ exports.registerDebugCommands = registerDebugCommands;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerEnvironmentCommands(program: Command): void;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerEnvironmentCommands = void 0;
7
+ const client_1 = require("../lib/client");
8
+ const config_1 = require("../lib/config");
9
+ const output_1 = require("../lib/output");
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ function requireWorkspace(opts) {
12
+ const ws = opts.workspace || (0, config_1.getConfig)().workspace;
13
+ if (!ws) {
14
+ console.error(chalk_1.default.red("Workspace required. Use --workspace or `podge config set --workspace <key>`."));
15
+ process.exit(1);
16
+ }
17
+ return ws;
18
+ }
19
+ function registerEnvironmentCommands(program) {
20
+ const env = program
21
+ .command("environments")
22
+ .alias("env")
23
+ .description("Manage environments");
24
+ env
25
+ .command("list")
26
+ .description("List environments")
27
+ .option("-w, --workspace <key>", "Workspace key")
28
+ .option("--json", "Output as JSON")
29
+ .action(async (opts) => {
30
+ try {
31
+ const ws = requireWorkspace(opts);
32
+ const { data } = await (0, client_1.getClient)().get(`/api/v1/workspace/${ws}/environments`);
33
+ if (opts.json) {
34
+ (0, output_1.printJson)(data);
35
+ }
36
+ else {
37
+ const rows = (Array.isArray(data) ? data : []).map((e) => [
38
+ String(e.id),
39
+ e.key,
40
+ e.name,
41
+ ]);
42
+ (0, output_1.printTable)(["ID", "KEY", "NAME"], rows);
43
+ }
44
+ }
45
+ catch (err) {
46
+ (0, client_1.handleError)(err);
47
+ }
48
+ });
49
+ env
50
+ .command("get <key>")
51
+ .description("Get environment details")
52
+ .option("-w, --workspace <key>", "Workspace key")
53
+ .option("--json", "Output as JSON")
54
+ .action(async (key, opts) => {
55
+ try {
56
+ const ws = requireWorkspace(opts);
57
+ const { data } = await (0, client_1.getClient)().get(`/api/v1/workspace/${ws}/environment/${key}`);
58
+ if (opts.json) {
59
+ (0, output_1.printJson)(data);
60
+ }
61
+ else {
62
+ console.log(`Name: ${data.name}`);
63
+ console.log(`Key: ${data.key}`);
64
+ }
65
+ }
66
+ catch (err) {
67
+ (0, client_1.handleError)(err);
68
+ }
69
+ });
70
+ }
71
+ exports.registerEnvironmentCommands = registerEnvironmentCommands;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerItemCommands(program: Command): void;