fix(core): update

This commit is contained in:
Philipp Kunz 2022-02-15 18:53:02 +01:00
parent 145505b891
commit db80f2df7e
6 changed files with 18984 additions and 3886 deletions

22773
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,17 +23,17 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartrequest#README", "homepage": "https://gitlab.com/pushrocks/smartrequest#README",
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.1.5", "@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smarturl": "^2.0.1", "@pushrocks/smarturl": "^2.0.1",
"agentkeepalive": "^4.1.4", "agentkeepalive": "^4.2.0",
"form-data": "^4.0.0" "form-data": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.29",
"@gitzone/tsrun": "^1.2.12", "@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.54", "@gitzone/tstest": "^1.0.64",
"@pushrocks/tapbundle": "^3.2.14", "@pushrocks/tapbundle": "^4.0.7",
"@types/node": "^15.3.0", "@types/node": "^17.0.18",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },

View File

@ -1,31 +1,23 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
import * as smartrequest from '../ts/index'; import * as smartrequest from '../ts/index';
tap.test('should request a html document over https', async () => { tap.test('should request a html document over https', async () => {
await expect(smartrequest.getJson('https://encrypted.google.com/')) await expectAsync(smartrequest.getJson('https://encrypted.google.com/')).toHaveProperty('body')
.to.eventually.property('body')
.be.a('string');
await expect(smartrequest.getJson('https://encrypted.google.com/'))
.to.eventually.property('body')
.be.a('string');
await expect(smartrequest.getJson('https://encrypted.google.com/'))
.to.eventually.property('body')
.be.a('string');
}); });
tap.test('should request a JSON document over https', async () => { tap.test('should request a JSON document over https', async () => {
await expect(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1')) await expectAsync(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
.to.eventually.property('body') .property('body')
.property('id') .property('id')
.equal(1); .toEqual(1);
}); });
tap.skip.test('should post a JSON document over http', async () => { tap.skip.test('should post a JSON document over http', async () => {
await expect(smartrequest.postJson('http://md5.jsontest.com/?text=example_text')) await expectAsync(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
.to.eventually.property('body') .property('body')
.property('md5') .property('md5')
.equal('fa4c6baa0812e5b5c80ed8885e55a8a6'); .toEqual('fa4c6baa0812e5b5c80ed8885e55a8a6');
}); });
tap.skip.test('should deal with unix socks', async () => { tap.skip.test('should deal with unix socks', async () => {

View File

@ -14,10 +14,10 @@ export const getBinary = async (
}; };
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
const response = await request(domainArg, optionsArg, true); const response = await request(domainArg, optionsArg, true);
const data = []; const data: Array<Buffer> = [];
response response
.on('data', function (chunk) { .on('data', function (chunk: Buffer) {
data.push(chunk); data.push(chunk);
}) })
.on('end', function () { .on('end', function () {

View File

@ -66,3 +66,32 @@ export const postFormData = async (
const response = await request(urlArg, requestOptions); const response = await request(urlArg, requestOptions);
return response; return response;
}; };
export const postFormDataUrlEncoded = async (
urlArg: string,
optionsArg: interfaces.ISmartRequestOptions = {},
payloadArg: {key: string, content: string}[]
) => {
const requestOptions = {
...optionsArg,
method: 'POST',
headers: {
...optionsArg.headers,
'content-type': 'application/x-www-form-urlencoded'
}
};
let resultString = '';
for (const keyContentPair of payloadArg) {
if (resultString) {
resultString += '&';
}
resultString += `${encodeURIComponent(keyContentPair.key)}=${encodeURIComponent(keyContentPair.content)}`;
}
// lets fire the actual request for sending the formdata
const response = await request(urlArg + resultString, requestOptions);
return response;
};

View File

@ -158,7 +158,7 @@ export let request = async (
// lets write the requestBody // lets write the requestBody
if (optionsArg.requestBody) { if (optionsArg.requestBody) {
if (optionsArg.requestBody instanceof plugins.formData) { if (optionsArg.requestBody instanceof plugins.formData) {
optionsArg.requestBody.pipe(requestToFire).on('finish', (event) => { optionsArg.requestBody.pipe(requestToFire).on('finish', (event: any) => {
requestToFire.end(); requestToFire.end();
}); });
} else { } else {