Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-curl-impersonate

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-curl-impersonate - npm Package Compare versions

Comparing version 1.2.6 to 1.2.7

dist/index.js.map

2

dist/index.d.ts

@@ -21,5 +21,5 @@ interface CurlImpersonateOptions {

getRequest(flags: Array<string>, headers: string): Promise<string>;
postRequest(flags: Array<string>, headers: string): Promise<string>;
postRequest(flags: Array<string>, headers: string, body: Object | undefined): Promise<string>;
convertHeaderObjectToCURL(): string;
}
export default CurlImpersonate;

@@ -0,1 +1,8 @@

/*
curl-impersonate by wearr.
IF YOU PAID FOR THIS SOFTWARE, YOU HAVE BEEN SCAMMED!
*/
import * as proc from "child_process";

@@ -11,3 +18,3 @@ import * as path from 'path';

makeRequest() {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
if (this.validateOptions(this.options)) {

@@ -17,19 +24,20 @@ this.setProperBinary();

let flags = this.options.flags || [];
if (this.options.followRedirects) {
flags.push("-L");
if (this.options.method == "GET") {
this.getRequest(flags, headers)
.then(response => resolve(response))
.catch(error => reject(error));
}
if (this.options.timeout) {
flags.push(`--connect-timeout ${this.options.timeout / 1000}`);
else if (this.options.method == "POST") {
this.postRequest(flags, headers, this.options.body)
.then(response => resolve(response))
.catch(error => reject(error));
}
switch (this.options.method.toUpperCase()) {
case "GET":
resolve(await this.getRequest(flags, headers));
break;
case "POST":
resolve(await this.postRequest(flags, headers));
break;
default:
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods);
else {
// Handle other HTTP methods if needed
reject(new Error("Unsupported HTTP method"));
}
}
else {
reject(new Error("Invalid options"));
}
});

@@ -78,12 +86,14 @@ }

async getRequest(flags, headers) {
// GET REQUEST
let binpath = path.join(__dirname, '..', 'bin', this.binary);
let args = `${flags.join(' ')} ${headers} ${this.url}`;
const result = proc.spawnSync(`${binpath} ${args}`, { shell: true });
return result.stdout.toString();
return result.stdout.toString(); // Convert the stdout buffer to a string and return it
}
async postRequest(flags, headers) {
async postRequest(flags, headers, body) {
// POST REQUEST
let binpath = path.join(__dirname, '..', 'bin', this.binary);
let args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`;
let args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(body)}' ${this.url}`;
const result = proc.spawnSync(`${binpath} ${args}`, { shell: true });
return result.stdout.toString();
return result.stdout.toString(); // Convert the stdout buffer to a string and return it
}

@@ -95,1 +105,2 @@ convertHeaderObjectToCURL() {

export default CurlImpersonate;
//# sourceMappingURL=index.js.map
{
"name": "node-curl-impersonate",
"version": "1.2.6",
"version": "1.2.7",
"description": "A wrapper around cURL-impersonate, a binary which can be used to bypass TLS fingerprinting.",

@@ -8,3 +8,4 @@ "main": "dist/index.js",

"scripts": {
"build": "tsc"
"build": "tsc",
"test": "jest"
},

@@ -20,4 +21,11 @@ "keywords": [

"devDependencies": {
"@types/node": "^20.5.9"
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.5",
"@types/node": "^20.5.9",
"ts-jest": "^29.1.1"
},
"dependencies": {
"jest": "^29.7.0",
"ts-node": "^10.9.1"
}
}

@@ -34,2 +34,3 @@ /*

followRedirects?: boolean | true;
verbose?: boolean | false;
}

@@ -44,2 +45,9 @@

export interface CurlResponse {
statusCode: number;
response: string;
responseHeaders: Object;
requestHeaders: Object;
}
export class CurlImpersonate {

@@ -54,28 +62,39 @@ constructor(url: string, options: CurlImpersonateOptions) {

makeRequest() {
// Convert code to be promise based
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
if (this.validateOptions(this.options)) {
this.setProperBinary()
this.setProperBinary();
let headers = this.convertHeaderObjectToCURL();
let flags = this.options.flags || [];
if (this.options.followRedirects) {
flags.push("-L")
if (this.options.method == "GET") {
if (this.options.verbose) {
console.log("GET REQUEST: " + this.url)
}
this.getRequest(flags, headers)
.then(response => {
if (this.options.verbose) {
console.log("RESPONSE: " + response)
}
resolve(response);
})
.catch(error => {
if (this.options.verbose) {
console.log("ERROR: " + error)
}
reject(error);
});
} else if (this.options.method == "POST") {
this.postRequest(flags, headers, this.options.body)
.then(response => resolve(response))
.catch(error => reject(error));
} else {
// Handle other HTTP methods if needed
reject(new Error("Unsupported HTTP method"));
}
if (this.options.timeout) {
flags.push(`--connect-timeout ${this.options.timeout / 1000}`)
}
switch (this.options.method.toUpperCase()) {
case "GET":
resolve(await this.getRequest(flags, headers));
break;
case "POST":
resolve(await this.postRequest(flags, headers));
break;
default:
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods)
}
}
})
} else {
reject(new Error("Invalid options"));
}
});
}
validateOptions(options: CurlImpersonateOptions) {

@@ -124,6 +143,6 @@ if (this.validMethods.includes(options.method.toUpperCase())) {

async postRequest(flags: Array<string>, headers: string) {
async postRequest(flags: Array<string>, headers: string, body: Object | undefined) {
// POST REQUEST
let binpath = path.join(__dirname, '..', 'bin', this.binary);
let args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`;
let args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(body)}' ${this.url}`;
const result = proc.spawnSync(`${binpath} ${args}`, { shell: true });

@@ -130,0 +149,0 @@ return result.stdout.toString(); // Convert the stdout buffer to a string and return it

{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"target": "ES2020",
"module": "ES2020",
"rootDir": "./src",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"outDir": "dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"outDir": "./dist",
"removeComments": true,
"declaration": true,
"lib": ["ESNext", "DOM", "DOM.Iterable"],
}
"skipLibCheck": true
},
"ts-node": {
"esm": true
},
"exclude": ["tests", "jest.config.ts", "dist"],
"lib": ["esnext"],
"include": ["src"]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc