@capbypass/sdk 1.0.7 → 1.0.9

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 CHANGED
@@ -11,7 +11,7 @@ Works in both Node.js and browser environments.
11
11
  ## Features
12
12
 
13
13
  - ✅ **Simple API**: One-line `solve()` method or advanced `createTask()`/`getTaskResult()` control
14
- - 🔄 **Automatic Polling**: Built-in adaptive polling with exponential backoff
14
+ - 🔄 **Automatic Polling**: Built-in adaptive polling (first poll after 1 s, then every 1-3 s)
15
15
  - 🛡️ **Robust Error Handling**: Typed errors for all API and network failures
16
16
  - 🔁 **Smart Retry Logic**: Automatic retry on network/gateway errors
17
17
  - 🎯 **Full TypeScript Support**: Complete type definitions for excellent IDE support
@@ -105,6 +105,8 @@ const solution = await client.solve(task, timeout);
105
105
  - `timeout`: Maximum wait time in seconds (default: 120)
106
106
  - Returns: Promise<Solution>
107
107
 
108
+ `solve()` waits 1 s after creating the task before its first `getTaskResult` request, then waits 1, 1, 2 and 2 s between the next requests, and 3 s between requests from then on. These are waits between requests: the time a request itself takes comes on top. `timeout` is counted from the end of `createTask` and is not changed by the waiting schedule.
109
+
108
110
  ### Advanced API
109
111
 
110
112
  For full control over task lifecycle:
@@ -113,8 +115,26 @@ For full control over task lifecycle:
113
115
  // Create task
114
116
  const taskId = await client.createTask(task);
115
117
 
116
- // Poll for result
117
- const result = await client.getTaskResult(taskId);
118
+ // Poll for result. getTaskResult does not wait by itself: wait 1 s after
119
+ // createTask, then 1 to 3 s between calls (not faster), until the task is
120
+ // ready or failed, and give up after your own deadline.
121
+ const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
122
+ const deadline = Date.now() + 120_000;
123
+ await sleep(1000);
124
+ while (true) {
125
+ const result = await client.getTaskResult(taskId);
126
+ if (result.status === 'ready') {
127
+ console.log(result.solution);
128
+ break;
129
+ }
130
+ if (result.status === 'failed') {
131
+ throw new Error(result.errorDescription || 'Task failed');
132
+ }
133
+ if (Date.now() > deadline) {
134
+ throw new Error('Task not ready in time');
135
+ }
136
+ await sleep(2000);
137
+ }
118
138
 
119
139
  // Check balance
120
140
  const balance = await client.getBalance();
package/dist/index.d.mts CHANGED
@@ -62,6 +62,7 @@ interface ClientOptions {
62
62
  developerKey?: string;
63
63
  }
64
64
 
65
+ declare const SDK_VERSION: string;
65
66
  /**
66
67
  * CapBypass API Client
67
68
  */
@@ -106,7 +107,10 @@ declare class CapBypassClient {
106
107
  */
107
108
  getBalance(): Promise<number>;
108
109
  /**
109
- * Create a task and poll until solved or timeout
110
+ * Create a task and poll until solved or timeout.
111
+ *
112
+ * The first poll happens 1 s after the task is created, then every 1 s for
113
+ * the first three polls, growing to 3 s (waits: 1, 1, 1, 2, 2, 3, 3, ...).
110
114
  * @param task - Task configuration
111
115
  * @param timeout - Maximum wait time in seconds (default: 120)
112
116
  * @returns Solution object
@@ -206,4 +210,4 @@ declare class ParseError extends Error {
206
210
  constructor(message: string, cause?: Error | undefined);
207
211
  }
208
212
 
209
- export { AuthenticationError, type BaseTask, CapBypassClient, CapBypassError, type ClientOptions, GatewayError, InsufficientBalanceError, InternalError, NetworkError, ParseError, type PricingItem, type ProxyConfig, RateLimitError, ServerError, SolverError, TaskNotFoundError, type TaskResult, TaskType, type TaskTypeValue, TimeoutError, ValidationError };
213
+ export { AuthenticationError, type BaseTask, CapBypassClient, CapBypassError, type ClientOptions, GatewayError, InsufficientBalanceError, InternalError, NetworkError, ParseError, type PricingItem, type ProxyConfig, RateLimitError, SDK_VERSION, ServerError, SolverError, TaskNotFoundError, type TaskResult, TaskType, type TaskTypeValue, TimeoutError, ValidationError };
package/dist/index.d.ts CHANGED
@@ -62,6 +62,7 @@ interface ClientOptions {
62
62
  developerKey?: string;
63
63
  }
64
64
 
65
+ declare const SDK_VERSION: string;
65
66
  /**
66
67
  * CapBypass API Client
67
68
  */
@@ -106,7 +107,10 @@ declare class CapBypassClient {
106
107
  */
107
108
  getBalance(): Promise<number>;
108
109
  /**
109
- * Create a task and poll until solved or timeout
110
+ * Create a task and poll until solved or timeout.
111
+ *
112
+ * The first poll happens 1 s after the task is created, then every 1 s for
113
+ * the first three polls, growing to 3 s (waits: 1, 1, 1, 2, 2, 3, 3, ...).
110
114
  * @param task - Task configuration
111
115
  * @param timeout - Maximum wait time in seconds (default: 120)
112
116
  * @returns Solution object
@@ -206,4 +210,4 @@ declare class ParseError extends Error {
206
210
  constructor(message: string, cause?: Error | undefined);
207
211
  }
208
212
 
209
- export { AuthenticationError, type BaseTask, CapBypassClient, CapBypassError, type ClientOptions, GatewayError, InsufficientBalanceError, InternalError, NetworkError, ParseError, type PricingItem, type ProxyConfig, RateLimitError, ServerError, SolverError, TaskNotFoundError, type TaskResult, TaskType, type TaskTypeValue, TimeoutError, ValidationError };
213
+ export { AuthenticationError, type BaseTask, CapBypassClient, CapBypassError, type ClientOptions, GatewayError, InsufficientBalanceError, InternalError, NetworkError, ParseError, type PricingItem, type ProxyConfig, RateLimitError, SDK_VERSION, ServerError, SolverError, TaskNotFoundError, type TaskResult, TaskType, type TaskTypeValue, TimeoutError, ValidationError };
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  NetworkError: () => NetworkError,
40
40
  ParseError: () => ParseError,
41
41
  RateLimitError: () => RateLimitError,
42
+ SDK_VERSION: () => SDK_VERSION,
42
43
  ServerError: () => ServerError,
43
44
  SolverError: () => SolverError,
44
45
  TaskNotFoundError: () => TaskNotFoundError,
@@ -166,8 +167,13 @@ function parseError(errorCode, errorDescription) {
166
167
 
167
168
  // src/client.ts
168
169
  var DEFAULT_BASE_URL = "https://api.capbypass.pro";
169
- var SDK_VERSION = "1.0.0";
170
+ var SDK_VERSION = true ? "1.0.9" : "unknown";
170
171
  var USER_AGENT = `capbypass-sdk-typescript/${SDK_VERSION}`;
172
+ var POLL_DELAYS_SECONDS = [1, 1, 1, 2, 2];
173
+ var MAX_POLL_DELAY_SECONDS = 3;
174
+ function pollDelaySeconds(poll) {
175
+ return POLL_DELAYS_SECONDS[poll - 1] ?? MAX_POLL_DELAY_SECONDS;
176
+ }
171
177
  var CapBypassClient = class {
172
178
  /**
173
179
  * Create a new CapBypass client
@@ -344,7 +350,10 @@ var CapBypassClient = class {
344
350
  return response.balance;
345
351
  }
346
352
  /**
347
- * Create a task and poll until solved or timeout
353
+ * Create a task and poll until solved or timeout.
354
+ *
355
+ * The first poll happens 1 s after the task is created, then every 1 s for
356
+ * the first three polls, growing to 3 s (waits: 1, 1, 1, 2, 2, 3, 3, ...).
348
357
  * @param task - Task configuration
349
358
  * @param timeout - Maximum wait time in seconds (default: 120)
350
359
  * @returns Solution object
@@ -352,8 +361,10 @@ var CapBypassClient = class {
352
361
  async solve(task, timeout = 120) {
353
362
  const taskId = await this.createTask(task);
354
363
  const startTime = Date.now();
355
- let attempt = 0;
364
+ let poll = 0;
356
365
  while (true) {
366
+ poll++;
367
+ await this.sleep(pollDelaySeconds(poll) * 1e3);
357
368
  const elapsed = (Date.now() - startTime) / 1e3;
358
369
  if (elapsed > timeout) {
359
370
  throw new TimeoutError();
@@ -367,9 +378,6 @@ var CapBypassClient = class {
367
378
  result.errorDescription || "Task failed"
368
379
  );
369
380
  }
370
- attempt++;
371
- const pollInterval = Math.min(5, Math.ceil(attempt / 2));
372
- await this.sleep(pollInterval * 1e3);
373
381
  }
374
382
  }
375
383
  };
@@ -409,6 +417,7 @@ var TaskType = {
409
417
  NetworkError,
410
418
  ParseError,
411
419
  RateLimitError,
420
+ SDK_VERSION,
412
421
  ServerError,
413
422
  SolverError,
414
423
  TaskNotFoundError,
package/dist/index.mjs CHANGED
@@ -116,8 +116,13 @@ function parseError(errorCode, errorDescription) {
116
116
 
117
117
  // src/client.ts
118
118
  var DEFAULT_BASE_URL = "https://api.capbypass.pro";
119
- var SDK_VERSION = "1.0.0";
119
+ var SDK_VERSION = true ? "1.0.9" : "unknown";
120
120
  var USER_AGENT = `capbypass-sdk-typescript/${SDK_VERSION}`;
121
+ var POLL_DELAYS_SECONDS = [1, 1, 1, 2, 2];
122
+ var MAX_POLL_DELAY_SECONDS = 3;
123
+ function pollDelaySeconds(poll) {
124
+ return POLL_DELAYS_SECONDS[poll - 1] ?? MAX_POLL_DELAY_SECONDS;
125
+ }
121
126
  var CapBypassClient = class {
122
127
  /**
123
128
  * Create a new CapBypass client
@@ -294,7 +299,10 @@ var CapBypassClient = class {
294
299
  return response.balance;
295
300
  }
296
301
  /**
297
- * Create a task and poll until solved or timeout
302
+ * Create a task and poll until solved or timeout.
303
+ *
304
+ * The first poll happens 1 s after the task is created, then every 1 s for
305
+ * the first three polls, growing to 3 s (waits: 1, 1, 1, 2, 2, 3, 3, ...).
298
306
  * @param task - Task configuration
299
307
  * @param timeout - Maximum wait time in seconds (default: 120)
300
308
  * @returns Solution object
@@ -302,8 +310,10 @@ var CapBypassClient = class {
302
310
  async solve(task, timeout = 120) {
303
311
  const taskId = await this.createTask(task);
304
312
  const startTime = Date.now();
305
- let attempt = 0;
313
+ let poll = 0;
306
314
  while (true) {
315
+ poll++;
316
+ await this.sleep(pollDelaySeconds(poll) * 1e3);
307
317
  const elapsed = (Date.now() - startTime) / 1e3;
308
318
  if (elapsed > timeout) {
309
319
  throw new TimeoutError();
@@ -317,9 +327,6 @@ var CapBypassClient = class {
317
327
  result.errorDescription || "Task failed"
318
328
  );
319
329
  }
320
- attempt++;
321
- const pollInterval = Math.min(5, Math.ceil(attempt / 2));
322
- await this.sleep(pollInterval * 1e3);
323
330
  }
324
331
  }
325
332
  };
@@ -358,6 +365,7 @@ export {
358
365
  NetworkError,
359
366
  ParseError,
360
367
  RateLimitError,
368
+ SDK_VERSION,
361
369
  ServerError,
362
370
  SolverError,
363
371
  TaskNotFoundError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capbypass/sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Official TypeScript/JavaScript SDK for CapBypass CAPTCHA solving service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -16,7 +16,7 @@
16
16
  "dist"
17
17
  ],
18
18
  "scripts": {
19
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
19
+ "build": "tsup",
20
20
  "test": "jest",
21
21
  "test:watch": "jest --watch",
22
22
  "test:coverage": "jest --coverage",