fix(core): update

This commit is contained in:
Philipp Kunz 2022-07-28 16:23:11 +02:00
parent e6279c00f1
commit a64d47c02e
4 changed files with 29 additions and 13 deletions

14
package-lock.json generated
View File

@ -22,7 +22,7 @@
"@gitzone/tstest": "^1.0.72",
"@pushrocks/smartexpress": "^4.0.5",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.6.1",
"@types/node": "^18.6.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}
@ -2087,9 +2087,9 @@
"license": "MIT"
},
"node_modules/@types/node": {
"version": "18.6.1",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-18.6.1.tgz",
"integrity": "sha512-z+2vB6yDt1fNwKOeGbckpmirO+VBDuQqecXkgeIqDlaOtmKn6hPR/viQ8cxCfqLU4fTlvM3+YjM367TukWdxpg==",
"version": "18.6.2",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-18.6.2.tgz",
"integrity": "sha512-KcfkBq9H4PI6Vpu5B/KoPeuVDAbmi+2mDBqGPGUgoL7yXQtcWGu2vJWmmRkneWK3Rh0nIAX192Aa87AqKHYChQ==",
"dev": true,
"license": "MIT"
},
@ -10274,9 +10274,9 @@
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ=="
},
"@types/node": {
"version": "18.6.1",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-18.6.1.tgz",
"integrity": "sha512-z+2vB6yDt1fNwKOeGbckpmirO+VBDuQqecXkgeIqDlaOtmKn6hPR/viQ8cxCfqLU4fTlvM3+YjM367TukWdxpg==",
"version": "18.6.2",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-18.6.2.tgz",
"integrity": "sha512-KcfkBq9H4PI6Vpu5B/KoPeuVDAbmi+2mDBqGPGUgoL7yXQtcWGu2vJWmmRkneWK3Rh0nIAX192Aa87AqKHYChQ==",
"dev": true
},
"@types/parse5": {

View File

@ -18,7 +18,7 @@
"@gitzone/tstest": "^1.0.72",
"@pushrocks/smartexpress": "^4.0.5",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.6.1",
"@types/node": "^18.6.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/webrequest',
version: '3.0.8',
version: '3.0.9',
description: 'securely request from browsers'
}

View File

@ -1,5 +1,9 @@
import * as plugins from './webrequest.plugins.js';
export interface IWebrequestContructorOptions {
logging?: boolean;
}
/**
* web request
*/
@ -26,7 +30,13 @@ export class WebRequest {
storeName: 'webrequest',
});
constructor() {
public options: IWebrequestContructorOptions;
constructor(public optionsArg: IWebrequestContructorOptions = {}) {
this.options = {
logging: true,
...optionsArg
}
WebRequest.loadNeededPolyfills();
}
@ -133,7 +143,7 @@ export class WebRequest {
const buffer = await response.clone().arrayBuffer();
await this.cacheStore.set(urlArg, buffer);
}
console.log(`${urlArg} answers with status: ${response.status}`);
this.log(`${urlArg} answers with status: ${response.status}`);
return response;
}
@ -185,7 +195,7 @@ export class WebRequest {
if (!urlToUse) {
throw new Error('request failed permanently');
}
console.log(`Getting ${urlToUse} with method ${optionsArg.method}`);
this.log(`Getting ${urlToUse} with method ${optionsArg.method}`);
const response = await fetch(urlToUse, {
method: optionsArg.method,
headers: {
@ -194,7 +204,7 @@ export class WebRequest {
},
body: optionsArg.body,
});
console.log(`${urlToUse} answers with status: ${response.status}`);
this.log(`${urlToUse} answers with status: ${response.status}`);
if (response.status >= 200 && response.status < 300) {
return response;
@ -210,4 +220,10 @@ export class WebRequest {
const finalResponse: Response = await doRequest(allUrls[usedUrlIndex]);
return finalResponse;
}
public log(logArg: string) {
if (this.options.logging) {
console.log(logArg);
}
}
}