@crawl82/cli 0.0.0-stage → 0.5.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.
Files changed (53) hide show
  1. package/AGENTS.md +257 -0
  2. package/README.md +120 -2
  3. package/dist/api-types.generated.js +12 -0
  4. package/dist/api-types.generated.js.map +1 -0
  5. package/dist/commands/api.js +111 -0
  6. package/dist/commands/api.js.map +1 -0
  7. package/dist/commands/auth.js +284 -0
  8. package/dist/commands/auth.js.map +1 -0
  9. package/dist/commands/completion.js +120 -0
  10. package/dist/commands/completion.js.map +1 -0
  11. package/dist/commands/doctor.js +141 -0
  12. package/dist/commands/doctor.js.map +1 -0
  13. package/dist/commands/feedback.js +39 -0
  14. package/dist/commands/feedback.js.map +1 -0
  15. package/dist/commands/help-json.js +144 -0
  16. package/dist/commands/help-json.js.map +1 -0
  17. package/dist/commands/mcp.js +129 -0
  18. package/dist/commands/mcp.js.map +1 -0
  19. package/dist/commands/read.js +107 -0
  20. package/dist/commands/read.js.map +1 -0
  21. package/dist/commands/sites.js +604 -0
  22. package/dist/commands/sites.js.map +1 -0
  23. package/dist/credentials.js +151 -0
  24. package/dist/credentials.js.map +1 -0
  25. package/dist/errors.js +150 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/exit-codes.js +82 -0
  28. package/dist/exit-codes.js.map +1 -0
  29. package/dist/http.js +260 -0
  30. package/dist/http.js.map +1 -0
  31. package/dist/index.js +158 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/keychain.js +185 -0
  34. package/dist/keychain.js.map +1 -0
  35. package/dist/oauth/browser.js +33 -0
  36. package/dist/oauth/browser.js.map +1 -0
  37. package/dist/oauth/pkce.js +118 -0
  38. package/dist/oauth/pkce.js.map +1 -0
  39. package/dist/oauth/server.js +281 -0
  40. package/dist/oauth/server.js.map +1 -0
  41. package/dist/operations.generated.js +6290 -0
  42. package/dist/operations.generated.js.map +1 -0
  43. package/dist/output.js +161 -0
  44. package/dist/output.js.map +1 -0
  45. package/dist/refresh-lock.js +84 -0
  46. package/dist/refresh-lock.js.map +1 -0
  47. package/dist/run.js +186 -0
  48. package/dist/run.js.map +1 -0
  49. package/dist/session.js +147 -0
  50. package/dist/session.js.map +1 -0
  51. package/dist/version.js +34 -0
  52. package/dist/version.js.map +1 -0
  53. package/package.json +47 -4
