Compare commits

...

8 Commits

Author SHA1 Message Date
763afa62cd 3.0.32 2023-07-27 13:59:38 +02:00
ee4ced4395 fix(core): update 2023-07-27 13:59:37 +02:00
8a06f09405 3.0.31 2023-07-27 13:59:22 +02:00
8030851d2e fix(core): update 2023-07-27 13:59:21 +02:00
a8bbec3c17 3.0.30 2023-07-10 22:48:02 +02:00
27f351c541 fix(core): update 2023-07-10 22:48:01 +02:00
342d93e34d 3.0.29 2023-07-10 22:31:55 +02:00
4a0f2288ca fix(core): update 2023-07-10 22:31:55 +02:00
9 changed files with 585 additions and 582 deletions

View File

@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -7,10 +7,10 @@
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "webrequest", "gitrepo": "webrequest",
"description": "securely request from browsers", "description": "securely request from browsers",
"npmPackagename": "@pushrocks/webrequest", "npmPackagename": "@push.rocks/webrequest",
"license": "MIT" "license": "MIT"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/webrequest", "name": "@push.rocks/webrequest",
"version": "3.0.28", "version": "3.0.32",
"private": false, "private": false,
"description": "securely request from browsers", "description": "securely request from browsers",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -16,19 +16,18 @@
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.66", "@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsbundle": "^2.0.8", "@gitzone/tsbundle": "^2.0.8",
"@gitzone/tsrun": "^1.2.42", "@gitzone/tsrun": "^1.2.44",
"@gitzone/tstest": "^1.0.73", "@gitzone/tstest": "^1.0.77",
"@pushrocks/tapbundle": "^5.0.8", "@push.rocks/tapbundle": "^5.0.12",
"@types/node": "^20.3.3" "@types/node": "^20.4.5"
}, },
"dependencies": { "dependencies": {
"@adobe/fetch": "^4.0.13",
"@apiglobal/typedserver": "^2.0.65", "@apiglobal/typedserver": "^2.0.65",
"@pushrocks/smartdelay": "^3.0.1", "@push.rocks/smartdelay": "^3.0.5",
"@pushrocks/smartenv": "^5.0.2", "@push.rocks/smartenv": "^5.0.5",
"@pushrocks/smartjson": "^5.0.6", "@push.rocks/smartjson": "^5.0.6",
"@pushrocks/smartpromise": "^4.0.2", "@push.rocks/smartpromise": "^4.0.3",
"@pushrocks/webstore": "^2.0.8" "@push.rocks/webstore": "^2.0.8"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

928
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as webrequest from '../ts/index.js'; import * as webrequest from '../ts/index.js';
tap.test('should run multiendpoint request', async (tools) => { tap.test('should run multiendpoint request', async (tools) => {

View File

@ -1,4 +1,4 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as webrequest from '../ts/index.js'; import * as webrequest from '../ts/index.js';
// test dependencies // test dependencies

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @pushrocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/webrequest', name: '@push.rocks/webrequest',
version: '3.0.28', version: '3.0.32',
description: 'securely request from browsers' description: 'securely request from browsers'
} }

View File

@ -8,42 +8,6 @@ export interface IWebrequestContructorOptions {
* web request * web request
*/ */
export class WebRequest { export class WebRequest {
private static polyfillStatusEvaluated = false;
private static neededPolyfillsLoadedDeferred = plugins.smartpromise.defer<{
fetch: typeof fetch;
Response: typeof Response;
AbortController?: typeof AbortController;
helixTimeout?: any;
}>();
/**
* loads the needed polyfill
* @returns
*/
public static async loadNeededPolyfills() {
if (this.polyfillStatusEvaluated) {
return this.neededPolyfillsLoadedDeferred.promise;
}
this.polyfillStatusEvaluated = true;
const smartenv = new plugins.smartenv.Smartenv();
if (!smartenv.isBrowser) {
this.polyfillStatusEvaluated = true;
const fetchMod = await smartenv.getSafeNodeModule('@adobe/fetch');
this.neededPolyfillsLoadedDeferred.resolve({
fetch: fetchMod.fetch,
Response: fetchMod.Response,
helixTimeout: fetchMod.timeoutSignal,
});
} else {
this.neededPolyfillsLoadedDeferred.resolve({
fetch: (...args) => {
return fetch(...args);
},
Response: globalThis.Response,
AbortController: globalThis.AbortController,
});
}
}
public cacheStore = new plugins.webstore.WebStore({ public cacheStore = new plugins.webstore.WebStore({
dbName: 'webrequest', dbName: 'webrequest',
@ -57,11 +21,9 @@ export class WebRequest {
logging: true, logging: true,
...optionsArg, ...optionsArg,
}; };
WebRequest.loadNeededPolyfills();
} }
public async getJson(urlArg: string, useCacheArg: boolean = false) { public async getJson(urlArg: string, useCacheArg: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
method: 'GET', method: 'GET',
useCache: useCacheArg, useCache: useCacheArg,
@ -75,7 +37,6 @@ export class WebRequest {
* postJson * postJson
*/ */
public async postJson(urlArg: string, requestBody?: any, useCacheArg: boolean = false) { public async postJson(urlArg: string, requestBody?: any, useCacheArg: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
method: 'POST', method: 'POST',
headers: { headers: {
@ -93,7 +54,6 @@ export class WebRequest {
* put js * put js
*/ */
public async putJson(urlArg: string, requestBody?: any, useStoreAsFallback: boolean = false) { public async putJson(urlArg: string, requestBody?: any, useStoreAsFallback: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
method: 'PUT', method: 'PUT',
headers: { headers: {
@ -110,7 +70,6 @@ export class WebRequest {
* put js * put js
*/ */
public async deleteJson(urlArg: string, useStoreAsFallback: boolean = false) { public async deleteJson(urlArg: string, useStoreAsFallback: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -138,20 +97,10 @@ export class WebRequest {
...optionsArg, ...optionsArg,
}; };
const fetchObject = await WebRequest.neededPolyfillsLoadedDeferred.promise; let controller = new AbortController();
let controller: AbortController; plugins.smartdelay.delayFor(optionsArg.timeoutMs).then(() => {
if (optionsArg.timeoutMs) { controller.abort();
if (fetchObject.AbortController) { });
controller = new fetchObject.AbortController();
plugins.smartdelay.delayFor(optionsArg.timeoutMs).then(() => {
controller.abort();
});
} else {
controller = {
signal: fetchObject.helixTimeout(optionsArg.timeoutMs),
} as any;
}
}
let cachedResponseDeferred = plugins.smartpromise.defer<Response>(); let cachedResponseDeferred = plugins.smartpromise.defer<Response>();
let cacheUsed = false; let cacheUsed = false;
if (optionsArg.useCache && (await this.cacheStore.check(urlArg))) { if (optionsArg.useCache && (await this.cacheStore.check(urlArg))) {
@ -160,9 +109,8 @@ export class WebRequest {
} else { } else {
cachedResponseDeferred.resolve(null); cachedResponseDeferred.resolve(null);
} }
let response: Response = await fetchObject let response: Response = await fetch(urlArg, {
.fetch(urlArg, { signal: controller.signal,
signal: controller ? controller.signal : null,
method: optionsArg.method, method: optionsArg.method,
headers: { headers: {
...(optionsArg.headers || {}), ...(optionsArg.headers || {}),
@ -201,7 +149,7 @@ export class WebRequest {
headers?: HeadersInit; headers?: HeadersInit;
} }
): Promise<Response> { ): Promise<Response> {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
let allUrls: string[]; let allUrls: string[];
let usedUrlIndex = 0; let usedUrlIndex = 0;

View File

@ -1,7 +1,7 @@
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@push.rocks/smartdelay';
import * as smartenv from '@pushrocks/smartenv'; import * as smartenv from '@push.rocks/smartenv';
import * as smartjson from '@pushrocks/smartjson'; import * as smartjson from '@push.rocks/smartjson';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@push.rocks/smartpromise';
import * as webstore from '@pushrocks/webstore'; import * as webstore from '@push.rocks/webstore';
export { smartdelay, smartenv, smartjson, smartpromise, webstore }; export { smartdelay, smartenv, smartjson, smartpromise, webstore };