Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules
dist
coverage
*.log

# TypeScript
*.d.ts

# IDE
.vscode
.idea

# OS
.DS_Store
13 changes: 7 additions & 6 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 16.x
- name: yarn install
run: yarn install
node-version: 22.x
cache: npm
- name: npm ci
run: npm ci
- name: tsc
uses: icrawl/action-tsc@v1
- run: npm run build
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 22.x
registry-url: 'https://registry.npmjs.org'
- name: yarn install
run: yarn install
cache: npm
- name: npm ci
run: npm ci
- name: tsc
uses: icrawl/action-tsc@v1
- run: npm run build
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
node_modules/

.idea
.idea
.vscode
118 changes: 98 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,68 @@
# Zennolab CapMonsterCloud JS Client

> [!IMPORTANT]
> This repository has been moved and is no longer maintained.
>
> New repository: [https://github.com/CapMonsterCloud/client-js](https://github.com/CapMonsterCloud/client-js)
>
> Please update your references and use the new repository for all future development.


Official JS client library for [capmonster.cloud](https://capmonster.cloud/) captcha recognition service

## Installation

Via [NPM](https://www.npmjs.com/package/@zennolab_com/capmonstercloud-client):

npm i @zennolab_com/capmonstercloud-client
```bash
npm i @zennolab_com/capmonstercloud-client
```

## Quick Start

1. Get your API key in the [CapMonster Cloud dashboard](https://capmonster.cloud/).
2. Install the package (see above).
3. Copy a snippet below, replace `YOUR_API_KEY`, and run it.

### reCAPTCHA v2

```ts
import {
CapMonsterCloudClientFactory,
ClientOptions,
RecaptchaV2Request,
} from '@zennolab_com/capmonstercloud-client';

const client = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: 'YOUR_API_KEY' }),
);

const result = await client.Solve(
new RecaptchaV2Request({
websiteURL: 'https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high',
websiteKey: '6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd',
}),
);

console.log(result.solution); // { gRecaptchaResponse: '...' }
```

### Cloudflare Turnstile

```ts
import {
CapMonsterCloudClientFactory,
ClientOptions,
TurnstileRequest,
} from '@zennolab_com/capmonstercloud-client';

const client = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: 'YOUR_API_KEY' }),
);

const result = await client.Solve(
new TurnstileRequest({
websiteURL: 'https://tsinvisble.zlsupport.com',
websiteKey: '0x4AAAAAAABUY0VLtOUMAHxE',
}),
);

console.log(result.solution); // { token: '...' }
```

For CommonJS (`require`), see the Node usage section below.

## Usage with Node (with or without Typescript)

Expand Down Expand Up @@ -44,6 +92,30 @@ run()
});
```

## Usage with CommonCaptcha

Use `CommonCaptcha` when you want to pass a full task payload directly, for example when a new captcha type is not yet covered by a dedicated request class.

```javascript
const { CapMonsterCloudClientFactory, ClientOptions, CommonCaptcha } = require('@zennolab_com/capmonstercloud-client');

async function run() {
const cmcClient = CapMonsterCloudClientFactory.Create(new ClientOptions({ clientKey: '<your capmonster.cloud API key>' }));

const commonCaptcha = new CommonCaptcha({
task: {
type: 'RecaptchaV2Task',
websiteURL: 'https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high',
websiteKey: '6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd',
},
});

console.log(await cmcClient.Solve(commonCaptcha));
}

run();
```

## Usage with Browser (with or without Typescript)

Browser implementation use [fetch](https://caniuse.com/fetch) instead of [http(s)](https://nodejs.org/api/http.html).
Expand Down Expand Up @@ -83,26 +155,32 @@ DEBUG=cmc-* node app.js

## Supported captcha recognition requests:

- [AlibabaRequest](https://docs.capmonster.cloud/docs/captchas/alibaba-task/)
- [AltchaRequest](https://zenno.link/doc-altcha-en)
- [AmazonRequest](https://zenno.link/doc-amazon-en)
- [BasiliskRequest](https://zenno.link/doc-basilisk-en)
- [BinanceRequest](https://zenno.link/doc-binance-en)
- [CastleRequest](https://zenno.link/castle-en)
- [ComplexImageFunCaptchaRequest](https://zenno.link/doc-complextask-rc-en)
- [ComplexImageHCaptchaRequest](https://zenno.link/doc-complextask-hc-en)
- [ComplexImageRecaptchaRequest](https://zenno.link/doc-complextask-rc-en)
- [ComplexImageTaskRecognitionRequest](https://zenno.link/doc-complex-image-recognition)
- [DataDomeRequest](https://zenno.link/doc-datadome-en)
- [FriendlyRequest](https://docs.capmonster.cloud/docs/captchas/friendly-task/)
- [FunCaptchaRequest](https://docs.capmonster.cloud/docs/captchas/funcaptcha-task/)
- [GeeTestRequest](https://zenno.link/doc-geetest-proxy-en)
- [HcaptchaComplexImageTaskRequest](https://zenno.link/doc-complextask-hc-en)
- [HCaptchaRequest](https://docs.capmonster.cloud/docs/captchas/)
- [HuntRequest](https://zenno.link/hunt-en)
- [ImageToTextRequest](https://zenno.link/doc-ImageToTextTask-en)
- [ImpervaRequest](https://zenno.link/doc-imperva-en)
- [MTCaptcha](https://zenno.link/doc-mt-captcha-en)
- [ImpervaRequest](https://docs.capmonster.cloud/docs/captchas/incapsula/)
- [MTCaptchaRequest](https://zenno.link/doc-mt-captcha-en)
- [ProsopoRequest](https://zenno.link/doc-prosopo-en)
- [RecaptchaComplexImageTaskRequest](https://zenno.link/doc-complextask-rc-en)
- [RecaptchaV2EnterpriseRequest](https://zenno.link/doc-recaptcha2e-proxy-en)
- [RecaptchaV3EnterpriseRequest](https://zenno.link/doc-recaptcha3e-proxy-en)
- [RecaptchaV2Request](https://zenno.link/doc-recaptcha2-proxy-en)
- [RecaptchaV3EnterpriseRequest](https://zenno.link/doc-recaptcha3e-proxy-en)
- [RecaptchaV3ProxylessRequest](https://zenno.link/doc-recaptcha3-en)
- [Temu](https://zenno.link/doc-temu-en)
- [TemuRequest](https://zenno.link/doc-temu-en)
- [TenDIRequest](https://zenno.link/doc-tendi-en)
- [TSPDRequest](https://zenno.link/tspd-en)
- [TurnstileRequest](https://zenno.link/doc-turnstile-proxy-en)
- [Yidun](https://zenno.link/doc-yidun-en)
- [Altcha](https://zenno.link/doc-altcha-en)
- [Castle](https://zenno.link/castle-en)
- [TSPD](https://zenno.link/tspd-en)
- [Hunt](https://zenno.link/hunt-en)
- [YidunRequest](https://zenno.link/doc-yidun-en)
43 changes: 43 additions & 0 deletions js-fix-esm-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint @typescript-eslint/no-var-requires: 0 */
const fs = require('fs');
const path = require('path');

const esmDir = path.join(__dirname, 'dist', 'esm');

function walk(dir) {
return fs.readdirSync(dir).flatMap((entry) => {
const fullPath = path.join(dir, entry);
return fs.statSync(fullPath).isDirectory() ? walk(fullPath) : [fullPath];
});
}

function resolveImportPath(filePath, importPath) {
if (!importPath.startsWith('.')) {
return importPath;
}

const absoluteTarget = path.resolve(path.dirname(filePath), importPath);
if (fs.existsSync(`${absoluteTarget}.js`)) {
return `${importPath}.js`;
}

if (fs.existsSync(path.join(absoluteTarget, 'index.js'))) {
return `${importPath}/index.js`;
}

return importPath;
}

function fixImports(filePath) {
const source = fs.readFileSync(filePath, 'utf8');
const fixed = source.replace(/(from\s+['"])([^'"]+)(['"])/g, (_, prefix, importPath, suffix) => {
return `${prefix}${resolveImportPath(filePath, importPath)}${suffix}`;
});
fs.writeFileSync(filePath, fixed);
}

if (fs.existsSync(esmDir)) {
walk(esmDir)
.filter((filePath) => filePath.endsWith('.js'))
.forEach(fixImports);
}
Loading
Loading