package/dist/run.js ADDED
@@ -0,0 +1,186 @@
1
+ /**
2
+ * The single error boundary.
3
+ *
4
+ * Every command body runs inside `run()`, so there is exactly one place that
5
+ * decides how a failure is printed and which exit code it produces. A command
6
+ * that wants to fail simply throws.
7
+ */
8
+ import readline from "node:readline";
9
+ import { CliError, forceRequired, toErrorReport, yesRequired } from "./errors.js";
10
+ import { EXIT } from "./exit-codes.js";
11
+ import { createPrinter, resolveOutput } from "./output.js";
12
+ import { createSession } from "./session.js";
13
+ /**
14
+ * Commands whose `--output` means the display mode. A download command owns a
15
+ * `--output <path>` of its own (that is the flag people expect for "write it
16
+ * here"), so its value must never be read as a display mode.
17
+ */
18
+ export const OWNS_GLOBAL_OUTPUT_FLAG = new WeakSet();
19
+ /**
20
+ * Global flags are declared on the root *and* on every leaf, so both
21
+ * `crawl82 --json sites list` and `crawl82 sites list --json` work. This walks
22
+ * the chain root-to-leaf and merges them.
23
+ *
24
+ * `--no-retry` is merged specially: commander gives a negated option a default
25
+ * of `true`, so a leaf's untouched default would otherwise silently cancel a
26
+ * `--no-retry` typed before the subcommand. Any `false` anywhere wins.
27
+ */
28
+ export function collectGlobalOptions(command) {
29
+ const chain = [];
30
+ for (let node = command; node; node = node.parent)
31
+ chain.push(node);
32
+ chain.reverse();
33
+ const merged = {};
34
+ for (const node of chain) {
35
+ const options = node.opts();
36
+ if (options.output !== undefined && OWNS_GLOBAL_OUTPUT_FLAG.has(node)) {
37
+ merged.output = options.output;
38
+ }
39
+ if (options.json !== undefined)
40
+ merged.json = options.json;
41
+ if (options.profile !== undefined)
42
+ merged.profile = options.profile;
43
+ if (options.retry === false)
44
+ merged.retry = false;
45
+ if (options.timeout !== undefined)
46
+ merged.timeout = options.timeout;
47
+ }
48
+ return merged;
49
+ }
50
+ export async function run(command, handler) {
51
+ let session;
52
+ try {
53
+ session = createSession(collectGlobalOptions(command));
54
+ await handler(session);
55
+ }
56
+ catch (error) {
57
+ if (error instanceof SilentAbort) {
58
+ // The person answered "no" at a confirmation prompt. That is not a failure.
59
+ process.exitCode = EXIT.OK;
60
+ return;
61
+ }
62
+ const { envelope, exitCode } = toErrorReport(error);
63
+ const printer = session?.printer ??
64
+ createPrinter(resolveOutput({}, { env: process.env, stdoutIsTTY: Boolean(process.stdout.isTTY) }));
65
+ printer.error(envelope);
66
+ process.exitCode = exitCode;
67
+ }
68
+ }
69
+ /** `{ data, request_id }` → `data`. Tolerates a bare payload for robustness. */
70
+ export function unwrap(body) {
71
+ if (body && typeof body === "object" && "data" in body) {
72
+ return body.data;
73
+ }
74
+ return body;
75
+ }
76
+ export function paginationOf(body) {
77
+ const record = (body ?? {});
78
+ return {
79
+ has_more: record.has_more === true,
80
+ next_cursor: typeof record.next_cursor === "string" ? record.next_cursor : null,
81
+ limit: typeof record.limit === "number" ? record.limit : null,
82
+ };
83
+ }
84
+ /**
85
+ * Follows `next_cursor` until a list is exhausted, for `--all`.
86
+ *
87
+ * `ndjson` mode wants every row printed as it arrives rather than held in
88
+ * memory until the last page lands — pass `onPage` for that. Table and JSON
89
+ * mode want the whole set at once, which is the return value.
90
+ *
91
+ * Capped at `maxPages` (200, ~20,000 rows at the max page size) as a backstop
92
+ * against a cursor that never terminates; a real account is expected to hit
93
+ * `has_more: false` long before that.
94
+ */
95
+ export async function collectPages(fetchPage, options = {}) {
96
+ const maxPages = options.maxPages ?? 200;
97
+ const all = [];
98
+ let cursor = options.startCursor;
99
+ for (let page = 0; page < maxPages; page++) {
100
+ const result = await fetchPage(cursor);
101
+ all.push(...result.rows);
102
+ options.onPage?.(result.rows, page);
103
+ if (!result.has_more || !result.next_cursor)
104
+ return { rows: all, pages: page + 1 };
105
+ cursor = result.next_cursor;
106
+ }
107
+ throw new CliError(`Stopped after fetching ${maxPages} pages with --all, that is an unusually large result set. Narrow the filters, or page manually with --cursor.`, { exitCode: EXIT.API_ERROR, code: "internal_error", type: "api_error" });
108
+ }
109
+ /**
110
+ * Destructive commands ask before acting. When there is no terminal to ask,
111
+ * they fail with an error naming `--force` rather than hanging on a prompt
112
+ * nobody will ever answer — that hang is the classic way an agent burns a
113
+ * timeout budget.
114
+ */
115
+ export async function confirmDestructive(session, question, options) {
116
+ if (options.force)
117
+ return;
118
+ if (!session.canPrompt || !session.printer.resolution.interactive) {
119
+ throw forceRequired(options.command);
120
+ }
121
+ const answer = await ask(`${question} [y/N] `);
122
+ if (!/^y(es)?$/i.test(answer.trim())) {
123
+ session.printer.note("Cancelled.");
124
+ process.exitCode = EXIT.OK;
125
+ throw new SilentAbort();
126
+ }
127
+ }
128
+ /** The command as it was typed, without the program name, quoted so it can be run again as printed. */
129
+ export function typedCommand(command, drop = []) {
130
+ let root = command;
131
+ while (root.parent)
132
+ root = root.parent;
133
+ return root.rawArgs
134
+ .slice(2)
135
+ .filter((a) => !drop.includes(a))
136
+ .map((a) => (/^[\w@%+=:,./-]+$/.test(a) ? a : `'${a.replace(/'/g, "'\\''")}'`))
137
+ .join(" ");
138
+ }
139
+ /**
140
+ * The same gate for a command that SPENDS rather than deletes (`sites add`, `crawls start`, a paid
141
+ * `recipes run`). Its own flag, `--yes`, because "force" says "I know this destroys something", and
142
+ * starting a crawl destroys nothing: it commits pages and credits. With no terminal and no `--yes`
143
+ * it fails naming the flag and the command to run again, never hanging.
144
+ */
145
+ export async function confirmSpend(session, question, options) {
146
+ if (options.yes)
147
+ return;
148
+ if (!session.canPrompt || !session.printer.resolution.interactive) {
149
+ throw yesRequired(options.command, options.reviewCommand, options.spends);
150
+ }
151
+ const answer = await ask(`${question} [y/N] `);
152
+ if (!/^y(es)?$/i.test(answer.trim())) {
153
+ session.printer.note("Cancelled. Nothing was charged.");
154
+ process.exitCode = EXIT.OK;
155
+ throw new SilentAbort();
156
+ }
157
+ }
158
+ /** Thrown after a user-cancelled confirmation; produces no output and exit 0. */
159
+ export class SilentAbort extends Error {
160
+ exitCode = EXIT.OK;
161
+ constructor() {
162
+ super("cancelled");
163
+ this.name = "SilentAbort";
164
+ }
165
+ toEnvelope() {
166
+ return {
167
+ error: {
168
+ type: "invalid_request_error",
169
+ code: "invalid_request",
170
+ message: "Cancelled.",
171
+ docs_url: "https://crawl82.com/docs/api/errors#invalid_request",
172
+ },
173
+ request_id: null,
174
+ };
175
+ }
176
+ }
177
+ function ask(prompt) {
178
+ return new Promise((resolve) => {
179
+ const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
180
+ rl.question(prompt, (answer) => {
181
+ rl.close();
182
+ resolve(answer);
183
+ });
184
+ });
185
+ }
186
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAoC,MAAM,cAAc,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,OAAO,EAAW,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB;IACnD,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,KAAK,IAAI,IAAI,GAAmB,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpF,KAA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AC,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,WAAW,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC;IAC5B;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;IACD,UAAU;QACR,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,uBAAuB;gBAC7B,IAAI,EAAE,iBAAiB;gBACvB,OAAO,EAAE,YAAY;gBACrB,QAAQ,EAAE,qDAAqD;aAChE;YACD,UAAU,EAAE,IAAI;SACjB,CAAC;IACJ,CAAC;CACF;AAED,SAAS,GAAG,CAAC,MAAc;IACzB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YAC7B,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The per-invocation context: which profile, which credential, which output
3
+ * mode, and a ready-to-use API client.
4
+ *
5
+ * Every command receives one of these, so no command reads `process.env` or
6
+ * decides on its own how to print a failure.
7
+ */
8
+ import path from "node:path";
9
+ import { clearCredential, configDir, loadCredential, resolveProfile, saveCredential, } from "./credentials.js";
10
+ import { CliError, notAuthenticated } from "./errors.js";
11
+ import { ApiClient } from "./http.js";
12
+ import { createPrinter, resolveOutput } from "./output.js";
13
+ import { AuthServer, defaultEndpoints } from "./oauth/server.js";
14
+ import { withRefreshLock } from "./refresh-lock.js";
15
+ import { apiBaseUrl, apiOrigin, authBaseUrl, mcpBaseUrl } from "./version.js";
16
+ /**
17
+ * A hung request is the worst outcome for an unattended caller: it produces no
18
+ * output at all and burns the whole budget of whatever is waiting on it. The
19
+ * ceiling exists so `--timeout 0` or a typo cannot switch that protection off.
20
+ */
21
+ export function resolveTimeoutMs(value) {
22
+ if (value === undefined)
23
+ return undefined;
24
+ const seconds = Number(value);
25
+ if (!Number.isFinite(seconds) || seconds <= 0) {
26
+ throw new CliError(`--timeout expects a positive number of seconds, got '${value}'.`, { code: "invalid_parameter", param: "timeout" });
27
+ }
28
+ return Math.round(seconds * 1000);
29
+ }
30
+ /** An access token is used as long as it has at least this much life left. */
31
+ const EXPIRY_MARGIN_MS = 60_000;
32
+ const isFresh = (record) => !record.expires_at || record.expires_at - Date.now() > EXPIRY_MARGIN_MS;
33
+ export function createSession(options, env = process.env, deps = {}) {
34
+ const resolution = resolveOutput(options, {
35
+ env,
36
+ stdoutIsTTY: Boolean(process.stdout.isTTY),
37
+ });
38
+ const printer = createPrinter(resolution);
39
+ const profile = resolveProfile(options.profile, env);
40
+ let cachedCredential;
41
+ const credentialDeps = { ...deps.credentials, env };
42
+ const peekCredential = async () => {
43
+ if (cachedCredential === undefined) {
44
+ cachedCredential = await loadCredential(profile, credentialDeps);
45
+ }
46
+ return cachedCredential;
47
+ };
48
+ const authServer = deps.authServer ?? new AuthServer(authBaseUrl(env));
49
+ const requireToken = async () => {
50
+ const resolved = await peekCredential();
51
+ if (!resolved)
52
+ throw notAuthenticated();
53
+ if (resolved.record.kind === "api_key") {
54
+ return { token: resolved.record.api_key, source: resolved.source, kind: "api_key" };
55
+ }
56
+ if (isFresh(resolved.record)) {
57
+ return { token: resolved.record.access_token, source: resolved.source, kind: "oauth" };
58
+ }
59
+ if (!resolved.record.refresh_token)
60
+ throw notAuthenticated();
61
+ // Refreshing rotates the refresh token, so two processes refreshing at the
62
+ // same time cannot both win. One at a time, and whoever comes second finds
63
+ // the credential the first already saved.
64
+ const lockPath = path.join(configDir(env), `refresh-${profile.replace(/[^A-Za-z0-9._-]/g, "_")}.lock`);
65
+ return withRefreshLock(lockPath, () => refreshStored(resolved), deps.lock);
66
+ };
67
+ /** Called with the refresh lock held (or after it timed out). */
68
+ const refreshStored = async (seen) => {
69
+ let current = seen;
70
+ // At most one retry: the second pass exists only for "another process
71
+ // rotated the token while this request was in flight".
72
+ for (let attempt = 0;; attempt++) {
73
+ // Re-read: the process holding the lock before us may have refreshed.
74
+ const latest = await loadCredential(profile, credentialDeps);
75
+ if (latest && latest.record.kind === "oauth") {
76
+ current = latest;
77
+ cachedCredential = latest;
78
+ }
79
+ const record = current.record;
80
+ if (record.kind !== "oauth")
81
+ throw notAuthenticated();
82
+ if (isFresh(record)) {
83
+ return { token: record.access_token, source: current.source, kind: "oauth" };
84
+ }
85
+ if (!record.refresh_token)
86
+ throw notAuthenticated();
87
+ const tokenEndpoint = record.token_endpoint ?? defaultEndpoints(authBaseUrl(env)).token_endpoint;
88
+ let refreshed;
89
+ try {
90
+ refreshed = await authServer.refresh(tokenEndpoint, record.refresh_token);
91
+ }
92
+ catch (error) {
93
+ if (error instanceof CliError && error.code === "api_key_revoked") {
94
+ // `invalid_grant` is either a real revocation or the loser of a race:
95
+ // another process rotated the token between our read and our request.
96
+ // The store tells them apart, because the winner saved a new refresh
97
+ // token before releasing the lock.
98
+ const after = await loadCredential(profile, credentialDeps);
99
+ const rotatedByAnother = after?.record.kind === "oauth" &&
100
+ after.record.refresh_token !== undefined &&
101
+ after.record.refresh_token !== record.refresh_token;
102
+ if (rotatedByAnother && attempt === 0)
103
+ continue;
104
+ // A revoked or expired grant can never be refreshed again, so keeping
105
+ // it on disk leaves every later command retrying the same doomed
106
+ // request and reporting a confusing failure. Dropping it makes `auth
107
+ // status` tell the truth and turns the next command into a plain
108
+ // "not logged in".
109
+ await clearCredential(profile, credentialDeps);
110
+ cachedCredential = null;
111
+ }
112
+ throw error;
113
+ }
114
+ const updated = {
115
+ ...record,
116
+ access_token: refreshed.access_token,
117
+ refresh_token: refreshed.refresh_token ?? record.refresh_token,
118
+ expires_at: refreshed.expires_in ? Date.now() + refreshed.expires_in * 1000 : undefined,
119
+ };
120
+ await saveCredential(profile, updated, credentialDeps);
121
+ cachedCredential = { ...current, record: updated };
122
+ return { token: refreshed.access_token, source: current.source, kind: "oauth" };
123
+ }
124
+ };
125
+ const client = new ApiClient({
126
+ baseUrl: apiBaseUrl(env),
127
+ getToken: async () => (await requireToken()).token,
128
+ retry: options.retry !== false,
129
+ timeoutMs: resolveTimeoutMs(options.timeout),
130
+ onNotice: (message) => printer.warn(message),
131
+ });
132
+ return {
133
+ profile,
134
+ printer,
135
+ apiUrl: apiBaseUrl(env),
136
+ apiOrigin: apiOrigin(env),
137
+ authUrl: authBaseUrl(env),
138
+ mcpUrl: mcpBaseUrl(env),
139
+ env,
140
+ requireToken,
141
+ peekCredential,
142
+ client,
143
+ authServer,
144
+ canPrompt: Boolean(process.stdin.isTTY),
145
+ };
146
+ }
147
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,cAAc,GAMf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,eAAe,EAA2B,MAAM,mBAAmB,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CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC;QACxB,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,KAAK;QAClD,KAAK,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,SAAS,EAAE,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC;QAC5C,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;KAC7C,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,OAAO;QACP,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC;QACvB,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC;QACzB,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC;QACzB,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC;QACvB,GAAG;QACH,YAAY;QACZ,cAAc;QACd,MAAM;QACN,UAAU;QACV,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;KACxC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+ const pkg = require("../package.json");
4
+ export const PACKAGE_NAME = pkg.name;
5
+ export const VERSION = pkg.version;
6
+ /** Sent on every request, so the API can distinguish CLI traffic and flag old versions. */
7
+ export const USER_AGENT = `crawl82/${VERSION}`;
8
+ export const DEFAULT_API_URL = "https://api.crawl82.com/v1";
9
+ export const DEFAULT_MCP_URL = "https://mcp.crawl82.com";
10
+ export function apiBaseUrl(env = process.env) {
11
+ return (env.CRAWL82_API_URL || DEFAULT_API_URL).replace(/\/+$/, "");
12
+ }
13
+ export function mcpBaseUrl(env = process.env) {
14
+ return (env.CRAWL82_MCP_URL || DEFAULT_MCP_URL).replace(/\/+$/, "");
15
+ }
16
+ /**
17
+ * The authorization server sits one level above the versioned API base:
18
+ * `https://api.crawl82.com/v1` → `https://api.crawl82.com`. `CRAWL82_AUTH_URL`
19
+ * overrides it for anyone running the two on different hosts.
20
+ */
21
+ export function authBaseUrl(env = process.env) {
22
+ if (env.CRAWL82_AUTH_URL)
23
+ return env.CRAWL82_AUTH_URL.replace(/\/+$/, "");
24
+ const api = new URL(apiBaseUrl(env));
25
+ const segments = api.pathname.split("/").filter(Boolean);
26
+ segments.pop();
27
+ api.pathname = segments.length ? `/${segments.join("/")}` : "/";
28
+ return api.toString().replace(/\/+$/, "");
29
+ }
30
+ /** The origin of the API, where the unauthenticated meta routes live. */
31
+ export function apiOrigin(env = process.env) {
32
+ return new URL(apiBaseUrl(env)).origin;
33
+ }
34
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAsC,CAAC;AAE5E,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC;AACrC,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;AAEnC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,OAAO,EAAE,CAAC;AAE/C,MAAM,CAAC,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,MAAM,CAAC,MAAM,eAAe,GAAG,yBAAyB,CAAC;AAEzD,MAAM,UAAU,UAAU,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC7D,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC7D,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC9D,IAAI,GAAG,CAAC,gBAAgB;QAAE,OAAO,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzD,QAAQ,CAAC,GAAG,EAAE,CAAC;IACf,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAChE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,SAAS,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC5D,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;AACzC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@crawl82/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "The official Crawl82 CLI: crawl a site, read its findings and Search Console figures, get the fixes worth doing first and run SEO and AI-search recipes, from a terminal, a CI job or an AI agent.",
5
+ "type": "module",
6
+ "bin": {
7
+ "crawl82": "dist/index.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "AGENTS.md"
14
+ ],
15
+ "engines": {
16
+ "node": ">=20.0.0"
17
+ },
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.build.json && node -e \"require('fs').chmodSync('dist/index.js', 0o755)\"",
20
+ "typecheck": "tsc --noEmit",
21
+ "generate:types": "node scripts/generate-api-types.mjs",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "prepublishOnly": "npm run typecheck && npm test && npm run test:package",
25
+ "test:package": "npm run build && node scripts/smoke-package.mjs"
26
+ },
27
+ "keywords": [
28
+ "crawl82",
29
+ "cli",
30
+ "api",
31
+ "mcp",
32
+ "agent",
33
+ "automation"
34
+ ],
35
+ "author": "REPLACE_ME_AUTHOR",
36
+ "license": "MIT",
37
+ "homepage": "https://crawl82.com",
38
+ "dependencies": {
39
+ "commander": "^14.0.3"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.10.0",
43
+ "typescript": "^5.9.3",
44
+ "vitest": "^4.1.11"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }