readlint.com 0.4.0 → 0.6.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 +8 -26
- package/dist/cli.js +38 -6
- package/dist/gen/index.d.ts +1 -1
- package/dist/gen/types.gen.d.ts +604 -0
- package/dist/index.d.ts +28 -3
- package/dist/index.js +60 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,35 +1,17 @@
|
|
|
1
1
|
# readlint.com
|
|
2
2
|
|
|
3
|
-
TypeScript SDK, CLI and
|
|
3
|
+
TypeScript SDK, CLI and local MCP server for readlint.com. Requires Node.js 22+.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
|
|
7
|
-
npx readlint.com
|
|
6
|
+
npm install readlint.com
|
|
7
|
+
npx readlint.com login
|
|
8
|
+
npx readlint.com list --limit 25 --offset 0 --json
|
|
8
9
|
```
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
npm install https://github.com/writeitai/readlint-clients/releases/download/v0.3.0/readlint.com-0.3.0.tgz
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { Readlint } from "readlint.com";
|
|
21
|
-
|
|
22
|
-
const client = new Readlint(); // Set READLINT_API_KEY on your server.
|
|
23
|
-
const result = await client.evaluate("# Article\n\nUseful text.", {
|
|
24
|
-
idempotencyKey: "article-v1", // Retain this key and identical input for retries.
|
|
25
|
-
});
|
|
26
|
-
console.log(result.id, result.report);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
See the [SDK guide](https://github.com/writeitai/readlint-clients/blob/main/docs/typescript.md)
|
|
30
|
-
for authentication, pagination, errors, retries and device login, and the
|
|
31
|
-
[development guide](https://github.com/writeitai/readlint-clients/blob/main/docs/development.md)
|
|
32
|
-
for source builds and contract checks.
|
|
11
|
+
Follow the maintained [TypeScript SDK](https://readlint.com/docs/typescript),
|
|
12
|
+
[CLI](https://readlint.com/docs/cli) and [MCP](https://readlint.com/docs/mcp)
|
|
13
|
+
guides for authentication, examples, expected results and recovery.
|
|
14
|
+
Python users can install `readlint` from PyPI or use `uvx readlint`.
|
|
33
15
|
|
|
34
16
|
Licensed under Apache-2.0. Transport adapted from `writeitai/mountable`
|
|
35
17
|
`d936589b1e200e347f03dfc32609c5d368668ae2`.
|
package/dist/cli.js
CHANGED
|
@@ -14,6 +14,10 @@ Commands:
|
|
|
14
14
|
check FILE, evaluate FILE Submit Markdown/MDX (- reads stdin)
|
|
15
15
|
list List evaluations (--limit N --offset N)
|
|
16
16
|
get UUID, delete UUID Read or delete an evaluation
|
|
17
|
+
agent-permissions get Read the owner’s agent billing policy
|
|
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
|
|
20
|
+
billing cancel --idempotency-key UUID (retain for recovery)
|
|
17
21
|
login, logout Approve device login or remove local credentials
|
|
18
22
|
mcp Serve four MCP tools over stdio
|
|
19
23
|
version Print the installed version
|
|
@@ -38,6 +42,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
38
42
|
const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, strict: true, options: {
|
|
39
43
|
json: { type: "boolean" }, "api-key": { type: "string" }, "base-url": { type: "string" }, timeout: { type: "string" },
|
|
40
44
|
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" },
|
|
41
46
|
description: { type: "string" }, "idempotency-key": { type: "string" }, limit: { type: "string" }, offset: { type: "string" },
|
|
42
47
|
} });
|
|
43
48
|
if (values.help) {
|
|
@@ -49,12 +54,16 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
49
54
|
return 0;
|
|
50
55
|
}
|
|
51
56
|
const [command, argument] = positionals;
|
|
52
|
-
const takesArgument = ["check", "evaluate", "get", "delete"].includes(command);
|
|
53
|
-
if (!command || !["check", "evaluate", "list", "get", "delete", "login", "logout", "version", "mcp"].includes(command) ||
|
|
57
|
+
const takesArgument = ["check", "evaluate", "get", "delete", "agent-permissions", "billing"].includes(command);
|
|
58
|
+
if (!command || !["check", "evaluate", "list", "get", "delete", "login", "logout", "version", "mcp", "agent-permissions", "billing"].includes(command) ||
|
|
54
59
|
positionals.length !== (takesArgument ? 2 : 1))
|
|
55
60
|
throw new TypeError();
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
if (command === "agent-permissions" && argument !== "get")
|
|
62
|
+
throw new TypeError();
|
|
63
|
+
if (command === "billing" && !["status", "quote", "portal", "order", "cancel"].includes(argument))
|
|
64
|
+
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))
|
|
58
67
|
throw new TypeError();
|
|
59
68
|
}
|
|
60
69
|
const timeoutMs = values.timeout === undefined ? 120_000 : Math.ceil(Number(values.timeout) * 1000);
|
|
@@ -93,6 +102,29 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
93
102
|
throw new TypeError();
|
|
94
103
|
result = await client.listEvaluations({ limit: values.limit === undefined ? undefined : Number(values.limit), offset: values.offset === undefined ? 0 : Number(values.offset) });
|
|
95
104
|
}
|
|
105
|
+
else if (command === "agent-permissions")
|
|
106
|
+
result = await client.getAgentPermissions();
|
|
107
|
+
else if (command === "billing") {
|
|
108
|
+
if (argument === "status")
|
|
109
|
+
result = await client.getBillingStatus();
|
|
110
|
+
else if (argument === "quote")
|
|
111
|
+
result = await client.createBillingQuote();
|
|
112
|
+
else if (argument === "portal")
|
|
113
|
+
result = await client.createBillingPortal();
|
|
114
|
+
else {
|
|
115
|
+
if (!values["idempotency-key"] || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(values["idempotency-key"]))
|
|
116
|
+
throw new TypeError();
|
|
117
|
+
if (argument === "order" && (!values["quote-id"] || !values["terms-version"] || values["agree-to-pay"] !== true))
|
|
118
|
+
throw new TypeError();
|
|
119
|
+
submissionKey = values["idempotency-key"].toLowerCase();
|
|
120
|
+
activeSubmissionKey = submissionKey;
|
|
121
|
+
console.error(`Idempotency key: ${submissionKey}`);
|
|
122
|
+
if (argument === "cancel")
|
|
123
|
+
result = await client.cancelBillingPlan({ idempotencyKey: submissionKey });
|
|
124
|
+
else
|
|
125
|
+
result = await client.confirmBillingOrder(values["quote-id"], { termsVersion: values["terms-version"], paidOrderConfirmed: true, idempotencyKey: submissionKey });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
96
128
|
else if (command === "get")
|
|
97
129
|
result = await client.getEvaluation(argument);
|
|
98
130
|
else {
|
|
@@ -105,12 +137,12 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
105
137
|
return 0;
|
|
106
138
|
}
|
|
107
139
|
catch (error) {
|
|
108
|
-
const problem = error instanceof ReadlintError ? { code: error.code, message: error.message, status: error.status, evaluation_id: error.evaluationId } : {
|
|
140
|
+
const problem = error instanceof ReadlintError ? { code: error.code, message: error.message, status: error.status, evaluation_id: error.evaluationId, ...error.details } : {
|
|
109
141
|
code: "invalid_input", message: "Check the command, UTF-8 input file, URL and credential file permissions. Run `readlint --help`.",
|
|
110
142
|
};
|
|
111
143
|
if (submissionKey)
|
|
112
144
|
problem.idempotency_key = submissionKey;
|
|
113
|
-
console.error(machine ? JSON.stringify({ error: problem }) : `${problem.code}: ${problem.message}`);
|
|
145
|
+
console.error(machine ? JSON.stringify({ error: problem }) : `${problem.code}: ${problem.message}${problem.settings_url ? ` ${problem.action} ${problem.settings_url}` : problem.action_url ? ` ${problem.action_url}` : ""}`);
|
|
114
146
|
return 1;
|
|
115
147
|
}
|
|
116
148
|
}
|
package/dist/gen/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { BodyCreateDeviceCode, BodyCreateDeviceToken, CheckResult, ClientOptions, CreateDeviceCodeData, CreateDeviceCodeError, CreateDeviceCodeErrors, CreateDeviceCodeResponse, CreateDeviceCodeResponses, CreateDeviceTokenData, CreateDeviceTokenError, CreateDeviceTokenErrors, CreateDeviceTokenResponse, CreateDeviceTokenResponses, CreateEvaluationV1EvaluationsPostData, CreateEvaluationV1EvaluationsPostError, CreateEvaluationV1EvaluationsPostErrors, CreateEvaluationV1EvaluationsPostResponse, CreateEvaluationV1EvaluationsPostResponses, DeviceCodeResponse, DeviceTokenResponse, ErrorDetail, ErrorResponse, EvaluationPage, EvaluationReport, EvaluationRequest, EvaluationResult, EvaluationSummary, GetEvaluationV1EvaluationsEvaluationIdGetData, GetEvaluationV1EvaluationsEvaluationIdGetError, GetEvaluationV1EvaluationsEvaluationIdGetErrors, GetEvaluationV1EvaluationsEvaluationIdGetResponse, GetEvaluationV1EvaluationsEvaluationIdGetResponses, HttpValidationError, InvalidField, ListEvaluationsV1EvaluationsGetData, ListEvaluationsV1EvaluationsGetError, ListEvaluationsV1EvaluationsGetErrors, ListEvaluationsV1EvaluationsGetResponse, ListEvaluationsV1EvaluationsGetResponses, OAuthError, PhraseResult, ProseResult, RemoveEvaluationV1EvaluationsEvaluationIdDeleteData, RemoveEvaluationV1EvaluationsEvaluationIdDeleteError, RemoveEvaluationV1EvaluationsEvaluationIdDeleteErrors, RemoveEvaluationV1EvaluationsEvaluationIdDeleteResponse, RemoveEvaluationV1EvaluationsEvaluationIdDeleteResponses, ValidationDetail, ValidationError, ValidationResponse } from './types.gen.js';
|
|
1
|
+
export type { AgentBillingStatus, AgentPermissions, AgentQuote, BillingErrorDetail, BillingErrorResponse, BodyCreateDeviceCode, BodyCreateDeviceToken, CancelBillingPlanData, CancelBillingPlanError, CancelBillingPlanErrors, CancelBillingPlanResponse, CancelBillingPlanResponses, Cancellation, CheckResult, ClientOptions, ConfirmBillingOrderData, ConfirmBillingOrderError, ConfirmBillingOrderErrors, ConfirmBillingOrderResponse, ConfirmBillingOrderResponses, CreateBillingPortalData, CreateBillingPortalError, CreateBillingPortalErrors, CreateBillingPortalResponse, CreateBillingPortalResponses, CreateBillingQuoteData, CreateBillingQuoteError, CreateBillingQuoteErrors, CreateBillingQuoteResponse, CreateBillingQuoteResponses, CreateDeviceCodeData, CreateDeviceCodeError, CreateDeviceCodeErrors, CreateDeviceCodeResponse, CreateDeviceCodeResponses, CreateDeviceTokenData, CreateDeviceTokenError, CreateDeviceTokenErrors, CreateDeviceTokenResponse, CreateDeviceTokenResponses, CreateEvaluationV1EvaluationsPostData, CreateEvaluationV1EvaluationsPostError, CreateEvaluationV1EvaluationsPostErrors, CreateEvaluationV1EvaluationsPostResponse, CreateEvaluationV1EvaluationsPostResponses, DeviceCodeResponse, DeviceTokenResponse, EmptyInstruction, ErrorDetail, ErrorResponse, EvaluationPage, EvaluationReport, EvaluationRequest, EvaluationResult, EvaluationSummary, GetAgentPermissionsData, GetAgentPermissionsError, GetAgentPermissionsErrors, GetAgentPermissionsResponse, GetAgentPermissionsResponses, GetBillingStatusData, GetBillingStatusError, GetBillingStatusErrors, GetBillingStatusResponse, GetBillingStatusResponses, GetEvaluationV1EvaluationsEvaluationIdGetData, GetEvaluationV1EvaluationsEvaluationIdGetError, GetEvaluationV1EvaluationsEvaluationIdGetErrors, GetEvaluationV1EvaluationsEvaluationIdGetResponse, GetEvaluationV1EvaluationsEvaluationIdGetResponses, HttpValidationError, InvalidField, InvoiceView, ListEvaluationsV1EvaluationsGetData, ListEvaluationsV1EvaluationsGetError, ListEvaluationsV1EvaluationsGetErrors, ListEvaluationsV1EvaluationsGetResponse, ListEvaluationsV1EvaluationsGetResponses, OAuthError, OrderAccepted, PaidInstruction, PaymentAction, PendingSetup, PermissionDenial, PermissionErrorResponse, PhraseResult, PortalLink, ProseResult, RemoveEvaluationV1EvaluationsEvaluationIdDeleteData, RemoveEvaluationV1EvaluationsEvaluationIdDeleteError, RemoveEvaluationV1EvaluationsEvaluationIdDeleteErrors, RemoveEvaluationV1EvaluationsEvaluationIdDeleteResponse, RemoveEvaluationV1EvaluationsEvaluationIdDeleteResponses, ValidationDetail, ValidationError, ValidationResponse } from './types.gen.js';
|
package/dist/gen/types.gen.d.ts
CHANGED
|
@@ -1,6 +1,194 @@
|
|
|
1
1
|
export type ClientOptions = {
|
|
2
2
|
baseUrl: `${string}://${string}` | (string & {});
|
|
3
3
|
};
|
|
4
|
+
/**
|
|
5
|
+
* AgentBillingStatus
|
|
6
|
+
*/
|
|
7
|
+
export type AgentBillingStatus = {
|
|
8
|
+
/**
|
|
9
|
+
* Access Active
|
|
10
|
+
*/
|
|
11
|
+
access_active: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Cancelled At
|
|
14
|
+
*/
|
|
15
|
+
cancelled_at: string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Credits Remaining Cents
|
|
18
|
+
*/
|
|
19
|
+
credits_remaining_cents: number;
|
|
20
|
+
/**
|
|
21
|
+
* Enabled
|
|
22
|
+
*/
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Fractional Balance Cents
|
|
26
|
+
*/
|
|
27
|
+
fractional_balance_cents: number;
|
|
28
|
+
/**
|
|
29
|
+
* Invoices
|
|
30
|
+
*/
|
|
31
|
+
invoices: Array<InvoiceView>;
|
|
32
|
+
/**
|
|
33
|
+
* Order Id
|
|
34
|
+
*/
|
|
35
|
+
order_id: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Order State
|
|
38
|
+
*/
|
|
39
|
+
order_state: 'none' | 'scheduled' | 'payment_pending' | 'requires_action' | 'active' | 'cancelled';
|
|
40
|
+
/**
|
|
41
|
+
* Paid Order Confirmed
|
|
42
|
+
*/
|
|
43
|
+
paid_order_confirmed: boolean;
|
|
44
|
+
payment_action: PaymentAction | null;
|
|
45
|
+
/**
|
|
46
|
+
* Payment Method Ready
|
|
47
|
+
*/
|
|
48
|
+
payment_method_ready: boolean;
|
|
49
|
+
pending_setup: PendingSetup | null;
|
|
50
|
+
/**
|
|
51
|
+
* Period Ends At
|
|
52
|
+
*/
|
|
53
|
+
period_ends_at: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Period Kind
|
|
56
|
+
*/
|
|
57
|
+
period_kind: 'trial' | 'paid' | null;
|
|
58
|
+
/**
|
|
59
|
+
* Suspended
|
|
60
|
+
*/
|
|
61
|
+
suspended: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Trial Available
|
|
64
|
+
*/
|
|
65
|
+
trial_available: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Trial Ends At
|
|
68
|
+
*/
|
|
69
|
+
trial_ends_at: string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Usage Above Credits Cents
|
|
72
|
+
*/
|
|
73
|
+
usage_above_credits_cents: number;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* AgentPermissions
|
|
77
|
+
*/
|
|
78
|
+
export type AgentPermissions = {
|
|
79
|
+
/**
|
|
80
|
+
* Agents Can Cancel Plans
|
|
81
|
+
*/
|
|
82
|
+
agents_can_cancel_plans: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Agents Can Confirm Paid Orders
|
|
85
|
+
*/
|
|
86
|
+
agents_can_confirm_paid_orders: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Agents Can Start Trials
|
|
89
|
+
*/
|
|
90
|
+
agents_can_start_trials: boolean;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* AgentQuote
|
|
94
|
+
*/
|
|
95
|
+
export type AgentQuote = {
|
|
96
|
+
/**
|
|
97
|
+
* Affirmation
|
|
98
|
+
*/
|
|
99
|
+
affirmation: string;
|
|
100
|
+
/**
|
|
101
|
+
* Cancellation Terms
|
|
102
|
+
*/
|
|
103
|
+
cancellation_terms: string;
|
|
104
|
+
/**
|
|
105
|
+
* Credit Expiry
|
|
106
|
+
*/
|
|
107
|
+
credit_expiry: string;
|
|
108
|
+
/**
|
|
109
|
+
* Currency
|
|
110
|
+
*/
|
|
111
|
+
currency: 'usd';
|
|
112
|
+
/**
|
|
113
|
+
* Disclosure Text
|
|
114
|
+
*/
|
|
115
|
+
disclosure_text: string;
|
|
116
|
+
/**
|
|
117
|
+
* Disclosure Version
|
|
118
|
+
*/
|
|
119
|
+
disclosure_version: string;
|
|
120
|
+
/**
|
|
121
|
+
* Expires At
|
|
122
|
+
*/
|
|
123
|
+
expires_at: string;
|
|
124
|
+
/**
|
|
125
|
+
* First Charge Timing
|
|
126
|
+
*/
|
|
127
|
+
first_charge_timing: string;
|
|
128
|
+
/**
|
|
129
|
+
* Monthly Credits Cents
|
|
130
|
+
*/
|
|
131
|
+
monthly_credits_cents: number;
|
|
132
|
+
/**
|
|
133
|
+
* Privacy Url
|
|
134
|
+
*/
|
|
135
|
+
privacy_url: string;
|
|
136
|
+
/**
|
|
137
|
+
* Privacy Version
|
|
138
|
+
*/
|
|
139
|
+
privacy_version: string;
|
|
140
|
+
/**
|
|
141
|
+
* Quote Id
|
|
142
|
+
*/
|
|
143
|
+
quote_id: string;
|
|
144
|
+
/**
|
|
145
|
+
* Renewal Terms
|
|
146
|
+
*/
|
|
147
|
+
renewal_terms: string;
|
|
148
|
+
/**
|
|
149
|
+
* Subtotal Cents
|
|
150
|
+
*/
|
|
151
|
+
subtotal_cents: number;
|
|
152
|
+
/**
|
|
153
|
+
* Tax Cents
|
|
154
|
+
*/
|
|
155
|
+
tax_cents: number;
|
|
156
|
+
/**
|
|
157
|
+
* Terms Url
|
|
158
|
+
*/
|
|
159
|
+
terms_url: string;
|
|
160
|
+
/**
|
|
161
|
+
* Terms Version
|
|
162
|
+
*/
|
|
163
|
+
terms_version: string;
|
|
164
|
+
/**
|
|
165
|
+
* Total Cents
|
|
166
|
+
*/
|
|
167
|
+
total_cents: number;
|
|
168
|
+
/**
|
|
169
|
+
* Usage Rate Cents Per Million
|
|
170
|
+
*/
|
|
171
|
+
usage_rate_cents_per_million: number;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* BillingErrorDetail
|
|
175
|
+
*/
|
|
176
|
+
export type BillingErrorDetail = {
|
|
177
|
+
/**
|
|
178
|
+
* Action Url
|
|
179
|
+
*/
|
|
180
|
+
action_url?: string | null;
|
|
181
|
+
/**
|
|
182
|
+
* Code
|
|
183
|
+
*/
|
|
184
|
+
code: string;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* BillingErrorResponse
|
|
188
|
+
*/
|
|
189
|
+
export type BillingErrorResponse = {
|
|
190
|
+
detail: BillingErrorDetail;
|
|
191
|
+
};
|
|
4
192
|
/**
|
|
5
193
|
* Body_createDeviceCode
|
|
6
194
|
*/
|
|
@@ -35,6 +223,24 @@ export type BodyCreateDeviceToken = {
|
|
|
35
223
|
*/
|
|
36
224
|
grant_type: string;
|
|
37
225
|
};
|
|
226
|
+
/**
|
|
227
|
+
* Cancellation
|
|
228
|
+
*/
|
|
229
|
+
export type Cancellation = {
|
|
230
|
+
/**
|
|
231
|
+
* Cancelled
|
|
232
|
+
*/
|
|
233
|
+
cancelled: true;
|
|
234
|
+
current: AgentBillingStatus;
|
|
235
|
+
/**
|
|
236
|
+
* Order Id
|
|
237
|
+
*/
|
|
238
|
+
order_id: string | null;
|
|
239
|
+
/**
|
|
240
|
+
* Trial Period Id
|
|
241
|
+
*/
|
|
242
|
+
trial_period_id: string | null;
|
|
243
|
+
};
|
|
38
244
|
/**
|
|
39
245
|
* CheckResult
|
|
40
246
|
*/
|
|
@@ -102,6 +308,12 @@ export type DeviceTokenResponse = {
|
|
|
102
308
|
*/
|
|
103
309
|
token_type?: string;
|
|
104
310
|
};
|
|
311
|
+
/**
|
|
312
|
+
* EmptyInstruction
|
|
313
|
+
*/
|
|
314
|
+
export type EmptyInstruction = {
|
|
315
|
+
[key: string]: never;
|
|
316
|
+
};
|
|
105
317
|
/**
|
|
106
318
|
* ErrorDetail
|
|
107
319
|
*/
|
|
@@ -271,6 +483,35 @@ export type InvalidField = {
|
|
|
271
483
|
*/
|
|
272
484
|
type: string;
|
|
273
485
|
};
|
|
486
|
+
/**
|
|
487
|
+
* InvoiceView
|
|
488
|
+
*/
|
|
489
|
+
export type InvoiceView = {
|
|
490
|
+
/**
|
|
491
|
+
* Amount Paid Cents
|
|
492
|
+
*/
|
|
493
|
+
amount_paid_cents: number;
|
|
494
|
+
/**
|
|
495
|
+
* Amount Remaining Cents
|
|
496
|
+
*/
|
|
497
|
+
amount_remaining_cents: number | null;
|
|
498
|
+
/**
|
|
499
|
+
* Id
|
|
500
|
+
*/
|
|
501
|
+
id: string;
|
|
502
|
+
/**
|
|
503
|
+
* Status
|
|
504
|
+
*/
|
|
505
|
+
status: string;
|
|
506
|
+
/**
|
|
507
|
+
* Subtotal Cents
|
|
508
|
+
*/
|
|
509
|
+
subtotal_cents: number;
|
|
510
|
+
/**
|
|
511
|
+
* Url
|
|
512
|
+
*/
|
|
513
|
+
url: string | null;
|
|
514
|
+
};
|
|
274
515
|
/**
|
|
275
516
|
* OAuthError
|
|
276
517
|
*/
|
|
@@ -280,6 +521,114 @@ export type OAuthError = {
|
|
|
280
521
|
*/
|
|
281
522
|
error: string;
|
|
282
523
|
};
|
|
524
|
+
/**
|
|
525
|
+
* OrderAccepted
|
|
526
|
+
*/
|
|
527
|
+
export type OrderAccepted = {
|
|
528
|
+
/**
|
|
529
|
+
* Accepted
|
|
530
|
+
*/
|
|
531
|
+
accepted: true;
|
|
532
|
+
/**
|
|
533
|
+
* Accepted At
|
|
534
|
+
*/
|
|
535
|
+
accepted_at: string;
|
|
536
|
+
/**
|
|
537
|
+
* Accepted State
|
|
538
|
+
*/
|
|
539
|
+
accepted_state: 'scheduled' | 'payment_pending' | null;
|
|
540
|
+
current: AgentBillingStatus;
|
|
541
|
+
/**
|
|
542
|
+
* Order Id
|
|
543
|
+
*/
|
|
544
|
+
order_id: string;
|
|
545
|
+
/**
|
|
546
|
+
* Retryable
|
|
547
|
+
*/
|
|
548
|
+
retryable: boolean;
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* PaidInstruction
|
|
552
|
+
*/
|
|
553
|
+
export type PaidInstruction = {
|
|
554
|
+
/**
|
|
555
|
+
* Paid Order Confirmed
|
|
556
|
+
*/
|
|
557
|
+
paid_order_confirmed: boolean;
|
|
558
|
+
/**
|
|
559
|
+
* Quote Id
|
|
560
|
+
*/
|
|
561
|
+
quote_id: string;
|
|
562
|
+
/**
|
|
563
|
+
* Terms Version
|
|
564
|
+
*/
|
|
565
|
+
terms_version: string;
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
568
|
+
* PaymentAction
|
|
569
|
+
*/
|
|
570
|
+
export type PaymentAction = {
|
|
571
|
+
/**
|
|
572
|
+
* Action Url
|
|
573
|
+
*/
|
|
574
|
+
action_url: string;
|
|
575
|
+
/**
|
|
576
|
+
* Reason
|
|
577
|
+
*/
|
|
578
|
+
reason: 'payment_authentication_required' | 'payment_method_required';
|
|
579
|
+
};
|
|
580
|
+
/**
|
|
581
|
+
* PendingSetup
|
|
582
|
+
*/
|
|
583
|
+
export type PendingSetup = {
|
|
584
|
+
/**
|
|
585
|
+
* Action Url
|
|
586
|
+
*/
|
|
587
|
+
action_url: string | null;
|
|
588
|
+
/**
|
|
589
|
+
* Attempt Id
|
|
590
|
+
*/
|
|
591
|
+
attempt_id: string;
|
|
592
|
+
/**
|
|
593
|
+
* Expires At
|
|
594
|
+
*/
|
|
595
|
+
expires_at: string;
|
|
596
|
+
/**
|
|
597
|
+
* State
|
|
598
|
+
*/
|
|
599
|
+
state: 'pending' | 'complete' | 'expired' | 'blocked';
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* PermissionDenial
|
|
603
|
+
*/
|
|
604
|
+
export type PermissionDenial = {
|
|
605
|
+
/**
|
|
606
|
+
* Action
|
|
607
|
+
*/
|
|
608
|
+
action: string;
|
|
609
|
+
/**
|
|
610
|
+
* Code
|
|
611
|
+
*/
|
|
612
|
+
code: 'agent_permission_disabled';
|
|
613
|
+
/**
|
|
614
|
+
* Message
|
|
615
|
+
*/
|
|
616
|
+
message: string;
|
|
617
|
+
/**
|
|
618
|
+
* Retryable
|
|
619
|
+
*/
|
|
620
|
+
retryable: false;
|
|
621
|
+
/**
|
|
622
|
+
* Settings Url
|
|
623
|
+
*/
|
|
624
|
+
settings_url: '/app/settings#agent-permissions';
|
|
625
|
+
};
|
|
626
|
+
/**
|
|
627
|
+
* PermissionErrorResponse
|
|
628
|
+
*/
|
|
629
|
+
export type PermissionErrorResponse = {
|
|
630
|
+
detail: PermissionDenial;
|
|
631
|
+
};
|
|
283
632
|
/**
|
|
284
633
|
* PhraseResult
|
|
285
634
|
*/
|
|
@@ -297,6 +646,15 @@ export type PhraseResult = {
|
|
|
297
646
|
*/
|
|
298
647
|
where: string;
|
|
299
648
|
};
|
|
649
|
+
/**
|
|
650
|
+
* PortalLink
|
|
651
|
+
*/
|
|
652
|
+
export type PortalLink = {
|
|
653
|
+
/**
|
|
654
|
+
* Url
|
|
655
|
+
*/
|
|
656
|
+
url: string;
|
|
657
|
+
};
|
|
300
658
|
/**
|
|
301
659
|
* ProseResult
|
|
302
660
|
*/
|
|
@@ -416,6 +774,252 @@ export type CreateDeviceTokenResponses = {
|
|
|
416
774
|
200: DeviceTokenResponse;
|
|
417
775
|
};
|
|
418
776
|
export type CreateDeviceTokenResponse = CreateDeviceTokenResponses[keyof CreateDeviceTokenResponses];
|
|
777
|
+
export type GetAgentPermissionsData = {
|
|
778
|
+
body?: never;
|
|
779
|
+
path?: never;
|
|
780
|
+
query?: never;
|
|
781
|
+
url: '/v1/agent-permissions';
|
|
782
|
+
};
|
|
783
|
+
export type GetAgentPermissionsErrors = {
|
|
784
|
+
/**
|
|
785
|
+
* Unauthorized
|
|
786
|
+
*/
|
|
787
|
+
401: ErrorResponse;
|
|
788
|
+
/**
|
|
789
|
+
* Service Unavailable
|
|
790
|
+
*/
|
|
791
|
+
503: ErrorResponse;
|
|
792
|
+
};
|
|
793
|
+
export type GetAgentPermissionsError = GetAgentPermissionsErrors[keyof GetAgentPermissionsErrors];
|
|
794
|
+
export type GetAgentPermissionsResponses = {
|
|
795
|
+
/**
|
|
796
|
+
* Successful Response
|
|
797
|
+
*/
|
|
798
|
+
200: AgentPermissions;
|
|
799
|
+
};
|
|
800
|
+
export type GetAgentPermissionsResponse = GetAgentPermissionsResponses[keyof GetAgentPermissionsResponses];
|
|
801
|
+
export type CancelBillingPlanData = {
|
|
802
|
+
body: EmptyInstruction;
|
|
803
|
+
headers: {
|
|
804
|
+
/**
|
|
805
|
+
* Idempotency-Key
|
|
806
|
+
*/
|
|
807
|
+
'Idempotency-Key': string;
|
|
808
|
+
};
|
|
809
|
+
path?: never;
|
|
810
|
+
query?: never;
|
|
811
|
+
url: '/v1/billing/cancel';
|
|
812
|
+
};
|
|
813
|
+
export type CancelBillingPlanErrors = {
|
|
814
|
+
/**
|
|
815
|
+
* Unauthorized
|
|
816
|
+
*/
|
|
817
|
+
401: ErrorResponse;
|
|
818
|
+
/**
|
|
819
|
+
* Response 403 Cancelbillingplan
|
|
820
|
+
*
|
|
821
|
+
* Forbidden
|
|
822
|
+
*/
|
|
823
|
+
403: PermissionErrorResponse | ErrorResponse;
|
|
824
|
+
/**
|
|
825
|
+
* Not Found
|
|
826
|
+
*/
|
|
827
|
+
404: ErrorResponse;
|
|
828
|
+
/**
|
|
829
|
+
* Conflict
|
|
830
|
+
*/
|
|
831
|
+
409: BillingErrorResponse;
|
|
832
|
+
/**
|
|
833
|
+
* Unprocessable Content
|
|
834
|
+
*/
|
|
835
|
+
422: ValidationResponse;
|
|
836
|
+
/**
|
|
837
|
+
* Service Unavailable
|
|
838
|
+
*/
|
|
839
|
+
503: ErrorResponse;
|
|
840
|
+
};
|
|
841
|
+
export type CancelBillingPlanError = CancelBillingPlanErrors[keyof CancelBillingPlanErrors];
|
|
842
|
+
export type CancelBillingPlanResponses = {
|
|
843
|
+
/**
|
|
844
|
+
* Successful Response
|
|
845
|
+
*/
|
|
846
|
+
200: Cancellation;
|
|
847
|
+
};
|
|
848
|
+
export type CancelBillingPlanResponse = CancelBillingPlanResponses[keyof CancelBillingPlanResponses];
|
|
849
|
+
export type ConfirmBillingOrderData = {
|
|
850
|
+
body: PaidInstruction;
|
|
851
|
+
headers: {
|
|
852
|
+
/**
|
|
853
|
+
* Idempotency-Key
|
|
854
|
+
*/
|
|
855
|
+
'Idempotency-Key': string;
|
|
856
|
+
};
|
|
857
|
+
path?: never;
|
|
858
|
+
query?: never;
|
|
859
|
+
url: '/v1/billing/order';
|
|
860
|
+
};
|
|
861
|
+
export type ConfirmBillingOrderErrors = {
|
|
862
|
+
/**
|
|
863
|
+
* Unauthorized
|
|
864
|
+
*/
|
|
865
|
+
401: ErrorResponse;
|
|
866
|
+
/**
|
|
867
|
+
* Response 403 Confirmbillingorder
|
|
868
|
+
*
|
|
869
|
+
* Forbidden
|
|
870
|
+
*/
|
|
871
|
+
403: PermissionErrorResponse | ErrorResponse;
|
|
872
|
+
/**
|
|
873
|
+
* Not Found
|
|
874
|
+
*/
|
|
875
|
+
404: ErrorResponse;
|
|
876
|
+
/**
|
|
877
|
+
* Conflict
|
|
878
|
+
*/
|
|
879
|
+
409: BillingErrorResponse;
|
|
880
|
+
/**
|
|
881
|
+
* Unprocessable Content
|
|
882
|
+
*/
|
|
883
|
+
422: ValidationResponse;
|
|
884
|
+
/**
|
|
885
|
+
* Service Unavailable
|
|
886
|
+
*/
|
|
887
|
+
503: ErrorResponse;
|
|
888
|
+
};
|
|
889
|
+
export type ConfirmBillingOrderError = ConfirmBillingOrderErrors[keyof ConfirmBillingOrderErrors];
|
|
890
|
+
export type ConfirmBillingOrderResponses = {
|
|
891
|
+
/**
|
|
892
|
+
* Successful Response
|
|
893
|
+
*/
|
|
894
|
+
200: OrderAccepted;
|
|
895
|
+
};
|
|
896
|
+
export type ConfirmBillingOrderResponse = ConfirmBillingOrderResponses[keyof ConfirmBillingOrderResponses];
|
|
897
|
+
export type CreateBillingPortalData = {
|
|
898
|
+
body?: never;
|
|
899
|
+
path?: never;
|
|
900
|
+
query?: never;
|
|
901
|
+
url: '/v1/billing/portal';
|
|
902
|
+
};
|
|
903
|
+
export type CreateBillingPortalErrors = {
|
|
904
|
+
/**
|
|
905
|
+
* Unauthorized
|
|
906
|
+
*/
|
|
907
|
+
401: ErrorResponse;
|
|
908
|
+
/**
|
|
909
|
+
* Response 403 Createbillingportal
|
|
910
|
+
*
|
|
911
|
+
* Forbidden
|
|
912
|
+
*/
|
|
913
|
+
403: PermissionErrorResponse | ErrorResponse;
|
|
914
|
+
/**
|
|
915
|
+
* Not Found
|
|
916
|
+
*/
|
|
917
|
+
404: ErrorResponse;
|
|
918
|
+
/**
|
|
919
|
+
* Conflict
|
|
920
|
+
*/
|
|
921
|
+
409: BillingErrorResponse;
|
|
922
|
+
/**
|
|
923
|
+
* Unprocessable Content
|
|
924
|
+
*/
|
|
925
|
+
422: ValidationResponse;
|
|
926
|
+
/**
|
|
927
|
+
* Service Unavailable
|
|
928
|
+
*/
|
|
929
|
+
503: ErrorResponse;
|
|
930
|
+
};
|
|
931
|
+
export type CreateBillingPortalError = CreateBillingPortalErrors[keyof CreateBillingPortalErrors];
|
|
932
|
+
export type CreateBillingPortalResponses = {
|
|
933
|
+
/**
|
|
934
|
+
* Successful Response
|
|
935
|
+
*/
|
|
936
|
+
200: PortalLink;
|
|
937
|
+
};
|
|
938
|
+
export type CreateBillingPortalResponse = CreateBillingPortalResponses[keyof CreateBillingPortalResponses];
|
|
939
|
+
export type CreateBillingQuoteData = {
|
|
940
|
+
body?: never;
|
|
941
|
+
path?: never;
|
|
942
|
+
query?: never;
|
|
943
|
+
url: '/v1/billing/quote';
|
|
944
|
+
};
|
|
945
|
+
export type CreateBillingQuoteErrors = {
|
|
946
|
+
/**
|
|
947
|
+
* Unauthorized
|
|
948
|
+
*/
|
|
949
|
+
401: ErrorResponse;
|
|
950
|
+
/**
|
|
951
|
+
* Response 403 Createbillingquote
|
|
952
|
+
*
|
|
953
|
+
* Forbidden
|
|
954
|
+
*/
|
|
955
|
+
403: PermissionErrorResponse | ErrorResponse;
|
|
956
|
+
/**
|
|
957
|
+
* Not Found
|
|
958
|
+
*/
|
|
959
|
+
404: ErrorResponse;
|
|
960
|
+
/**
|
|
961
|
+
* Conflict
|
|
962
|
+
*/
|
|
963
|
+
409: BillingErrorResponse;
|
|
964
|
+
/**
|
|
965
|
+
* Unprocessable Content
|
|
966
|
+
*/
|
|
967
|
+
422: ValidationResponse;
|
|
968
|
+
/**
|
|
969
|
+
* Service Unavailable
|
|
970
|
+
*/
|
|
971
|
+
503: ErrorResponse;
|
|
972
|
+
};
|
|
973
|
+
export type CreateBillingQuoteError = CreateBillingQuoteErrors[keyof CreateBillingQuoteErrors];
|
|
974
|
+
export type CreateBillingQuoteResponses = {
|
|
975
|
+
/**
|
|
976
|
+
* Successful Response
|
|
977
|
+
*/
|
|
978
|
+
200: AgentQuote;
|
|
979
|
+
};
|
|
980
|
+
export type CreateBillingQuoteResponse = CreateBillingQuoteResponses[keyof CreateBillingQuoteResponses];
|
|
981
|
+
export type GetBillingStatusData = {
|
|
982
|
+
body?: never;
|
|
983
|
+
path?: never;
|
|
984
|
+
query?: never;
|
|
985
|
+
url: '/v1/billing/status';
|
|
986
|
+
};
|
|
987
|
+
export type GetBillingStatusErrors = {
|
|
988
|
+
/**
|
|
989
|
+
* Unauthorized
|
|
990
|
+
*/
|
|
991
|
+
401: ErrorResponse;
|
|
992
|
+
/**
|
|
993
|
+
* Response 403 Getbillingstatus
|
|
994
|
+
*
|
|
995
|
+
* Forbidden
|
|
996
|
+
*/
|
|
997
|
+
403: PermissionErrorResponse | ErrorResponse;
|
|
998
|
+
/**
|
|
999
|
+
* Not Found
|
|
1000
|
+
*/
|
|
1001
|
+
404: ErrorResponse;
|
|
1002
|
+
/**
|
|
1003
|
+
* Conflict
|
|
1004
|
+
*/
|
|
1005
|
+
409: BillingErrorResponse;
|
|
1006
|
+
/**
|
|
1007
|
+
* Unprocessable Content
|
|
1008
|
+
*/
|
|
1009
|
+
422: ValidationResponse;
|
|
1010
|
+
/**
|
|
1011
|
+
* Service Unavailable
|
|
1012
|
+
*/
|
|
1013
|
+
503: ErrorResponse;
|
|
1014
|
+
};
|
|
1015
|
+
export type GetBillingStatusError = GetBillingStatusErrors[keyof GetBillingStatusErrors];
|
|
1016
|
+
export type GetBillingStatusResponses = {
|
|
1017
|
+
/**
|
|
1018
|
+
* Successful Response
|
|
1019
|
+
*/
|
|
1020
|
+
200: AgentBillingStatus;
|
|
1021
|
+
};
|
|
1022
|
+
export type GetBillingStatusResponse = GetBillingStatusResponses[keyof GetBillingStatusResponses];
|
|
419
1023
|
export type ListEvaluationsV1EvaluationsGetData = {
|
|
420
1024
|
body?: never;
|
|
421
1025
|
path?: never;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import type { EvaluationResult, EvaluationPage, DeviceCodeResponse, DeviceTokenResponse } from "./gen/types.gen.js";
|
|
2
|
-
export type { EvaluationResult as Evaluation, EvaluationPage, EvaluationReport, EvaluationSummary, CheckResult, ProseResult, PhraseResult, DeviceCodeResponse, DeviceTokenResponse, } from "./gen/types.gen.js";
|
|
1
|
+
import type { EvaluationResult, EvaluationPage, DeviceCodeResponse, DeviceTokenResponse, AgentPermissions, AgentBillingStatus, AgentQuote, OrderAccepted, Cancellation, PortalLink } from "./gen/types.gen.js";
|
|
2
|
+
export type { EvaluationResult as Evaluation, EvaluationPage, EvaluationReport, EvaluationSummary, CheckResult, ProseResult, PhraseResult, DeviceCodeResponse, DeviceTokenResponse, AgentPermissions, AgentBillingStatus, AgentQuote, OrderAccepted, Cancellation, PortalLink, } from "./gen/types.gen.js";
|
|
3
3
|
/** Sanitized failure. status is null when no reliable HTTP answer arrived. */
|
|
4
4
|
export declare class ReadlintError extends Error {
|
|
5
5
|
readonly code: string;
|
|
6
6
|
readonly status: number | null;
|
|
7
7
|
readonly evaluationId: string | null;
|
|
8
|
+
readonly details: {
|
|
9
|
+
action?: string;
|
|
10
|
+
settings_url?: string;
|
|
11
|
+
retryable?: false;
|
|
12
|
+
action_url?: string;
|
|
13
|
+
};
|
|
8
14
|
readonly name = "ReadlintError";
|
|
9
|
-
constructor(code: string, message: string, status?: number | null, evaluationId?: string | null
|
|
15
|
+
constructor(code: string, message: string, status?: number | null, evaluationId?: string | null, details?: {
|
|
16
|
+
action?: string;
|
|
17
|
+
settings_url?: string;
|
|
18
|
+
retryable?: false;
|
|
19
|
+
action_url?: string;
|
|
20
|
+
});
|
|
10
21
|
}
|
|
11
22
|
export interface ReadlintOptions {
|
|
12
23
|
apiKey?: string;
|
|
@@ -29,6 +40,20 @@ export declare class Readlint {
|
|
|
29
40
|
#private;
|
|
30
41
|
readonly baseUrl: string;
|
|
31
42
|
constructor(options?: ReadlintOptions);
|
|
43
|
+
/** Read account-wide policy. Changes require the owner's browser session. */
|
|
44
|
+
getAgentPermissions(): Promise<AgentPermissions>;
|
|
45
|
+
getBillingStatus(): Promise<AgentBillingStatus>;
|
|
46
|
+
createBillingQuote(): Promise<AgentQuote>;
|
|
47
|
+
/** Explicit paid instruction; never automatically retried. */
|
|
48
|
+
confirmBillingOrder(quoteId: string, options: {
|
|
49
|
+
termsVersion: string;
|
|
50
|
+
paidOrderConfirmed: true;
|
|
51
|
+
idempotencyKey: string;
|
|
52
|
+
}): Promise<OrderAccepted>;
|
|
53
|
+
cancelBillingPlan(options: {
|
|
54
|
+
idempotencyKey: string;
|
|
55
|
+
}): Promise<Cancellation>;
|
|
56
|
+
createBillingPortal(): Promise<PortalLink>;
|
|
32
57
|
evaluate(article: string, options: EvaluateOptions): Promise<EvaluationResult>;
|
|
33
58
|
listEvaluations(options?: {
|
|
34
59
|
limit?: number;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,17 @@ const RECOVERY = {
|
|
|
5
5
|
evaluation_disabled: "Try again later with the same idempotency key and article.",
|
|
6
6
|
evaluation_context_exceeded: "Shorten the article and submit with a new key.",
|
|
7
7
|
evaluation_not_found: "List evaluations to find an unexpired evaluation ID.",
|
|
8
|
-
idempotency_key_reused: "
|
|
8
|
+
idempotency_key_reused: "Reuse the original key and identical input to recover its outcome; use a new key only for a deliberate new instruction.",
|
|
9
|
+
agent_orders_unavailable: "API-key paid orders are not available yet. Use the owner Billing page.",
|
|
10
|
+
billing_disabled: "Billing is not available. Read billing status before trying again.",
|
|
11
|
+
quote_expired: "Read billing status, then request a fresh quote for a new instruction.",
|
|
12
|
+
quote_changed: "Review a fresh quote and its disclosure before confirming a new instruction.",
|
|
13
|
+
quote_not_found: "Use a quote belonging to this account.",
|
|
14
|
+
terms_version_mismatch: "Use the Terms version in a fresh quote.",
|
|
15
|
+
paid_order_consent_required: "Explicit paid-order confirmation is required.",
|
|
16
|
+
paid_order_already_confirmed: "Read the current order in billing status.",
|
|
17
|
+
save_card_first: "Save a payment method using the returned payment link.",
|
|
18
|
+
billing_address_required: "Complete the billing address using the returned payment link.",
|
|
9
19
|
validation_error: "Check the input before retrying.",
|
|
10
20
|
invalid_request: "Check the request fields before trying again.",
|
|
11
21
|
invalid_page_size: "Choose a smaller limit.",
|
|
@@ -21,12 +31,14 @@ export class ReadlintError extends Error {
|
|
|
21
31
|
code;
|
|
22
32
|
status;
|
|
23
33
|
evaluationId;
|
|
34
|
+
details;
|
|
24
35
|
name = "ReadlintError";
|
|
25
|
-
constructor(code, message, status = null, evaluationId = null) {
|
|
36
|
+
constructor(code, message, status = null, evaluationId = null, details = {}) {
|
|
26
37
|
super(message);
|
|
27
38
|
this.code = code;
|
|
28
39
|
this.status = status;
|
|
29
40
|
this.evaluationId = evaluationId;
|
|
41
|
+
this.details = details;
|
|
30
42
|
}
|
|
31
43
|
}
|
|
32
44
|
function env(name) {
|
|
@@ -49,18 +61,37 @@ function origin(value) {
|
|
|
49
61
|
}
|
|
50
62
|
function uuid(value) {
|
|
51
63
|
if (typeof value !== "string" || value.length !== 36 || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value)) {
|
|
52
|
-
throw new TypeError("Use a valid
|
|
64
|
+
throw new TypeError("Use a valid UUID.");
|
|
53
65
|
}
|
|
54
66
|
return value.toLowerCase();
|
|
55
67
|
}
|
|
56
68
|
function object(value) {
|
|
57
69
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
70
|
}
|
|
59
|
-
function problem(status, body) {
|
|
71
|
+
function problem(status, body, baseUrl) {
|
|
60
72
|
const raw = object(body) ? (object(body.detail) ? body.detail.code : body.error) : null;
|
|
73
|
+
const detail = object(body) && object(body.detail) ? body.detail : null;
|
|
74
|
+
if (status === 403 && detail && raw === "agent_permission_disabled") {
|
|
75
|
+
for (const label of ["Agents can start trials", "Agents can confirm paid orders", "Agents can cancel plans"]) {
|
|
76
|
+
const message = `The account has turned off "${label}".`;
|
|
77
|
+
const action = `Ask the account owner to enable "${label}" in Settings → Agent permissions.`;
|
|
78
|
+
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 });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
61
83
|
const code = typeof raw === "string" && Object.hasOwn(RECOVERY, raw) ? raw :
|
|
62
84
|
({ 401: "authentication_required", 422: "validation_error", 429: "rate_limited" }[status] ?? "api_error");
|
|
63
|
-
|
|
85
|
+
let action_url;
|
|
86
|
+
if (["save_card_first", "billing_address_required"].includes(code) && typeof detail?.action_url === "string") {
|
|
87
|
+
try {
|
|
88
|
+
const url = new URL(detail.action_url);
|
|
89
|
+
if (url.protocol === "https:" && ["billing.stripe.com", "checkout.stripe.com"].includes(url.host) && !url.username && !url.password && !url.hash && !/[\x00-\x20]/.test(detail.action_url))
|
|
90
|
+
action_url = detail.action_url;
|
|
91
|
+
}
|
|
92
|
+
catch { /* omit an unsafe recovery URL */ }
|
|
93
|
+
}
|
|
94
|
+
return new ReadlintError(code, `HTTP ${status}: ${code}. ${RECOVERY[code] ?? "Retry later; for a submission reuse its key and identical input."}`, status, null, action_url ? { action_url } : {});
|
|
64
95
|
}
|
|
65
96
|
function retryDelay(response, attempt) {
|
|
66
97
|
let seconds = 2 ** attempt;
|
|
@@ -93,6 +124,28 @@ export class Readlint {
|
|
|
93
124
|
}
|
|
94
125
|
this.#fetch = options.fetch ?? globalThis.fetch;
|
|
95
126
|
}
|
|
127
|
+
/** Read account-wide policy. Changes require the owner's browser session. */
|
|
128
|
+
getAgentPermissions() {
|
|
129
|
+
return this.#request("GET", "/v1/agent-permissions", true);
|
|
130
|
+
}
|
|
131
|
+
getBillingStatus() {
|
|
132
|
+
return this.#request("GET", "/v1/billing/status", true);
|
|
133
|
+
}
|
|
134
|
+
createBillingQuote() {
|
|
135
|
+
return this.#request("POST", "/v1/billing/quote", false);
|
|
136
|
+
}
|
|
137
|
+
/** Explicit paid instruction; never automatically retried. */
|
|
138
|
+
confirmBillingOrder(quoteId, options) {
|
|
139
|
+
if (options?.paidOrderConfirmed !== true)
|
|
140
|
+
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) });
|
|
142
|
+
}
|
|
143
|
+
cancelBillingPlan(options) {
|
|
144
|
+
return this.#request("POST", "/v1/billing/cancel", false, "{}", { "Content-Type": "application/json", "Idempotency-Key": uuid(options.idempotencyKey) });
|
|
145
|
+
}
|
|
146
|
+
createBillingPortal() {
|
|
147
|
+
return this.#request("POST", "/v1/billing/portal", false);
|
|
148
|
+
}
|
|
96
149
|
evaluate(article, options) {
|
|
97
150
|
if (typeof options?.idempotencyKey !== "string" || !/^[!-~]{1,255}$(?![\s\S])/.test(options.idempotencyKey)) {
|
|
98
151
|
throw new TypeError("idempotencyKey must be 1–255 printable ASCII characters without spaces.");
|
|
@@ -180,13 +233,13 @@ export class Readlint {
|
|
|
180
233
|
throw new ReadlintError("evaluation_failed", "Evaluation failed. Read its ID for details; a deliberate new attempt needs a new idempotency key.", response.status, id);
|
|
181
234
|
}
|
|
182
235
|
if (!retry || ![429, 502, 503, 504].includes(response.status) || attempt === this.#maxRetries) {
|
|
183
|
-
throw problem(response.status, json);
|
|
236
|
+
throw problem(response.status, json, this.baseUrl);
|
|
184
237
|
}
|
|
185
238
|
}
|
|
186
239
|
const delay = retryDelay(response, attempt);
|
|
187
240
|
if (delay === null) {
|
|
188
241
|
if (response)
|
|
189
|
-
throw problem(response.status, json);
|
|
242
|
+
throw problem(response.status, json, this.baseUrl);
|
|
190
243
|
throw new ReadlintError("network_error", "No reliable response. Check your connection; for a submission reuse its key and identical input.");
|
|
191
244
|
}
|
|
192
245
|
await new Promise(resolve => setTimeout(resolve, delay));
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.6.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.6.0";
|