🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@testring/http-api

Package Overview
Dependencies
Maintainers
1
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testring/http-api - npm Package Compare versions

Comparing version
0.5.14
to
0.5.15
+24
-12
dist/abstract-http-client.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -16,20 +17,23 @@ });

class AbstractHttpClient {
constructor(transportInstance, params) {
constructor(transportInstance, params = {}) {
this.transportInstance = transportInstance;
this.params = params;
this.loggerClient = logger_1.loggerClient.withPrefix('[http client]');
this.params = {
httpThrottle: 0,
};
this.queueRunning = false;
this.requestQueue = new utils_1.Queue();
this.params = Object.assign(this.params, params);
}
post(options, cookieJar) {
return this.pushToQueue(Object.assign({}, options, { method: 'POST' }), cookieJar);
return this.pushToQueue(Object.assign(Object.assign({}, options), { method: 'POST' }), cookieJar);
}
get(options, cookieJar) {
return this.pushToQueue(Object.assign({}, options, { method: 'GET' }), cookieJar);
return this.pushToQueue(Object.assign(Object.assign({}, options), { method: 'GET' }), cookieJar);
}
delete(options, cookieJar) {
return this.pushToQueue(Object.assign({}, options, { method: 'DELETE' }), cookieJar);
return this.pushToQueue(Object.assign(Object.assign({}, options), { method: 'DELETE' }), cookieJar);
}
put(options, cookieJar) {
return this.pushToQueue(Object.assign({}, options, { method: 'PUT' }), cookieJar);
return this.pushToQueue(Object.assign(Object.assign({}, options), { method: 'PUT' }), cookieJar);
}

@@ -46,4 +50,9 @@ send(options, cookieJar) {

isValidRequest(request) {
return (this.isValidData(request) && request.hasOwnProperty('url'));
return (this.isValidData(request) && Object.prototype.hasOwnProperty.call(request, 'url'));
}
throttleDelay() {
return __awaiter(this, void 0, void 0, function* () {
yield new Promise(resolve => setTimeout(resolve, this.params.httpThrottle));
});
}
runQueue() {

@@ -59,3 +68,3 @@ return __awaiter(this, void 0, void 0, function* () {

yield item();
yield new Promise(resolve => setTimeout(resolve, this.params.httpThrottle));
yield this.throttleDelay();
}

@@ -67,12 +76,15 @@ }

pushToQueue(requestParameters, cookieJar) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const sendRequest = () => this.sendRequest(requestParameters, cookieJar).then(resolve, reject);
this.requestQueue.push(sendRequest);
// TODO (flops) move throttling into HttpServer
this.runQueue();
}));
});
}
// TODO (flops) refactor this function
// eslint-disable-next-line sonarjs/cognitive-complexity
sendRequest(requestParameters, cookieJar) {
return __awaiter(this, void 0, void 0, function* () {
if (cookieJar) {
requestParameters = Object.assign({}, requestParameters, { cookies: cookieJar.getCookies(requestParameters.url).map(toString) });
requestParameters = Object.assign(Object.assign({}, requestParameters), { cookies: cookieJar.getCookies(requestParameters.url).map(toString) });
}

@@ -79,0 +91,0 @@ if (!this.isValidRequest(requestParameters)) {

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -8,0 +9,0 @@ });

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -34,3 +35,3 @@ });

body: response.body,
cookies: cookies,
cookies,
});

@@ -37,0 +38,0 @@ function requestFunction(request) {

{
"name": "@testring/http-api",
"version": "0.5.14",
"version": "0.5.15",
"main": "./dist/index.js",

@@ -13,9 +13,9 @@ "types": "./src/index.ts",

"dependencies": {
"@testring/logger": "0.5.14",
"@testring/pluggable-module": "0.5.14",
"@testring/test-utils": "0.5.14",
"@testring/transport": "0.5.14",
"@testring/types": "0.5.14",
"@testring/utils": "0.5.14",
"@types/node": "10.5.6",
"@testring/logger": "0.5.15",
"@testring/pluggable-module": "0.5.15",
"@testring/test-utils": "0.5.15",
"@testring/transport": "0.5.15",
"@testring/types": "0.5.15",
"@testring/utils": "0.5.15",
"@types/node": "12.12.21",
"@types/request-promise-native": "1.0.15",

@@ -22,0 +22,0 @@ "@types/tough-cookie": "2.3.3",

@@ -26,6 +26,12 @@ import {

private params: HttpClientParams = {
httpThrottle: 0,
};
private queueRunning = false;
constructor(protected transportInstance: ITransport, private params: HttpClientParams) {
constructor(protected transportInstance: ITransport, params: Partial<HttpClientParams> = {}) {
this.requestQueue = new Queue();
this.params = Object.assign<HttpClientParams, Partial<HttpClientParams>>(this.params, params);
}

@@ -62,5 +68,9 @@

private isValidRequest(request: IHttpRequest): boolean {
return (this.isValidData(request) && request.hasOwnProperty('url'));
return (this.isValidData(request) && Object.prototype.hasOwnProperty.call(request,'url'));
}
private async throttleDelay() {
await new Promise(resolve => setTimeout(resolve, this.params.httpThrottle));
}
private async runQueue(): Promise<void> {

@@ -78,3 +88,3 @@ if (this.queueRunning) {

await item();
await new Promise(resolve => setTimeout(resolve, this.params.httpThrottle));
await this.throttleDelay();
}

@@ -87,5 +97,7 @@ }

private pushToQueue(requestParameters: IHttpRequest, cookieJar?: IHttpCookieJar): Promise<any> {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
const sendRequest = () => this.sendRequest(requestParameters, cookieJar).then(resolve, reject);
this.requestQueue.push(sendRequest);
// TODO (flops) move throttling into HttpServer
this.runQueue();

@@ -95,2 +107,4 @@ });

// TODO (flops) refactor this function
// eslint-disable-next-line sonarjs/cognitive-complexity
private async sendRequest(requestParameters: IHttpRequest, cookieJar?: IHttpCookieJar): Promise<any> {

@@ -136,3 +150,3 @@ if (cookieJar) {

}
}
},
);

@@ -153,3 +167,3 @@

}
}
},
);

@@ -156,0 +170,0 @@

@@ -24,3 +24,3 @@ import { IHttpRequest, IHttpResponse } from '@testring/types';

private transportInstance: ITransport,
private request: MakeRequest
private request: MakeRequest,
) {

@@ -41,3 +41,3 @@ super([

this.makeRequest(data, src);
}
},
);

@@ -44,0 +44,0 @@ }

@@ -32,3 +32,3 @@ import { IHttpRequest, IHttpResponse } from '@testring/types';

body: response.body,
cookies: cookies,
cookies,
});

@@ -35,0 +35,0 @@