Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR Testing: Fetch Adapter, v1.6.8 #17

Open
wants to merge 77 commits into
base: v1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
d8bc138
feat: add `fetch` adapter with cross-platform support
sgammon Nov 14, 2022
ac79b8c
fix: add polyfill for `AbortController` on Node 14
sgammon Oct 17, 2022
847571c
chore: add web streams polyfill
sgammon Nov 14, 2022
a584083
chore: add `whatwg-fetch` polyfill
sgammon Dec 16, 2022
6add26b
feat(fetch): continue with implementation of Fetch adapter + API
sgammon Dec 17, 2022
84171fd
chore: add karma-coverage for instrumentation
sgammon Dec 17, 2022
97b38cd
feat(fetch): implement mock `fetch` for testing
sgammon Dec 17, 2022
b57d896
feat(fetch): add browser-side test suite
sgammon Dec 17, 2022
0ea0b0a
chore: ignore nyc-output / .husky
sgammon Dec 17, 2022
3b79be5
chore: add `FetchAdapter` to ESM export
sgammon Dec 17, 2022
b141d45
feat(fetch): update typescript typings with fetch types
sgammon Dec 17, 2022
079e193
feat(fetch): add new `generic` library target (ESM/pure JS)
sgammon Dec 17, 2022
d327984
feat(fetch): implement structure for abstract fetch testsuite
sgammon Dec 17, 2022
21ee695
feat(fetch): add Deno benchmark and example
sgammon Dec 17, 2022
5cf9879
feat(fetch): add browser example
sgammon Dec 17, 2022
c823ca6
feat(fetch): add minimal browser samples
sgammon Dec 17, 2022
f783bc4
feat(fetch): add simple Node fetch sample
sgammon Dec 17, 2022
53f5733
feat(fetch): add CloudFlare Workers sample
sgammon Dec 17, 2022
fac5d2b
fix: build matrix, initial ci config for deno testing
sgammon Dec 17, 2022
78f857f
fix: drop default fetch cache setting
sgammon Dec 17, 2022
dbe9353
fix: browser example fixes
sgammon Dec 17, 2022
7125e21
feat(fetch): platform-driven default adapters for each build
sgammon Dec 17, 2022
dd6bc2e
fix: copy new correct typings for generic bundle
sgammon Dec 17, 2022
4c1f890
feat(fetch): tools to analyze browser/generic bundle sizes
sgammon Dec 17, 2022
c75abe9
fix: tweaks to Node sample for fetch
sgammon Dec 17, 2022
ca226d9
feat(fetch): construction on workers sample for axios/fetch
sgammon Dec 17, 2022
77f765d
chore: test against Node 19
sgammon Dec 17, 2022
e29bdb8
fix: labs CI matrix
sgammon Dec 17, 2022
223cca0
feat(fetch): platform-specific defaults for `fetchOptions`
sgammon Dec 18, 2022
3665213
fix(fetch): fully mockable responses for fetch testing
sgammon Dec 18, 2022
6817bbd
fix: tweaks to fetch examples
sgammon Dec 18, 2022
b3375dc
feat(fetch): fetch example improvements + READMEs (browser, deno)
sgammon Dec 18, 2022
d23fa4f
feat(fetch): only ship .d.cts with non-modern targets
sgammon Dec 18, 2022
ccd2b81
feat(fetch): add explicit `axios/generic` bundle export
sgammon Dec 18, 2022
5a33664
feat(fetch): variants and README for node fetch examples
sgammon Dec 18, 2022
f0e3861
feat(fetch): better debug logging, assertions, support for `Blob`
sgammon Dec 18, 2022
111a96a
feat(fetch): allow importing specific files for generic bundle
sgammon Dec 18, 2022
e586ee6
feat(fetch): document new fetch config in main README
sgammon Dec 18, 2022
62db627
fix(fetch): refactor and cleanup response handler selection
sgammon Dec 18, 2022
a7dda93
fix(fetch): fixes for Fetch adapter in CloudFlare Workers env
sgammon Dec 18, 2022
ae675b9
feat(fetch): sample for CloudFlare Workers
sgammon Dec 18, 2022
baa0553
chore: add doc for workers sample
sgammon Dec 18, 2022
a80dab3
chore: updates to main README docs
sgammon Dec 18, 2022
640bcca
feat(fetch): pure-ESM web testing
sgammon Dec 18, 2022
cbd5c42
chore: add bundle sizes for generic entrypoint
sgammon Dec 18, 2022
72ea94a
chore: additional bundle size testing
sgammon Dec 18, 2022
d110264
feat: export utils as individual symbols
sgammon Dec 18, 2022
79b4d06
fix(fetch): avoid re-defining any variables named 'fetch'
sgammon Dec 18, 2022
5a304e8
feat(fetch): treeshaking and terser tweaks, optimize license
sgammon Dec 18, 2022
44a6fc4
fix: don't require Content-Type for body
sgammon Dec 18, 2022
a8de64a
feat(fetch): improvements to fetch typings
sgammon Dec 19, 2022
0e7cd28
chore: cleanup abstract fetch testsuite
sgammon Dec 19, 2022
8445ed8
fix: keep console debug statements during beta
sgammon Dec 19, 2022
a4d2ba6
fix: 'modern' export profile types
sgammon Dec 19, 2022
e4cfe15
chore: smaller bundle size limits
sgammon Dec 19, 2022
358d896
fix: handler selection with no `Content-Type` present
sgammon Dec 19, 2022
71dbee0
fix: errors with previous typing updates
sgammon Dec 19, 2022
e6771b3
chore: drop unused webpack config
sgammon Dec 19, 2022
a0e215f
chore: package spec cleanup
sgammon Dec 19, 2022
7310032
chore: setup CI testing for Bun
sgammon Dec 19, 2022
d791176
fix: polynomial-capable regex in combineURLs helper
sgammon Dec 19, 2022
3c42865
fix: pass relative URLs directly to the underlying fetcher
sgammon Dec 19, 2022
2f4802b
test: ESM API spec
sgammon Dec 19, 2022
bdf4b15
chore: cleanup abstract fetch testsuite
sgammon Dec 19, 2022
07a8770
fix: disable protocol-relative URL testing for combineURLs (temp)
sgammon Dec 19, 2022
39af694
fix: drop missing test
sgammon Dec 19, 2022
29fc3e6
fix: allow version tag in user-agent test
sgammon Sep 14, 2023
baa53f6
chore: version bump for `fetch` testing → `1.6.8-fetch`
sgammon Sep 14, 2023
b004d39
chore: lock packages, rebuild dist
sgammon Sep 14, 2023
ae14db6
fixup! amend testsuite to fix combineURLs updates
sgammon Apr 11, 2024
3a968e0
test: add entrypoint for bun testing
sgammon Apr 11, 2024
41c787c
chore: shutoff debug logging for release at `1.6.8`
sgammon Apr 11, 2024
060f45f
chore: rebuild dist
sgammon Apr 11, 2024
746a6ef
fixup! disable ci matrix failfast, upgrade bun in ci
sgammon Apr 11, 2024
ca8ac8d
chore: add node 21.x to test matrices
sgammon Apr 11, 2024
cde5fd8
fixup! deno test `await`
sgammon Apr 11, 2024
7b83ff9
fixup! browser fetch mock polyfill
sgammon Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/ci.labs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 'CI: Labs'

