node-curl-impersonate
Advanced tools
Comparing version 1.0.2 to 1.2.0
@@ -17,7 +17,9 @@ interface CurlImpersonateOptions { | ||
constructor(url: string, options: CurlImpersonateOptions); | ||
makeRequest(): void; | ||
makeRequest(): Promise<unknown> | undefined; | ||
validateOptions(options: CurlImpersonateOptions): boolean; | ||
setProperBinary(): void; | ||
convertHeaderObjectToCURL(): string; | ||
getRequest(flags?: string[], headers?: string): Promise<unknown>; | ||
postRequest(flags?: string[], headers?: string, body?: Object): Promise<unknown>; | ||
} | ||
export default CurlImpersonate; |
@@ -1,7 +0,37 @@ | ||
import * as proc from "child_process"; | ||
import { fileURLToPath } from 'url'; | ||
import * as path from 'path'; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
export class CurlImpersonate { | ||
"use strict"; | ||
/* | ||
curl-impersonate by wearr. | ||
IF YOU PAID FOR THIS SOFTWARE, YOU HAVE BEEN SCAMMED! | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CurlImpersonate = void 0; | ||
const proc = __importStar(require("child_process")); | ||
const path = __importStar(require("path")); | ||
class CurlImpersonate { | ||
constructor(url, options) { | ||
@@ -19,12 +49,7 @@ this.url = url; | ||
if (this.options.method == "GET") { | ||
if (this.options.followRedirects) { | ||
flags.push("-L"); | ||
} | ||
if (this.options.timeout) { | ||
flags.push(`--connect-timeout ${this.options.timeout / 1000}`); | ||
} | ||
let binpath = path.join(__dirname, "..", "bin", this.binary); | ||
let args = `${flags.join(" ")} ${headers} ${this.url}`; | ||
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" }); | ||
return this.getRequest(flags, headers); | ||
} | ||
if (this.options.method == "POST") { | ||
return this.postRequest(flags, headers, this.options.body); | ||
} | ||
} | ||
@@ -75,3 +100,81 @@ } | ||
} | ||
// Headers is a string because it is parsed down into a cURL supported format for headers before this. | ||
async getRequest(flags = this.options.flags || [], headers = '') { | ||
if (this.options.followRedirects) { | ||
flags.push('-L'); | ||
} | ||
if (this.options.timeout) { | ||
flags.push(`--connect-timeout ${this.options.timeout / 1000}`); | ||
} | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = [...flags, headers, this.url]; | ||
try { | ||
const curl = proc.spawn(binpath, args, { shell: true, stdio: ['inherit', 'pipe', 'pipe'] }); | ||
let stdoutData = ''; | ||
curl.stdout.on('data', (data) => { | ||
stdoutData += data; | ||
}); | ||
return new Promise((resolve, reject) => { | ||
curl.on('close', (code) => { | ||
if (code === 0) { | ||
// Curl command exited successfully | ||
resolve({ stdout: stdoutData }); | ||
} | ||
else { | ||
// Curl command exited with an error | ||
reject({ code, stdout: stdoutData }); | ||
} | ||
}); | ||
curl.on('error', (err) => { | ||
// Handle any errors that occur during spawn | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
catch (err) { | ||
// Handle any exceptions thrown during spawn | ||
console.error(err); | ||
return { stdout: '', stderr: '' }; | ||
} | ||
} | ||
async postRequest(flags = this.options.flags || [], headers = '', body = this.options.body || {}) { | ||
if (this.options.followRedirects) { | ||
flags.push('-L'); | ||
} | ||
if (this.options.timeout) { | ||
flags.push(`--connect-timeout ${this.options.timeout / 1000}`); | ||
} | ||
flags.push(`--data '${JSON.stringify(this.options.body)}'`); | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = [...flags, headers, this.url]; | ||
try { | ||
const curl = proc.spawn(binpath, args, { shell: true, stdio: ['inherit', 'pipe', 'pipe'] }); | ||
let stdoutData = ''; | ||
curl.stdout.on('data', (data) => { | ||
stdoutData += data; | ||
}); | ||
return new Promise((resolve, reject) => { | ||
curl.on('close', (code) => { | ||
if (code === 0) { | ||
// Curl command exited successfully | ||
resolve({ stdout: stdoutData }); | ||
} | ||
else { | ||
// Curl command exited with an error | ||
reject({ code, stdout: stdoutData }); | ||
} | ||
}); | ||
curl.on('error', (err) => { | ||
// Handle any errors that occur during spawn | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
catch (err) { | ||
console.error(err); | ||
return { stdout: '', stderr: '' }; | ||
} | ||
} | ||
} | ||
export default CurlImpersonate; | ||
exports.CurlImpersonate = CurlImpersonate; | ||
exports.default = CurlImpersonate; |
{ | ||
"name": "node-curl-impersonate", | ||
"version": "1.0.2", | ||
"version": "1.2.0", | ||
"description": "A wrapper around cURL-impersonate, a binary which can be used to bypass TLS fingerprinting.", | ||
@@ -8,10 +8,22 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsc", | ||
"test": "jest" | ||
}, | ||
"keywords": ["web-scraping", "tls-fingerprinting", "curl-impersonate", "typescript"], | ||
"keywords": [ | ||
"web-scraping", | ||
"tls-fingerprinting", | ||
"curl-impersonate", | ||
"typescript" | ||
], | ||
"author": "", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^20.5.9" | ||
"@jest/globals": "^29.6.4", | ||
"@types/jest": "^29.5.4", | ||
"@types/node": "^20.5.9", | ||
"jest": "^29.6.4", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
108
src/index.ts
@@ -10,9 +10,5 @@ /* | ||
import * as proc from "child_process"; | ||
import { fileURLToPath } from 'url'; | ||
import * as path from 'path'; | ||
import { inherits } from "util"; | ||
import { stdout } from "process"; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
/* | ||
@@ -61,13 +57,7 @@ | ||
if (this.options.method == "GET") { | ||
// GET REQUEST | ||
if (this.options.followRedirects) { | ||
flags.push("-L") | ||
} | ||
if (this.options.timeout) { | ||
flags.push(`--connect-timeout ${this.options.timeout / 1000}`) | ||
} | ||
let binpath = path.join(__dirname, "..", "bin", this.binary) | ||
let args = `${flags.join(" ")} ${headers} ${this.url}` | ||
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" }) | ||
return this.getRequest(flags, headers) | ||
} | ||
if (this.options.method == "POST") { | ||
return this.postRequest(flags, headers, this.options.body) | ||
} | ||
} | ||
@@ -113,4 +103,90 @@ } | ||
} | ||
} | ||
// Headers is a string because it is parsed down into a cURL supported format for headers before this. | ||
async getRequest(flags = this.options.flags || [], headers: string = '') { | ||
if (this.options.followRedirects) { | ||
flags.push('-L'); | ||
} | ||
if (this.options.timeout) { | ||
flags.push(`--connect-timeout ${this.options.timeout / 1000}`); | ||
} | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = [...flags, headers, this.url]; | ||
try { | ||
const curl = proc.spawn(binpath, args, { shell: true, stdio: ['inherit', 'pipe', 'pipe'] }); | ||
let stdoutData = ''; | ||
curl.stdout.on('data', (data: string) => { | ||
stdoutData += data; | ||
}); | ||
return new Promise((resolve, reject) => { | ||
curl.on('close', (code: number) => { | ||
if (code === 0) { | ||
// Curl command exited successfully | ||
resolve({ stdout: stdoutData }); | ||
} else { | ||
// Curl command exited with an error | ||
reject({ code, stdout: stdoutData }); | ||
} | ||
}); | ||
curl.on('error', (err) => { | ||
// Handle any errors that occur during spawn | ||
reject(err); | ||
}); | ||
}); | ||
} catch (err) { | ||
// Handle any exceptions thrown during spawn | ||
console.error(err); | ||
return { stdout: '', stderr: '' }; | ||
} | ||
} | ||
async postRequest(flags = this.options.flags || [], headers: string = '', body = this.options.body || {}) { | ||
if (this.options.followRedirects) { | ||
flags.push('-L'); | ||
} | ||
if (this.options.timeout) { | ||
flags.push(`--connect-timeout ${this.options.timeout / 1000}`); | ||
} | ||
flags.push(`--data '${JSON.stringify(this.options.body)}'`); | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = [...flags, headers, this.url]; | ||
try { | ||
const curl = proc.spawn(binpath, args, { shell: true, stdio: ['inherit', 'pipe', 'pipe'] }); | ||
let stdoutData = ''; | ||
curl.stdout.on('data', (data: string) => { | ||
stdoutData += data; | ||
}); | ||
return new Promise((resolve, reject) => { | ||
curl.on('close', (code: number) => { | ||
if (code === 0) { | ||
// Curl command exited successfully | ||
resolve({ stdout: stdoutData }); | ||
} else { | ||
// Curl command exited with an error | ||
reject({ code, stdout: stdoutData }); | ||
} | ||
}); | ||
curl.on('error', (err) => { | ||
// Handle any errors that occur during spawn | ||
reject(err); | ||
}); | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
return { stdout: '', stderr: '' }; | ||
} | ||
} | ||
} | ||
export default CurlImpersonate |
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"esModuleInterop": true, | ||
"target": "ES2020", | ||
"module": "CommonJS", | ||
"rootDir": "./src/", | ||
"declaration": true, | ||
"outDir": "./dist/", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"outDir": "./dist", | ||
"removeComments": true, | ||
"declaration": true, | ||
"lib": ["ESNext", "DOM", "DOM.Iterable"], | ||
} | ||
"skipLibCheck": true, | ||
"lib": ["ES2020", "DOM"] | ||
}, | ||
"exclude": ["./tests/", "./dist/", "jest.config.ts"] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
8843102
11
450
0
7
3