Compare commits

...

43 Commits

Author SHA1 Message Date
e228ed4ba0 update description 2024-05-29 14:17:42 +02:00
9425489f4f 3.0.37 2024-04-17 20:19:51 +02:00
46ef3857e9 fix(core): update 2024-04-17 20:19:51 +02:00
c173fd3761 3.0.36 2024-04-17 20:15:46 +02:00
98f224e6f4 fix(core): update 2024-04-17 20:15:46 +02:00
a7751006cc update tsconfig 2024-04-14 18:41:19 +02:00
bb4a2a660a update tsconfig 2024-04-01 21:42:43 +02:00
c32fc4c3be update npmextra.json: githost 2024-04-01 20:00:22 +02:00
6d943687ad update npmextra.json: githost 2024-03-30 21:49:20 +01:00
d216a5e8b9 3.0.35 2024-03-03 10:36:24 +01:00
adca345da1 fix(core): update 2024-03-03 10:36:24 +01:00
ab880d704a 3.0.34 2023-10-20 18:01:13 +02:00
5af1863264 fix(core): update 2023-10-20 18:01:12 +02:00
b43050ff0c 3.0.33 2023-08-27 16:33:11 +02:00
627fc42962 fix(core): update 2023-08-27 16:33:10 +02:00
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
5c7f9e5bfa 3.0.28 2023-07-09 17:24:53 +02:00
14bda0bfa3 fix(core): update 2023-07-09 17:24:52 +02:00
4a57f7070a 3.0.27 2023-07-09 17:20:12 +02:00
f36bdcb181 fix(core): update 2023-07-09 17:20:12 +02:00
d3c90b0e7e 3.0.26 2023-07-03 10:08:45 +02:00
2397e69572 fix(core): update 2023-07-03 10:08:44 +02:00
7f7738d69f 3.0.25 2023-07-03 10:08:16 +02:00
f375e36a99 fix(core): update 2023-07-03 10:08:16 +02:00
0e827e508e 3.0.24 2023-07-03 10:08:05 +02:00
43820d0278 fix(core): update 2023-07-03 10:08:04 +02:00
98a18f4243 3.0.23 2023-05-01 13:11:42 +02:00
ba231de502 fix(core): update 2023-05-01 13:11:41 +02:00
363bc1c025 3.0.22 2023-05-01 12:26:16 +02:00
f28f5b8f46 fix(core): update 2023-05-01 12:26:15 +02:00
b30a7b57d3 3.0.21 2023-03-07 16:04:08 +01:00
240b2fc69a fix(core): update 2023-03-07 16:04:08 +01:00
0e1da04c3c 3.0.20 2023-03-07 11:31:26 +01:00
2a715e5b80 fix(core): update 2023-03-07 11:31:25 +01:00
5ff76b5c9f 3.0.19 2023-03-07 11:30:01 +01:00
76733cc96a fix(core): update 2023-03-07 11:30:00 +01:00
14 changed files with 2786 additions and 1896 deletions

View 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

View 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

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

@ -6,12 +6,28 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "webrequest",
"description": "securely request from browsers",
"npmPackagename": "@pushrocks/webrequest",
"license": "MIT"
"description": "A module for making secure web requests from browsers with support for caching and fault tolerance.",
"npmPackagename": "@push.rocks/webrequest",
"license": "MIT",
"keywords": [
"webrequest",
"HTTP",
"secure",
"browsers",
"caching",
"fault tolerance",
"json",
"abort",
"timeout",
"multi-endpoint",
"fetch API"
]
}
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

View File

@ -1,8 +1,8 @@
{
"name": "@pushrocks/webrequest",
"version": "3.0.18",
"name": "@push.rocks/webrequest",
"version": "3.0.37",
"private": false,
"description": "securely request from browsers",
"description": "A module for making secure web requests from browsers with support for caching and fault tolerance.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -14,21 +14,20 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsbundle": "^2.0.7",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.73",
"@pushrocks/smartexpress": "^4.0.21",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.13.0"
"@api.global/typedserver": "^3.0.27",
"@git.zone/tsbuild": "^2.1.72",
"@git.zone/tsbundle": "^2.0.15",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.88",
"@push.rocks/tapbundle": "^5.0.23",
"@types/node": "^20.12.7"
},
"dependencies": {
"@adobe/fetch": "^4.0.1",
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartenv": "^5.0.2",
"@pushrocks/smartjson": "^5.0.1",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/webstore": "^2.0.5"
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartenv": "^5.0.12",
"@push.rocks/smartjson": "^5.0.19",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/webstore": "^2.0.13"
},
"files": [
"ts/**/*",
@ -44,5 +43,23 @@
],
"browserslist": [
"last 1 chrome versions"
]
}
],
"keywords": [
"webrequest",
"HTTP",
"secure",
"browsers",
"caching",
"fault tolerance",
"json",
"abort",
"timeout",
"multi-endpoint",
"fetch API"
],
"homepage": "https://code.foss.global/push.rocks/webrequest",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/webrequest.git"
}
}