on:
push:
branches: '**'
pull_request:
branches: '**'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
engine: [deno]
version: [v1.x]
mode: [labs]
include:
- engine: deno
version: v1.x
- engine: node
version: 21.x
mode: labs
- engine: bun
version: '1.1.3'
mode: labs

steps:
- uses: actions/checkout@v3
with:
persist-credentials: false

## --- Runtime Setup

- name: Setup node
uses: actions/setup-node@v3
if: ${{ matrix.engine == 'node' }}
with:
node-version: ${{ matrix.version }}
cache: npm
- name: Setup Deno
uses: denoland/setup-deno@v1
if: ${{ matrix.engine == 'deno' }}
with:
deno-version: ${{ matrix.version }}
- name: Setup Bun
uses: antongolub/action-setup-bun@v1
if: ${{ matrix.engine == 'bun' }}
with:
bun-version: ${{ matrix.version }}

## --- Build + Test

- run: npm install
- run: npm run build
if: ${{ matrix.engine == 'deno' }}
- run: npm run test:${{ matrix.engine }}
continue-on-error: ${{ matrix.mode == 'labs' }}
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x, 16.x, 18.x, 20.x]
node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 21.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ backup/
/.husky/
.npmrc
.env
.husky/
.nyc_output/
133 changes: 132 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
## Features

- Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser
- Make [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) requests from the browser, node.js, or pure-JS
runtimes like Workers, Deno, Bun, etc.
- Make [http](https://nodejs.org/api/http.html) requests from node.js
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
- Intercept request and response
Expand Down Expand Up @@ -224,6 +226,23 @@ Using unpkg CDN:
<script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>
```

### Pure JS environments

Using Axios in **Deno**:
```js
import axios from "https://cdn.jsdelivr.net/npm/[email protected]/dist/generic/axios.min.mjs";
```

Using in CloudFlare Workers, Bun, and other environments which support the Fetch API:
```js
{npm|pnpm|yarn} install axios
```

Then:
```js
import axios from "axios/generic";
```

## Example

> **Note**: CommonJS usage
Expand Down Expand Up @@ -345,6 +364,9 @@ axios({
```js
// Send a GET request (default method)
axios('/user/12345');

// You can also use a `URL` object
axios(new URL('https://example.com/user/12345'));
```

### Request method aliases
Expand Down Expand Up @@ -405,7 +427,8 @@ These are the available config options for making requests. Only the `url` is re

```js
{
// `url` is the server URL that will be used for the request
// `url` is the server URL that will be used for the request. you can
// also pass `new URL(...)`, in environments that support it.
url: '/user',

// `method` is the request method to be used when making the request
Expand Down Expand Up @@ -603,6 +626,114 @@ These are the available config options for making requests. Only the `url` is re
// an alternative way to cancel Axios requests using AbortController
signal: new AbortController().signal,

// pre-parsed URL, to avoid re-parsing the URL when using the fetch adapter.
// optional.
parsedUrl: new URL('...'),

// fetch implementation to use. defaults to the native fetch implementation for
// the active platform, or falls back to a polyfill (`whatwg-fetch`), or a cross-
// platform polyfill (`cross-fetch`).
fetcher: fetch,

// options passed to the underlying `fetch` implementation; only active when
// `adapter` is set to `{adapter: 'fetch'}` or `{adapter: axios.FetchAdapter}`.
// default values below are for `fetch` implementation in browsers. certain fetch
// implementations may require different or limited options.
//
// see MDN for more information (`options` parameter):
// https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
fetchOptions: {
// the general request mode to apply to an operation. options are:
// - `cors` (default): allow cross-origin requests.
// - `no-cors`: do not allow cross-origin requests.
// - `same-origin`: only allow requests to the same origin.
//
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/mode
mode: 'cors',

// should the user's credentials and cookies be sent with the request? options are:
// - `same-origin` (default): only send for same-origin requests.
// - `include`: include credentials for all requests.
// - `omit`: do not send credentials.
//
// DANGER: Be careful with this property. Setting the request to `include` can expose
// users to serious privacy and security risks. Make sure the origins you are exchanging
// data with use HTTPS and are covered by other strong security practices.
//
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
credentials: 'same-origin',

// allow caching of fetched responses? options are:
// - `default` (default): default environment behavior. in browsers, caching
// is typically enabled for GET requests that are marked cacheable.
// - `no-store`: do not store responses in cache.
// - `reload`: fetch from server and update cache.
// - `no-cache`: fetch from server and do not update cache.
// - `force-cache`: use cache if available, otherwise fetch from server and
// update the cache.
// - `only-if-cached`: use cache if available, otherwise fail. this mode can
// only be used when `mode` is set to `same-origin`.
//
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
cache: 'default',

// follow redirects returned in fetch calls? options are:
// - `follow` (default): follow redirects
// - `error`: reject with an error
// - `manual`: handle redirects manually
//
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
redirect: 'follow',

// what referrer, if any, should be sent with requests? options are:
// - `about:client` (default): anonymized referrer is sent.
// - `no-referrer`: no referrer is sent.
// - `client`: full referrer is sent.
// - `<url>`: a custom URL value can be set and sent.
//
// See also: `referrerPolicy`.
//
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/referrer
referrer: 'about:client',

// what policy should be applied when deciding whether to send a referrer? options are:
// - `strict-origin-when-cross-origin` (default): send the origin, path, and querystring
// when performing same-origin requests. For cross-origin requests, send only the origin.
// The referrer is never sent to non-secure origins in this mode.
// - `no-referrer-when-downgrade`: send referrer only when navigating to a more or
// equivalently secure origin.
// - `no-referrer`: never send a referrer.
// - `origin`: send the origin only.
// - `origin-when-cross-origin`: send only the origin when interacting with a different origin.
// - `same-origin`: send the referrer only when interacting with same-origin endpoints.
// - `strict-origin`: send the origin only when the protocol level stays the same.
// - `unsafe-url`: send the full referrer URL unconditionally to all origins.
//
// See also: https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy
referrerPolicy: 'strict-origin-when-cross-origin',

// should an integrity value be applied and checked for the request? options are:
// - no value (default): no integrity is checked.
// - `<hash-algorithm>-<base64-value>`: integrity is checked using the specified algorithm.
// for example, `sha256-<hash>`.
//
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity
integrity: 'sha256-<base64-encoded-hash>',

// should the connection to the server be kept alive? options are:
// - true (default): keep the connection alive.
// - false: close the connection after the request is complete.
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
keepalive: true,

// an `AbortSignal` object which can be used to communicate with or abort the request;
// if both this property and the main config `signal` property are set, this property
// takes precedence.
//
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/signal
signal: new AbortController().signal
},

// `decompress` indicates whether or not the response body should be decompressed
// automatically. If set to `true` will also remove the 'content-encoding' header
// from the responses objects of all decompressed responses
Expand Down
Loading
Loading