Compare commits

...

6 Commits

Author SHA1 Message Date
e55a521395 1.1.55 2022-02-15 19:02:44 +01:00
06fc279caf fix(core): update 2022-02-15 19:02:43 +01:00
e89e317bbc 1.1.54 2022-02-15 18:57:42 +01:00
d182832e47 fix(core): update 2022-02-15 18:57:42 +01:00
92059a50de 1.1.53 2022-02-15 18:53:02 +01:00
db80f2df7e fix(core): update 2022-02-15 18:53:02 +01:00
10 changed files with 18997 additions and 3912 deletions

View File

@ -12,6 +12,9 @@ stages:
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
@ -36,6 +39,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
"type": "node-terminal"
}
]
}

View File

@ -12,7 +12,7 @@
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartrequest",
"shortDescription": "dropin replacement for request",
"description": "dropin replacement for request",
"npmPackagename": "@pushrocks/smartrequest",
"license": "MIT"
}

22799
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartrequest",
"version": "1.1.52",
"version": "1.1.55",
"private": false,
"description": "dropin replacement for request",
"main": "dist_ts/index.js",
@ -23,17 +23,17 @@
},
"homepage": "https://gitlab.com/pushrocks/smartrequest#README",
"dependencies": {
"@pushrocks/smartpromise": "^3.1.5",
"@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smarturl": "^2.0.1",
"agentkeepalive": "^4.1.4",
"agentkeepalive": "^4.2.0",
"form-data": "^4.0.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.54",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^15.3.0",
"@gitzone/tsbuild": "^2.1.29",
"@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.64",
"@pushrocks/tapbundle": "^4.0.7",
"@types/node": "^17.0.18",
"tslint": "^6.1.3",
"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';
tap.test('should request a html document over https', async () => {
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');
await expect(smartrequest.getJson('https://encrypted.google.com/'))
.to.eventually.property('body')
.be.a('string');
await expectAsync(smartrequest.getJson('https://encrypted.google.com/')).toHaveProperty('body');
});
tap.test('should request a JSON document over https', async () => {
await expect(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
.to.eventually.property('body')
await expectAsync(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
.property('body')
.property('id')
.equal(1);
.toEqual(1);
});
tap.skip.test('should post a JSON document over http', async () => {
await expect(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
.to.eventually.property('body')
await expectAsync(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
.property('body')
.property('md5')
.equal('fa4c6baa0812e5b5c80ed8885e55a8a6');
.toEqual('fa4c6baa0812e5b5c80ed8885e55a8a6');
});
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 response = await request(domainArg, optionsArg, true);
const data = [];
const data: Array<Buffer> = [];
response
.on('data', function (chunk) {
.on('data', function (chunk: Buffer) {
data.push(chunk);
})
.on('end', function () {

View File

@ -66,3 +66,33 @@ export const postFormData = async (
const response = await request(urlArg, requestOptions);
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

@ -5,5 +5,5 @@ export interface ISmartRequestOptions extends https.RequestOptions {
keepAlive?: boolean;
requestBody?: any;
autoJsonParse?: boolean;
queryParams?: {[key: string]: string}
queryParams?: { [key: string]: string };
}

View File

@ -104,7 +104,7 @@ export let request = async (
// parse url
const parsedUrl = plugins.smarturl.Smarturl.createFromUrl(urlArg, {
searchParams: optionsArg.queryParams || {}
searchParams: optionsArg.queryParams || {},
});
optionsArg.hostname = parsedUrl.hostname;
if (parsedUrl.port) {
@ -158,7 +158,7 @@ export let request = async (
// lets write the requestBody
if (optionsArg.requestBody) {
if (optionsArg.requestBody instanceof plugins.formData) {
optionsArg.requestBody.pipe(requestToFire).on('finish', (event) => {
optionsArg.requestBody.pipe(requestToFire).on('finish', (event: any) => {
requestToFire.end();
});
} else {