From 4899cbd9e09ee0dd8df658e44f7df0b792641f44 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Mon, 25 Mar 2024 16:58:53 +0100 Subject: [PATCH 01/10] feat: http and https agent packages updated --- package.json | 12 +- src/classes/providers/base/types.ts | 6 +- src/classes/providers/bright-data/index.ts | 7 +- src/classes/providers/proxyrack/index.ts | 7 +- src/classes/providers/shifter/index.ts | 7 +- tsconfig.json | 3 +- yarn.lock | 197 +++++++++------------ 7 files changed, 103 insertions(+), 136 deletions(-) diff --git a/package.json b/package.json index d6d7387..ea03774 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,14 @@ "license": "GPL-3.0", "dependencies": { "@rimiti/stimmy": "1.11.0", - "axios": "1.6.7", - "http-proxy-agent": "4.0.1", - "https-proxy-agent": "2.2.4" + "axios": "1.6.8", + "http-proxy-agent": "7.0.2", + "https-proxy-agent": "7.0.4" }, "devDependencies": { "@types/jest": "29.5.12", - "@typescript-eslint/eslint-plugin": "7.2.0", - "@typescript-eslint/parser": "7.2.0", + "@typescript-eslint/eslint-plugin": "7.3.1", + "@typescript-eslint/parser": "7.3.1", "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-prettier": "5.1.3", @@ -23,7 +23,7 @@ "nock": "13.5.4", "prettier": "3.2.5", "ts-jest": "29.1.2", - "typescript": "5.4.2" + "typescript": "5.4.3" }, "scripts": { "clean": "rm -rf dist coverage", diff --git a/src/classes/providers/base/types.ts b/src/classes/providers/base/types.ts index 6e78b22..3f575ec 100644 --- a/src/classes/providers/base/types.ts +++ b/src/classes/providers/base/types.ts @@ -1,4 +1,4 @@ -import * as HttpsProxyAgent from 'https-proxy-agent'; +import { HttpsProxyAgent } from 'https-proxy-agent'; import { HttpProxyAgent } from 'http-proxy-agent'; import { AxiosRequestConfig } from 'axios'; @@ -12,8 +12,8 @@ interface IBaseConfig { } interface ICreateProxyConfig { - httpsAgent: HttpsProxyAgent; - httpAgent: HttpProxyAgent; + httpsAgent: HttpsProxyAgent; + httpAgent: HttpProxyAgent; } interface IProviderConfig { diff --git a/src/classes/providers/bright-data/index.ts b/src/classes/providers/bright-data/index.ts index 8beac66..36efa68 100644 --- a/src/classes/providers/bright-data/index.ts +++ b/src/classes/providers/bright-data/index.ts @@ -1,6 +1,7 @@ import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from 'axios'; -import * as HttpsProxyAgent from 'https-proxy-agent'; +import { HttpsProxyAgent } from 'https-proxy-agent'; import { HttpProxyAgent } from 'http-proxy-agent'; +import { URL } from 'node:url'; import { ICreateProxyConfig, EStrategyMode } from '../base/types'; import { replacer } from '../../../utils/replacer'; import { Base } from '../base'; @@ -170,8 +171,8 @@ export class BrightData extends Base { this.country = country; return { - httpsAgent: new HttpsProxyAgent({ ...proxy, rejectUnauthorized: false }), - httpAgent: new HttpProxyAgent({ ...proxy, rejectUnauthorized: false }), + httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`)), + httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`)), }; } } diff --git a/src/classes/providers/proxyrack/index.ts b/src/classes/providers/proxyrack/index.ts index 1217955..acfa112 100644 --- a/src/classes/providers/proxyrack/index.ts +++ b/src/classes/providers/proxyrack/index.ts @@ -1,10 +1,11 @@ import { AxiosPromise, AxiosRequestConfig } from 'axios'; -import * as HttpsProxyAgent from 'https-proxy-agent'; +import { HttpsProxyAgent } from 'https-proxy-agent'; import { HttpProxyAgent } from 'http-proxy-agent'; import { EStrategyMode, ICreateProxyConfig } from '../base/types'; import { replacer } from '../../../utils/replacer'; import { Base } from '../base'; import { TProxyrackConfig } from './types'; +import { URL } from 'node:url'; /** * @description Proxyrack proxy provider. @@ -81,8 +82,8 @@ export class Proxyrack extends Base { }; return { - httpsAgent: new HttpsProxyAgent({ ...proxy, rejectUnauthorized: false }), - httpAgent: new HttpProxyAgent({ ...proxy, rejectUnauthorized: false }), + httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`)), + httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`)), }; } } diff --git a/src/classes/providers/shifter/index.ts b/src/classes/providers/shifter/index.ts index e072b65..86785bd 100644 --- a/src/classes/providers/shifter/index.ts +++ b/src/classes/providers/shifter/index.ts @@ -1,5 +1,5 @@ import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from 'axios'; -import * as HttpsProxyAgent from 'https-proxy-agent'; +import { HttpsProxyAgent } from 'https-proxy-agent'; import { HttpProxyAgent } from 'http-proxy-agent'; import { ICreateProxyConfig, EStrategyMode, IProviderConfig } from '../base/types'; import { Base } from '../base'; @@ -10,6 +10,7 @@ import { TShifterStrategy, TShifterCountryPortMapping, } from './types'; +import { URL } from 'node:url'; /** * @description Schifter proxy provider. @@ -127,8 +128,8 @@ export class Shifter extends Base { }; return { - httpsAgent: new HttpsProxyAgent({ ...proxy, rejectUnauthorized: false }), - httpAgent: new HttpProxyAgent({ ...proxy, rejectUnauthorized: false }), + httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`)), + httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`)), }; } } diff --git a/tsconfig.json b/tsconfig.json index 8aa2c5a..ee6130d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "sourceMap": true, "resolveJsonModule": true, "declaration": true, - "noUnusedLocals": true + "noUnusedLocals": true, + "skipLibCheck": true }, "include": ["src/**/*.ts"] } diff --git a/yarn.lock b/yarn.lock index c375ea3..a9e3cf2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -847,11 +847,6 @@ dependencies: "@sinonjs/commons" "^3.0.0" -"@tootallnate/once@1": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" - integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== - "@types/babel__core@^7.1.14": version "7.1.16" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.16.tgz#bc12c74b7d65e82d29876b5d0baf5c625ac58702" @@ -951,16 +946,16 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.2.0.tgz#5a5fcad1a7baed85c10080d71ad901f98c38d5b7" - integrity sha512-mdekAHOqS9UjlmyF/LSs6AIEvfceV749GFxoBAjwAv0nkevfKHWQFDMcBZWUiIC5ft6ePWivXoS36aKQ0Cy3sw== +"@typescript-eslint/eslint-plugin@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.3.1.tgz#0d8f38a6c8a1802139e62184ee7a68ed024f30a1" + integrity sha512-STEDMVQGww5lhCuNXVSQfbfuNII5E08QWkvAw5Qwf+bj2WT+JkG1uc+5/vXA3AOYMDHVOSpL+9rcbEUiHIm2dw== dependencies: "@eslint-community/regexpp" "^4.5.1" - "@typescript-eslint/scope-manager" "7.2.0" - "@typescript-eslint/type-utils" "7.2.0" - "@typescript-eslint/utils" "7.2.0" - "@typescript-eslint/visitor-keys" "7.2.0" + "@typescript-eslint/scope-manager" "7.3.1" + "@typescript-eslint/type-utils" "7.3.1" + "@typescript-eslint/utils" "7.3.1" + "@typescript-eslint/visitor-keys" "7.3.1" debug "^4.3.4" graphemer "^1.4.0" ignore "^5.2.4" @@ -968,47 +963,47 @@ semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/parser@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.2.0.tgz#44356312aea8852a3a82deebdacd52ba614ec07a" - integrity sha512-5FKsVcHTk6TafQKQbuIVkXq58Fnbkd2wDL4LB7AURN7RUOu1utVP+G8+6u3ZhEroW3DF6hyo3ZEXxgKgp4KeCg== +"@typescript-eslint/parser@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.3.1.tgz#c4ba7dc2744318a5e4506596cbc3a0086255c526" + integrity sha512-Rq49+pq7viTRCH48XAbTA+wdLRrB/3sRq4Lpk0oGDm0VmnjBrAOVXH/Laalmwsv2VpekiEfVFwJYVk6/e8uvQw== dependencies: - "@typescript-eslint/scope-manager" "7.2.0" - "@typescript-eslint/types" "7.2.0" - "@typescript-eslint/typescript-estree" "7.2.0" - "@typescript-eslint/visitor-keys" "7.2.0" + "@typescript-eslint/scope-manager" "7.3.1" + "@typescript-eslint/types" "7.3.1" + "@typescript-eslint/typescript-estree" "7.3.1" + "@typescript-eslint/visitor-keys" "7.3.1" debug "^4.3.4" -"@typescript-eslint/scope-manager@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.2.0.tgz#cfb437b09a84f95a0930a76b066e89e35d94e3da" - integrity sha512-Qh976RbQM/fYtjx9hs4XkayYujB/aPwglw2choHmf3zBjB4qOywWSdt9+KLRdHubGcoSwBnXUH2sR3hkyaERRg== +"@typescript-eslint/scope-manager@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.3.1.tgz#73fd0cb4211a7be23e49e5b6efec8820caa6ec36" + integrity sha512-fVS6fPxldsKY2nFvyT7IP78UO1/I2huG+AYu5AMjCT9wtl6JFiDnsv4uad4jQ0GTFzcUV5HShVeN96/17bTBag== dependencies: - "@typescript-eslint/types" "7.2.0" - "@typescript-eslint/visitor-keys" "7.2.0" + "@typescript-eslint/types" "7.3.1" + "@typescript-eslint/visitor-keys" "7.3.1" -"@typescript-eslint/type-utils@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.2.0.tgz#7be5c30e9b4d49971b79095a1181324ef6089a19" - integrity sha512-xHi51adBHo9O9330J8GQYQwrKBqbIPJGZZVQTHHmy200hvkLZFWJIFtAG/7IYTWUyun6DE6w5InDReePJYJlJA== +"@typescript-eslint/type-utils@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.3.1.tgz#cbf90d3d7e788466aa8a5c0ab3f46103f098aa0d" + integrity sha512-iFhaysxFsMDQlzJn+vr3OrxN8NmdQkHks4WaqD4QBnt5hsq234wcYdyQ9uquzJJIDAj5W4wQne3yEsYA6OmXGw== dependencies: - "@typescript-eslint/typescript-estree" "7.2.0" - "@typescript-eslint/utils" "7.2.0" + "@typescript-eslint/typescript-estree" "7.3.1" + "@typescript-eslint/utils" "7.3.1" debug "^4.3.4" ts-api-utils "^1.0.1" -"@typescript-eslint/types@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.2.0.tgz#0feb685f16de320e8520f13cca30779c8b7c403f" - integrity sha512-XFtUHPI/abFhm4cbCDc5Ykc8npOKBSJePY3a3s+lwumt7XWJuzP5cZcfZ610MIPHjQjNsOLlYK8ASPaNG8UiyA== +"@typescript-eslint/types@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.3.1.tgz#ae104de8efa4227a462c0874d856602c5994413c" + integrity sha512-2tUf3uWggBDl4S4183nivWQ2HqceOZh1U4hhu4p1tPiIJoRRXrab7Y+Y0p+dozYwZVvLPRI6r5wKe9kToF9FIw== -"@typescript-eslint/typescript-estree@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.2.0.tgz#5beda2876c4137f8440c5a84b4f0370828682556" - integrity sha512-cyxS5WQQCoBwSakpMrvMXuMDEbhOo9bNHHrNcEWis6XHx6KF518tkF1wBvKIn/tpq5ZpUYK7Bdklu8qY0MsFIA== +"@typescript-eslint/typescript-estree@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.3.1.tgz#598848195fad34c7aa73f548bd00a4d4e5f5e2bb" + integrity sha512-tLpuqM46LVkduWP7JO7yVoWshpJuJzxDOPYIVWUUZbW+4dBpgGeUdl/fQkhuV0A8eGnphYw3pp8d2EnvPOfxmQ== dependencies: - "@typescript-eslint/types" "7.2.0" - "@typescript-eslint/visitor-keys" "7.2.0" + "@typescript-eslint/types" "7.3.1" + "@typescript-eslint/visitor-keys" "7.3.1" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" @@ -1016,25 +1011,25 @@ semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/utils@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.2.0.tgz#fc8164be2f2a7068debb4556881acddbf0b7ce2a" - integrity sha512-YfHpnMAGb1Eekpm3XRK8hcMwGLGsnT6L+7b2XyRv6ouDuJU1tZir1GS2i0+VXRatMwSI1/UfcyPe53ADkU+IuA== +"@typescript-eslint/utils@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.3.1.tgz#fc28fd508ccf89495012561b7c02a6fdad162460" + integrity sha512-jIERm/6bYQ9HkynYlNZvXpzmXWZGhMbrOvq3jJzOSOlKXsVjrrolzWBjDW6/TvT5Q3WqaN4EkmcfdQwi9tDjBQ== dependencies: "@eslint-community/eslint-utils" "^4.4.0" "@types/json-schema" "^7.0.12" "@types/semver" "^7.5.0" - "@typescript-eslint/scope-manager" "7.2.0" - "@typescript-eslint/types" "7.2.0" - "@typescript-eslint/typescript-estree" "7.2.0" + "@typescript-eslint/scope-manager" "7.3.1" + "@typescript-eslint/types" "7.3.1" + "@typescript-eslint/typescript-estree" "7.3.1" semver "^7.5.4" -"@typescript-eslint/visitor-keys@7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.2.0.tgz#5035f177752538a5750cca1af6044b633610bf9e" - integrity sha512-c6EIQRHhcpl6+tO8EMR+kjkkV+ugUNXOmeASA1rlzkd8EPIriavpWoiEz1HR/VLhbVIdhqnV6E7JZm00cBDx2A== +"@typescript-eslint/visitor-keys@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.3.1.tgz#6ddef14a3ce2a79690f01176f5305c34d7b93d8c" + integrity sha512-9RMXwQF8knsZvfv9tdi+4D/j7dMG28X/wMJ8Jj6eOHyHWwDW4ngQJcqEczSsqIKKjFiLFr40Mnr7a5ulDD3vmw== dependencies: - "@typescript-eslint/types" "7.2.0" + "@typescript-eslint/types" "7.3.1" eslint-visitor-keys "^3.4.1" "@ungap/structured-clone@^1.2.0": @@ -1052,19 +1047,12 @@ acorn@^8.9.0: resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg== -agent-base@6: - version "6.0.2" - resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" - integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== +agent-base@^7.0.2, agent-base@^7.1.0: + version "7.1.0" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.0.tgz#536802b76bc0b34aa50195eb2442276d613e3434" + integrity sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg== dependencies: - debug "4" - -agent-base@^4.3.0: - version "4.3.0" - resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee" - integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg== - dependencies: - es6-promisify "^5.0.0" + debug "^4.3.4" ajv@^6.12.4: version "6.12.6" @@ -1137,12 +1125,12 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= -axios@1.6.7: - version "1.6.7" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7" - integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== +axios@1.6.8: + version "1.6.8" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" + integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== dependencies: - follow-redirects "^1.15.4" + follow-redirects "^1.15.6" form-data "^4.0.0" proxy-from-env "^1.1.0" @@ -1426,13 +1414,6 @@ debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2: dependencies: ms "2.1.2" -debug@^3.1.0: - version "3.2.7" - resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" - integrity sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ== - dependencies: - ms "^2.1.1" - debug@^4.3.1, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" @@ -1511,18 +1492,6 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -es6-promise@^4.0.3: - version "4.2.8" - resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a" - integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w== - -es6-promisify@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203" - integrity sha512-C+d6UdsYDk0lMebHNR4S2NybQMMngAOnOwYBQjTOiv0MkoJMP0Myw2mgpDLBcpfCmRLxyFqYhS/CfOENq4SJhQ== - dependencies: - es6-promise "^4.0.3" - escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -1770,10 +1739,10 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561" integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA== -follow-redirects@^1.15.4: - version "1.15.4" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.4.tgz#cdc7d308bf6493126b17ea2191ea0ccf3e535adf" - integrity sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw== +follow-redirects@^1.15.6: + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== form-data@^4.0.0: version "4.0.0" @@ -1901,22 +1870,21 @@ html-escaper@^2.0.0: resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453" integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg== -http-proxy-agent@4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz#8a8c8ef7f5932ccf953c296ca8291b95aa74aa3a" - integrity sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg== +http-proxy-agent@7.0.2: + version "7.0.2" + resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz#9a8b1f246866c028509486585f62b8f2c18c270e" + integrity sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig== dependencies: - "@tootallnate/once" "1" - agent-base "6" - debug "4" + agent-base "^7.1.0" + debug "^4.3.4" -https-proxy-agent@2.2.4: - version "2.2.4" - resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz#4ee7a737abd92678a293d9b34a1af4d0d08c787b" - integrity sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg== +https-proxy-agent@7.0.4: + version "7.0.4" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz#8e97b841a029ad8ddc8731f26595bad868cb4168" + integrity sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg== dependencies: - agent-base "^4.3.0" - debug "^3.1.0" + agent-base "^7.0.2" + debug "4" human-signals@^2.1.0: version "2.1.0" @@ -2630,11 +2598,6 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -ms@^2.1.1: - version "2.1.3" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" - integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== - natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -3146,10 +3109,10 @@ type-fest@^0.21.3: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -typescript@5.4.2: - version "5.4.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.2.tgz#0ae9cebcfae970718474fe0da2c090cad6577372" - integrity sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ== +typescript@5.4.3: + version "5.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff" + integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg== update-browserslist-db@^1.0.13: version "1.0.13" From 1828ff0089885f67d4ac26cb077e682f0bcd4c4f Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Mon, 25 Mar 2024 16:59:30 +0100 Subject: [PATCH 02/10] 5.0.0-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea03774..8c64aaa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tictactrip/luminator", - "version": "4.0.0", + "version": "5.0.0-0", "description": "Axios proxy provider agent.", "author": "Tictactrip ", "main": "dist/index.js", From 635394693784777f14bbee6cdc26d55ba7742178 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Mon, 25 Mar 2024 17:32:32 +0100 Subject: [PATCH 03/10] feat: format auth --- src/classes/providers/bright-data/index.ts | 8 ++++++-- src/classes/providers/proxyrack/index.ts | 8 ++++++-- src/classes/providers/shifter/index.ts | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/classes/providers/bright-data/index.ts b/src/classes/providers/bright-data/index.ts index 36efa68..257903a 100644 --- a/src/classes/providers/bright-data/index.ts +++ b/src/classes/providers/bright-data/index.ts @@ -171,8 +171,12 @@ export class BrightData extends Base { this.country = country; return { - httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`)), - httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`)), + httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.auth}@${proxy.host}:${proxy.port}`), { + rejectUnauthorized: false, + }), + httpAgent: new HttpProxyAgent(new URL(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), { + rejectUnauthorized: false, + }), }; } } diff --git a/src/classes/providers/proxyrack/index.ts b/src/classes/providers/proxyrack/index.ts index acfa112..8b22565 100644 --- a/src/classes/providers/proxyrack/index.ts +++ b/src/classes/providers/proxyrack/index.ts @@ -82,8 +82,12 @@ export class Proxyrack extends Base { }; return { - httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`)), - httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`)), + httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.auth}@${proxy.host}:${proxy.port}`), { + rejectUnauthorized: false, + }), + httpAgent: new HttpProxyAgent(new URL(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), { + rejectUnauthorized: false, + }), }; } } diff --git a/src/classes/providers/shifter/index.ts b/src/classes/providers/shifter/index.ts index 86785bd..36c0dd7 100644 --- a/src/classes/providers/shifter/index.ts +++ b/src/classes/providers/shifter/index.ts @@ -128,8 +128,12 @@ export class Shifter extends Base { }; return { - httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`)), - httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`)), + httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`), { + rejectUnauthorized: false, + }), + httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`), { + rejectUnauthorized: false, + }), }; } } From 9e8a89f61141d00c4e0c572c8604990151683da8 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Mon, 25 Mar 2024 17:33:47 +0100 Subject: [PATCH 04/10] 5.0.1-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c64aaa..94edecb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tictactrip/luminator", - "version": "5.0.0-0", + "version": "5.0.1-0", "description": "Axios proxy provider agent.", "author": "Tictactrip ", "main": "dist/index.js", From 1d5211c50075464d0f7639b9930db551add17e92 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Mon, 25 Mar 2024 17:49:11 +0100 Subject: [PATCH 05/10] feat: remove URL for string --- src/classes/providers/bright-data/index.ts | 9 +++------ src/classes/providers/proxyrack/index.ts | 9 +++------ src/classes/providers/shifter/index.ts | 9 +++------ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/classes/providers/bright-data/index.ts b/src/classes/providers/bright-data/index.ts index 257903a..9c3209a 100644 --- a/src/classes/providers/bright-data/index.ts +++ b/src/classes/providers/bright-data/index.ts @@ -1,7 +1,6 @@ import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from 'axios'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { HttpProxyAgent } from 'http-proxy-agent'; -import { URL } from 'node:url'; import { ICreateProxyConfig, EStrategyMode } from '../base/types'; import { replacer } from '../../../utils/replacer'; import { Base } from '../base'; @@ -171,12 +170,10 @@ export class BrightData extends Base { this.country = country; return { - httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.auth}@${proxy.host}:${proxy.port}`), { - rejectUnauthorized: false, - }), - httpAgent: new HttpProxyAgent(new URL(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), { - rejectUnauthorized: false, + httpsAgent: new HttpsProxyAgent(`https://${proxy.auth}@${proxy.host}:${proxy.port}`, { + rejectUnauthorized: true, }), + httpAgent: new HttpProxyAgent(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), }; } } diff --git a/src/classes/providers/proxyrack/index.ts b/src/classes/providers/proxyrack/index.ts index 8b22565..f65a558 100644 --- a/src/classes/providers/proxyrack/index.ts +++ b/src/classes/providers/proxyrack/index.ts @@ -5,7 +5,6 @@ import { EStrategyMode, ICreateProxyConfig } from '../base/types'; import { replacer } from '../../../utils/replacer'; import { Base } from '../base'; import { TProxyrackConfig } from './types'; -import { URL } from 'node:url'; /** * @description Proxyrack proxy provider. @@ -82,12 +81,10 @@ export class Proxyrack extends Base { }; return { - httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.auth}@${proxy.host}:${proxy.port}`), { - rejectUnauthorized: false, - }), - httpAgent: new HttpProxyAgent(new URL(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), { - rejectUnauthorized: false, + httpsAgent: new HttpsProxyAgent(`https://${proxy.auth}@${proxy.host}:${proxy.port}`, { + rejectUnauthorized: true, }), + httpAgent: new HttpProxyAgent(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), }; } } diff --git a/src/classes/providers/shifter/index.ts b/src/classes/providers/shifter/index.ts index 36c0dd7..9590ccc 100644 --- a/src/classes/providers/shifter/index.ts +++ b/src/classes/providers/shifter/index.ts @@ -10,7 +10,6 @@ import { TShifterStrategy, TShifterCountryPortMapping, } from './types'; -import { URL } from 'node:url'; /** * @description Schifter proxy provider. @@ -128,12 +127,10 @@ export class Shifter extends Base { }; return { - httpsAgent: new HttpsProxyAgent(new URL(`https://${proxy.host}:${proxy.port}`), { - rejectUnauthorized: false, - }), - httpAgent: new HttpProxyAgent(new URL(`http://${proxy.host}:${proxy.port}`), { - rejectUnauthorized: false, + httpsAgent: new HttpsProxyAgent(`https://${proxy.host}:${proxy.port}`, { + rejectUnauthorized: true, }), + httpAgent: new HttpProxyAgent(`http://${proxy.host}:${proxy.port}`), }; } } From 7a5548f9f37e030c79211c6f391a1f947ed2dfc3 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Mon, 25 Mar 2024 17:49:32 +0100 Subject: [PATCH 06/10] 5.0.2-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94edecb..72013a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tictactrip/luminator", - "version": "5.0.1-0", + "version": "5.0.2-0", "description": "Axios proxy provider agent.", "author": "Tictactrip ", "main": "dist/index.js", From 5bb4f6d16690b4d0ce086936a875167e72947d56 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 26 Mar 2024 10:13:18 +0100 Subject: [PATCH 07/10] feat: rejectUnauthorized: false --- src/classes/providers/bright-data/index.ts | 2 +- src/classes/providers/proxyrack/index.ts | 2 +- src/classes/providers/shifter/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/classes/providers/bright-data/index.ts b/src/classes/providers/bright-data/index.ts index 9c3209a..d65f474 100644 --- a/src/classes/providers/bright-data/index.ts +++ b/src/classes/providers/bright-data/index.ts @@ -171,7 +171,7 @@ export class BrightData extends Base { return { httpsAgent: new HttpsProxyAgent(`https://${proxy.auth}@${proxy.host}:${proxy.port}`, { - rejectUnauthorized: true, + rejectUnauthorized: false, }), httpAgent: new HttpProxyAgent(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), }; diff --git a/src/classes/providers/proxyrack/index.ts b/src/classes/providers/proxyrack/index.ts index f65a558..df2d9c6 100644 --- a/src/classes/providers/proxyrack/index.ts +++ b/src/classes/providers/proxyrack/index.ts @@ -82,7 +82,7 @@ export class Proxyrack extends Base { return { httpsAgent: new HttpsProxyAgent(`https://${proxy.auth}@${proxy.host}:${proxy.port}`, { - rejectUnauthorized: true, + rejectUnauthorized: false, }), httpAgent: new HttpProxyAgent(`http://${proxy.auth}@${proxy.host}:${proxy.port}`), }; diff --git a/src/classes/providers/shifter/index.ts b/src/classes/providers/shifter/index.ts index 9590ccc..0f501d4 100644 --- a/src/classes/providers/shifter/index.ts +++ b/src/classes/providers/shifter/index.ts @@ -128,7 +128,7 @@ export class Shifter extends Base { return { httpsAgent: new HttpsProxyAgent(`https://${proxy.host}:${proxy.port}`, { - rejectUnauthorized: true, + rejectUnauthorized: false, }), httpAgent: new HttpProxyAgent(`http://${proxy.host}:${proxy.port}`), }; From fae4cfed609f230aae7933c9e846a33959566409 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 26 Mar 2024 10:39:19 +0100 Subject: [PATCH 08/10] tests: test fixed --- __tests__/unit/bright-data.ts | 44 +++++++++++++++++++---------------- __tests__/unit/shifter.ts | 32 ++++++++----------------- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/__tests__/unit/bright-data.ts b/__tests__/unit/bright-data.ts index a3bd444..2b349fd 100644 --- a/__tests__/unit/bright-data.ts +++ b/__tests__/unit/bright-data.ts @@ -93,11 +93,12 @@ describe('BrightData', () => { 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'); - expect(agent.axios.defaults.httpsAgent.proxy.port).toBe(22225); - expect(agent.axios.defaults.httpsAgent.proxy.rejectUnauthorized).toBe(false); - expect(agent.axios.defaults.httpsAgent.proxy.auth).toMatch( - new RegExp(`${proxy.username}-session-([0-9])*-country-(${regexPatternAllCountries}):${proxy.password}`), + expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io:22225'); + expect(agent.axios.defaults.httpsAgent.proxy.port).toBe('22225'); + expect(agent.axios.defaults.httpsAgent.proxy.href).toMatch( + new RegExp( + `https://${proxy.username}-session-([0-9])*-country-(${regexPatternAllCountries}):${proxy.password}@zproxy.lum-superproxy.io:22225/`, + ), ); }); @@ -107,11 +108,12 @@ describe('BrightData', () => { 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'); - expect(agent.axios.defaults.httpsAgent.proxy.port).toBe(22225); - expect(agent.axios.defaults.httpsAgent.proxy.rejectUnauthorized).toBe(false); - expect(agent.axios.defaults.httpsAgent.proxy.auth).toMatch( - new RegExp(`${proxy.username}-session-([0-9])*-country-fr:${proxy.password}`), + expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io:22225'); + expect(agent.axios.defaults.httpsAgent.proxy.port).toBe('22225'); + expect(agent.axios.defaults.httpsAgent.proxy.href).toMatch( + new RegExp( + `https://${proxy.username}-session-([0-9])*-country-fr:${proxy.password}@zproxy.lum-superproxy.io:22225/`, + ), ); }); @@ -123,11 +125,12 @@ describe('BrightData', () => { 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'); - expect(agent.axios.defaults.httpsAgent.proxy.port).toBe(22225); - expect(agent.axios.defaults.httpsAgent.proxy.rejectUnauthorized).toBe(false); - expect(agent.axios.defaults.httpsAgent.proxy.auth).toMatch( - new RegExp(`${proxy.username}-session-${sessionId}-country-fr:${proxy.password}`), + expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io:22225'); + expect(agent.axios.defaults.httpsAgent.proxy.port).toBe('22225'); + expect(agent.axios.defaults.httpsAgent.proxy.href).toMatch( + new RegExp( + `https://${proxy.username}-session-${sessionId}-country-fr:${proxy.password}@zproxy.lum-superproxy.io:22225/`, + ), ); }); @@ -139,11 +142,12 @@ describe('BrightData', () => { 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'); - expect(agent.axios.defaults.httpsAgent.proxy.port).toBe(22225); - expect(agent.axios.defaults.httpsAgent.proxy.rejectUnauthorized).toBe(false); - expect(agent.axios.defaults.httpsAgent.proxy.auth).toMatch( - new RegExp(`${proxy.username}-session-${sessionId}-country-(${regexPatternAllCountries}):${proxy.password}`), + expect(agent.axios.defaults.httpsAgent.proxy.host).toBe('zproxy.lum-superproxy.io:22225'); + expect(agent.axios.defaults.httpsAgent.proxy.port).toBe('22225'); + expect(agent.axios.defaults.httpsAgent.proxy.href).toMatch( + new RegExp( + `https://${proxy.username}-session-${sessionId}-country-(${regexPatternAllCountries}):${proxy.password}@zproxy.lum-superproxy.io:22225/`, + ), ); }); diff --git a/__tests__/unit/shifter.ts b/__tests__/unit/shifter.ts index 00ad4bb..f35d1f5 100644 --- a/__tests__/unit/shifter.ts +++ b/__tests__/unit/shifter.ts @@ -62,21 +62,15 @@ describe('Shifter', () => { it('creates a properly formed proxy agent', () => { const agent: Shifter = shifter.setIp(); - const expectedProxyAgent = { - host: proxy.host, - port: expect.any(Number), - rejectUnauthorized: false, - }; - - expect(agent.axios.defaults.httpsAgent.proxy).toMatchObject(expectedProxyAgent); - expect(agent.axios.defaults.httpAgent.proxy).toMatchObject(expectedProxyAgent); + expect(agent.axios.defaults.httpsAgent.proxy).toMatchSnapshot(); + expect(agent.axios.defaults.httpAgent.proxy).toMatchSnapshot(); }); it('creates a proxy agent having a random port among the given mapping', () => { const agent: Shifter = shifter.setIp(); - expect(getMappingPorts(mapping)).toEqual(expect.arrayContaining([agent.axios.defaults.httpsAgent.proxy.port])); - expect(getMappingPorts(mapping)).toEqual(expect.arrayContaining([agent.axios.defaults.httpAgent.proxy.port])); + expect(getMappingPorts(mapping).includes(Number(agent.axios.defaults.httpsAgent.proxy.port))).toBeTruthy(); + expect(getMappingPorts(mapping).includes(Number(agent.axios.defaults.httpAgent.proxy.port))).toBeTruthy(); }); }); @@ -84,22 +78,16 @@ describe('Shifter', () => { it('creates a properly formed proxy agent', () => { const agent: Shifter = shifter.setIp(); - const expectedProxyAgent = { - host: proxy.host, - port: expect.any(Number), - rejectUnauthorized: false, - }; - - expect(agent.axios.defaults.httpsAgent.proxy).toMatchObject(expectedProxyAgent); - expect(agent.axios.defaults.httpAgent.proxy).toMatchObject(expectedProxyAgent); + expect(agent.axios.defaults.httpsAgent.proxy).toMatchSnapshot(); + expect(agent.axios.defaults.httpAgent.proxy).toMatchSnapshot(); }); it('create a proxy agent having a port matching one of the options in the mapping', () => { const country: EShifterCountry = EShifterCountry.FRANCE; const agent: Shifter = shifter.setIp({ countries: [country] }); - expect(mapping[country]).toEqual(expect.arrayContaining([agent.axios.defaults.httpsAgent.proxy.port])); - expect(mapping[country]).toEqual(expect.arrayContaining([agent.axios.defaults.httpAgent.proxy.port])); + expect(mapping[country].includes(Number(agent.axios.defaults.httpsAgent.proxy.port))).toBeTruthy(); + expect(mapping[country].includes(Number(agent.axios.defaults.httpAgent.proxy.port))).toBeTruthy(); }); it('create a proxy agent having a port matching several of the options in the mapping', () => { @@ -107,8 +95,8 @@ describe('Shifter', () => { const mappedPorts: number[] = countries.map((c) => mapping[c]).reduce((acc, c) => [...acc, ...c], []); const agent: Shifter = shifter.setIp({ countries: countries }); - expect(mappedPorts).toEqual(expect.arrayContaining([agent.axios.defaults.httpsAgent.proxy.port])); - expect(mappedPorts).toEqual(expect.arrayContaining([agent.axios.defaults.httpAgent.proxy.port])); + expect(mappedPorts.includes(Number(agent.axios.defaults.httpsAgent.proxy.port))).toBeTruthy(); + expect(mappedPorts.includes(Number(agent.axios.defaults.httpAgent.proxy.port))).toBeTruthy(); }); }); }); From 698d0d0e977994d71b3ac8d28abd743eedcf3599 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 26 Mar 2024 10:40:46 +0100 Subject: [PATCH 09/10] tests: snapshot included --- __tests__/unit/__snapshots__/shifter.ts.snap | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 __tests__/unit/__snapshots__/shifter.ts.snap diff --git a/__tests__/unit/__snapshots__/shifter.ts.snap b/__tests__/unit/__snapshots__/shifter.ts.snap new file mode 100644 index 0000000..1ef7027 --- /dev/null +++ b/__tests__/unit/__snapshots__/shifter.ts.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Shifter #setIp when given one or more specific countries to target creates a properly formed proxy agent 1`] = `"https://50.14.52.12:12356/"`; + +exports[`Shifter #setIp when given one or more specific countries to target creates a properly formed proxy agent 2`] = `"http://50.14.52.12:12356/"`; + +exports[`Shifter #setIp when not given any specific country to target creates a properly formed proxy agent 1`] = `"https://50.14.52.12:12356/"`; + +exports[`Shifter #setIp when not given any specific country to target creates a properly formed proxy agent 2`] = `"http://50.14.52.12:12356/"`; From 27da30f94ff08f58a47632309c16f051a8dbb961 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 26 Mar 2024 10:53:15 +0100 Subject: [PATCH 10/10] tests: test updated --- __tests__/unit/__snapshots__/shifter.ts.snap | 9 --------- __tests__/unit/shifter.ts | 8 ++++---- 2 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 __tests__/unit/__snapshots__/shifter.ts.snap diff --git a/__tests__/unit/__snapshots__/shifter.ts.snap b/__tests__/unit/__snapshots__/shifter.ts.snap deleted file mode 100644 index 1ef7027..0000000 --- a/__tests__/unit/__snapshots__/shifter.ts.snap +++ /dev/null @@ -1,9 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Shifter #setIp when given one or more specific countries to target creates a properly formed proxy agent 1`] = `"https://50.14.52.12:12356/"`; - -exports[`Shifter #setIp when given one or more specific countries to target creates a properly formed proxy agent 2`] = `"http://50.14.52.12:12356/"`; - -exports[`Shifter #setIp when not given any specific country to target creates a properly formed proxy agent 1`] = `"https://50.14.52.12:12356/"`; - -exports[`Shifter #setIp when not given any specific country to target creates a properly formed proxy agent 2`] = `"http://50.14.52.12:12356/"`; diff --git a/__tests__/unit/shifter.ts b/__tests__/unit/shifter.ts index f35d1f5..754e5ee 100644 --- a/__tests__/unit/shifter.ts +++ b/__tests__/unit/shifter.ts @@ -62,8 +62,8 @@ describe('Shifter', () => { it('creates a properly formed proxy agent', () => { const agent: Shifter = shifter.setIp(); - expect(agent.axios.defaults.httpsAgent.proxy).toMatchSnapshot(); - expect(agent.axios.defaults.httpAgent.proxy).toMatchSnapshot(); + expect(agent.axios.defaults.httpsAgent.proxy.toString()).toMatch(new RegExp(`https://${proxy.host}:[0-9]+`)); + expect(agent.axios.defaults.httpAgent.proxy.toString()).toMatch(new RegExp(`http://${proxy.host}:[0-9]+`)); }); it('creates a proxy agent having a random port among the given mapping', () => { @@ -78,8 +78,8 @@ describe('Shifter', () => { it('creates a properly formed proxy agent', () => { const agent: Shifter = shifter.setIp(); - expect(agent.axios.defaults.httpsAgent.proxy).toMatchSnapshot(); - expect(agent.axios.defaults.httpAgent.proxy).toMatchSnapshot(); + expect(agent.axios.defaults.httpsAgent.proxy.toString()).toMatch(new RegExp(`https://${proxy.host}:[0-9]+`)); + expect(agent.axios.defaults.httpAgent.proxy.toString()).toMatch(new RegExp(`http://${proxy.host}:[0-9]+`)); }); it('create a proxy agent having a port matching one of the options in the mapping', () => {