@trawlme/cli 3.15.0 → 3.17.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 CHANGED
@@ -59,6 +59,9 @@ trawl data <id> [--json] [--fresh] [--errors] Get scrap data (last persisted ru
59
59
  trawl runs|history <id> [--json] [-n <limit>] List past runs for a scrap (newest first)
60
60
  trawl run-info <hid> [--json] Show details of a single run
61
61
  trawl whoami [--json] Show the authenticated user's identity
62
+ trawl orgs list [--json] List your organizations (id, name, role) — session login only; bare `trawl orgs` is the same
63
+ trawl orgs current [--json] Show the current organization
64
+ trawl orgs switch <id> [--json] Switch the current organization (403 = not a member)
62
65
  trawl token [--json] Print the stored credential — API key or session JWT (for MCP Bearer auth)
63
66
  trawl ping [--json] Health/version handshake against the Trawl API
64
67
  trawl spec [--json] Print a versioned, machine-readable description of the command tree
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const admin: Command;
@@ -0,0 +1,35 @@
1
+ import { Command, Option } from 'commander';
2
+ import { ApiError, api } from '../lib/api.js';
3
+ import { json } from '../lib/format.js';
4
+ const FORBIDDEN_HINT = 'Forbidden: this key needs the trawl:admin:read scope and a platform-admin owner (or log in as an admin).';
5
+ async function getAdmin(path, query) {
6
+ const qs = new URLSearchParams(Object.entries(query).filter(([, v]) => v !== undefined)).toString();
7
+ try {
8
+ json(await api.get(qs ? `${path}?${qs}` : path));
9
+ }
10
+ catch (err) {
11
+ if (err instanceof ApiError && err.status === 403)
12
+ throw new ApiError(403, `${FORBIDDEN_HINT} (${err.message})`);
13
+ throw err;
14
+ }
15
+ }
16
+ const windowOption = () => new Option('--window <window>', 'Time window (7d|30d|90d)').choices(['7d', '30d', '90d']);
17
+ export const admin = new Command('admin').description('Platform-admin read-only views (needs trawl:admin:read + an admin owner)');
18
+ admin
19
+ .command('orgs', { hidden: true })
20
+ .description('Per-organization health and churn signals (GET /api/admin/monitoring/organizations)')
21
+ .addOption(windowOption())
22
+ .option('--json', 'Output as JSON (default: on)', true)
23
+ .action((opts) => getAdmin('/api/admin/monitoring/organizations', { window: opts.window }));
24
+ admin
25
+ .command('series', { hidden: true })
26
+ .description('Platform-wide runs per day (GET /api/admin/monitoring/series)')
27
+ .addOption(windowOption())
28
+ .option('--json', 'Output as JSON (default: on)', true)
29
+ .action((opts) => getAdmin('/api/admin/monitoring/series', { window: opts.window }));
30
+ admin
31
+ .command('costs', { hidden: true })
32
+ .description('Aggregate costs over a period (GET /api/admin/costs)')
33
+ .addOption(new Option('--period <period>', 'Reporting period (day|week|month)').choices(['day', 'week', 'month']))
34
+ .option('--json', 'Output as JSON (default: on)', true)
35
+ .action((opts) => getAdmin('/api/admin/costs', { period: opts.period }));
@@ -0,0 +1,11 @@
1
+ import { Command } from 'commander';
2
+ export interface OrgItem {
3
+ _id?: string;
4
+ id?: string;
5
+ name?: string;
6
+ role?: string;
7
+ membership?: {
8
+ role?: string;
9
+ };
10
+ }
11
+ export declare const orgs: Command;
@@ -0,0 +1,98 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { ApiError, api, apiKeyUnsupportedError } from '../lib/api.js';
4
+ import { getAuthMode } from '../lib/config.js';
5
+ import { json } from '../lib/format.js';
6
+ import { UsageError } from '../lib/errors.js';
7
+ function requireSession(command) {
8
+ if (getAuthMode() === 'apiKey')
9
+ throw apiKeyUnsupportedError(command);
10
+ }
11
+ function orgRef(ref) {
12
+ if (!ref)
13
+ return {};
14
+ if (typeof ref === 'string')
15
+ return { id: ref };
16
+ return { id: ref._id ?? ref.id, name: ref.name };
17
+ }
18
+ function currentOrg(ref) {
19
+ const { id, name } = orgRef(ref);
20
+ return { id: id ?? null, name: name ?? null };
21
+ }
22
+ function printCurrent(org, emptyMsg) {
23
+ if (!org.id) {
24
+ console.log(chalk.dim(emptyMsg));
25
+ return;
26
+ }
27
+ console.log(chalk.bold(org.name ?? org.id));
28
+ console.log(chalk.dim(' ID: ') + org.id);
29
+ if (org.name)
30
+ console.log(chalk.dim(' Name: ') + org.name);
31
+ }
32
+ const wantsJson = (cmd) => Boolean(cmd.optsWithGlobals().json);
33
+ async function listOrgs(_opts, cmd) {
34
+ requireSession('trawl orgs');
35
+ const data = await api.get('/api/organizations');
36
+ const items = (Array.isArray(data) ? data : []).map((o) => ({
37
+ id: o._id ?? o.id ?? null,
38
+ name: o.name ?? null,
39
+ role: o.role ?? o.membership?.role ?? null,
40
+ }));
41
+ if (wantsJson(cmd)) {
42
+ json(items);
43
+ return;
44
+ }
45
+ if (!items.length) {
46
+ console.log(chalk.dim('No organizations.'));
47
+ return;
48
+ }
49
+ for (const o of items)
50
+ console.log(`${o.id ?? '—'} ${o.name ?? '—'} ${chalk.dim(o.role ?? '—')}`);
51
+ }
52
+ export const orgs = new Command('orgs')
53
+ .description('List your organizations (GET /api/organizations)')
54
+ .option('--json', 'Output as JSON')
55
+ .action(listOrgs);
56
+ orgs
57
+ .command('list')
58
+ .description('Same as `trawl orgs` (GET /api/organizations)')
59
+ .option('--json', 'Output as JSON')
60
+ .action(listOrgs);
61
+ orgs
62
+ .command('current')
63
+ .description('Show the current organization (GET /api/auth/token)')
64
+ .option('--json', 'Output as JSON')
65
+ .action(async (_opts, cmd) => {
66
+ requireSession('trawl orgs current');
67
+ const data = await api.get('/api/auth/token');
68
+ const org = currentOrg(data?.user?.currentOrganization);
69
+ if (wantsJson(cmd))
70
+ json(org);
71
+ else
72
+ printCurrent(org, 'No current organization.');
73
+ });
74
+ orgs
75
+ .command('switch <id>')
76
+ .description('Switch the current organization (POST /api/organizations/:id/switch)')
77
+ .option('--json', 'Output as JSON')
78
+ .action(async (id, _opts, cmd) => {
79
+ requireSession('trawl orgs switch');
80
+ if (!/^[0-9a-fA-F]{24}$/.test(id)) {
81
+ throw new UsageError(`Invalid organization ID: "${id}" — expected a 24-char hex ObjectId`);
82
+ }
83
+ let data;
84
+ try {
85
+ data = await api.post(`/api/organizations/${id}/switch`);
86
+ }
87
+ catch (err) {
88
+ if (err instanceof ApiError && err.status === 403) {
89
+ throw new ApiError(403, 'Not a member of this organization.');
90
+ }
91
+ throw err;
92
+ }
93
+ const org = currentOrg(data?.user?.currentOrganization ?? id);
94
+ if (wantsJson(cmd))
95
+ json(org);
96
+ else
97
+ printCurrent(org, 'Switched.');
98
+ });
package/dist/index.js CHANGED
@@ -13,6 +13,8 @@ import { upgrade } from './commands/upgrade.js';
13
13
  import { create } from './commands/create.js';
14
14
  import { whoami } from './commands/whoami.js';
15
15
  import { ping } from './commands/ping.js';
16
+ import { admin } from './commands/admin.js';
17
+ import { orgs } from './commands/orgs.js';
16
18
  import { spec } from './commands/spec.js';
17
19
  import { autoUpdateInstalledSkills } from './lib/skills.js';
18
20
  import { maybeSuggestSkillsInstall } from './lib/skillsNudge.js';
@@ -70,6 +72,8 @@ export function createProgram() {
70
72
  program.commandsGroup(MANAGEMENT_GROUP);
71
73
  program.addCommand(scraps);
72
74
  program.addCommand(skills);
75
+ program.addCommand(admin, { hidden: true });
76
+ program.addCommand(orgs);
73
77
  program.addCommand(login);
74
78
  program.addCommand(logout);
75
79
  program.addCommand(telemetry);
@@ -218,7 +222,7 @@ export async function runCli(argv = process.argv) {
218
222
  exit_code: exitCode,
219
223
  error: err.name,
220
224
  });
221
- const wantsJson = Boolean(currentCommand?.opts()?.json);
225
+ const wantsJson = Boolean(currentCommand?.optsWithGlobals()?.json);
222
226
  if (isDebug)
223
227
  console.error(err);
224
228
  process.exitCode = reportError(err, { json: wantsJson, quiet: isDebug });
@@ -243,7 +247,7 @@ export async function runCli(argv = process.argv) {
243
247
  if (process.exitCode === undefined || process.exitCode === 0) {
244
248
  try {
245
249
  maybeSuggestSkillsInstall({
246
- json: Boolean(currentCommand?.opts()?.json),
250
+ json: Boolean(currentCommand?.optsWithGlobals()?.json),
247
251
  });
248
252
  }
249
253
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "3.15.0",
3
+ "version": "3.17.0",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {