@capbypass/sdk 1.0.7 → 1.0.8

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
@@ -106,7 +106,10 @@ declare class CapBypassClient {
106
106
  */
107
107
  getBalance(): Promise<number>;
108
108
  /**
109
- * Create a task and poll until solved or timeout
109
+ * Create a task and poll until solved or timeout.
110
+ *
111
+ * The first poll happens 1 s after the task is created, then every 1 s for
112
+ * the first three polls, growing to 3 s (waits: 1, 1, 1, 2, 2, 3, 3, ...).
110
113
  * @param task - Task configuration
111
114
  * @param timeout - Maximum wait time in seconds (default: 120)
112
115
  * @returns Solution object
package/dist/index.d.ts CHANGED
@@ -106,7 +106,10 @@ declare class CapBypassClient {
106
106
  */
107
107
  getBalance(): Promise<number>;
108
108
  /**
109
- * Create a task and poll until solved or timeout
109
+ * Create a task and poll until solved or timeout.
110
+ *
111
+ * The first poll happens 1 s after the task is created, then every 1 s for
112
+ * the first three polls, growing to 3 s (waits: 1, 1, 1, 2, 2, 3, 3, ...).
110
113
  * @param task - Task configuration
111
114
  * @param timeout - Maximum wait time in seconds (default: 120)
112
115
  * @returns Solution object
package/dist/index.js CHANGED
@@ -168,6 +168,11 @@ function parseError(errorCode, errorDescription) {
168
168
  var DEFAULT_BASE_URL = "https://api.capbypass.pro";
169
169
  var SDK_VERSION = "1.0.0";
170
170
  var USER_AGENT = `capbypass-sdk-typescript/${SDK_VERSION}`;
171
+ var POLL_DELAYS_SECONDS = [1, 1, 1, 2, 2];
172
+ var MAX_POLL_DELAY_SECONDS = 3;
173
+ function pollDelaySeconds(poll) {
174
+ return POLL_DELAYS_SECONDS[poll - 1] ?? MAX_POLL_DELAY_SECONDS;
175
+ }
171
176
  var CapBypassClient = class {
172
177
  /**
173
178
  * Create a new CapBypass client
@@ -344,7 +349,10 @@ var CapBypassClient = class {
344
349
  return response.balance;
345
350
  }
346
351
  /**
347
- * Create a task and poll until solved or timeout
352
+ * Create a task and poll until solved or timeout.
353
+ *
354
+ * The first poll happens 1 s after the task is created, then every 1 s for
355
+ * the first three polls, growing to 3 s (waits: 1, 1, 1, 2, 2, 3, 3, ...).
348
356
  * @param task - Task configuration
349
357
  * @param timeout - Maximum wait time in seconds (default: 120)
350
358
  * @returns Solution object
@@ -352,8 +360,10 @@ var CapBypassClient = class {
352
360
  async solve(task, timeout = 120) {
353
361
  const taskId = await this.createTask(task);
354
362
  const startTime = Date.now();
355
- let attempt = 0;
363
+ let poll = 0;
356
364
  while (true) {
365
+ poll++;
366
+ await this.sleep(pollDelaySeconds(poll) * 1e3);
357
367
  const elapsed = (Date.now() - startTime) / 1e3;
358
368
  if (elapsed > timeout) {
359
369
  throw new TimeoutError();
@@ -367,9 +377,6 @@ var CapBypassClient = class {
367
377
  result.errorDescription || "Task failed"
368
378
  );
369
379
  }
370
- attempt++;
371
- const pollInterval = Math.min(5, Math.ceil(attempt / 2));
372
- await this.sleep(pollInterval * 1e3);
373
380
  }
374
381
  }
375
382
  };
package/dist/index.mjs CHANGED
@@ -118,6 +118,11 @@ function parseError(errorCode, errorDescription) {
118
118
  var DEFAULT_BASE_URL = "https://api.capbypass.pro";
119
119
  var SDK_VERSION = "1.0.0";
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capbypass/sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Official TypeScript/JavaScript SDK for CapBypass CAPTCHA solving service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",