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/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.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
|
||||
|
||||
cache:
|
||||
@ -78,19 +78,11 @@ release:
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--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]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command tslint -c tslint.json ./ts/**/*.ts
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@ -109,10 +101,10 @@ pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
@ -2,5 +2,15 @@
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"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": {
|
||||
"@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 {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
fetch: any;
|
||||
fetch: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
global.fetch = fetch;
|
||||
|
||||
|
||||
// test dependencies
|
||||
import * as smartexpress from '@pushrocks/smartexpress';
|
||||
|
||||
@ -24,43 +23,52 @@ tap.test('setup test server', async () => {
|
||||
port: 2345
|
||||
});
|
||||
|
||||
testServer.addRoute('/apiroute1', new smartexpress.Handler("GET", (req, res) => {
|
||||
res.status(429);
|
||||
res.end();
|
||||
}));
|
||||
testServer.addRoute(
|
||||
'/apiroute1',
|
||||
new smartexpress.Handler('GET', (req, res) => {
|
||||
res.status(429);
|
||||
res.end();
|
||||
})
|
||||
);
|
||||
|
||||
testServer.addRoute('/apiroute2', new smartexpress.Handler("GET", (req, res) => {
|
||||
res.status(500);
|
||||
res.end();
|
||||
}));
|
||||
testServer.addRoute(
|
||||
'/apiroute2',
|
||||
new smartexpress.Handler('GET', (req, res) => {
|
||||
res.status(500);
|
||||
res.end();
|
||||
})
|
||||
);
|
||||
|
||||
testServer.addRoute('/apiroute3', new smartexpress.Handler("GET", (req, res) => {
|
||||
res.status(200);
|
||||
res.send({
|
||||
hithere: 'hi'
|
||||
});
|
||||
}));
|
||||
testServer.addRoute(
|
||||
'/apiroute3',
|
||||
new smartexpress.Handler('GET', (req, res) => {
|
||||
res.status(200);
|
||||
res.send({
|
||||
hithere: 'hi'
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
await testServer.start();
|
||||
})
|
||||
});
|
||||
|
||||
tap.test('first test', async (tools) => {
|
||||
const response = await (new webrequest.WebRequest()).request([
|
||||
tap.test('first test', async tools => {
|
||||
const response = await new webrequest.WebRequest().getJson([
|
||||
'http://localhost:2345/apiroute1',
|
||||
'http://localhost:2345/apiroute2',
|
||||
'http://localhost:2345/apiroute4',
|
||||
'http://localhost:2345/apiroute3'
|
||||
], {
|
||||
method: 'GET'
|
||||
})
|
||||
]);
|
||||
|
||||
console.log(response);
|
||||
|
||||
expect(response).property('hithere').to.equal('hi');
|
||||
})
|
||||
expect(response)
|
||||
.property('hithere')
|
||||
.to.equal('hi');
|
||||
});
|
||||
|
||||
tap.test('tear down server', async () => {
|
||||
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
|
||||
*/
|
||||
export class WebRequest {
|
||||
/**
|
||||
* gets json
|
||||
*/
|
||||
public async getJson(urlArg: string | string[], requestBody?) {
|
||||
const response = await this.request(urlArg, {
|
||||
public async getJson(urlArg: string | string[], requestBody?: any) {
|
||||
const response: Response = await this.request(urlArg, {
|
||||
body: requestBody,
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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';
|
||||
body?: any;
|
||||
}
|
||||
) {
|
||||
): Promise<Response> {
|
||||
let allUrls: string[];
|
||||
let usedUrlIndex = 0;
|
||||
|
||||
@ -47,22 +67,21 @@ export class WebRequest {
|
||||
|
||||
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
|
||||
) => {
|
||||
requestHistory.push(historyEntryTypeArg);
|
||||
if (historyEntryTypeArg === '429') {
|
||||
console.log('got 429, so waiting a little bit.')
|
||||
await plugins.smartdelay.delayFor(
|
||||
Math.floor(Math.random() * (2000 - 1000 +1)) + 1000
|
||||
); // wait between 1 and 10 seconds
|
||||
console.log('got 429, so waiting a little bit.');
|
||||
await plugins.smartdelay.delayFor(Math.floor(Math.random() * (2000 - 1000 + 1)) + 1000); // wait between 1 and 10 seconds
|
||||
}
|
||||
|
||||
let numOfHistoryType = 0;
|
||||
for (const entry of requestHistory) {
|
||||
if (entry === historyEntryTypeArg) numOfHistoryType++;
|
||||
}
|
||||
if (numOfHistoryType > (2 * allUrls.length * usedUrlIndex)) {
|
||||
if (numOfHistoryType > 2 * allUrls.length * usedUrlIndex) {
|
||||
usedUrlIndex++;
|
||||
}
|
||||
};
|
||||
@ -93,6 +112,6 @@ export class WebRequest {
|
||||
|
||||
const finalResponse: Response = await doRequest(urlArg[usedUrlIndex]);
|
||||
console.log(finalResponse);
|
||||
return JSON.parse(await finalResponse.text());
|
||||
return finalResponse;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
|
||||
export {
|
||||
smartdelay
|
||||
}
|
||||
export { smartdelay };
|
||||
|
Loading…
Reference in New Issue
Block a user