@trawlme/cli 1.15.0 → 1.16.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
@@ -117,9 +117,15 @@ TRAWL_TELEMETRY=0 trawl scraps list
117
117
  | Variable | Description |
118
118
  |--------------------|-------------------------------------------------------------------|
119
119
  | `TRAWL_TOKEN` | JWT token — bypasses login prompt, useful for CI/CD |
120
- | `TRAWL_API_URL` | Override the default API URL (`https://api.trawl.me`) |
120
+ | `TRAWL_API_URL` | Override the API base URL for the session (takes precedence over `trawl login --url`) |
121
121
  | `TRAWL_TELEMETRY` | Set to `0` to disable telemetry for the current session |
122
122
 
123
+ Session override (no `trawl login` mutation, ideal for CI/QA against another env):
124
+
125
+ ```bash
126
+ TRAWL_API_URL=https://dev.trawl.me TRAWL_TOKEN=<jwt> trawl scraps list --json
127
+ ```
128
+
123
129
  ## API documentation
124
130
 
125
131
  The Trawl API is documented at [trawl.me/api/spec.json](https://trawl.me/api/spec.json) (OpenAPI 3).
@@ -1,6 +1,6 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import config from '../lib/config.js';
3
+ import config, { getApiUrl } from '../lib/config.js';
4
4
  import { api } from '../lib/api.js';
5
5
  import { requireJwt, requireUrl } from '../lib/validate.js';
6
6
  import { promptPassword } from '../lib/prompt.js';
@@ -30,7 +30,7 @@ export const login = new Command('login')
30
30
  if (envToken) {
31
31
  config.set('token', requireJwt(envToken, 'TRAWL_TOKEN'));
32
32
  console.log(chalk.green('✓ Logged in'));
33
- console.log(chalk.dim(` API: ${config.get('apiUrl')}`));
33
+ console.log(chalk.dim(` API: ${getApiUrl()}`));
34
34
  console.log(chalk.dim(` Config: ${config.path}`));
35
35
  return;
36
36
  }
@@ -38,7 +38,7 @@ export const login = new Command('login')
38
38
  if (opts.token) {
39
39
  config.set('token', requireJwt(opts.token, '--token'));
40
40
  console.log(chalk.green('✓ Logged in'));
41
- console.log(chalk.dim(` API: ${config.get('apiUrl')}`));
41
+ console.log(chalk.dim(` API: ${getApiUrl()}`));
42
42
  console.log(chalk.dim(` Config: ${config.path}`));
43
43
  return;
44
44
  }
@@ -63,7 +63,7 @@ export const login = new Command('login')
63
63
  const token = requireJwt(raw, 'token');
64
64
  config.set('token', token);
65
65
  console.log(chalk.green(`✓ Logged in as ${email}`));
66
- console.log(chalk.dim(` API: ${config.get('apiUrl')}`));
66
+ console.log(chalk.dim(` API: ${getApiUrl()}`));
67
67
  console.log(chalk.dim(` Config: ${config.path}`));
68
68
  });
69
69
  export const logout = new Command('logout')
package/dist/lib/api.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { dirname, resolve } from 'node:path';
4
- import config from './config.js';
4
+ import config, { getApiUrl } from './config.js';
5
5
  const __dirname = dirname(fileURLToPath(import.meta.url));
6
6
  const pkg = JSON.parse(readFileSync(resolve(__dirname, '../../package.json'), 'utf8'));
7
7
  const USER_AGENT = `@trawlme/cli/${pkg.version}`;
@@ -60,7 +60,7 @@ async function request(path, options = {}) {
60
60
  const token = config.get('token');
61
61
  if (!token)
62
62
  throw new Error('Not logged in. Run: trawl login');
63
- const url = `${config.get('apiUrl')}${path}`;
63
+ const url = `${getApiUrl()}${path}`;
64
64
  const res = await fetch(url, {
65
65
  ...options,
66
66
  headers: {
@@ -90,7 +90,7 @@ async function upload(path, formData) {
90
90
  const token = config.get('token');
91
91
  if (!token)
92
92
  throw new Error('Not logged in. Run: trawl login');
93
- const url = `${config.get('apiUrl')}${path}`;
93
+ const url = `${getApiUrl()}${path}`;
94
94
  // Do NOT set Content-Type — fetch sets it automatically with the correct multipart boundary
95
95
  const res = await fetch(url, {
96
96
  method: 'POST',
@@ -117,7 +117,7 @@ async function upload(path, formData) {
117
117
  }
118
118
  }
119
119
  async function publicPost(path, body) {
120
- const url = `${config.get('apiUrl')}${path}`;
120
+ const url = `${getApiUrl()}${path}`;
121
121
  const res = await fetch(url, {
122
122
  method: 'POST',
123
123
  headers: { 'Content-Type': 'application/json', 'User-Agent': USER_AGENT },
@@ -137,7 +137,7 @@ async function getText(path) {
137
137
  const token = config.get('token');
138
138
  if (!token)
139
139
  throw new Error('Not logged in. Run: trawl login');
140
- const url = `${config.get('apiUrl')}${path}`;
140
+ const url = `${getApiUrl()}${path}`;
141
141
  const res = await fetch(url, {
142
142
  headers: {
143
143
  'User-Agent': USER_AGENT,
@@ -165,7 +165,7 @@ export const api = {
165
165
  const token = config.get('token');
166
166
  if (!token)
167
167
  throw new Error('Not logged in. Run: trawl login');
168
- const url = `${config.get('apiUrl')}${path}`;
168
+ const url = `${getApiUrl()}${path}`;
169
169
  const res = await fetch(url, {
170
170
  headers: {
171
171
  Accept: 'text/event-stream',
@@ -6,4 +6,12 @@ interface TrawlConfig {
6
6
  telemetryUserId: string;
7
7
  }
8
8
  declare const config: Conf<TrawlConfig>;
9
+ /**
10
+ * Resolve the effective API base URL.
11
+ * Precedence: TRAWL_API_URL env > stored `trawl login --url` > default.
12
+ * Mirrors the TRAWL_TOKEN / TRAWL_TELEMETRY session-override pattern so scripts
13
+ * (e.g. infra /trawl-prod-qa against https://dev.trawl.me) can retarget the CLI
14
+ * without mutating the operator's persisted config. (#56)
15
+ */
16
+ export declare function getApiUrl(): string;
9
17
  export default config;
@@ -8,4 +8,15 @@ const config = new Conf({
8
8
  telemetryUserId: '',
9
9
  },
10
10
  });
11
+ /**
12
+ * Resolve the effective API base URL.
13
+ * Precedence: TRAWL_API_URL env > stored `trawl login --url` > default.
14
+ * Mirrors the TRAWL_TOKEN / TRAWL_TELEMETRY session-override pattern so scripts
15
+ * (e.g. infra /trawl-prod-qa against https://dev.trawl.me) can retarget the CLI
16
+ * without mutating the operator's persisted config. (#56)
17
+ */
18
+ export function getApiUrl() {
19
+ const override = process.env['TRAWL_API_URL']?.trim();
20
+ return override ? override : config.get('apiUrl');
21
+ }
11
22
  export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {