BREAKING CHANGE(core): switch to support binary files in future versions
This commit is contained in:
parent
a8e6462f55
commit
9a9523cc13
18
.gitignore
vendored
18
.gitignore
vendored
@ -1,6 +1,22 @@
|
|||||||
.nogit/
|
.nogit/
|
||||||
node_modules/
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
.yarn/
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,4 +1,4 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
@ -78,19 +78,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command tslint -c tslint.json ./ts/**/*.ts
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -109,10 +101,10 @@ pages:
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
@ -2,5 +2,15 @@
|
|||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "webrequest",
|
||||||
|
"shortDescription": "securely request from browsers",
|
||||||
|
"npmPackagename": "@pushrocks/webrequest",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
12
package.json
12
package.json
@ -24,5 +24,15 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.2"
|
"@pushrocks/smartdelay": "^2.0.2"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
26
readme.md
Normal file
26
readme.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# @pushrocks/webrequest
|
||||||
|
securely request from browsers
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/webrequest)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/webrequest)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/webrequest)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/webrequest/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[![build status](https://gitlab.com/pushrocks/webrequest/badges/master/build.svg)](https://gitlab.com/pushrocks/webrequest/commits/master)
|
||||||
|
[![coverage report](https://gitlab.com/pushrocks/webrequest/badges/master/coverage.svg)](https://gitlab.com/pushrocks/webrequest/commits/master)
|
||||||
|
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/webrequest.svg)](https://www.npmjs.com/package/@pushrocks/webrequest)
|
||||||
|
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/webrequest/badge.svg)](https://snyk.io/test/npm/@pushrocks/webrequest)
|
||||||
|
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
|
60
test/test.ts
60
test/test.ts
@ -5,13 +5,12 @@ import * as fetch from 'node-fetch';
|
|||||||
declare global {
|
declare global {
|
||||||
namespace NodeJS {
|
namespace NodeJS {
|
||||||
interface Global {
|
interface Global {
|
||||||
fetch: any;
|
fetch: any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
global.fetch = fetch;
|
global.fetch = fetch;
|
||||||
|
|
||||||
|
|
||||||
// test dependencies
|
// test dependencies
|
||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
|
|
||||||
@ -24,43 +23,52 @@ tap.test('setup test server', async () => {
|
|||||||
port: 2345
|
port: 2345
|
||||||
});
|
});
|
||||||
|
|
||||||
testServer.addRoute('/apiroute1', new smartexpress.Handler("GET", (req, res) => {
|
testServer.addRoute(
|
||||||
res.status(429);
|
'/apiroute1',
|
||||||
res.end();
|
new smartexpress.Handler('GET', (req, res) => {
|
||||||
}));
|
res.status(429);
|
||||||
|
res.end();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
testServer.addRoute('/apiroute2', new smartexpress.Handler("GET", (req, res) => {
|
testServer.addRoute(
|
||||||
res.status(500);
|
'/apiroute2',
|
||||||
res.end();
|
new smartexpress.Handler('GET', (req, res) => {
|
||||||
}));
|
res.status(500);
|
||||||
|
res.end();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
testServer.addRoute('/apiroute3', new smartexpress.Handler("GET", (req, res) => {
|
testServer.addRoute(
|
||||||
res.status(200);
|
'/apiroute3',
|
||||||
res.send({
|
new smartexpress.Handler('GET', (req, res) => {
|
||||||
hithere: 'hi'
|
res.status(200);
|
||||||
});
|
res.send({
|
||||||
}));
|
hithere: 'hi'
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
await testServer.start();
|
await testServer.start();
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.test('first test', async (tools) => {
|
tap.test('first test', async tools => {
|
||||||
const response = await (new webrequest.WebRequest()).request([
|
const response = await new webrequest.WebRequest().getJson([
|
||||||
'http://localhost:2345/apiroute1',
|
'http://localhost:2345/apiroute1',
|
||||||
'http://localhost:2345/apiroute2',
|
'http://localhost:2345/apiroute2',
|
||||||
'http://localhost:2345/apiroute4',
|
'http://localhost:2345/apiroute4',
|
||||||
'http://localhost:2345/apiroute3'
|
'http://localhost:2345/apiroute3'
|
||||||
], {
|
]);
|
||||||
method: 'GET'
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
||||||
expect(response).property('hithere').to.equal('hi');
|
expect(response)
|
||||||
})
|
.property('hithere')
|
||||||
|
.to.equal('hi');
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('tear down server', async () => {
|
tap.test('tear down server', async () => {
|
||||||
testServer.stop();
|
testServer.stop();
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.start();
|
||||||
|
51
ts/index.ts
51
ts/index.ts
@ -4,26 +4,46 @@ import * as plugins from './webrequest.plugins';
|
|||||||
* web request
|
* web request
|
||||||
*/
|
*/
|
||||||
export class WebRequest {
|
export class WebRequest {
|
||||||
/**
|
public async getJson(urlArg: string | string[], requestBody?: any) {
|
||||||
* gets json
|
const response: Response = await this.request(urlArg, {
|
||||||
*/
|
|
||||||
public async getJson(urlArg: string | string[], requestBody?) {
|
|
||||||
const response = await this.request(urlArg, {
|
|
||||||
body: requestBody,
|
body: requestBody,
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
});
|
});
|
||||||
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* postJson
|
* postJson
|
||||||
*/
|
*/
|
||||||
postJson() {}
|
public async postJson(urlArg: string, requestBody?: any) {
|
||||||
|
const response: Response = await this.request(urlArg, {
|
||||||
|
body: requestBody,
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* put js
|
* put js
|
||||||
*/
|
*/
|
||||||
putJson() {}
|
public async putJson(urlArg: string, requestBody?: any) {
|
||||||
|
const response: Response = await this.request(urlArg, {
|
||||||
|
body: requestBody,
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* put js
|
||||||
|
*/
|
||||||
|
public async deleteJson(urlArg: string, requestBody?: any) {
|
||||||
|
const response: Response = await this.request(urlArg, {
|
||||||
|
body: requestBody,
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -34,7 +54,7 @@ export class WebRequest {
|
|||||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||||
body?: any;
|
body?: any;
|
||||||
}
|
}
|
||||||
) {
|
): Promise<Response> {
|
||||||
let allUrls: string[];
|
let allUrls: string[];
|
||||||
let usedUrlIndex = 0;
|
let usedUrlIndex = 0;
|
||||||
|
|
||||||
@ -47,22 +67,21 @@ export class WebRequest {
|
|||||||
|
|
||||||
const requestHistory: string[] = []; // keep track of the request history
|
const requestHistory: string[] = []; // keep track of the request history
|
||||||
|
|
||||||
const doHistoryCheck = async ( // check history for a
|
const doHistoryCheck = async (
|
||||||
|
// check history for a
|
||||||
historyEntryTypeArg: string
|
historyEntryTypeArg: string
|
||||||
) => {
|
) => {
|
||||||
requestHistory.push(historyEntryTypeArg);
|
requestHistory.push(historyEntryTypeArg);
|
||||||
if (historyEntryTypeArg === '429') {
|
if (historyEntryTypeArg === '429') {
|
||||||
console.log('got 429, so waiting a little bit.')
|
console.log('got 429, so waiting a little bit.');
|
||||||
await plugins.smartdelay.delayFor(
|
await plugins.smartdelay.delayFor(Math.floor(Math.random() * (2000 - 1000 + 1)) + 1000); // wait between 1 and 10 seconds
|
||||||
Math.floor(Math.random() * (2000 - 1000 +1)) + 1000
|
|
||||||
); // wait between 1 and 10 seconds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let numOfHistoryType = 0;
|
let numOfHistoryType = 0;
|
||||||
for (const entry of requestHistory) {
|
for (const entry of requestHistory) {
|
||||||
if (entry === historyEntryTypeArg) numOfHistoryType++;
|
if (entry === historyEntryTypeArg) numOfHistoryType++;
|
||||||
}
|
}
|
||||||
if (numOfHistoryType > (2 * allUrls.length * usedUrlIndex)) {
|
if (numOfHistoryType > 2 * allUrls.length * usedUrlIndex) {
|
||||||
usedUrlIndex++;
|
usedUrlIndex++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -93,6 +112,6 @@ export class WebRequest {
|
|||||||
|
|
||||||
const finalResponse: Response = await doRequest(urlArg[usedUrlIndex]);
|
const finalResponse: Response = await doRequest(urlArg[usedUrlIndex]);
|
||||||
console.log(finalResponse);
|
console.log(finalResponse);
|
||||||
return JSON.parse(await finalResponse.text());
|
return finalResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
|
|
||||||
export {
|
export { smartdelay };
|
||||||
smartdelay
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user