Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
342d93e34d | |||
4a0f2288ca | |||
5c7f9e5bfa | |||
14bda0bfa3 | |||
4a57f7070a | |||
f36bdcb181 | |||
d3c90b0e7e | |||
2397e69572 | |||
7f7738d69f | |||
f375e36a99 | |||
0e827e508e | |||
43820d0278 | |||
98a18f4243 | |||
ba231de502 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @gitzone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
package.json
22
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/webrequest",
|
"name": "@push.rocks/webrequest",
|
||||||
"version": "3.0.22",
|
"version": "3.0.29",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "securely request from browsers",
|
"description": "securely request from browsers",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -14,21 +14,21 @@
|
|||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.65",
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsbundle": "^2.0.7",
|
"@gitzone/tsbundle": "^2.0.8",
|
||||||
"@gitzone/tsrun": "^1.2.39",
|
"@gitzone/tsrun": "^1.2.42",
|
||||||
"@gitzone/tstest": "^1.0.73",
|
"@gitzone/tstest": "^1.0.73",
|
||||||
"@pushrocks/smartexpress": "^4.0.35",
|
"@pushrocks/tapbundle": "^5.0.8",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@types/node": "^20.3.3"
|
||||||
"@types/node": "^18.16.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@adobe/fetch": "^4.0.10",
|
"@adobe/fetch": "^4.0.13",
|
||||||
|
"@apiglobal/typedserver": "^2.0.65",
|
||||||
"@pushrocks/smartdelay": "^3.0.1",
|
"@pushrocks/smartdelay": "^3.0.1",
|
||||||
"@pushrocks/smartenv": "^5.0.2",
|
"@pushrocks/smartenv": "^5.0.2",
|
||||||
"@pushrocks/smartjson": "^5.0.1",
|
"@pushrocks/smartjson": "^5.0.6",
|
||||||
"@pushrocks/smartpromise": "^4.0.2",
|
"@pushrocks/smartpromise": "^4.0.2",
|
||||||
"@pushrocks/webstore": "^2.0.6"
|
"@pushrocks/webstore": "^2.0.8"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
1553
pnpm-lock.yaml
generated
1553
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
12
test/test.ts
12
test/test.ts
@ -2,12 +2,12 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
import * as webrequest from '../ts/index.js';
|
import * as webrequest from '../ts/index.js';
|
||||||
|
|
||||||
// test dependencies
|
// test dependencies
|
||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as typedserver from '@apiglobal/typedserver';
|
||||||
|
|
||||||
let testServer: smartexpress.Server;
|
let testServer: typedserver.servertools.Server;
|
||||||
|
|
||||||
tap.test('setup test server', async () => {
|
tap.test('setup test server', async () => {
|
||||||
testServer = new smartexpress.Server({
|
testServer = new typedserver.servertools.Server({
|
||||||
cors: false,
|
cors: false,
|
||||||
forceSsl: false,
|
forceSsl: false,
|
||||||
port: 2345,
|
port: 2345,
|
||||||
@ -15,7 +15,7 @@ tap.test('setup test server', async () => {
|
|||||||
|
|
||||||
testServer.addRoute(
|
testServer.addRoute(
|
||||||
'/apiroute1',
|
'/apiroute1',
|
||||||
new smartexpress.Handler('GET', (req, res) => {
|
new typedserver.servertools.Handler('GET', (req, res) => {
|
||||||
res.status(429);
|
res.status(429);
|
||||||
res.end();
|
res.end();
|
||||||
})
|
})
|
||||||
@ -23,7 +23,7 @@ tap.test('setup test server', async () => {
|
|||||||
|
|
||||||
testServer.addRoute(
|
testServer.addRoute(
|
||||||
'/apiroute2',
|
'/apiroute2',
|
||||||
new smartexpress.Handler('GET', (req, res) => {
|
new typedserver.servertools.Handler('GET', (req, res) => {
|
||||||
res.status(500);
|
res.status(500);
|
||||||
res.end();
|
res.end();
|
||||||
})
|
})
|
||||||
@ -31,7 +31,7 @@ tap.test('setup test server', async () => {
|
|||||||
|
|
||||||
testServer.addRoute(
|
testServer.addRoute(
|
||||||
'/apiroute3',
|
'/apiroute3',
|
||||||
new smartexpress.Handler('GET', (req, res) => {
|
new typedserver.servertools.Handler('GET', (req, res) => {
|
||||||
res.status(200);
|
res.status(200);
|
||||||
res.send({
|
res.send({
|
||||||
hithere: 'hi',
|
hithere: 'hi',
|
||||||
|
@ -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.22',
|
version: '3.0.29',
|
||||||
description: 'securely request from browsers'
|
description: 'securely request from browsers'
|
||||||
}
|
}
|
||||||
|
62
ts/index.ts
62
ts/index.ts
@ -8,44 +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) {
|
|
||||||
console.log('webrequest using node context.');
|
|
||||||
this.polyfillStatusEvaluated = true;
|
|
||||||
const fetchMod = await smartenv.getSafeNodeModule('@adobe/fetch');
|
|
||||||
this.neededPolyfillsLoadedDeferred.resolve({
|
|
||||||
fetch: fetchMod.fetch,
|
|
||||||
Response: fetchMod.Response,
|
|
||||||
helixTimeout: fetchMod.timeoutSignal,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log('webrequest using browser context.');
|
|
||||||
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',
|
||||||
@ -59,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,
|
||||||
@ -77,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: {
|
||||||
@ -95,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: {
|
||||||
@ -112,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',
|
||||||
@ -140,20 +97,10 @@ export class WebRequest {
|
|||||||
...optionsArg,
|
...optionsArg,
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchObject = await WebRequest.neededPolyfillsLoadedDeferred.promise;
|
let controller = new AbortController();
|
||||||
let controller: AbortController;
|
|
||||||
if (optionsArg.timeoutMs) {
|
|
||||||
if (fetchObject.AbortController) {
|
|
||||||
controller = new fetchObject.AbortController();
|
|
||||||
plugins.smartdelay.delayFor(optionsArg.timeoutMs).then(() => {
|
plugins.smartdelay.delayFor(optionsArg.timeoutMs).then(() => {
|
||||||
controller.abort();
|
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))) {
|
||||||
@ -162,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 || {}),
|
||||||
@ -203,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;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "ES2022",
|
"module": "ES2022",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user