nonecap 0.1.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/LICENSE +21 -0
- package/README.md +155 -0
- package/dist/index.cjs +294 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +279 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for the NoneCap API. Field names are snake_case to match the JSON
|
|
3
|
+
* on the wire exactly, so what you read in the docs is what you write in code.
|
|
4
|
+
*/
|
|
5
|
+
/** Captcha type a solve targets. */
|
|
6
|
+
type SolveType = "hcaptcha" | "hcaptcha_enterprise";
|
|
7
|
+
/** Lifecycle of a solve. `solved` and `failed`/`expired`/`cancelled` are terminal. */
|
|
8
|
+
type SolveStatus = "pending" | "solving" | "solved" | "failed" | "cancelled" | "expired";
|
|
9
|
+
/** A proxy the solve should egress through. */
|
|
10
|
+
interface Proxy {
|
|
11
|
+
scheme?: string;
|
|
12
|
+
host?: string;
|
|
13
|
+
port?: string | number;
|
|
14
|
+
username?: string;
|
|
15
|
+
password?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Fields common to every solve submission. */
|
|
18
|
+
interface SolveCreateBase {
|
|
19
|
+
/** The captcha's sitekey. */
|
|
20
|
+
sitekey: string;
|
|
21
|
+
/** The page URL the captcha is served on. */
|
|
22
|
+
url: string;
|
|
23
|
+
/** User agent to present to the captcha. */
|
|
24
|
+
user_agent?: string;
|
|
25
|
+
/** Proxy to route the solve through, as a structured object or a URL string. */
|
|
26
|
+
proxy?: Proxy | string;
|
|
27
|
+
/** URL to POST the solve to when it reaches a terminal state. */
|
|
28
|
+
webhook_url?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parameters for {@link NoneCap.solves.create} and {@link NoneCap.solve}.
|
|
32
|
+
*
|
|
33
|
+
* Modeled as a discriminated union on `type`: `rqdata` is optional for
|
|
34
|
+
* `hcaptcha` but required for `hcaptcha_enterprise`, enforced at compile time.
|
|
35
|
+
*/
|
|
36
|
+
type SolveCreateParams = (SolveCreateBase & {
|
|
37
|
+
type: "hcaptcha";
|
|
38
|
+
rqdata?: string;
|
|
39
|
+
}) | (SolveCreateBase & {
|
|
40
|
+
type: "hcaptcha_enterprise";
|
|
41
|
+
rqdata: string;
|
|
42
|
+
});
|
|
43
|
+
/** The error attached to a solve that did not succeed. */
|
|
44
|
+
interface SolveError {
|
|
45
|
+
code: string;
|
|
46
|
+
message: string;
|
|
47
|
+
}
|
|
48
|
+
/** A solve resource. */
|
|
49
|
+
interface Solve {
|
|
50
|
+
id: string;
|
|
51
|
+
object: "solve";
|
|
52
|
+
type: SolveType;
|
|
53
|
+
status: SolveStatus;
|
|
54
|
+
sitekey: string;
|
|
55
|
+
url: string;
|
|
56
|
+
/** The captcha token once `status === "solved"`, otherwise null. */
|
|
57
|
+
token: string | null;
|
|
58
|
+
/** Set when the solve did not succeed, otherwise null. */
|
|
59
|
+
error: SolveError | null;
|
|
60
|
+
/** Credits charged for this solve. Only successful solves are charged. */
|
|
61
|
+
credits_charged: number | null;
|
|
62
|
+
/** Bytes that egressed through the metered proxy, or null if none was used. */
|
|
63
|
+
proxy_bytes: number | null;
|
|
64
|
+
created_at: string;
|
|
65
|
+
started_at: string | null;
|
|
66
|
+
finished_at: string | null;
|
|
67
|
+
/** Milliseconds the solve waited in the queue before a worker picked it up. */
|
|
68
|
+
queue_ms: number | null;
|
|
69
|
+
/** Milliseconds of actual solving. */
|
|
70
|
+
resolve_ms: number | null;
|
|
71
|
+
}
|
|
72
|
+
/** Parameters for {@link NoneCap.solves.list}. */
|
|
73
|
+
interface SolveListParams {
|
|
74
|
+
/** Page size, 1–100. Defaults to 20. */
|
|
75
|
+
limit?: number;
|
|
76
|
+
/** Return solves created after this solve id (cursor pagination). */
|
|
77
|
+
starting_after?: string;
|
|
78
|
+
/** Only solves with this status. */
|
|
79
|
+
status?: SolveStatus;
|
|
80
|
+
/** Only solves of this type. */
|
|
81
|
+
type?: SolveType;
|
|
82
|
+
}
|
|
83
|
+
/** One page of solves. */
|
|
84
|
+
interface SolveList {
|
|
85
|
+
object: "list";
|
|
86
|
+
data: Solve[];
|
|
87
|
+
has_more: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** Your account, including the current credit balance. */
|
|
90
|
+
interface Account {
|
|
91
|
+
object: "account";
|
|
92
|
+
id: string;
|
|
93
|
+
email: string;
|
|
94
|
+
credits_balance: number;
|
|
95
|
+
created_at: string;
|
|
96
|
+
}
|
|
97
|
+
/** Error codes returned in the API's error envelope. */
|
|
98
|
+
type ErrorCode = "unauthorized" | "forbidden" | "account_locked" | "insufficient_credits" | "invalid_request" | "validation_error" | "not_found" | "conflict" | "rate_limited" | "ext_daily_limit" | "concurrency_limit_exceeded" | "internal_error" | "pool_exhausted";
|
|
99
|
+
/** The Stripe-style error envelope every non-2xx response carries. */
|
|
100
|
+
interface ErrorEnvelope {
|
|
101
|
+
error: {
|
|
102
|
+
code: ErrorCode;
|
|
103
|
+
message: string;
|
|
104
|
+
param: string | null;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Is this a terminal solve status? */
|
|
109
|
+
declare function isTerminal(status: SolveStatus): boolean;
|
|
110
|
+
/** A `fetch` implementation. Defaults to the global `fetch`. */
|
|
111
|
+
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
112
|
+
/** Options for constructing a {@link NoneCap} client. */
|
|
113
|
+
interface NoneCapOptions {
|
|
114
|
+
/** Your NoneCap API key. Find it at https://dashboard.nonecap.com. */
|
|
115
|
+
apiKey: string;
|
|
116
|
+
/** Override the API base URL. Defaults to https://api.nonecap.com. */
|
|
117
|
+
baseURL?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Per-request timeout in milliseconds for a single HTTP call. Defaults to
|
|
120
|
+
* 100000 (just above the 90s server long-poll). Note this bounds one HTTP
|
|
121
|
+
* round trip, not the whole {@link NoneCap.solve} wait — use the `timeout`
|
|
122
|
+
* option on `solve()` for that.
|
|
123
|
+
*/
|
|
124
|
+
timeout?: number;
|
|
125
|
+
/** Inject a custom `fetch` (for testing, proxies, or non-standard runtimes). */
|
|
126
|
+
fetch?: FetchLike;
|
|
127
|
+
}
|
|
128
|
+
/** Per-call options for the long-polling endpoints. */
|
|
129
|
+
interface WaitOptions {
|
|
130
|
+
/**
|
|
131
|
+
* Hold the connection open up to this many seconds (1–90) waiting for the
|
|
132
|
+
* solve to finish before responding. Omit to return immediately.
|
|
133
|
+
*/
|
|
134
|
+
wait?: number;
|
|
135
|
+
/** Abort the request. */
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}
|
|
138
|
+
/** Options for {@link NoneCap.solve}. */
|
|
139
|
+
interface SolveHelperOptions {
|
|
140
|
+
/**
|
|
141
|
+
* Give up after this many milliseconds and throw {@link TimeoutError}.
|
|
142
|
+
* Defaults to 180000 (3 minutes).
|
|
143
|
+
*/
|
|
144
|
+
timeout?: number;
|
|
145
|
+
/** Abort waiting. */
|
|
146
|
+
signal?: AbortSignal;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The NoneCap API client.
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
152
|
+
* const nc = new NoneCap({ apiKey: process.env.NONECAP_KEY! });
|
|
153
|
+
* const { token } = await nc.solve({ type: "hcaptcha", sitekey, url });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare class NoneCap {
|
|
157
|
+
#private;
|
|
158
|
+
constructor(options: NoneCapOptions);
|
|
159
|
+
/** Operations on solves. */
|
|
160
|
+
readonly solves: {
|
|
161
|
+
/** Submit a solve. Pass `{ wait }` to hold the connection until it finishes. */
|
|
162
|
+
create: (params: SolveCreateParams, options?: WaitOptions) => Promise<Solve>;
|
|
163
|
+
/** Fetch a solve by id. Pass `{ wait }` to long-poll until it finishes. */
|
|
164
|
+
retrieve: (id: string, options?: WaitOptions) => Promise<Solve>;
|
|
165
|
+
/** Cancel a pending or in-flight solve. */
|
|
166
|
+
cancel: (id: string, options?: {
|
|
167
|
+
signal?: AbortSignal;
|
|
168
|
+
}) => Promise<Solve>;
|
|
169
|
+
/** Fetch one page of solves. */
|
|
170
|
+
list: (params?: SolveListParams, options?: {
|
|
171
|
+
signal?: AbortSignal;
|
|
172
|
+
}) => Promise<SolveList>;
|
|
173
|
+
/**
|
|
174
|
+
* Iterate every solve across pages, newest first.
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* for await (const solve of nc.solves.listAll()) { ... }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
listAll: (params?: SolveListParams, options?: {
|
|
181
|
+
signal?: AbortSignal;
|
|
182
|
+
}) => AsyncIterableIterator<Solve>;
|
|
183
|
+
};
|
|
184
|
+
/** Fetch your account, including the current credit balance. */
|
|
185
|
+
me(options?: {
|
|
186
|
+
signal?: AbortSignal;
|
|
187
|
+
}): Promise<Account>;
|
|
188
|
+
/**
|
|
189
|
+
* Submit a solve and wait for it to finish, returning the solved solve.
|
|
190
|
+
*
|
|
191
|
+
* Uses the server's long-poll under the hood and keeps polling until the
|
|
192
|
+
* solve is terminal or `timeout` elapses. Throws {@link SolveFailedError} if
|
|
193
|
+
* the solve fails/expires/is cancelled, or {@link TimeoutError} on timeout.
|
|
194
|
+
*/
|
|
195
|
+
solve(params: SolveCreateParams, options?: SolveHelperOptions): Promise<Solve>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Base class for every error this library throws. Catch `NoneCapError` to
|
|
200
|
+
* handle all of them, or catch a subclass to handle one kind.
|
|
201
|
+
*/
|
|
202
|
+
declare class NoneCapError extends Error {
|
|
203
|
+
/** Machine-readable error code from the API envelope, when there is one. */
|
|
204
|
+
readonly code: ErrorCode | undefined;
|
|
205
|
+
/** HTTP status, when the error came from a response. */
|
|
206
|
+
readonly status: number | undefined;
|
|
207
|
+
/** The request field that was rejected, for validation errors. */
|
|
208
|
+
readonly param: string | null;
|
|
209
|
+
constructor(message: string, opts?: {
|
|
210
|
+
code?: ErrorCode;
|
|
211
|
+
status?: number;
|
|
212
|
+
param?: string | null;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/** 401 — the API key is missing, malformed, or revoked. */
|
|
216
|
+
declare class AuthenticationError extends NoneCapError {
|
|
217
|
+
}
|
|
218
|
+
/** 403 — the key is valid but not allowed to do this (scope or locked account). */
|
|
219
|
+
declare class PermissionError extends NoneCapError {
|
|
220
|
+
}
|
|
221
|
+
/** 402 — the account is out of credits. */
|
|
222
|
+
declare class InsufficientCreditsError extends NoneCapError {
|
|
223
|
+
}
|
|
224
|
+
/** 422 / 400 — the request was rejected. `param` names the offending field. */
|
|
225
|
+
declare class ValidationError extends NoneCapError {
|
|
226
|
+
}
|
|
227
|
+
/** 404 — no such resource. */
|
|
228
|
+
declare class NotFoundError extends NoneCapError {
|
|
229
|
+
}
|
|
230
|
+
/** 409 — the solve is already in a terminal state (e.g. cancelling a finished solve). */
|
|
231
|
+
declare class ConflictError extends NoneCapError {
|
|
232
|
+
}
|
|
233
|
+
/** 429 — too many concurrent solves, or rate limited. Back off and retry. */
|
|
234
|
+
declare class RateLimitError extends NoneCapError {
|
|
235
|
+
}
|
|
236
|
+
/** 5xx, or a response that wasn't the expected shape. */
|
|
237
|
+
declare class APIError extends NoneCapError {
|
|
238
|
+
}
|
|
239
|
+
/** The request never reached the API (DNS, TCP, TLS, timeout, offline). */
|
|
240
|
+
declare class ConnectionError extends NoneCapError {
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Thrown by {@link NoneCap.solve} when a solve reaches a terminal state without
|
|
244
|
+
* a token: `failed`, `expired`, or `cancelled`. The full solve is attached so
|
|
245
|
+
* you can inspect `solve.error` and timings.
|
|
246
|
+
*/
|
|
247
|
+
declare class SolveFailedError extends NoneCapError {
|
|
248
|
+
readonly solve: Solve;
|
|
249
|
+
constructor(solve: Solve);
|
|
250
|
+
}
|
|
251
|
+
/** Thrown by {@link NoneCap.solve} when the client-side timeout elapses first. */
|
|
252
|
+
declare class TimeoutError extends NoneCapError {
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export { APIError, type Account, AuthenticationError, ConflictError, ConnectionError, type ErrorCode, type ErrorEnvelope, type FetchLike, InsufficientCreditsError, NoneCap, NoneCapError, type NoneCapOptions, NotFoundError, PermissionError, type Proxy, RateLimitError, type Solve, type SolveCreateParams, type SolveError, SolveFailedError, type SolveHelperOptions, type SolveList, type SolveListParams, type SolveStatus, type SolveType, TimeoutError, ValidationError, type WaitOptions, isTerminal };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for the NoneCap API. Field names are snake_case to match the JSON
|
|
3
|
+
* on the wire exactly, so what you read in the docs is what you write in code.
|
|
4
|
+
*/
|
|
5
|
+
/** Captcha type a solve targets. */
|
|
6
|
+
type SolveType = "hcaptcha" | "hcaptcha_enterprise";
|
|
7
|
+
/** Lifecycle of a solve. `solved` and `failed`/`expired`/`cancelled` are terminal. */
|
|
8
|
+
type SolveStatus = "pending" | "solving" | "solved" | "failed" | "cancelled" | "expired";
|
|
9
|
+
/** A proxy the solve should egress through. */
|
|
10
|
+
interface Proxy {
|
|
11
|
+
scheme?: string;
|
|
12
|
+
host?: string;
|
|
13
|
+
port?: string | number;
|
|
14
|
+
username?: string;
|
|
15
|
+
password?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Fields common to every solve submission. */
|
|
18
|
+
interface SolveCreateBase {
|
|
19
|
+
/** The captcha's sitekey. */
|
|
20
|
+
sitekey: string;
|
|
21
|
+
/** The page URL the captcha is served on. */
|
|
22
|
+
url: string;
|
|
23
|
+
/** User agent to present to the captcha. */
|
|
24
|
+
user_agent?: string;
|
|
25
|
+
/** Proxy to route the solve through, as a structured object or a URL string. */
|
|
26
|
+
proxy?: Proxy | string;
|
|
27
|
+
/** URL to POST the solve to when it reaches a terminal state. */
|
|
28
|
+
webhook_url?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parameters for {@link NoneCap.solves.create} and {@link NoneCap.solve}.
|
|
32
|
+
*
|
|
33
|
+
* Modeled as a discriminated union on `type`: `rqdata` is optional for
|
|
34
|
+
* `hcaptcha` but required for `hcaptcha_enterprise`, enforced at compile time.
|
|
35
|
+
*/
|
|
36
|
+
type SolveCreateParams = (SolveCreateBase & {
|
|
37
|
+
type: "hcaptcha";
|
|
38
|
+
rqdata?: string;
|
|
39
|
+
}) | (SolveCreateBase & {
|
|
40
|
+
type: "hcaptcha_enterprise";
|
|
41
|
+
rqdata: string;
|
|
42
|
+
});
|
|
43
|
+
/** The error attached to a solve that did not succeed. */
|
|
44
|
+
interface SolveError {
|
|
45
|
+
code: string;
|
|
46
|
+
message: string;
|
|
47
|
+
}
|
|
48
|
+
/** A solve resource. */
|
|
49
|
+
interface Solve {
|
|
50
|
+
id: string;
|
|
51
|
+
object: "solve";
|
|
52
|
+
type: SolveType;
|
|
53
|
+
status: SolveStatus;
|
|
54
|
+
sitekey: string;
|
|
55
|
+
url: string;
|
|
56
|
+
/** The captcha token once `status === "solved"`, otherwise null. */
|
|
57
|
+
token: string | null;
|
|
58
|
+
/** Set when the solve did not succeed, otherwise null. */
|
|
59
|
+
error: SolveError | null;
|
|
60
|
+
/** Credits charged for this solve. Only successful solves are charged. */
|
|
61
|
+
credits_charged: number | null;
|
|
62
|
+
/** Bytes that egressed through the metered proxy, or null if none was used. */
|
|
63
|
+
proxy_bytes: number | null;
|
|
64
|
+
created_at: string;
|
|
65
|
+
started_at: string | null;
|
|
66
|
+
finished_at: string | null;
|
|
67
|
+
/** Milliseconds the solve waited in the queue before a worker picked it up. */
|
|
68
|
+
queue_ms: number | null;
|
|
69
|
+
/** Milliseconds of actual solving. */
|
|
70
|
+
resolve_ms: number | null;
|
|
71
|
+
}
|
|
72
|
+
/** Parameters for {@link NoneCap.solves.list}. */
|
|
73
|
+
interface SolveListParams {
|
|
74
|
+
/** Page size, 1–100. Defaults to 20. */
|
|
75
|
+
limit?: number;
|
|
76
|
+
/** Return solves created after this solve id (cursor pagination). */
|
|
77
|
+
starting_after?: string;
|
|
78
|
+
/** Only solves with this status. */
|
|
79
|
+
status?: SolveStatus;
|
|
80
|
+
/** Only solves of this type. */
|
|
81
|
+
type?: SolveType;
|
|
82
|
+
}
|
|
83
|
+
/** One page of solves. */
|
|
84
|
+
interface SolveList {
|
|
85
|
+
object: "list";
|
|
86
|
+
data: Solve[];
|
|
87
|
+
has_more: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** Your account, including the current credit balance. */
|
|
90
|
+
interface Account {
|
|
91
|
+
object: "account";
|
|
92
|
+
id: string;
|
|
93
|
+
email: string;
|
|
94
|
+
credits_balance: number;
|
|
95
|
+
created_at: string;
|
|
96
|
+
}
|
|
97
|
+
/** Error codes returned in the API's error envelope. */
|
|
98
|
+
type ErrorCode = "unauthorized" | "forbidden" | "account_locked" | "insufficient_credits" | "invalid_request" | "validation_error" | "not_found" | "conflict" | "rate_limited" | "ext_daily_limit" | "concurrency_limit_exceeded" | "internal_error" | "pool_exhausted";
|
|
99
|
+
/** The Stripe-style error envelope every non-2xx response carries. */
|
|
100
|
+
interface ErrorEnvelope {
|
|
101
|
+
error: {
|
|
102
|
+
code: ErrorCode;
|
|
103
|
+
message: string;
|
|
104
|
+
param: string | null;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Is this a terminal solve status? */
|
|
109
|
+
declare function isTerminal(status: SolveStatus): boolean;
|
|
110
|
+
/** A `fetch` implementation. Defaults to the global `fetch`. */
|
|
111
|
+
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
112
|
+
/** Options for constructing a {@link NoneCap} client. */
|
|
113
|
+
interface NoneCapOptions {
|
|
114
|
+
/** Your NoneCap API key. Find it at https://dashboard.nonecap.com. */
|
|
115
|
+
apiKey: string;
|
|
116
|
+
/** Override the API base URL. Defaults to https://api.nonecap.com. */
|
|
117
|
+
baseURL?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Per-request timeout in milliseconds for a single HTTP call. Defaults to
|
|
120
|
+
* 100000 (just above the 90s server long-poll). Note this bounds one HTTP
|
|
121
|
+
* round trip, not the whole {@link NoneCap.solve} wait — use the `timeout`
|
|
122
|
+
* option on `solve()` for that.
|
|
123
|
+
*/
|
|
124
|
+
timeout?: number;
|
|
125
|
+
/** Inject a custom `fetch` (for testing, proxies, or non-standard runtimes). */
|
|
126
|
+
fetch?: FetchLike;
|
|
127
|
+
}
|
|
128
|
+
/** Per-call options for the long-polling endpoints. */
|
|
129
|
+
interface WaitOptions {
|
|
130
|
+
/**
|
|
131
|
+
* Hold the connection open up to this many seconds (1–90) waiting for the
|
|
132
|
+
* solve to finish before responding. Omit to return immediately.
|
|
133
|
+
*/
|
|
134
|
+
wait?: number;
|
|
135
|
+
/** Abort the request. */
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}
|
|
138
|
+
/** Options for {@link NoneCap.solve}. */
|
|
139
|
+
interface SolveHelperOptions {
|
|
140
|
+
/**
|
|
141
|
+
* Give up after this many milliseconds and throw {@link TimeoutError}.
|
|
142
|
+
* Defaults to 180000 (3 minutes).
|
|
143
|
+
*/
|
|
144
|
+
timeout?: number;
|
|
145
|
+
/** Abort waiting. */
|
|
146
|
+
signal?: AbortSignal;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The NoneCap API client.
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
152
|
+
* const nc = new NoneCap({ apiKey: process.env.NONECAP_KEY! });
|
|
153
|
+
* const { token } = await nc.solve({ type: "hcaptcha", sitekey, url });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare class NoneCap {
|
|
157
|
+
#private;
|
|
158
|
+
constructor(options: NoneCapOptions);
|
|
159
|
+
/** Operations on solves. */
|
|
160
|
+
readonly solves: {
|
|
161
|
+
/** Submit a solve. Pass `{ wait }` to hold the connection until it finishes. */
|
|
162
|
+
create: (params: SolveCreateParams, options?: WaitOptions) => Promise<Solve>;
|
|
163
|
+
/** Fetch a solve by id. Pass `{ wait }` to long-poll until it finishes. */
|
|
164
|
+
retrieve: (id: string, options?: WaitOptions) => Promise<Solve>;
|
|
165
|
+
/** Cancel a pending or in-flight solve. */
|
|
166
|
+
cancel: (id: string, options?: {
|
|
167
|
+
signal?: AbortSignal;
|
|
168
|
+
}) => Promise<Solve>;
|
|
169
|
+
/** Fetch one page of solves. */
|
|
170
|
+
list: (params?: SolveListParams, options?: {
|
|
171
|
+
signal?: AbortSignal;
|
|
172
|
+
}) => Promise<SolveList>;
|
|
173
|
+
/**
|
|
174
|
+
* Iterate every solve across pages, newest first.
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* for await (const solve of nc.solves.listAll()) { ... }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
listAll: (params?: SolveListParams, options?: {
|
|
181
|
+
signal?: AbortSignal;
|
|
182
|
+
}) => AsyncIterableIterator<Solve>;
|
|
183
|
+
};
|
|
184
|
+
/** Fetch your account, including the current credit balance. */
|
|
185
|
+
me(options?: {
|
|
186
|
+
signal?: AbortSignal;
|
|
187
|
+
}): Promise<Account>;
|
|
188
|
+
/**
|
|
189
|
+
* Submit a solve and wait for it to finish, returning the solved solve.
|
|
190
|
+
*
|
|
191
|
+
* Uses the server's long-poll under the hood and keeps polling until the
|
|
192
|
+
* solve is terminal or `timeout` elapses. Throws {@link SolveFailedError} if
|
|
193
|
+
* the solve fails/expires/is cancelled, or {@link TimeoutError} on timeout.
|
|
194
|
+
*/
|
|
195
|
+
solve(params: SolveCreateParams, options?: SolveHelperOptions): Promise<Solve>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Base class for every error this library throws. Catch `NoneCapError` to
|
|
200
|
+
* handle all of them, or catch a subclass to handle one kind.
|
|
201
|
+
*/
|
|
202
|
+
declare class NoneCapError extends Error {
|
|
203
|
+
/** Machine-readable error code from the API envelope, when there is one. */
|
|
204
|
+
readonly code: ErrorCode | undefined;
|
|
205
|
+
/** HTTP status, when the error came from a response. */
|
|
206
|
+
readonly status: number | undefined;
|
|
207
|
+
/** The request field that was rejected, for validation errors. */
|
|
208
|
+
readonly param: string | null;
|
|
209
|
+
constructor(message: string, opts?: {
|
|
210
|
+
code?: ErrorCode;
|
|
211
|
+
status?: number;
|
|
212
|
+
param?: string | null;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/** 401 — the API key is missing, malformed, or revoked. */
|
|
216
|
+
declare class AuthenticationError extends NoneCapError {
|
|
217
|
+
}
|
|
218
|
+
/** 403 — the key is valid but not allowed to do this (scope or locked account). */
|
|
219
|
+
declare class PermissionError extends NoneCapError {
|
|
220
|
+
}
|
|
221
|
+
/** 402 — the account is out of credits. */
|
|
222
|
+
declare class InsufficientCreditsError extends NoneCapError {
|
|
223
|
+
}
|
|
224
|
+
/** 422 / 400 — the request was rejected. `param` names the offending field. */
|
|
225
|
+
declare class ValidationError extends NoneCapError {
|
|
226
|
+
}
|
|
227
|
+
/** 404 — no such resource. */
|
|
228
|
+
declare class NotFoundError extends NoneCapError {
|
|
229
|
+
}
|
|
230
|
+
/** 409 — the solve is already in a terminal state (e.g. cancelling a finished solve). */
|
|
231
|
+
declare class ConflictError extends NoneCapError {
|
|
232
|
+
}
|
|
233
|
+
/** 429 — too many concurrent solves, or rate limited. Back off and retry. */
|
|
234
|
+
declare class RateLimitError extends NoneCapError {
|
|
235
|
+
}
|
|
236
|
+
/** 5xx, or a response that wasn't the expected shape. */
|
|
237
|
+
declare class APIError extends NoneCapError {
|
|
238
|
+
}
|
|
239
|
+
/** The request never reached the API (DNS, TCP, TLS, timeout, offline). */
|
|
240
|
+
declare class ConnectionError extends NoneCapError {
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Thrown by {@link NoneCap.solve} when a solve reaches a terminal state without
|
|
244
|
+
* a token: `failed`, `expired`, or `cancelled`. The full solve is attached so
|
|
245
|
+
* you can inspect `solve.error` and timings.
|
|
246
|
+
*/
|
|
247
|
+
declare class SolveFailedError extends NoneCapError {
|
|
248
|
+
readonly solve: Solve;
|
|
249
|
+
constructor(solve: Solve);
|
|
250
|
+
}
|
|
251
|
+
/** Thrown by {@link NoneCap.solve} when the client-side timeout elapses first. */
|
|
252
|
+
declare class TimeoutError extends NoneCapError {
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export { APIError, type Account, AuthenticationError, ConflictError, ConnectionError, type ErrorCode, type ErrorEnvelope, type FetchLike, InsufficientCreditsError, NoneCap, NoneCapError, type NoneCapOptions, NotFoundError, PermissionError, type Proxy, RateLimitError, type Solve, type SolveCreateParams, type SolveError, SolveFailedError, type SolveHelperOptions, type SolveList, type SolveListParams, type SolveStatus, type SolveType, TimeoutError, ValidationError, type WaitOptions, isTerminal };
|