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MAAM,qCAAqC,EAAO,YAG9D,OAAO,IACN,CACD,UACA,WAAY,KACT,IACD,EACN,EAGF,OAAO,QAAU","file":"/npm/captcha-solver@0.0.6/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/captcha-solver@0.0.6/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict'\n\nconst base64Image = require('node-base64-image')\nconst isUrl = require('is-url-superb')\nconst ow = require('ow')\nconst pify = require('pify')\nconst pRetry = require('p-retry')\nconst pTimeout = require('p-timeout')\n\nconst CaptchaSolverProvider = require('captcha-solver-provider')\nconst providers = require('./lib/providers')\n\n/**\n * Main entrypoint for solving captchas.\n *\n * @param {string|CaptchaSolverProvider} provider - Name of built-in provider or an instance of\n * a custom provider to use for solving.\n */\nclass CaptchaSolver {\n  constructor (provider, opts = { }) {\n    this._provider = typeof provider === 'object'\n      ? provider\n      : providers.getProviderByName(provider, opts)\n    ow(this._provider, ow.object.instanceOf(CaptchaSolverProvider))\n    ow(opts, ow.object.plain)\n  }\n\n  /**\n   * Provider powering this solver.\n   *\n   * @member {CaptchaSolverProvider}\n   */\n  get provider () { return this._provider }\n\n  /**\n   * Creates a new captcha solving task.\n   *\n   * Valid values for `opts.type` are:\n   * - image-to-text\n   * - recaptcha\n   * - recaptcha-proxyless\n   * - nocaptcha\n   * - nocaptcha-proxyless\n   * - funcaptcha\n   * - funcaptcha-proxyless\n   *\n   * Note that not all providers support all captcha types. See\n   * `provider.supportedTaskTypes` for a Set containing all task types a given\n   * provider supports.\n   *\n   * Note that most of these options will be unused depending on the task type.\n   *\n   * @param {object} opts - Options\n   * @param {string} opts.type - Type of captcha to solve\n   * @param {buffer|string} [opts.image] - Path, URL, or buffer of an image to process\n   * @param {string} [opts.websiteURL] - Website URL for nocaptcha, recaptcha, and funcaptcha\n   * @param {string} [opts.websiteKey] - Recaptcha website key\n   * @param {string} [opts.websiteSToken] - Secret token for old versions of Recaptcha\n   * @param {string} [opts.websitePublicKey] - Funcaptcha public key\n   * @param {string} [opts.proxyType] - Proxy type (http/socks4/socks5)\n   * @param {string} [opts.proxyAddress] - Proxy IP address (ipv4/ipv6)\n   * @param {string|number} [opts.proxyPort] - Proxy port\n   * @param {string} [opts.proxyLogin] - Proxy login for basic auth\n   * @param {string} [opts.proxyPassword] - Proxy password\n   * @param {string} [opts.userAgent] - Browser's User-Agent to emulate\n   * @param {string} [opts.cookies] - Additional cookies to emulate\n   *\n   * @return {Promise<string>} Unique task identifier\n   */\n  async createTask (opts) {\n    ow(opts, ow.object.plain.nonEmpty)\n    ow(opts.type, ow.string.nonEmpty)\n\n    if (!this._provider.supportedTaskTypes.has(opts.type)) {\n      throw new Error(`provider ${this._provider.name} does not support task type \"${opts.type}\"`)\n    }\n\n    if (opts.image) {\n      if (Buffer.isBuffer(opts.image)) {\n        opts.image = opts.image.toString('base64')\n      } else if (typeof opts.image === 'string') {\n        opts.image = await pify(base64Image.encode)(opts.image, {\n          string: true,\n          local: !isUrl(opts.image)\n        })\n      } else {\n        throw new Error('unsupported image type')\n      }\n    }\n\n    return this._provider.createTask(opts)\n  }\n\n  /**\n   * Fetches the result of a previously created captcha solving task.\n   *\n   * @param {string} taskId - Unique task identifier\n   * @param {object} [opts] - Options\n   * @param {number} [opts.retries=3] - Number of retries to perform\n   * @param {number} [opts.timeout=30000] - Max timeout to wait in ms before aborting\n   *\n   * @return {Promise<object>}\n   */\n  async getTaskResult (taskId, opts = { }) {\n    ow(taskId, ow.string.nonEmpty)\n    ow(opts, ow.object.plain)\n\n    const {\n      retries = 3,\n      timeout = 30000,\n      ...rest\n    } = opts\n\n    return pTimeout(pRetry(async () => {\n      const result = await this._provider.getTaskResult(taskId)\n\n      if (result.status !== 'ready') {\n        throw new Error(`task is still processing (status \"${result.status}\")`)\n      }\n\n      return result\n    }, {\n      retries,\n      maxTimeout: timeout,\n      ...rest\n    }), timeout)\n  }\n}\n\nmodule.exports = CaptchaSolver\n"]}