readlint.com 0.6.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
@@ -16,7 +16,8 @@ Commands:
16
16
  get UUID, delete UUID Read or delete an evaluation
17
17
  agent-permissions get Read the owner’s agent billing policy
18
18
  billing status|quote|portal Read billing, get a nonbinding quote or payment link
19
- billing order --quote-id UUID --terms-version VERSION --agree-to-pay --idempotency-key UUID
19
+ billing order --quote-id UUID --terms-version VERSION --agree-to-pay --idempotency-key UUID [--start-now]
20
+ Consumers must pass --start-now: the paid start and withdrawal charges follow the quote disclosure and accepted Terms
20
21
  billing cancel --idempotency-key UUID (retain for recovery)
21
22
  login, logout Approve device login or remove local credentials
22
23
  mcp Serve four MCP tools over stdio
@@ -24,7 +25,7 @@ Commands:
24
25
  Options (before or after command):
25
26
  --json JSON stdout and JSON errors on stderr
26
27
  --api-key KEY Prefer READLINT_API_KEY to shell history
27
- --base-url URL HTTPS API origin; default https://readlint.com
28
+ --base-url URL HTTPS API origin; default https://api.readlint.com
28
29
  --timeout SECONDS HTTP timeout; default 120
29
30
  --title TEXT --description TEXT --idempotency-key KEY Submission options
30
31
  --help, -h; --version
@@ -42,7 +43,7 @@ export async function main(argv = process.argv.slice(2)) {
42
43
  const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, strict: true, options: {
43
44
  json: { type: "boolean" }, "api-key": { type: "string" }, "base-url": { type: "string" }, timeout: { type: "string" },
44
45
  help: { type: "boolean", short: "h" }, version: { type: "boolean" }, title: { type: "string" },
45
- "quote-id": { type: "string" }, "terms-version": { type: "string" }, "agree-to-pay": { type: "boolean" },
46
+ "quote-id": { type: "string" }, "terms-version": { type: "string" }, "agree-to-pay": { type: "boolean" }, "start-now": { type: "boolean" },
46
47
  description: { type: "string" }, "idempotency-key": { type: "string" }, limit: { type: "string" }, offset: { type: "string" },
47
48
  } });
