From a64d47c02e69c9130e8049c97bce52d297d7573c Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Thu, 28 Jul 2022 16:23:11 +0200 Subject: [PATCH] fix(core): update --- package-lock.json | 14 +++++++------- package.json | 2 +- ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 24 ++++++++++++++++++++---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index d1e1b6e..7654a1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index e61a4ec..b6a64b0 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index adf576e..823ba4f 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@pushrocks/webrequest', - version: '3.0.8', + version: '3.0.9', description: 'securely request from browsers' } diff --git a/ts/index.ts b/ts/index.ts index a80f554..65441a6 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -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); + } + } }