diff --git a/__tests__/unit/shifter.ts b/__tests__/unit/shifter.ts index b3a5156..00ad4bb 100644 --- a/__tests__/unit/shifter.ts +++ b/__tests__/unit/shifter.ts @@ -30,8 +30,8 @@ describe('Shifter', () => { }; describe('#constructor', () => { - describe('when is not given a strategy with a single country', () => { - it('should throw an error if a strategy has been set without any countries', async () => { + describe('when is not given a mapping with a single country', () => { + it('should throw an error if a mapping has been set without any countries', async () => { let error: Error; try { diff --git a/src/classes/providers/base/types.ts b/src/classes/providers/base/types.ts index f1b2f2f..7d013d8 100644 --- a/src/classes/providers/base/types.ts +++ b/src/classes/providers/base/types.ts @@ -3,6 +3,7 @@ import { HttpProxyAgent } from 'http-proxy-agent'; import { AxiosRequestConfig } from 'axios'; enum EStrategyMode { + MANUAL = 'MANUAL', CHANGE_IP_EVERY_REQUESTS = 'CHANGE_IP_EVERY_REQUESTS', } diff --git a/src/classes/providers/shifter/index.ts b/src/classes/providers/shifter/index.ts index 0a9d49e..e072b65 100644 --- a/src/classes/providers/shifter/index.ts +++ b/src/classes/providers/shifter/index.ts @@ -31,8 +31,10 @@ export class Shifter extends Base { this.config = config; this.strategy = config.strategy; - if (this.strategy && this.strategy.mode === EStrategyMode.CHANGE_IP_EVERY_REQUESTS) { - this.isCountryPortMappingEmpty(this.strategy.mapping); + this.isCountryPortMappingEmpty(this.strategy.mapping); + + if (!this.strategy.mode) { + this.strategy.mode == EStrategyMode.CHANGE_IP_EVERY_REQUESTS; } } diff --git a/src/classes/providers/shifter/types.ts b/src/classes/providers/shifter/types.ts index f56a132..dd396e5 100644 --- a/src/classes/providers/shifter/types.ts +++ b/src/classes/providers/shifter/types.ts @@ -1,8 +1,6 @@ import { AxiosRequestConfig } from 'axios'; import { IProviderConfig, EStrategyMode } from '../base/types'; -type TShifterStrategy = TShifterStrategyChangeIpEveryRequest; - interface IShifterConfig { proxy: IProviderConfig; axiosConfig?: AxiosRequestConfig; @@ -255,8 +253,8 @@ interface IShifterChangeIp { type TShifterCountryPortMapping = Partial>; -type TShifterStrategyChangeIpEveryRequest = { - mode: EStrategyMode.CHANGE_IP_EVERY_REQUESTS; +type TShifterStrategy = { + mode?: EStrategyMode.CHANGE_IP_EVERY_REQUESTS | EStrategyMode.MANUAL; mapping?: TShifterCountryPortMapping; };