48
49
  if (values.help) {
@@ -62,8 +63,8 @@ export async function main(argv = process.argv.slice(2)) {
62
63
  throw new TypeError();
63
64
  if (command === "billing" && !["status", "quote", "portal", "order", "cancel"].includes(argument))
64
65
  throw new TypeError();
65
- for (const flag of ["title", "description", "idempotency-key", "limit", "offset", "quote-id", "terms-version", "agree-to-pay"]) {
66
- if (values[flag] !== undefined && !(["check", "evaluate"].includes(command) ? ["title", "description", "idempotency-key"] : command === "list" ? ["limit", "offset"] : command === "billing" && argument === "order" ? ["idempotency-key", "quote-id", "terms-version", "agree-to-pay"] : command === "billing" && argument === "cancel" ? ["idempotency-key"] : []).includes(flag))
66
+ for (const flag of ["title", "description", "idempotency-key", "limit", "offset", "quote-id", "terms-version", "agree-to-pay", "start-now"]) {
67
+ if (values[flag] !== undefined && !(["check", "evaluate"].includes(command) ? ["title", "description", "idempotency-key"] : command === "list" ? ["limit", "offset"] : command === "billing" && argument === "order" ? ["idempotency-key", "quote-id", "terms-version", "agree-to-pay", "start-now"] : command === "billing" && argument === "cancel" ? ["idempotency-key"] : []).includes(flag))
67
68
  throw new TypeError();
68
69
  }
69
70
  const timeoutMs = values.timeout === undefined ? 120_000 : Math.ceil(Number(values.timeout) * 1000);
@@ -122,7 +123,7 @@ export async function main(argv = process.argv.slice(2)) {
122
123
  if (argument === "cancel")
123
124
  result = await client.cancelBillingPlan({ idempotencyKey: submissionKey });
124
125
  else
125
- result = await client.confirmBillingOrder(values["quote-id"], { termsVersion: values["terms-version"], paidOrderConfirmed: true, idempotencyKey: submissionKey });
126
+ result = await client.confirmBillingOrder(values["quote-id"], { termsVersion: values["terms-version"], paidOrderConfirmed: true, idempotencyKey: submissionKey, startNow: values["start-now"] === true });
126
127
  }
127
128
  }
128
129
  else if (command === "get")
@@ -138,7 +139,7 @@ export async function main(argv = process.argv.slice(2)) {
138
139
  }
139
140
  catch (error) {
140
141
  const problem = error instanceof ReadlintError ? { code: error.code, message: error.message, status: error.status, evaluation_id: error.evaluationId, ...error.details } : {
141
- 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`.",
142
143
  };
143
144
  if (submissionKey)
144
145
  problem.idempotency_key = submissionKey;
@@ -9,6 +9,10 @@ export type AgentBillingStatus = {
9
9
  * Access Active
10
10
  */
11
11
  access_active: boolean;
12
+ /**
13
+ * Business
14
+ */
15
+ business: boolean;
12
16
  /**
13
17
  * Cancelled At
14
18
  */
@@ -129,6 +133,10 @@ export type AgentQuote = {
129
133
  * Monthly Credits Cents
130
134
  */
131
135
  monthly_credits_cents: number;
136
+ /**
137
+ * Plan Line
138
+ */
139
+ plan_line: string;
132
140
  /**
133
141
  * Privacy Url
134
142
  */
@@ -145,6 +153,14 @@ export type AgentQuote = {
145
153
  * Renewal Terms
146
154
  */
147
155
  renewal_terms: string;
156
+ /**
157
+ * Start Now Action
158
+ */
159
+ start_now_action: string | null;
160
+ /**
161
+ * Start Now Required
162
+ */
163
+ start_now_required: boolean;
148
164
  /**
149
165
  * Subtotal Cents
150
166
  */
@@ -559,6 +575,10 @@ export type PaidInstruction = {
559
575
  * Quote Id
560
576
  */
561
577
  quote_id: string;
578
+ /**
579
+ * Start Now
580
+ */
581
+ start_now?: boolean;
562
582
  /**
563
583
  * Terms Version
564
584
  */
package/dist/index.d.ts CHANGED
@@ -44,11 +44,12 @@ export declare class Readlint {
44
44
  getAgentPermissions(): Promise<AgentPermissions>;
45
45
  getBillingStatus(): Promise<AgentBillingStatus>;
46
46
  createBillingQuote(): Promise<AgentQuote>;
47
- /** Explicit paid instruction; never automatically retried. */
47
+ /** Explicit paid instruction; never automatically retried. Consumers must pass startNow: true: start the paid plan as disclosed in the quote; withdrawal charges follow its disclosure and accepted Terms. */
48
48
  confirmBillingOrder(quoteId: string, options: {
49
49
  termsVersion: string;
50
50
  paidOrderConfirmed: true;
51
51
  idempotencyKey: string;
52
+ startNow?: boolean;
52
53
  }): Promise<OrderAccepted>;
53
54
  cancelBillingPlan(options: {
54
55
  idempotencyKey: string;
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.",
@@ -14,6 +14,7 @@ const RECOVERY = {
14
14
  terms_version_mismatch: "Use the Terms version in a fresh quote.",
15
15
  paid_order_consent_required: "Explicit paid-order confirmation is required.",
16
16
  paid_order_already_confirmed: "Read the current order in billing status.",
17
+ start_now_required: "Upgrade to readlint/readlint.com 0.7.0 or later if needed. Consumers must ask to start the paid plan now: pass --start-now / startNow: true after reading the quote's disclosure.",
17
18
  save_card_first: "Save a payment method using the returned payment link.",
18
19
  billing_address_required: "Complete the billing address using the returned payment link.",
19
20
  validation_error: "Check the input before retrying.",
@@ -68,6 +69,8 @@ function uuid(value) {
68
69
  function object(value) {
69
70
  return typeof value === "object" && value !== null && !Array.isArray(value);
70
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" };
71
74
  function problem(status, body, baseUrl) {
72
75
  const raw = object(body) ? (object(body.detail) ? body.detail.code : body.error) : null;
73
76
  const detail = object(body) && object(body.detail) ? body.detail : null;
@@ -76,7 +79,7 @@ function problem(status, body, baseUrl) {
76
79
  const message = `The account has turned off "${label}".`;
77
80
  const action = `Ask the account owner to enable "${label}" in Settings → Agent permissions.`;
78
81
  if (detail.message === message && detail.action === action && detail.settings_url === "/app/settings#agent-permissions" && detail.retryable === false) {
79
- 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 });
80
83
  }
81
84
  }
82
85
  }
@@ -114,7 +117,7 @@ export class Readlint {
114
117
  #maxRetries;
115
118
  #fetch;
116
119
  constructor(options = {}) {
117
- 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");
118
121
  this.#apiKey = options.apiKey || env("READLINT_API_KEY");
119
122
  this.#timeoutMs = options.timeoutMs ?? 120_000;
120
123
  this.#maxRetries = options.maxRetries ?? 2;
@@ -134,11 +137,11 @@ export class Readlint {
134
137
  createBillingQuote() {
135
138
  return this.#request("POST", "/v1/billing/quote", false);
136
139
  }
137
- /** Explicit paid instruction; never automatically retried. */
140
+ /** Explicit paid instruction; never automatically retried. Consumers must pass startNow: true: start the paid plan as disclosed in the quote; withdrawal charges follow its disclosure and accepted Terms. */
138
141
  confirmBillingOrder(quoteId, options) {
139
142
  if (options?.paidOrderConfirmed !== true)
140
143
  throw new TypeError("paidOrderConfirmed must be explicitly true.");
141
- return this.#request("POST", "/v1/billing/order", false, JSON.stringify({ quote_id: uuid(quoteId), terms_version: options.termsVersion, paid_order_confirmed: true }), { "Content-Type": "application/json", "Idempotency-Key": uuid(options.idempotencyKey) });
144
+ return this.#request("POST", "/v1/billing/order", false, JSON.stringify({ quote_id: uuid(quoteId), terms_version: options.termsVersion, paid_order_confirmed: true, start_now: options.startNow ?? false }), { "Content-Type": "application/json", "Idempotency-Key": uuid(options.idempotencyKey) });
142
145
  }
143
146
  cancelBillingPlan(options) {
144
147
  return this.#request("POST", "/v1/billing/cancel", false, "{}", { "Content-Type": "application/json", "Idempotency-Key": uuid(options.idempotencyKey) });
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.6.0";
1
+ export declare const VERSION = "0.8.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.6.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.6.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",
@@ -29,7 +29,8 @@
29
29
  "scripts": {
30
30
  "build": "tsc -p tsconfig.build.json",
31
31
  "typecheck": "tsc --noEmit",
32
- "test": "npm run build && node --test test/*.test.mjs",
32
+ "test": "npm run build && npm run build:examples && node --test test/*.test.mjs",
33
+ "build:examples": "tsc -p tsconfig.examples.json",
33
34
  "generate": "node scripts/openapi.mjs",
34
35
  "check:openapi": "node scripts/openapi.mjs --check",
35
36
  "prepack": "npm run build"