diff --git a/capsolver/README.md b/capsolver/README.md index fbbefdd..ceeefd7 100644 --- a/capsolver/README.md +++ b/capsolver/README.md @@ -79,7 +79,7 @@ const reCaptchaV3Request = new ReCaptchaV3EnterpriseTask({ ``` ### Features -* Supports all captcha types, solutions and methods from CapSolver docs (updated at May 2024) +* Supports all captcha types, solutions and methods from CapSolver docs (updated at June 2024) * TypeScript-first design * Automatically waits for solution * Fully tested task payloads @@ -94,6 +94,7 @@ What 'custom' does mean? Custom means that the parameters and solutions have bee * [FunCaptchaClassification](https://docs.capsolver.com/guide/recognition/FunCaptchaClassification.html) * [ReCaptchaClassification](https://docs.capsolver.com/guide/recognition/ReCaptchaClassification.html) * [AwsWafClassification](https://docs.capsolver.com/guide/recognition/AwsWafClassification.html) + * [VisionEngine](https://docs.capsolver.com/guide/recognition/VisionEngine.html) 2. Token * [HCaptchaTask | HCaptchaTaskProxyLess](https://docs.capsolver.com/guide/captcha/HCaptcha.html) * [FunCaptchaTaskProxyLess](https://docs.capsolver.com/guide/captcha/FunCaptcha.html) diff --git a/capsolver/package.json b/capsolver/package.json index bab7730..79ea8fb 100644 --- a/capsolver/package.json +++ b/capsolver/package.json @@ -1,6 +1,6 @@ { "name": "@captcha-libs/capsolver", - "version": "1.1.6", + "version": "1.1.7", "keywords": [ "CapSolver", "Captcha recognition", diff --git a/capsolver/src/lib/Requests/Classification/VisionEngine.ts b/capsolver/src/lib/Requests/Classification/VisionEngine.ts new file mode 100644 index 0000000..15c26e3 --- /dev/null +++ b/capsolver/src/lib/Requests/Classification/VisionEngine.ts @@ -0,0 +1,79 @@ +import type { _IsTaskType } from "../_BaseTaskRequest"; +import { BaseTask } from "../_BaseTaskRequest"; + +const _VisionEngineModules = [ + "slider_1", + "rotate_1", + "space_detection" +] as const; + +type VisionEngineModules = typeof _VisionEngineModules[number]; + +interface VisionEngineParams { + image: string; + imageBackground: string; + module: VisionEngineModules; + question?: string; + websiteURL?: string; +} + +/** + * @classdesc OCR VisionEngine + * @class + * @extends {BaseTask} + * {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html} + */ +export class VisionEngine extends BaseTask implements VisionEngineParams, _IsTaskType { + + /** + * @type {boolean} _isVisionEngine - Only used for correct method overloading intellisense + */ + readonly _isVisionEngine: _IsTaskType["_isVisionEngine"] = true; + + /** + * Create VisionEngine + * {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html} + * @param {Object} params - VisionEngineParams + * @param {string} [params.image] - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) + * @param {string} [params.imageBackground] - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) + * @param {string} [params.question] - required for "space_detection" module + * @param {VisionEngineModules=} [params.module] - Specifies the module. + * @param {string} [params.websiteURL] - Page source url to improve accuracy + */ + constructor({ + image, imageBackground, question, module, websiteURL + }: VisionEngineParams) { + super({ type: "VisionEngine" }); + this.image = image; + this.imageBackground = imageBackground; + this.question = question; + this.module = module; + this.websiteURL = websiteURL; + } + + /** + * @type {string} image - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) + */ + image: string; + + /** + * @type {string} image - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) + */ + imageBackground: string; + + /** + * @type {VisionEngineModules=} module - Specifies the module + * {@see https://docs.capsolver.com/guide/recognition/VisionEngine.html} + */ + module: VisionEngineModules; + + /** + * @param {string} question - required for "space_detection" module + */ + question?: string; + + /** + * @type {string} websiteURL - Page source url to improve accuracy + */ + websiteURL?: string; +} \ No newline at end of file diff --git a/capsolver/src/lib/Requests/Classification/index.ts b/capsolver/src/lib/Requests/Classification/index.ts index df0868f..d4ab717 100644 --- a/capsolver/src/lib/Requests/Classification/index.ts +++ b/capsolver/src/lib/Requests/Classification/index.ts @@ -1,13 +1,15 @@ -import type { AwsWafClassification } from "./AwsWafClassification"; -import type { FunCaptchaClassification } from "./FunCaptchaClassification"; -import type { HCaptchaClassification } from "./HCaptchaClassification"; -import type { ImageToTextTask } from "./ImageToTextTask"; -import type { ReCaptchaV2Classification } from "./ReCaptchaV2Classification"; +import { AwsWafClassification } from "./AwsWafClassification"; +import { FunCaptchaClassification } from "./FunCaptchaClassification"; +import { HCaptchaClassification } from "./HCaptchaClassification"; +import { ImageToTextTask } from "./ImageToTextTask"; +import { ReCaptchaV2Classification } from "./ReCaptchaV2Classification"; +import { VisionEngine } from "./VisionEngine"; export { AwsWafClassification, FunCaptchaClassification, HCaptchaClassification, ImageToTextTask, - ReCaptchaV2Classification + ReCaptchaV2Classification, + VisionEngine }; \ No newline at end of file diff --git a/capsolver/src/lib/Requests/_BaseTaskRequest.ts b/capsolver/src/lib/Requests/_BaseTaskRequest.ts index 98bdc44..99f37af 100644 --- a/capsolver/src/lib/Requests/_BaseTaskRequest.ts +++ b/capsolver/src/lib/Requests/_BaseTaskRequest.ts @@ -31,7 +31,8 @@ const _TaskTypes = [ "HCaptchaTaskProxyLess", "FunCaptchaTaskProxyLess", "GeeTestTask", - "GeeTestTaskProxyLess" + "GeeTestTaskProxyLess", + "VisionEngine" ] as const; export type TaskTypes = typeof _TaskTypes[number]; diff --git a/capsolver/src/lib/Requests/index.ts b/capsolver/src/lib/Requests/index.ts index 03a3146..47c1ad2 100644 --- a/capsolver/src/lib/Requests/index.ts +++ b/capsolver/src/lib/Requests/index.ts @@ -3,13 +3,14 @@ import type { FunCaptchaClassification, HCaptchaClassification, ImageToTextTask, - ReCaptchaV2Classification + ReCaptchaV2Classification, + VisionEngine } from "./Classification"; import type { AntiAkamaiPowTask, AntiAkamaiBMPTask, AntiAkamaiSensorTask, AntiAkamaiWebTask, AntiAwsWafTask, AntiAwsWafTaskProxyLess, AntiCloudflareChallengeTask, AntiCloudflareTurnstileTask, AntiCyberSiAraTask, AntiCyberSiAraTaskProxyLess, AntiImpervaTask, AntiImpervaTaskProxyLess, DataDomeSliderTask, FunCaptchaTaskProxyLess, GeeTestTask, GeeTestTaskProxyLess, GeeTestV3Task, GeeTestV3TaskProxyLess, GeeTestV4Task, GeeTestV4TaskProxyLess, HCaptchaTask, HCaptchaTaskProxyLess, MtCaptchaTask, MtCaptchaTaskProxyLess, ReCaptchaV2EnterpriseTask, ReCaptchaV2EnterpriseTaskProxyLess, ReCaptchaV2Task, ReCaptchaV2TaskProxyLess, ReCaptchaV3EnterpriseTask, ReCaptchaV3EnterpriseTaskProxyLess, ReCaptchaV3M1TaskProxyLess, ReCaptchaV3Task, ReCaptchaV3TaskProxyLess } from "./Token"; -export type Requests = AntiAkamaiBMPTask | AntiAkamaiPowTask | AntiAkamaiSensorTask | AntiAkamaiWebTask | AntiAwsWafTask | AntiAwsWafTaskProxyLess | AntiCloudflareChallengeTask | AntiCloudflareTurnstileTask | AntiCyberSiAraTask | AntiCyberSiAraTaskProxyLess | AntiImpervaTask | AntiImpervaTaskProxyLess | AwsWafClassification | DataDomeSliderTask | FunCaptchaClassification | FunCaptchaTaskProxyLess | GeeTestTask | GeeTestTaskProxyLess | GeeTestV3Task | GeeTestV3TaskProxyLess | GeeTestV4Task | GeeTestV4TaskProxyLess | HCaptchaClassification | HCaptchaTask | HCaptchaTaskProxyLess | ImageToTextTask | MtCaptchaTask | MtCaptchaTaskProxyLess | ReCaptchaV2Classification | ReCaptchaV2EnterpriseTask | ReCaptchaV2EnterpriseTaskProxyLess | ReCaptchaV2Task | ReCaptchaV2TaskProxyLess | ReCaptchaV3EnterpriseTask | ReCaptchaV3EnterpriseTaskProxyLess | ReCaptchaV3M1TaskProxyLess | ReCaptchaV3Task | ReCaptchaV3TaskProxyLess; +export type Requests = AntiAkamaiBMPTask | AntiAkamaiPowTask | AntiAkamaiSensorTask | AntiAkamaiWebTask | AntiAwsWafTask | AntiAwsWafTaskProxyLess | AntiCloudflareChallengeTask | AntiCloudflareTurnstileTask | AntiCyberSiAraTask | AntiCyberSiAraTaskProxyLess | AntiImpervaTask | AntiImpervaTaskProxyLess | AwsWafClassification | DataDomeSliderTask | FunCaptchaClassification | FunCaptchaTaskProxyLess | GeeTestTask | GeeTestTaskProxyLess | GeeTestV3Task | GeeTestV3TaskProxyLess | GeeTestV4Task | GeeTestV4TaskProxyLess | HCaptchaClassification | HCaptchaTask | HCaptchaTaskProxyLess | ImageToTextTask | MtCaptchaTask | MtCaptchaTaskProxyLess | ReCaptchaV2Classification | ReCaptchaV2EnterpriseTask | ReCaptchaV2EnterpriseTaskProxyLess | ReCaptchaV2Task | ReCaptchaV2TaskProxyLess | ReCaptchaV3EnterpriseTask | ReCaptchaV3EnterpriseTaskProxyLess | ReCaptchaV3M1TaskProxyLess | ReCaptchaV3Task | ReCaptchaV3TaskProxyLess | VisionEngine; export * from "./Classification"; diff --git a/capsolver/src/lib/Solution/Classification/VisionEngineSolution.ts b/capsolver/src/lib/Solution/Classification/VisionEngineSolution.ts new file mode 100644 index 0000000..278bd4a --- /dev/null +++ b/capsolver/src/lib/Solution/Classification/VisionEngineSolution.ts @@ -0,0 +1,17 @@ + +interface VisionEngineAngleSolution { + angle: number; +} + +interface VisionEngineDistanceSolution { + distance: number; +} + +interface VisionEngineSpaceDetectionSolution { + box: number[]; +} + +/** + * {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html#example-response} + */ +export type VisionEngineSolution = VisionEngineAngleSolution & VisionEngineDistanceSolution & VisionEngineSpaceDetectionSolution; diff --git a/capsolver/src/lib/Solution/Classification/index.ts b/capsolver/src/lib/Solution/Classification/index.ts index 2aa4a55..24bd95b 100644 --- a/capsolver/src/lib/Solution/Classification/index.ts +++ b/capsolver/src/lib/Solution/Classification/index.ts @@ -1,13 +1,15 @@ -import type { AwsWafClassificationSolution } from "./AwsWafClassificationSolution"; -import type { FunCaptchaClassificationSolution } from "./FunCaptchaClassificationSolution"; -import type { HCaptchaClassificationSolution } from "./HCaptchaClassificationSolution"; -import type { ImageToTextSolution } from "./ImageToTextSolution"; -import type { ReCaptchaV2ClassificationSolution } from "./ReCaptchaV2ClassificationSolution"; +import { VisionEngineSolution } from "./VisionEngineSolution"; +import { AwsWafClassificationSolution } from "./AwsWafClassificationSolution"; +import { FunCaptchaClassificationSolution } from "./FunCaptchaClassificationSolution"; +import { HCaptchaClassificationSolution } from "./HCaptchaClassificationSolution"; +import { ImageToTextSolution } from "./ImageToTextSolution"; +import { ReCaptchaV2ClassificationSolution } from "./ReCaptchaV2ClassificationSolution"; export { AwsWafClassificationSolution, FunCaptchaClassificationSolution, HCaptchaClassificationSolution, ImageToTextSolution, - ReCaptchaV2ClassificationSolution + ReCaptchaV2ClassificationSolution, + VisionEngineSolution }; diff --git a/capsolver/src/lib/capsolver.ts b/capsolver/src/lib/capsolver.ts index 0480239..10b2796 100644 --- a/capsolver/src/lib/capsolver.ts +++ b/capsolver/src/lib/capsolver.ts @@ -28,7 +28,8 @@ import type { HCaptchaClassificationSolution, ImageToTextSolution, ReCaptchaV2ClassificationSolution, - FunCaptchaClassificationSolution + FunCaptchaClassificationSolution, + VisionEngineSolution } from "./Solution"; import type { AntiAkamaiPowTask, @@ -69,7 +70,8 @@ import type { AwsWafClassification, HCaptchaClassification, ImageToTextTask, - ReCaptchaV2Classification + ReCaptchaV2Classification, + VisionEngine } from "./Requests"; import type { CapSolverSolution } from "./Solution/_BaseSolution"; process.removeAllListeners("warning"); @@ -323,6 +325,12 @@ export class CapSolver extends CaptchaClient>; + /** + * @param {VisionEngine} request - task payload to create task + * @return {Promise>} - response of createTask + */ + public async solve(request: VisionEngine): Promise>; + /** * @param {Requests} request - task payload to create task * @return {Promise>} - response of createTask @@ -372,6 +380,7 @@ export class CapSolver extends CaptchaClient { + it("To be equal to object", () => { + const task = new VisionEngine({ + image: "image-base64", + imageBackground: "imageBackground-base64", + module: "rotate_1", + question: "question", + websiteURL: "https://some-url.com" + }); + + expect(task).toEqual({ + _endpoint: "createTask", + _isVisionEngine: true, + image: "image-base64", + imageBackground: "imageBackground-base64", + module: "rotate_1", + question: "question", + type: "VisionEngine", + websiteURL: "https://some-url.com" + }); + }); + it("To be equal to object without optional params", () => { + const task = new VisionEngine({ + image: "image-base64", + imageBackground: "imageBackground-base64", + module: "rotate_1" + }); + + expect(task).toEqual({ + _endpoint: "createTask", + _isVisionEngine: true, + image: "image-base64", + imageBackground: "imageBackground-base64", + module: "rotate_1", + question: undefined, + type: "VisionEngine", + websiteURL: undefined + }); + }); +});