Skip to content

Commit

Permalink
feat: aws waf task support
Browse files Browse the repository at this point in the history
  • Loading branch information
alperensert committed Apr 27, 2024
1 parent e7f4c53 commit c663c4a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pnpm add node-capmonster
- Image to Text
- ReCAPTCHA v2 / v2 Enterprise / v3
- Turnstile
- TenDI
- AWS WAF

## Usage examples

Expand Down
98 changes: 98 additions & 0 deletions src/tasks/aws_waf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { ITask, ITaskSolution, UAProxy } from "../capmonster"

export class AmazonTask extends UAProxy {
/**
* Initialize a new AmazonTask for handling the captchas
* @param clientKey Unique key of your account
* @since v0.4.4
*/
constructor(clientKey: string) {
super(clientKey)
}

/**
* Creates a aws waf captcha task for solving
* @param task {@link task}
* @returns ID of the created task
* @since v0.4.4
*/
public createWithTask = async (
task: Omit<IAmazonTaskRequest, "type">
): Promise<number> => {
const data: IAmazonTaskRequest = {
type: "AmazonTaskProxyless",
...task,
}
const [userAgentData] = this.isUserAgentTask(data)
return await this._createTask(userAgentData)
}

/**
* Creates only the task configuration for reuseable tasks.
* @param task {@link IAmazonTaskRequest}
* @returns Only the task you created {@link IAmazonTaskRequest}
* @since v0.4.4
*/
public task = (task: Omit<IAmazonTaskRequest, "type">) => task

/**
* Get task result
* @param taskId Task id which returns from {@link createWithTask} function.
* @returns Returns the solution if captcha is solved, otherwise null
* @also see {@link joinTaskResult}
*/
public getTaskResult = async (taskId: number) =>
this._getTaskResult<IAmazonTaskResponse>(taskId)

/**
* Get task result. This function is waits until task to be solved.
* @param taskId Task id which returns from {@link createWithTask} function.
* @param timeout (as seconds) Sets the timeout for the current execution of this function.
* @returns Solution of the task
* @throws CapmonsterError, if task can't be solved in maximum time
* @also see {@link getTaskResult}
*/
public joinTaskResult = async (taskId: number, timeout?: number) =>
this._joinTaskResult<IAmazonTaskResponse>(taskId, timeout)
}

interface IAmazonTaskRequest extends ITask {
type: "AmazonTaskProxyless"
/**
* The address of the main page where captcha is solved
*/
websiteURL: string
/**
* A string that can be retrieved from an html page with a captcha
* or with javascript by executing the `window.gokuProps.key`
*/
websiteKey: string
/**
* Link to challenge.js
*/
challengeScript: string
/**
* Link to captcha.js
*/
captchaScript: string
/**
* A string that can be retrieved from an html page with a captcha
* or with javascript by executing the `window.gokuProps.context`
*/
context: string
/**
* A string that can be retrieved from an html page with a captcha
* or with javascript by executing the `window.gokuProps.iv`
*/
iv: string
/**
* By default false. If you need to use cookies "aws-waf-token", specify the value true.
* Otherwise, what you will get in return is "captcha_voucher" and "existing_token".
*/
cookieSolution?: boolean
}

interface IAmazonTaskResponse extends ITaskSolution {
cookies: Record<string, string>
userAgent: string
}

0 comments on commit c663c4a

Please sign in to comment.