Skip to content

Commit

Permalink
feat: packages updated + proxy provider renamed + proxy hostname changed
Browse files Browse the repository at this point in the history
  • Loading branch information
rimiti committed Mar 13, 2024
1 parent 9ca6d1c commit 2800a2a
Show file tree
Hide file tree
Showing 8 changed files with 1,348 additions and 1,297 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ yarn add @tictactrip/luminator

## Available proxy providers

- [Luminati](https://luminati.io)
- [BrightData](https://brightdata.com)
- [Proxyrack](https://www.proxyrack.com)
- [Shifter](https://www.shifter.io)

## How to use it?

### Luminati
### BrightData

#### Strategy: Manual
This kind of agent strategy allow to specifically set how and when a change of IP (through `country`) or `sessionId`
Expand All @@ -32,9 +32,9 @@ is done.
Create your instance:

```typescript
import { Luminati } from '@tictactrip/luminator';
import { BrightData } from '@tictactrip/luminator';

const luminati: Luminati = new Luminati({
const BrightData: BrightData = new BrightData({
proxy: {
username: 'tictactrip',
password: 'secret',
Expand All @@ -47,35 +47,35 @@ const luminati: Luminati = new Luminati({
- Create an agent with a random countries and sessionId

```typescript
const agent: Luminati = luminati.setIp();
const agent: BrightData = BrightData.setIp();
```

- Create an agent with a specific country and a random sessionId

```typescript
const agent: Luminati = luminati.setIp({ countries: [ELuminatiCountry.FRANCE] });
const agent: BrightData = BrightData.setIp({ countries: [EBrightDataCountry.FRANCE] });
```

- Create an agent with a specific country and a specific sessionId

```typescript
const agent: Luminati = luminati.setIp({ countries: [ELuminatiCountry.FRANCE], sessionId });
const agent: BrightData = BrightData.setIp({ countries: [EBrightDataCountry.FRANCE], sessionId });
```

- Create an agent with a random countries and a specific sessionId

```typescript
const agent: Luminati = luminati.setIp({ sessionId });
const agent: BrightData = BrightData.setIp({ sessionId });
```

#### Strategy: Change IP every requests

This strategy aims to make a GET request with a **FR** or **PT** IP randomly every requests.

```typescript
import { Luminati, EStrategyMode, ELuminatiCountry } from "@tictactrip/luminator";
import { BrightData, EStrategyMode, EBrightDataCountry } from "@tictactrip/luminator";

const luminati: Luminati = new Luminati({
const BrightData: BrightData = new BrightData({
proxy: {
username: 'tictactrip',
password: 'secret',
Expand All @@ -84,7 +84,7 @@ const luminati: Luminati = new Luminati({
},
strategy: {
mode: EStrategyMode.CHANGE_IP_EVERY_REQUESTS,
countries: [ELuminatiCountry.FRANCE, ELuminatiCountry.SPAIN],
countries: [EBrightDataCountry.FRANCE, EBrightDataCountry.SPAIN],
},
});

Expand All @@ -94,8 +94,8 @@ const requestConfig = {
url: '/myip.json',
}

const response1 = await luminati.fetch(requestConfig);
const response2 = await luminati.fetch(requestConfig);
const response1 = await BrightData.fetch(requestConfig);
const response2 = await BrightData.fetch(requestConfig);

console.log(response1.data);
console.log(response2.data);
Expand Down
58 changes: 29 additions & 29 deletions __tests__/unit/luminati.ts → __tests__/unit/bright-data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as nock from 'nock';
import { ELuminatiCountry, EStrategyMode, Luminati } from '../../src';
import { EBrightDataCountry, EStrategyMode, BrightData } from '../../src';

describe('Luminati', () => {
const countryKeys: string[] = Object.values(ELuminatiCountry);
describe('BrightData', () => {
const countryKeys: string[] = Object.values(EBrightDataCountry);
const proxy = {
username: 'tictactrip',
password: 'secret',
Expand All @@ -14,7 +14,7 @@ describe('Luminati', () => {
it('should throw an error if a strategy has been set without any countries', async () => {
let error: Error;
try {
new Luminati({
new BrightData({
proxy,
strategy: {
mode: EStrategyMode.CHANGE_IP_EVERY_REQUESTS,
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Luminati', () => {
.once()
.reply(200, response1);

const luminati: Luminati = new Luminati({
const brightData: BrightData = new BrightData({
proxy,
axiosConfig: {
headers: {
Expand All @@ -66,7 +66,7 @@ describe('Luminati', () => {
},
});

const { data } = await luminati.setIp().fetch({
const { data } = await brightData.setIp().fetch({
method: 'get',
baseURL: 'https://lumtest.com',
url: '/myip.json',
Expand All @@ -79,18 +79,18 @@ describe('Luminati', () => {
});

describe('#setIp', () => {
let luminati: Luminati;
let brightData: BrightData;

const regexPatternAllCountries = `${countryKeys.join('|')}`;

beforeEach(() => {
luminati = new Luminati({ proxy });
brightData = new BrightData({ proxy });
});

it('should create an agent with a random countries and sessionId', async () => {
const agent: Luminati = luminati.setIp();
const agent: BrightData = brightData.setIp();

expect(agent).toBeInstanceOf(Luminati);
expect(agent).toBeInstanceOf(BrightData);
expect(typeof agent.sessionId).toEqual('number');
expect(agent.country).toMatch(new RegExp(regexPatternAllCountries));
expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io');
Expand All @@ -102,9 +102,9 @@ describe('Luminati', () => {
});

it('should create an agent with a specific country and a random sessionId', async () => {
const agent: Luminati = luminati.setIp({ countries: [ELuminatiCountry.FRANCE] });
const agent: BrightData = brightData.setIp({ countries: [EBrightDataCountry.FRANCE] });

expect(agent).toBeInstanceOf(Luminati);
expect(agent).toBeInstanceOf(BrightData);
expect(typeof agent.sessionId).toEqual('number');
expect(agent.country).toMatch(/fr/);
expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io');
Expand All @@ -118,9 +118,9 @@ describe('Luminati', () => {
it('should create an agent with a specific country and a specific sessionId', async () => {
const sessionId = 123456789;

const agent: Luminati = luminati.setIp({ countries: [ELuminatiCountry.FRANCE], sessionId });
const agent: BrightData = brightData.setIp({ countries: [EBrightDataCountry.FRANCE], sessionId });

expect(agent).toBeInstanceOf(Luminati);
expect(agent).toBeInstanceOf(BrightData);
expect(agent.sessionId).toEqual(123456789);
expect(agent.country).toMatch(/fr/);
expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io');
Expand All @@ -134,9 +134,9 @@ describe('Luminati', () => {
it('should create an agent with a random countries and a specific sessionId', async () => {
const sessionId = 123456789;

const agent: Luminati = luminati.setIp({ sessionId });
const agent: BrightData = brightData.setIp({ sessionId });

expect(agent).toBeInstanceOf(Luminati);
expect(agent).toBeInstanceOf(BrightData);
expect(agent.sessionId).toEqual(123456789);
expect(agent.country).toMatch(new RegExp(regexPatternAllCountries));
expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io');
Expand All @@ -150,7 +150,7 @@ describe('Luminati', () => {
it('should throw an error if no countries have been given (only countries attribute)', async () => {
let error: Error;
try {
luminati.setIp({ countries: [] });
brightData.setIp({ countries: [] });
} catch (e) {
error = e;
}
Expand All @@ -161,7 +161,7 @@ describe('Luminati', () => {
it('should throw an error if no countries have been given (sessionId and countries attribute)', async () => {
let error: Error;
try {
luminati.setIp({ sessionId: 123, countries: [] });
brightData.setIp({ sessionId: 123, countries: [] });
} catch (e) {
error = e;
}
Expand All @@ -172,7 +172,7 @@ describe('Luminati', () => {
it('should throw an error if fetch() has been called without previously used setIp() or set a strategy', async () => {
let error: Error;
try {
await luminati.fetch({
await brightData.fetch({
method: 'get',
baseURL: 'https://lumtest.com',
url: '/myip.json',
Expand All @@ -189,11 +189,11 @@ describe('Luminati', () => {

describe('#strategy', () => {
describe('CHANGE_IP_EVERY_REQUESTS', () => {
const luminati: Luminati = new Luminati({
const brightData: BrightData = new BrightData({
proxy,
strategy: {
mode: EStrategyMode.CHANGE_IP_EVERY_REQUESTS,
countries: [ELuminatiCountry.FRANCE, ELuminatiCountry.SPAIN],
countries: [EBrightDataCountry.FRANCE, EBrightDataCountry.SPAIN],
},
});

Expand Down Expand Up @@ -242,20 +242,20 @@ describe('Luminati', () => {
const request1Mock = nock('http://lumtest.com').get('/myip.json').once().reply(200, response1);
const request2Mock = nock('http://lumtest.com').get('/myip.json').once().reply(200, response2);

const result1 = await luminati.fetch({
const result1 = await brightData.fetch({
method: 'get',
baseURL: 'http://lumtest.com',
url: '/myip.json',
});

const result2 = await luminati.fetch({
const result2 = await brightData.fetch({
method: 'get',
baseURL: 'http://lumtest.com',
url: '/myip.json',
});

expect(typeof luminati.sessionId).toEqual('number');
expect(luminati.country).toMatch(/fr|es/);
expect(typeof brightData.sessionId).toEqual('number');
expect(brightData.country).toMatch(/fr|es/);
expect(result1.data).toStrictEqual(response1);
expect(result2.data).toStrictEqual(response2);

Expand All @@ -269,20 +269,20 @@ describe('Luminati', () => {
const request1Mock = nock('https://lumtest.com').get('/myip.json').once().reply(200, response1);
const request2Mock = nock('https://lumtest.com').get('/myip.json').once().reply(200, response2);

const result1 = await luminati.fetch({
const result1 = await brightData.fetch({
method: 'get',
baseURL: 'https://lumtest.com',
url: '/myip.json',
});

const result2 = await luminati.fetch({
const result2 = await brightData.fetch({
method: 'get',
baseURL: 'https://lumtest.com',
url: '/myip.json',
});

expect(typeof luminati.sessionId).toEqual('number');
expect(luminati.country).toMatch(/fr|es/);
expect(typeof brightData.sessionId).toEqual('number');
expect(brightData.country).toMatch(/fr|es/);
expect(result1.data).toStrictEqual(response1);
expect(result2.data).toStrictEqual(response2);

Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
"types": "dist/index.d.ts",
"license": "GPL-3.0",
"dependencies": {
"@rimiti/stimmy": "1.10.0",
"axios": "0.24.0",
"@rimiti/stimmy": "1.11.0",
"axios": "1.6.7",
"http-proxy-agent": "4.0.1",
"https-proxy-agent": "2.2.4"
},
"devDependencies": {
"@types/jest": "27.0.2",
"@typescript-eslint/eslint-plugin": "5.3.0",
"@typescript-eslint/parser": "5.3.0",
"eslint": "8.2.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"jest": "27.3.1",
"nock": "13.2.0",
"prettier": "2.4.1",
"ts-jest": "27.0.7",
"typescript": "4.4.4"
"@types/jest": "29.5.12",
"@typescript-eslint/eslint-plugin": "7.2.0",
"@typescript-eslint/parser": "7.2.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"jest": "29.7.0",
"nock": "13.5.4",
"prettier": "3.2.5",
"ts-jest": "29.1.2",
"typescript": "5.4.2"
},
"scripts": {
"clean": "rm -rf dist coverage",
Expand Down
Loading

0 comments on commit 2800a2a

Please sign in to comment.