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

View File

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

View File

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

View File

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