@capbypass/sdk 1.0.6 → 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 +23 -3
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +14 -5
- package/dist/index.mjs +14 -5
- package/package.json +1 -1
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
|
|
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
|
-
|
|
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
|
@@ -145,6 +145,8 @@ function parseError(errorCode, errorDescription) {
|
|
|
145
145
|
case "ERROR_INVALID_TASK_DATA":
|
|
146
146
|
case "ERROR_INVALID_DEVELOPER_KEY":
|
|
147
147
|
case "ERROR_PROXY_NOT_DEFINED":
|
|
148
|
+
case "ERROR_PROXY_CONNECTION_FAILED":
|
|
149
|
+
case "ERROR_PROXY_BANNED":
|
|
148
150
|
case "ERROR_WRONG_TASK_TYPE":
|
|
149
151
|
case "ERROR_TASK_TYPE_COMING_SOON":
|
|
150
152
|
case "ERROR_TASK_TYPE_INACTIVE":
|
|
@@ -166,6 +168,11 @@ function parseError(errorCode, errorDescription) {
|
|
|
166
168
|
var DEFAULT_BASE_URL = "https://api.capbypass.pro";
|
|
167
169
|
var SDK_VERSION = "1.0.0";
|
|
168
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
|
+
}
|
|
169
176
|
var CapBypassClient = class {
|
|
170
177
|
/**
|
|
171
178
|
* Create a new CapBypass client
|
|
@@ -342,7 +349,10 @@ var CapBypassClient = class {
|
|
|
342
349
|
return response.balance;
|
|
343
350
|
}
|
|
344
351
|
/**
|
|
345
|
-
* 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, ...).
|
|
346
356
|
* @param task - Task configuration
|
|
347
357
|
* @param timeout - Maximum wait time in seconds (default: 120)
|
|
348
358
|
* @returns Solution object
|
|
@@ -350,8 +360,10 @@ var CapBypassClient = class {
|
|
|
350
360
|
async solve(task, timeout = 120) {
|
|
351
361
|
const taskId = await this.createTask(task);
|
|
352
362
|
const startTime = Date.now();
|
|
353
|
-
let
|
|
363
|
+
let poll = 0;
|
|
354
364
|
while (true) {
|
|
365
|
+
poll++;
|
|
366
|
+
await this.sleep(pollDelaySeconds(poll) * 1e3);
|
|
355
367
|
const elapsed = (Date.now() - startTime) / 1e3;
|
|
356
368
|
if (elapsed > timeout) {
|
|
357
369
|
throw new TimeoutError();
|
|
@@ -365,9 +377,6 @@ var CapBypassClient = class {
|
|
|
365
377
|
result.errorDescription || "Task failed"
|
|
366
378
|
);
|
|
367
379
|
}
|
|
368
|
-
attempt++;
|
|
369
|
-
const pollInterval = Math.min(5, Math.ceil(attempt / 2));
|
|
370
|
-
await this.sleep(pollInterval * 1e3);
|
|
371
380
|
}
|
|
372
381
|
}
|
|
373
382
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -95,6 +95,8 @@ function parseError(errorCode, errorDescription) {
|
|
|
95
95
|
case "ERROR_INVALID_TASK_DATA":
|
|
96
96
|
case "ERROR_INVALID_DEVELOPER_KEY":
|
|
97
97
|
case "ERROR_PROXY_NOT_DEFINED":
|
|
98
|
+
case "ERROR_PROXY_CONNECTION_FAILED":
|
|
99
|
+
case "ERROR_PROXY_BANNED":
|
|
98
100
|
case "ERROR_WRONG_TASK_TYPE":
|
|
99
101
|
case "ERROR_TASK_TYPE_COMING_SOON":
|
|
100
102
|
case "ERROR_TASK_TYPE_INACTIVE":
|
|
@@ -116,6 +118,11 @@ function parseError(errorCode, errorDescription) {
|
|
|
116
118
|
var DEFAULT_BASE_URL = "https://api.capbypass.pro";
|
|
117
119
|
var SDK_VERSION = "1.0.0";
|
|
118
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
|
+
}
|
|
119
126
|
var CapBypassClient = class {
|
|
120
127
|
/**
|
|
121
128
|
* Create a new CapBypass client
|
|
@@ -292,7 +299,10 @@ var CapBypassClient = class {
|
|
|
292
299
|
return response.balance;
|
|
293
300
|
}
|
|
294
301
|
/**
|
|
295
|
-
* 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, ...).
|
|
296
306
|
* @param task - Task configuration
|
|
297
307
|
* @param timeout - Maximum wait time in seconds (default: 120)
|
|
298
308
|
* @returns Solution object
|
|
@@ -300,8 +310,10 @@ var CapBypassClient = class {
|
|
|
300
310
|
async solve(task, timeout = 120) {
|
|
301
311
|
const taskId = await this.createTask(task);
|
|
302
312
|
const startTime = Date.now();
|
|
303
|
-
let
|
|
313
|
+
let poll = 0;
|
|
304
314
|
while (true) {
|
|
315
|
+
poll++;
|
|
316
|
+
await this.sleep(pollDelaySeconds(poll) * 1e3);
|
|
305
317
|
const elapsed = (Date.now() - startTime) / 1e3;
|
|
306
318
|
if (elapsed > timeout) {
|
|
307
319
|
throw new TimeoutError();
|
|
@@ -315,9 +327,6 @@ var CapBypassClient = class {
|
|
|
315
327
|
result.errorDescription || "Task failed"
|
|
316
328
|
);
|
|
317
329
|
}
|
|
318
|
-
attempt++;
|
|
319
|
-
const pollInterval = Math.min(5, Math.ceil(attempt / 2));
|
|
320
|
-
await this.sleep(pollInterval * 1e3);
|
|
321
330
|
}
|
|
322
331
|
}
|
|
323
332
|
};
|