Skip to content

Commit fe4c084

Browse files
authored
Merge pull request #32 from kir58/task/CCL-7162
CCL-7162 added new Captchas and fixed olds
2 parents 2364e72 + 0c445dd commit fe4c084

25 files changed

Lines changed: 314 additions & 65 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function run() {
2222
websiteKey: '6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd',
2323
});
2424

25-
console.log(await cmcClient.Solve(recaptchaV2ProxylessRequest));
25+
console.log(await cmcClient.Solve(recaptchaV2Request));
2626
}
2727

2828
run()
@@ -87,9 +87,11 @@ DEBUG=cmc-* node app.js
8787
- [ProsopoRequest](https://zenno.link/doc-prosopo-en)
8888
- [RecaptchaComplexImageTaskRequest](https://zenno.link/doc-complextask-rc-en)
8989
- [RecaptchaV2EnterpriseRequest](https://zenno.link/doc-recaptcha2e-proxy-en)
90+
- [RecaptchaV3EnterpriseRequest](https://zenno.link/doc-recaptcha3e-proxy-en)
9091
- [RecaptchaV2Request](https://zenno.link/doc-recaptcha2-proxy-en)
9192
- [RecaptchaV3ProxylessRequest](https://zenno.link/doc-recaptcha3-en)
9293
- [Temu](https://zenno.link/doc-temu-en)
9394
- [TenDIRequest](https://zenno.link/doc-tendi-en)
9495
- [TurnstileRequest](https://zenno.link/doc-turnstile-proxy-en)
9596
- [Yidun](https://zenno.link/doc-yidun-en)
97+
- [Altcha](https://zenno.link/doc-altcha-en)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zennolab_com/capmonstercloud-client",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "Official JS client library for https://capmonster.cloud/ captcha recognition service",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/CapMonsterCloudClient.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ import { YidunRequest } from './Requests/YidunRequest';
5353
import { YidunResponse } from './Responses/YidunResponse';
5454
import { MTCaptchaRequest } from './Requests/MTCaptchaRequest';
5555
import { MTCaptchaResponse } from './Responses/MTCaptchaResponse';
56+
import { AltchaRequest } from './Requests/AltchaRequest';
57+
import { AltchaResponse } from './Responses/AltchaResponse';
58+
import { RecaptchaV3EnterpriseRequest } from './Requests/RecaptchaV3EnterpriseRequest';
59+
import { RecaptchaV3EnterpriseResponse } from './Responses/RecaptchaV3EnterpriseResponse';
5660

5761
type CustomTaskUnion = TemuRequest | BasiliskRequest | ImpervaRequest;
5862

@@ -214,6 +218,15 @@ export class CapMonsterCloudClient {
214218
resultTimeouts?: GetResultTimeouts,
215219
cancellationController?: AbortController,
216220
): Promise<CaptchaResult<RecaptchaV2EnterpriseResponse>>;
221+
/**
222+
* Solve RecaptchaV3EnterpriseTask task
223+
* You will get response within 10 - 180 secs period depending on service workload.
224+
*/
225+
public async Solve(
226+
task: RecaptchaV3EnterpriseRequest,
227+
resultTimeouts?: GetResultTimeouts,
228+
cancellationController?: AbortController,
229+
): Promise<CaptchaResult<RecaptchaV3EnterpriseResponse>>;
217230
/**
218231
* Solve NoCaptchaTask task
219232
* You will get response within 10 - 180 secs period depending on service workload.
@@ -241,6 +254,15 @@ export class CapMonsterCloudClient {
241254
resultTimeouts?: GetResultTimeouts,
242255
cancellationController?: AbortController,
243256
): Promise<CaptchaResult<DataDomeResponse>>;
257+
/**
258+
* Solve AltchaRequest task
259+
* You will get response within 10 - 180 secs period depending on service workload.
260+
*/
261+
public async Solve(
262+
task: AltchaRequest,
263+
resultTimeouts?: GetResultTimeouts,
264+
cancellationController?: AbortController,
265+
): Promise<CaptchaResult<AltchaResponse>>;
244266
/**
245267
* Solve TenDI task
246268
* You will get response within 10 - 180 secs period depending on service workload.

src/CapMonsterCloudClientFactory.i.spec.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -731,44 +731,7 @@ describe('Check integration tests for CapMonsterCloudClientFactory()', () => {
731731

732732
expect(await srv.destroy()).toBeUndefined();
733733
});
734-
it('should solve Imperva Task', async () => {
735-
expect.assertions(5);
736-
737-
const srv = await createServerMock({
738-
responses: [
739-
{ responseBody: '{"errorId":0,"taskId":1234567}' },
740-
{
741-
responseBody:
742-
'{"errorId":0,"status":"ready","solution":{"domains": { "site.com" : { "cookies": { "___utmvc": "NMB", "reese84": "reese84"}} } }}',
743-
},
744-
],
745-
});
746734

747-
const cmcClient = CapMonsterCloudClientFactory.Create(
748-
new ClientOptions({ clientKey: '<your capmonster.cloud API key>', serviceUrl: `http://localhost:${srv.address.port}` }),
749-
);
750-
751-
const impervaRequest = new ImpervaRequest({
752-
websiteURL: 'https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=middle',
753-
metadata: {
754-
incapsulaScriptBase64: 'dmFyIF8weGQ2ZmU9Wydce..eDUzXHg2YV',
755-
incapsulaSessionCookie: 'l/LsGnrvyB9lNhXI8borDKa2IGc',
756-
},
757-
});
758-
759-
const task = await cmcClient.Solve(impervaRequest);
760-
761-
expect(srv.caughtRequests[0]).toHaveProperty(
762-
'body',
763-
'{"clientKey":"<your capmonster.cloud API key>","task":{"type":"CustomTask","websiteURL":"https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=middle","metadata":{"incapsulaScriptBase64":"dmFyIF8weGQ2ZmU9Wydce..eDUzXHg2YV","incapsulaSessionCookie":"l/LsGnrvyB9lNhXI8borDKa2IGc"},"class":"Imperva"},"softId":54}',
764-
);
765-
expect(srv.caughtRequests[1]).toHaveProperty('body', '{"clientKey":"<your capmonster.cloud API key>","taskId":1234567}');
766-
expect(task).toHaveProperty('solution');
767-
768-
expect(task).toHaveProperty('solution.domains', { 'site.com': { cookies: { ___utmvc: 'NMB', reese84: 'reese84' } } });
769-
770-
expect(await srv.destroy()).toBeUndefined();
771-
});
772735
it('should solve Imperva Task with Proxy', async () => {
773736
expect.assertions(5);
774737

src/GetTaskResult.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { BasiliskResponse } from './Responses/BasiliskResponse';
1414
import { ImpervaResponse } from './Responses/ImpervaResponse';
1515
import { BinanceResponse } from './Responses/BinanceResponse';
1616
import { ComplexImageRecognitionResponse } from './Responses/ComplexImageRecognitionResponse';
17+
import { AltchaResponse } from './Responses/AltchaResponse';
1718

1819
export enum TaskResultType {
1920
Failed = 'Failed',
@@ -45,7 +46,8 @@ export type TaskCompletedSolution =
4546
| BasiliskResponse
4647
| ImpervaResponse
4748
| BinanceResponse
48-
| ComplexImageRecognitionResponse;
49+
| ComplexImageRecognitionResponse
50+
| AltchaResponse;
4951

5052
export type TaskCompleted<S extends TaskCompletedSolution> = {
5153
type: TaskResultType.Completed;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { TaskType } from '../../TaskType';
2+
import { AltchaRequestBase, AltchaRequestBaseIn } from './AltchaRequestBase';
3+
import { ProxyInfo, ProxyInfoIn } from '../ProxyInfo';
4+
5+
export type AltchaRequestIn = Pick<AltchaRequestBaseIn, Exclude<keyof AltchaRequestBaseIn, 'type' | '_class'>> & {
6+
proxy?: ProxyInfoIn;
7+
};
8+
/**
9+
* Altcha recognition request.
10+
* {@link https://zenno.link/doc-altcha}
11+
*/
12+
export class AltchaRequest extends AltchaRequestBase {
13+
constructor({ proxy, ...argsObj }: AltchaRequestIn) {
14+
super({ type: TaskType.CustomTask, _class: 'altcha', ...argsObj });
15+
16+
if (proxy) {
17+
Object.assign(this, new ProxyInfo(proxy));
18+
}
19+
}
20+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { CaptchaRequestBase, CaptchaRequestBaseIn } from '../CaptchaRequestBase';
2+
3+
export type AltchaRequestBaseIn = {
4+
websiteURL: string;
5+
userAgent?: string;
6+
_class: string;
7+
metadata: Metadata;
8+
} & CaptchaRequestBaseIn;
9+
10+
export type Metadata = {
11+
challenge: string;
12+
iterations: string;
13+
salt: string;
14+
signature: string;
15+
};
16+
17+
/**
18+
* Base Altcha recognition request
19+
*/
20+
export abstract class AltchaRequestBase extends CaptchaRequestBase {
21+
/**
22+
* Address of a webpage with DataDome.
23+
*/
24+
public websiteURL!: string;
25+
26+
/**
27+
* Altcha website key.
28+
*/
29+
public websiteKey!: string;
30+
31+
/**
32+
* The object that contains additional data about the captcha - challenge, iterations, salt, signature
33+
*/
34+
public metadata!: Metadata;
35+
36+
/**
37+
* Browser User-Agent. Pass only the actual UA from Windows OS
38+
*/
39+
public userAgent?: string;
40+
41+
/**
42+
* Class of captcha object
43+
*/
44+
public class: string;
45+
46+
constructor({ type, nocache, websiteURL, userAgent, metadata, _class }: AltchaRequestBaseIn) {
47+
super({ type, nocache });
48+
this.websiteURL = websiteURL;
49+
this.metadata = metadata;
50+
this.userAgent = userAgent;
51+
this.class = _class;
52+
}
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './AltchaRequest';

src/Requests/DataDomeRequest/DataDomeRequestBase.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ export type DataDomeRequestBaseIn = {
88
} & CaptchaRequestBaseIn;
99

1010
export type MetadataWithHtml = {
11-
[key: string]: string;
11+
[key: string]: string | undefined;
1212
htmlPageBase64: string;
1313
datadomeCookie: string;
14+
datadomeVersion?: string;
1415
};
1516

1617
export type MetadataCaptchaUrl = {
17-
[key: string]: string;
18+
[key: string]: string | undefined;
1819
captchaUrl: string;
1920
datadomeCookie: string;
21+
datadomeVersion?: string;
2022
};
2123

2224
/**
@@ -38,7 +40,7 @@ export abstract class DataDomeRequestBase extends CaptchaRequestBase {
3840
* You can take the link from the page with the captcha.
3941
* Often it looks like https://geo.captcha-delivery.com/captcha/?initialCid=...
4042
*/
41-
public metadata!: Record<string, string>;
43+
public metadata!: Record<string, string | undefined>;
4244

4345
/**
4446
* Browser User-Agent. Pass only the actual UA from Windows OS

src/Requests/ImpervaRequest/ImpervaRequest.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ import { TaskType } from '../../TaskType';
22
import { ImpervaRequestBase, ImpervaRequestBaseIn } from './ImpervaRequestBase';
33
import { ProxyInfo, ProxyInfoIn } from '../ProxyInfo';
44

5-
export type ImpervaRequestIn = Pick<ImpervaRequestBaseIn, Exclude<keyof ImpervaRequestBaseIn, 'type' | '_class'>> & { proxy?: ProxyInfoIn };
5+
export type ImpervaRequestIn = Pick<ImpervaRequestBaseIn, Exclude<keyof ImpervaRequestBaseIn, 'type' | '_class'>> & { proxy: ProxyInfoIn };
66
/**
77
* Imperva recognition request.
88
* {@link https://zenno.link/doc-imperva-en}
99
*/
1010
export class ImpervaRequest extends ImpervaRequestBase {
1111
constructor({ proxy, ...argsObj }: ImpervaRequestIn) {
1212
super({ type: TaskType.CustomTask, _class: 'Imperva', ...argsObj });
13-
14-
if (proxy) {
15-
Object.assign(this, new ProxyInfo(proxy));
16-
}
13+
Object.assign(this, new ProxyInfo(proxy));
1714
}
1815
}

0 commit comments

Comments
 (0)