3979
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

193
readme.md
View File

@ -1,37 +1,178 @@
# @pushrocks/webrequest
# @push.rocks/webrequest
securely request from browsers
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/webrequest)
* [gitlab.com (source)](https://gitlab.com/pushrocks/webrequest)
* [github.com (source mirror)](https://github.com/pushrocks/webrequest)
* [docs (typedoc)](https://pushrocks.gitlab.io/webrequest/)
## Install
## Status for master
To use `@push.rocks/webrequest` in your project, install it using npm or yarn:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/webrequest/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/webrequest/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/webrequest)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/webrequest)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/webrequest)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/webrequest)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/webrequest)](https://lossless.cloud)
```bash
npm install @push.rocks/webrequest --save
# or with yarn
yarn add @push.rocks/webrequest
```
This package is designed to be used in an environment where ECMAScript Modules (ESM) and TypeScript are supported.
## Usage
Use TypeScript for best in class intellisense.
`@push.rocks/webrequest` is a powerful module designed to simplify making web requests securely from browsers. It leverages modern JavaScript features and TypeScript for a type-safe development experience. Below are comprehensive examples demonstrating how to utilize the module effectively:
## Contribution
### Setting Up
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
First, import `WebRequest` from the module:
For further information read the linked docs at the top of this readme.
```typescript
import { WebRequest } from '@push.rocks/webrequest';
```
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
Create an instance of `WebRequest`. You can optionally pass configuration options:
```typescript
const webRequest = new WebRequest({
logging: true // Optional: enables logging, defaults to true
});
```
### Making GET Requests
To fetch JSON data:
```typescript
// Fetch JSON data using GET request
async function fetchJsonData() {
const url = 'https://api.example.com/data';
try {
const jsonData = await webRequest.getJson(url);
console.log(jsonData);
} catch (error) {
console.error(error);
}
}
fetchJsonData();
```
### POST, PUT, and DELETE Requests
Similarly, you can make POST, PUT, and DELETE requests to send or manipulate data:
```typescript
// Example POST request to submit JSON data
async function postJsonData() {
const url = 'https://api.example.com/submit';
const data = { key: 'value' };
try {
const result = await webRequest.postJson(url, data);
console.log(result);
} catch (error) {
console.error(error);
}
}
postJsonData();
// PUT and DELETE can be similarly used
```
### Using Caches
The library provides mechanisms to cache responses, which is useful for reducing network load and improving performance. Heres how to fetch data with caching:
```typescript
// Fetch with caching enabled
async function fetchDataWithCache() {
const url = 'https://api.example.com/data';
try {
// The second parameter enables caching
const jsonData = await webRequest.getJson(url, true);
console.log(jsonData);
} catch (error) {
console.error(error);
}
}
fetchDataWithCache();
```
### Handling Multiple Endpoints
`@push.rocks/webrequest` supports querying multiple endpoints with fallbacks to handle the situation where some endpoints may fail or be unavailable:
```typescript
// Attempt to request from multiple endpoints
async function requestFromMultipleEndpoints() {
const endpoints = [
'https://api.primary-example.com/data',
'https://api.backup-example.com/data'
];
try {
const response = await webRequest.requestMultiEndpoint(endpoints, {
method: 'GET'
});
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Failed to retrieve data from any endpoint', error);
}
}
requestFromMultipleEndpoints();
```
### Advanced Usage
For advanced scenarios, you can directly use the `request` method to fully customize the request options including headers, request method, and body (for POST/PUT requests):
```typescript
// Custom request with timeout
async function customRequest() {
const url = 'https://api.example.com/advanced';
try {
const response = await webRequest.request(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ custom: 'data' }),
timeoutMs: 10000 // Timeout in milliseconds
});
if (response.ok) {
const result = await response.json();
console.log(result);
} else {
console.error('Response error:', response.status);
}
} catch (error) {
console.error('Request failed:', error);
}
}
customRequest();
```
### Conclusion
`@push.rocks/webrequest` offers a streamlined, secure way to handle web requests from browsers, supporting various HTTP methods, response caching, and requests to multiple endpoints with fault tolerance. Its TypeScript integration ensures type safety and enhances developer productivity by enabling IntelliSense in supported IDEs.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

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';
tap.test('should run multiendpoint request', async (tools) => {

View File

@ -1,13 +1,13 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@push.rocks/tapbundle';
import * as webrequest from '../ts/index.js';
// test dependencies
import * as smartexpress from '@pushrocks/smartexpress';
import * as typedserver from '@api.global/typedserver';
let testServer: smartexpress.Server;
let testServer: typedserver.servertools.Server;
tap.test('setup test server', async () => {
testServer = new smartexpress.Server({
testServer = new typedserver.servertools.Server({
cors: false,
forceSsl: false,
port: 2345,
@ -15,7 +15,7 @@ tap.test('setup test server', async () => {
testServer.addRoute(
'/apiroute1',
new smartexpress.Handler('GET', (req, res) => {
new typedserver.servertools.Handler('GET', (req, res) => {
res.status(429);
res.end();
})
@ -23,7 +23,7 @@ tap.test('setup test server', async () => {
testServer.addRoute(
'/apiroute2',
new smartexpress.Handler('GET', (req, res) => {
new typedserver.servertools.Handler('GET', (req, res) => {
res.status(500);
res.end();
})
@ -31,7 +31,7 @@ tap.test('setup test server', async () => {
testServer.addRoute(
'/apiroute3',
new smartexpress.Handler('GET', (req, res) => {
new typedserver.servertools.Handler('GET', (req, res) => {
res.status(200);
res.send({
hithere: 'hi',

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/webrequest',
version: '3.0.18',
description: 'securely request from browsers'
name: '@push.rocks/webrequest',
version: '3.0.37',
description: 'A module for making secure web requests from browsers with support for caching and fault tolerance.'
}

View File

@ -8,44 +8,6 @@ export interface IWebrequestContructorOptions {
* web request
*/
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({
dbName: 'webrequest',
@ -59,11 +21,9 @@ export class WebRequest {
logging: true,
...optionsArg,
};
WebRequest.loadNeededPolyfills();
}
public async getJson(urlArg: string, useCacheArg: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, {
method: 'GET',
useCache: useCacheArg,
@ -77,7 +37,6 @@ export class WebRequest {
* postJson
*/
public async postJson(urlArg: string, requestBody?: any, useCacheArg: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, {
method: 'POST',
headers: {
@ -95,7 +54,6 @@ export class WebRequest {
* put js
*/
public async putJson(urlArg: string, requestBody?: any, useStoreAsFallback: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, {
method: 'PUT',
headers: {
@ -112,7 +70,6 @@ export class WebRequest {
* put js
*/
public async deleteJson(urlArg: string, useStoreAsFallback: boolean = false) {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
const response: Response = await this.request(urlArg, {
headers: {
'Content-Type': 'application/json',
@ -140,20 +97,10 @@ export class WebRequest {
...optionsArg,
};
const fetchObject = await WebRequest.neededPolyfillsLoadedDeferred.promise;
let controller: AbortController;
if (optionsArg.timeoutMs) {
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 controller = new AbortController();
plugins.smartdelay.delayFor(optionsArg.timeoutMs).then(() => {
controller.abort();
});
let cachedResponseDeferred = plugins.smartpromise.defer<Response>();
let cacheUsed = false;
if (optionsArg.useCache && (await this.cacheStore.check(urlArg))) {
@ -162,9 +109,8 @@ export class WebRequest {
} else {
cachedResponseDeferred.resolve(null);
}
let response: Response = await fetchObject
.fetch(urlArg, {
signal: controller ? controller.signal : null,
let response: Response = await fetch(urlArg, {
signal: controller.signal,
method: optionsArg.method,
headers: {
...(optionsArg.headers || {}),
@ -203,7 +149,7 @@ export class WebRequest {
headers?: HeadersInit;
}
): Promise<Response> {
await WebRequest.neededPolyfillsLoadedDeferred.promise;
let allUrls: string[];
let usedUrlIndex = 0;

View File

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

View File

@ -3,8 +3,12 @@
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}