readlint.com 0.7.0 → 0.8.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/dist/auth.js CHANGED
@@ -11,6 +11,9 @@ export function credentialsPath() {
11
11
  process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
12
12
  return join(root, "readlint", "credentials.json");
13
13
  }
14
+ // Logins saved while the API was served from the website host stay valid on
15
+ // the API host; both are the same readlint.com service.
16
+ const MOVED = { "https://api.readlint.com": "https://readlint.com" };
14
17
  export async function loadCredentials(api) {
15
18
  try {
16
19
  const file = await open(credentialsPath(), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
@@ -19,7 +22,7 @@ export async function loadCredentials(api) {
19
22
  if (!info.isFile() || (platform() !== "win32" && ((info.mode & 0o077) || info.uid !== process.getuid?.())))
20
23
  throw new Error();
21
24
  const data = JSON.parse(await file.readFile("utf8"));
22
- if (data.api !== api || !Number.isFinite(data.expires_at) || data.expires_at <= Date.now() / 1000 ||
25
+ if (typeof data.api !== "string" || (data.api !== api && data.api !== (Object.hasOwn(MOVED, api) ? MOVED[api] : api)) || !Number.isFinite(data.expires_at) || data.expires_at <= Date.now() / 1000 ||
23
26
  typeof data.access_token !== "string" || !data.access_token)
24
27
  throw new Error();
25
28
  return data.access_token;
@@ -29,7 +32,7 @@ export async function loadCredentials(api) {
29
32
  }
30
33
  }
31
34
  catch {
32
- throw new ReadlintError("authentication_required", "No usable saved login. Run `readlint login` or set READLINT_API_KEY.");
35
+ throw new ReadlintError("authentication_required", "No usable saved login. Run `npx readlint.com login` or set READLINT_API_KEY.");
33
36
  }
34
37
  }
35
38
  export async function saveCredentials(api, token, expiresIn) {
@@ -63,7 +66,7 @@ export async function login(client) {
63
66
  if (typeof code.device_code !== "string" || typeof code.verification_uri_complete !== "string" ||
64
67
  typeof code.user_code !== "string" || !Number.isFinite(code.expires_in) || code.expires_in <= 0 ||
65
68
  !Number.isFinite(code.interval) || code.interval < 0)
66
- throw new ReadlintError("invalid_response", "Invalid device response. Update readlint or retry login later.");
69
+ throw new ReadlintError("invalid_response", "Invalid device response. Update readlint.com or retry login later.");
67
70
  let interval = Math.max(1, code.interval);
68
71
  const deadline = performance.now() + code.expires_in * 1000;
69
72
  console.error(`Open ${code.verification_uri_complete}\nCheck and approve code ${code.user_code}.`);
@@ -75,7 +78,7 @@ export async function login(client) {
75
78
  const token = await client.createDeviceToken(code.device_code);
76
79
  if (typeof token.access_token !== "string" || !token.access_token || !Number.isFinite(token.expires_in) || token.expires_in <= 0 ||
77
80
  typeof token.token_type !== "string" || token.token_type.toLowerCase() !== "bearer")
78
- throw new ReadlintError("invalid_response", "Invalid token response. Run `readlint login` again.");
81
+ throw new ReadlintError("invalid_response", "Invalid token response. Run `npx readlint.com login` again.");
79
82
  await saveCredentials(client.baseUrl, token.access_token, token.expires_in);
80
83
  return;
81
84
  }
@@ -95,5 +98,5 @@ export async function login(client) {
95
98
  throw error;
96
99
  }
97
100
  }
98
- throw new ReadlintError("expired_token", "The code expired; run `readlint login` again.");
101
+ throw new ReadlintError("expired_token", "The code expired; run `npx readlint.com login` again.");
99
102
  }
package/dist/cli.js CHANGED
@@ -25,7 +25,7 @@ Commands:
25
25
  Options (before or after command):
26
26
  --json JSON stdout and JSON errors on stderr
27
27
  --api-key KEY Prefer READLINT_API_KEY to shell history
28
- --base-url URL HTTPS API origin; default https://readlint.com
28
+ --base-url URL HTTPS API origin; default https://api.readlint.com
29
29
  --timeout SECONDS HTTP timeout; default 120
30
30
  --title TEXT --description TEXT --idempotency-key KEY Submission options
31
31
  --help, -h; --version
@@ -139,7 +139,7 @@ export async function main(argv = process.argv.slice(2)) {
139
139
  }
140
140
  catch (error) {
141
141
  const problem = error instanceof ReadlintError ? { code: error.code, message: error.message, status: error.status, evaluation_id: error.evaluationId, ...error.details } : {
142
- code: "invalid_input", message: "Check the command, UTF-8 input file, URL and credential file permissions. Run `readlint --help`.",
142
+ code: "invalid_input", message: "Check the command, UTF-8 input file, URL and credential file permissions. Run `npx readlint.com --help`.",
143
143
  };
144
144
  if (submissionKey)
145
145
  problem.idempotency_key = submissionKey;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const RECOVERY = {
2
- authentication_required: "Pass apiKey or set READLINT_API_KEY; obtain a key in the web app or with readlint login.",
2
+ authentication_required: "Pass apiKey or set READLINT_API_KEY; obtain a key in the web app or with `npx readlint.com login`.",
3
3
  evaluation_credit_exhausted: "Check your evaluation credit in the web app.",
4
4
  evaluation_not_allowed: "Ask support@readlint.com for evaluation access.",
5
5
  evaluation_disabled: "Try again later with the same idempotency key and article.",
@@ -69,6 +69,8 @@ function uuid(value) {
69
69
  function object(value) {
70
70
  return typeof value === "object" && value !== null && !Array.isArray(value);
71
71
  }
72
+ // The API host serves no web pages; its web app is on the website host.
73
+ const WEBSITE = { "https://api.readlint.com": "https://readlint.com" };
72
74
  function problem(status, body, baseUrl) {
73
75
  const raw = object(body) ? (object(body.detail) ? body.detail.code : body.error) : null;
74
76
  const detail = object(body) && object(body.detail) ? body.detail : null;
@@ -77,7 +79,7 @@ function problem(status, body, baseUrl) {
77
79
  const message = `The account has turned off "${label}".`;
78
80
  const action = `Ask the account owner to enable "${label}" in Settings → Agent permissions.`;
79
81
  if (detail.message === message && detail.action === action && detail.settings_url === "/app/settings#agent-permissions" && detail.retryable === false) {
80
- return new ReadlintError(raw, message, 403, null, { action, settings_url: baseUrl + "/app/settings#agent-permissions", retryable: false });
82
+ return new ReadlintError(raw, message, 403, null, { action, settings_url: (Object.hasOwn(WEBSITE, baseUrl) ? WEBSITE[baseUrl] : baseUrl) + "/app/settings#agent-permissions", retryable: false });
81
83
  }
82
84
  }
83
85
  }
@@ -115,7 +117,7 @@ export class Readlint {
115
117
  #maxRetries;
116
118
  #fetch;
117
119
  constructor(options = {}) {
118
- this.baseUrl = origin(options.baseUrl || env("READLINT_BASE_URL") || "https://readlint.com");
120
+ this.baseUrl = origin(options.baseUrl || env("READLINT_BASE_URL") || "https://api.readlint.com");
119
121
  this.#apiKey = options.apiKey || env("READLINT_API_KEY");
120
122
  this.#timeoutMs = options.timeoutMs ?? 120_000;
121
123
  this.#maxRetries = options.maxRetries ?? 2;
package/dist/mcp.js CHANGED
@@ -48,7 +48,7 @@ export async function callTool(name, args, options = {}) {
48
48
  failed = true;
49
49
  const problem = error instanceof ReadlintError ? errorBody(error) : error instanceof TypeError || error instanceof z.ZodError ? {
50
50
  code: "invalid_input", message: "Check the tool name, input schema, UUID, API origin and credential file permissions before retrying.",
51
- } : { code: "internal_error", message: "Restart readlint mcp or update the package. For a submission, retain the same key and input." };
51
+ } : { code: "internal_error", message: "Restart `npx readlint.com mcp` or update the package. For a submission, retain the same key and input." };
52
52
  if (error instanceof ReadlintError && name === "evaluate_article")
53
53
  problem.idempotency_key = args.idempotency_key;
54
54
  body = { error: problem };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.7.0";
1
+ export declare const VERSION = "0.8.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.7.0";
1
+ export const VERSION = "0.8.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "readlint.com",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "TypeScript SDK, CLI and MCP server for readlint.com",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",