From 537fb241d45eb700f48575c6241e0e1983195d9a Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Mon, 19 Sep 2022 17:16:57 +0200 Subject: [PATCH 01/13] feat: rename to adobe/fetch --- CONTRIBUTING.md | 4 +- README.md | 104 ++++++++++++++----------------- package-lock.json | 4 +- package.json | 8 +-- src/api.d.ts | 2 +- src/common/utils.js | 2 +- src/core/h1.js | 2 +- src/core/h2.js | 2 +- src/core/index.js | 4 +- src/core/request.js | 2 +- src/fetch/index.js | 2 +- test/fetch/index.http2.test.js | 2 +- v2-UPGRADE-GUIDE.md | 110 --------------------------------- 13 files changed, 65 insertions(+), 183 deletions(-) delete mode 100644 v2-UPGRADE-GUIDE.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3bcf422..8511d6c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -# Contributing to Project Helix +# Contributing to @adobe/fetch -This project (like almost all of Project Helix) is an Open Development project and welcomes contributions from everyone who finds it useful or lacking. +This project (like almost all of @adobe/fetch) is an Open Development project and welcomes contributions from everyone who finds it useful or lacking. ## Code Of Conduct diff --git a/README.md b/README.md index a1cac77..08ca18b 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ Helix Fetch

Light-weight Fetch API implementation transparently supporting both HTTP/1(.1) and HTTP/2

- codecov - CircleCI - GitHub license - GitHub issues - LGTM Code Quality Grade: JavaScript + codecov + CircleCI + GitHub license + GitHub issues + LGTM Code Quality Grade: JavaScript Renovate enabled semantic-release - Install size - Current version + Install size + Current version --- @@ -19,7 +19,6 @@ - [About](#about) - [Features](#features) - [Installation](#installation) -- [Upgrading](#upgrading) - [API](#api) - [Context](#context) - [Common Usage Examples](#common-usage-examples) @@ -56,17 +55,17 @@ ## About -`helix-fetch` in general adheres to the [Fetch API Specification](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), implementing a subset of the API. However, there are some notable deviations: +`adobe/fetch` in general adheres to the [Fetch API Specification](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), implementing a subset of the API. However, there are some notable deviations: * `Response.body` returns a Node.js [Readable stream](https://nodejs.org/api/stream.html#stream_readable_streams). * `Response.blob()` is not implemented. Use `Response.buffer()` instead. * `Response.formData()` is not implemented. * Cookies are not stored by default. However, cookies can be extracted and passed by manipulating request and response headers. * The following values of the `fetch()` option `cache` are supported: `'default'` (the implicit default) and `'no-store'`. All other values are currently ignored. -* The following `fetch()` options are ignored due to the nature of Node.js and since `helix-fetch` doesn't have the concept of web pages: `mode`, `referrer`, `referrerPolicy`, `integrity` and `credentials`. +* The following `fetch()` options are ignored due to the nature of Node.js and since `adobe/fetch` doesn't have the concept of web pages: `mode`, `referrer`, `referrerPolicy`, `integrity` and `credentials`. * The `fetch()` option `keepalive` is not supported. But you can use the `h1.keepAlive` context option, as demonstrated [here](#http11-keep-alive). -`helix-fetch` also supports the following extensions: +`adobe/fetch` also supports the following extensions: * `Response.buffer()` returns a Node.js `Buffer`. * `Response.url` contains the final url when following redirects. @@ -100,16 +99,9 @@ Note that non-standard Fetch options have been aligned with [node-fetch](https:/ > As of v2 Node version >= 12 is required. ```bash -$ npm install @adobe/helix-fetch +$ npm install @adobe/fetch ``` -## Upgrading - -Upgrading from an old version of `helix-fetch`? Check out the following files: - -- [1.x to 2.x Upgrade Guide](v2-UPGRADE-GUIDE.md) -- [Changelog](CHANGELOG.md) - ## API Apart from the standard Fetch API @@ -120,7 +112,7 @@ Apart from the standard Fetch API * `Headers` * `Body` -`helix-fetch` exposes the following extensions: +`adobe/fetch` exposes the following extensions: * `context()` - creates a new customized API context * `reset()` - resets the current API context, i.e. closes pending sessions/sockets, clears internal caches, etc ... @@ -146,7 +138,7 @@ The following options are supported: interface ContextOptions { /** * Value of `user-agent` request header - * @default 'helix-fetch/' + * @default 'adobe-fetch/' */ userAgent?: string; /** @@ -235,7 +227,7 @@ interface Http2Options { ### Access Response Headers and other Meta data ```javascript - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const resp = await fetch('https://httpbin.org/get'); console.log(resp.ok); @@ -249,7 +241,7 @@ interface Http2Options { ### Fetch JSON ```javascript - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const resp = await fetch('https://httpbin.org/json'); const jsonData = await resp.json(); @@ -258,7 +250,7 @@ interface Http2Options { ### Fetch text data ```javascript - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const resp = await fetch('https://httpbin.org/'); const textData = await resp.text(); @@ -267,7 +259,7 @@ interface Http2Options { ### Fetch binary data ```javascript - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const resp = await fetch('https://httpbin.org//stream-bytes/65535'); const imageData = await resp.buffer(); @@ -278,7 +270,7 @@ interface Http2Options { Using `timeoutSignal(ms)` extension: ```javascript - const { fetch, timeoutSignal, AbortError } = require('@adobe/helix-fetch'); + const { fetch, timeoutSignal, AbortError } = require('@adobe/fetch'); const signal = timeoutSignal(1000); try { @@ -297,7 +289,7 @@ Using `timeoutSignal(ms)` extension: Using `AbortController`: ```javascript - const { fetch, AbortController, AbortError } = require('@adobe/helix-fetch'); + const { fetch, AbortController, AbortError } = require('@adobe/fetch'); const controller = new AbortController(); const timerId = setTimeout(() => controller.abort(), 1000); @@ -320,7 +312,7 @@ Using `AbortController`: ```javascript const fs = require('fs'); - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const resp = await fetch('https://httpbin.org/image/jpeg'); resp.body.pipe(fs.createWriteStream('saved-image.jpg')); @@ -329,7 +321,7 @@ Using `AbortController`: ### Post JSON ```javascript - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const method = 'POST'; const body = { foo: 'bar' }; @@ -340,7 +332,7 @@ Using `AbortController`: ```javascript const fs = require('fs'); - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const method = 'POST'; const body = fs.createReadStream('some-image.jpg'); @@ -354,7 +346,7 @@ Using `AbortController`: const { FormData, Blob, File } = require('formdata-node'); // spec-compliant implementations const { fileFromPath } = require('formdata-node/file-from-path'); // helper for creating File instance from disk file - const { fetch } = require('@adobe/helix-fetch'); + const { fetch } = require('@adobe/fetch'); const method = 'POST'; const fd = new FormData(); @@ -369,7 +361,7 @@ Using `AbortController`: ### GET with query parameters object ```javascript -const { createUrl, fetch } = require('@adobe/helix-fetch'); +const { createUrl, fetch } = require('@adobe/fetch'); const qs = { helix: 'dummy', @@ -383,7 +375,7 @@ const resp = await fetch(createUrl('https://httpbin.org/json', qs)); or using `URLSearchParams`: ```javascript -const { fetch } = require('@adobe/helix-fetch'); +const { fetch } = require('@adobe/fetch'); const body = new URLSearchParams({ helix: 'dummy', @@ -399,7 +391,7 @@ const resp = await fetch('https://httpbin.org/json', { body }); Responses of `GET` and `HEAD` requests are by default cached, according to the rules of [RFC 7234](https://httpwg.org/specs/rfc7234.html): ```javascript -const { fetch } = require('@adobe/helix-fetch'); +const { fetch } = require('@adobe/fetch'); const url = 'https://httpbin.org/cache/60'; // -> max-age=60 (seconds) // send initial request, priming cache @@ -416,7 +408,7 @@ assert(resp.fromCache); You can disable caching per request with the `cache: 'no-store'` option: ```javascript -const { fetch } = require('@adobe/helix-fetch'); +const { fetch } = require('@adobe/fetch'); const resp = await fetch('https://httbin.org/', { cache: 'no-store' }); assert(resp.ok); @@ -426,7 +418,7 @@ assert(!resp.fromCache); You can disable caching entirely: ```javascript -const { fetch } = require('@adobe/helix-fetch').noCache(); +const { fetch } = require('@adobe/fetch').noCache(); ``` ## Advanced Usage Examples @@ -437,7 +429,7 @@ Note that pushed resources will be automatically and transparently added to the You can however add a listener which will be notified on every pushed (and cached) resource. ```javascript - const { fetch, onPush } = require('@adobe/helix-fetch'); + const { fetch, onPush } = require('@adobe/fetch'); onPush((url, response) => console.log(`received server push: ${url} status ${response.status}`)); @@ -448,7 +440,7 @@ You can however add a listener which will be notified on every pushed (and cache ### Force HTTP/1(.1) protocol ```javascript - const { fetch } = require('@adobe/helix-fetch').h1(); + const { fetch } = require('@adobe/fetch').h1(); const resp = await fetch('https://nghttp2.org'); console.log(`Http version: ${resp.httpVersion}`); @@ -457,7 +449,7 @@ You can however add a listener which will be notified on every pushed (and cache ### HTTP/1.1 Keep-Alive ```javascript -const { fetch } = require('@adobe/helix-fetch').keepAlive(); +const { fetch } = require('@adobe/fetch').keepAlive(); const resp = await fetch('https://httpbin.org/status/200'); console.log(`Connection: ${resp.headers.get('connection')}`); // -> keep-alive @@ -466,7 +458,7 @@ console.log(`Connection: ${resp.headers.get('connection')}`); // -> keep-alive ### Self-signed Certificates ```javascript -const { fetch } = require('@adobe/helix-fetch').context({ rejectUnauthorized: false }); +const { fetch } = require('@adobe/fetch').context({ rejectUnauthorized: false }); const resp = await fetch('https://localhost:8443/'); // a server using a self-signed certificate ``` @@ -474,7 +466,7 @@ const resp = await fetch('https://localhost:8443/'); // a server using a self-s ### Set cache size limit ```javascript - const { fetch, cacheStats } = require('@adobe/helix-fetch').context({ + const { fetch, cacheStats } = require('@adobe/fetch').context({ maxCacheSize: 100 * 1024, // 100kb (Default: 100mb) }); @@ -486,7 +478,7 @@ const resp = await fetch('https://localhost:8443/'); // a server using a self-s ### Disable caching ```javascript - const { fetch } = require('@adobe/helix-fetch').noCache(); + const { fetch } = require('@adobe/fetch').noCache(); let resp = await fetch('https://httpbin.org/cache/60'); // -> max-age=60 (seconds) // re-fetch @@ -497,7 +489,7 @@ const resp = await fetch('https://localhost:8443/'); // a server using a self-s ### Set a custom user agent ```javascript - const { fetch } = require('@adobe/helix-fetch').context({ + const { fetch } = require('@adobe/fetch').context({ userAgent: 'custom-fetch' }); @@ -532,26 +524,26 @@ $ npm run lint ### Troubleshooting -You can enable `helix-fetch` low-level debug console output by setting the `DEBUG` environment variable to `helix-fetch*`, e.g.: +You can enable `adobe/fetch` low-level debug console output by setting the `DEBUG` environment variable to `adobe/fetch*`, e.g.: ```bash -$ DEBUG=helix-fetch* node test.js +$ DEBUG=adobe/fetch* node test.js ``` This will produce console outout similar to: ```bash ... - helix-fetch:core established TLS connection: #48 (www.nghttp2.org) +2s - helix-fetch:core www.nghttp2.org -> h2 +0ms - helix-fetch:h2 reusing socket #48 (www.nghttp2.org) +2s - helix-fetch:h2 GET www.nghttp2.org/httpbin/user-agent +0ms - helix-fetch:h2 session https://www.nghttp2.org established +1ms - helix-fetch:h2 caching session https://www.nghttp2.org +0ms - helix-fetch:h2 session https://www.nghttp2.org remoteSettings: {"headerTableSize":8192,"enablePush":true,"initialWindowSize":1048576,"maxFrameSize":16384,"maxConcurrentStreams":100,"maxHeaderListSize":4294967295,"maxHeaderSize":4294967295,"enableConnectProtocol":true} +263ms - helix-fetch:h2 session https://www.nghttp2.org localSettings: {"headerTableSize":4096,"enablePush":true,"initialWindowSize":65535,"maxFrameSize":16384,"maxConcurrentStreams":4294967295,"maxHeaderListSize":4294967295,"maxHeaderSize":4294967295,"enableConnectProtocol":false} +0ms - helix-fetch:h2 session https://www.nghttp2.org closed +6ms - helix-fetch:h2 discarding cached session https://www.nghttp2.org +0ms + adobe/fetch:core established TLS connection: #48 (www.nghttp2.org) +2s + adobe/fetch:core www.nghttp2.org -> h2 +0ms + adobe/fetch:h2 reusing socket #48 (www.nghttp2.org) +2s + adobe/fetch:h2 GET www.nghttp2.org/httpbin/user-agent +0ms + adobe/fetch:h2 session https://www.nghttp2.org established +1ms + adobe/fetch:h2 caching session https://www.nghttp2.org +0ms + adobe/fetch:h2 session https://www.nghttp2.org remoteSettings: {"headerTableSize":8192,"enablePush":true,"initialWindowSize":1048576,"maxFrameSize":16384,"maxConcurrentStreams":100,"maxHeaderListSize":4294967295,"maxHeaderSize":4294967295,"enableConnectProtocol":true} +263ms + adobe/fetch:h2 session https://www.nghttp2.org localSettings: {"headerTableSize":4096,"enablePush":true,"initialWindowSize":65535,"maxFrameSize":16384,"maxConcurrentStreams":4294967295,"maxHeaderListSize":4294967295,"maxHeaderSize":4294967295,"enableConnectProtocol":false} +0ms + adobe/fetch:h2 session https://www.nghttp2.org closed +6ms + adobe/fetch:h2 discarding cached session https://www.nghttp2.org +0ms ... ``` @@ -559,7 +551,7 @@ Additionally, you can enable Node.js low-level debug console output by setting t ```bash $ export NODE_DEBUG=http*,stream* -$ export DEBUG=helix-fetch* +$ export DEBUG=adobe/fetch* $ node test.js ``` diff --git a/package-lock.json b/package-lock.json index f1adea0..b80f480 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@adobe/helix-fetch", + "name": "@adobe/fetch", "version": "3.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "@adobe/helix-fetch", + "name": "@adobe/fetch", "version": "3.1.2", "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 496e89d..63db796 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@adobe/helix-fetch", + "name": "@adobe/fetch", "version": "3.1.2", "description": "Light-weight Fetch implementation transparently supporting both HTTP/1(.1) and HTTP/2", "main": "src/index.js", @@ -24,14 +24,14 @@ }, "repository": { "type": "git", - "url": "https://github.com/adobe/helix-fetch" + "url": "https://github.com/adobe/fetch" }, "author": "", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/adobe/helix-fetch/issues" + "url": "https://github.com/adobe/fetch/issues" }, - "homepage": "https://github.com/adobe/helix-fetch#readme", + "homepage": "https://github.com/adobe/fetch#readme", "keywords": [ "fetch", "whatwg", diff --git a/src/api.d.ts b/src/api.d.ts index 02b7503..ea876c7 100644 --- a/src/api.d.ts +++ b/src/api.d.ts @@ -178,7 +178,7 @@ export interface Http2Options { export interface ContextOptions { /** * Value of `user-agent` request header - * @default 'helix-fetch/' + * @default 'adobe-fetch/' */ userAgent?: string; /** diff --git a/src/common/utils.js b/src/common/utils.js index 8c13b55..0517435 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -26,7 +26,7 @@ const { }, } = require('zlib'); -const debug = require('debug')('helix-fetch:utils'); +const debug = require('debug')('adobe/fetch:utils'); const asyncPipeline = promisify(pipeline); diff --git a/src/core/h1.js b/src/core/h1.js index 77501fc..48dde2b 100644 --- a/src/core/h1.js +++ b/src/core/h1.js @@ -16,7 +16,7 @@ const http = require('http'); const https = require('https'); const { Readable } = require('stream'); -const debug = require('debug')('helix-fetch:h1'); +const debug = require('debug')('adobe/fetch:h1'); const { RequestAbortedError } = require('./errors'); const { decodeStream } = require('../common/utils'); diff --git a/src/core/h2.js b/src/core/h2.js index 7a9f01f..bf91c67 100644 --- a/src/core/h2.js +++ b/src/core/h2.js @@ -22,7 +22,7 @@ const { } = require('http2'); const { Readable } = require('stream'); -const debug = require('debug')('helix-fetch:h2'); +const debug = require('debug')('adobe/fetch:h2'); const { RequestAbortedError } = require('./errors'); const { decodeStream } = require('../common/utils'); diff --git a/src/core/index.js b/src/core/index.js index 4776a66..0602b95 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -12,7 +12,7 @@ 'use strict'; -const debug = require('debug')('helix-fetch:core'); +const debug = require('debug')('adobe/fetch:core'); const { request, @@ -49,7 +49,7 @@ class RequestContext { request: async (url, options) => this.request(url, options), /** - * This function returns an object which looks like the global `helix-fetch` API, + * This function returns an object which looks like the global `adobe/fetch` API, * i.e. it will have the functions `request`, `reset`, etc. and provide its * own isolated caches. * diff --git a/src/core/request.js b/src/core/request.js index e8a96f5..8be0fe4 100644 --- a/src/core/request.js +++ b/src/core/request.js @@ -17,7 +17,7 @@ const tls = require('tls'); const { types: { isAnyArrayBuffer } } = require('util'); const LRU = require('lru-cache'); -const debug = require('debug')('helix-fetch:core'); +const debug = require('debug')('adobe/fetch:core'); const { RequestAbortedError } = require('./errors'); const h1 = require('./h1'); diff --git a/src/fetch/index.js b/src/fetch/index.js index ca823c6..9982d25 100644 --- a/src/fetch/index.js +++ b/src/fetch/index.js @@ -15,7 +15,7 @@ const { EventEmitter } = require('events'); const { Readable } = require('stream'); -const debug = require('debug')('helix-fetch'); +const debug = require('debug')('adobe/fetch'); const LRU = require('lru-cache'); const { Body } = require('./body'); diff --git a/test/fetch/index.http2.test.js b/test/fetch/index.http2.test.js index ebf5adb..d7d8e4b 100644 --- a/test/fetch/index.http2.test.js +++ b/test/fetch/index.http2.test.js @@ -140,7 +140,7 @@ describe('HTTP/2-specific Fetch Tests', () => { }); it('handles concurrent HTTP/2 requests to subdomains sharing the same IP address (using wildcard SAN cert)', async () => { - // https://github.com/adobe/helix-fetch/issues/52 + // https://github.com/adobe/fetch/issues/52 const doFetch = async (url) => { const res = await fetch(url); assert.strictEqual(res.httpVersion, '2.0'); diff --git a/v2-UPGRADE-GUIDE.md b/v2-UPGRADE-GUIDE.md deleted file mode 100644 index 7feabc9..0000000 --- a/v2-UPGRADE-GUIDE.md +++ /dev/null @@ -1,110 +0,0 @@ -

Upgrade to helix-fetch v2.x

- -While helix-fetch v1.x was based on [fetch-h2](https://github.com/grantila/fetch-h2) - v2.x is a complete re-implementation from scratch. The exposed API, options etc. have - been aligned with [node-fetch](https://github.com/node-fetch/node-fetch) where possible. - Due to the major changes there are numerous breaking changes both in the API and the options, - which means that apps written for helix-fetch v1.x will most likely need to be updated to - work with helix-fetch v2.x. This document helps you make this transition. - -Note that this document is not an exhaustive list of all changes made in v2.x, -but rather that of the most important breaking changes. See our [ChangeLog](CHANGELOG.md) -for more information. - - -- [Node version](#node-version) -- [API](#api) -- [Context options](#context-options) -- [Fetch options](#fetch-options) -- [Post JSON](#post-json) -- [Headers](#headers) -- [Response stream](#response-stream) - - ---- - -## Node version - -As of v2 Node version >= 12 is required. - -## API - -- ~~`disconnectAll()`~~ has been renamed to `reset()`. -- ~~`TimeoutError`~~ is no longer supported. `AbortError` is used instead. -- `fetch()` throws `FetchError` - -## Context options - -Forcing HTTP/1.1: - -v1.x: - -```js -const { fetch } = require('@adobe/helix-fetch').context({ - httpsProtocols: ['http1'], - }); -``` - -**=> v2.x:** - -```js -const { fetch } = require('@adobe/helix-fetch').context({ - alpnProtocols: ['http/1.1'] - }); -``` - -## Fetch options - -The ~~`timeout`~~ option is no longer supported. Use the standard `signal` option instead. - -## Post JSON - -The ~~`json`~~ Fetch option is no longer supported. If `body` is a plain JS object it will be serialized as JSON and sent with `Content-Type: application/json`. - -v1.x: - -```js -const { fetch } = require('@adobe/helix-fetch'); - -const method = 'POST'; -const json = { foo: 'bar' }; -const resp = await fetch('https://httpbin.org/post', { method, json }); -``` - -**=> v2.x:** - -```js -const { fetch } = require('@adobe/helix-fetch'); - -const method = 'POST'; -const body = { foo: 'bar' }; -const resp = await fetch('https://httpbin.org/post', { method, body }); -``` - -## Headers - -The ~~`Headers#raw()`~~ method has been renamed to `Headers#plain()`. - -## Response stream - -The ~~`Response#readable()`~~ method is no longer supported. Use the `Response#body` property instead. - -v1.x: - -```js -const fs = require('fs'); -const { fetch } = require('@adobe/helix-fetch'); - -const resp = await fetch('https://httpbin.org/image/jpeg'); -(await resp.readable()).pipe(fs.createWriteStream('saved-image.jpg')); -``` - -**=> v2.x:** - -```js -const fs = require('fs'); -const { fetch } = require('@adobe/helix-fetch'); - -const resp = await fetch('https://httpbin.org/image/jpeg'); -resp.body.pipe(fs.createWriteStream('saved-image.jpg')); -``` From de62188dea9e4ff97211abd3a3ca0c975d034109 Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Mon, 19 Sep 2022 18:42:32 +0200 Subject: [PATCH 02/13] feat: rename to adobe/fetch --- .eslintrc.js | 73 ++++++++++++++++++++++++++-- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .renovaterc.json | 42 +++++++++++++++- README.md | 6 +-- package-lock.json | 26 +--------- package.json | 2 +- src/index.d.ts | 14 +++--- test/fetch/misc.test.js | 4 +- 8 files changed, 126 insertions(+), 43 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 54b29f1..9344f68 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,5 @@ /* - * Copyright 2019 Adobe. All rights reserved. + * Copyright 2022 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 @@ -9,8 +9,75 @@ * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ - module.exports = { root: true, - extends: '@adobe/helix', + extends: [ + 'eslint-config-airbnb-base', + ].map(require.resolve), + + env: { + node: true, + es2020: true, + }, + parserOptions: { + sourceType: 'script', + ecmaVersion: 11, + }, + plugins: [ + 'header', + ], + rules: { + strict: 0, + + // Forbid multiple statements in one line + 'max-statements-per-line': ['error', { max: 1 }], + + // Allow for-of loops + 'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'], + + // Allow return before else & redundant else statements + 'no-else-return': 'off', + + // allow dangling underscores for 'fields' + 'no-underscore-dangle': ['error', { + allowAfterThis: true, + allow: [ + '__ow_method', + '__ow_headers', + '__ow_path', + '__ow_user', + '__ow_body', + '__ow_query'], + }], + + // allow '_' as a throw-away variable + 'no-unused-vars': ['error', { + argsIgnorePattern: '^_$', + }], + + 'no-shadow': ['error', { + allow: ['_'], + }], + + // don't enforce extension rules + 'import/extensions': 0, + + // enforce license header + 'header/header': [2, 'block', ['', + { pattern: ' * Copyright \\d{4} Adobe\\. All rights reserved\\.', template: ' * Copyright 2022 Adobe. All rights reserved.' }, + ' * This file is licensed to you under the Apache License, Version 2.0 (the "License");', + ' * you may not use this file except in compliance with the License. You may obtain a copy', + ' * of the License at http://www.apache.org/licenses/LICENSE-2.0', + ' *', + ' * Unless required by applicable law or agreed to in writing, software distributed under', + ' * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS', + ' * OF ANY KIND, either express or implied. See the License for the specific language', + ' * governing permissions and limitations under the License.', + ' ', + ]], + + 'id-match': ['error', '^(?!.*?([wW][hH][iI][tT][eE]|[bB][lL][aA][cC][kK]).*[lL][iI][sS][tT]).*$', { + properties: true, + }], + }, }; diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 1d21418..c9a7ea4 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -22,7 +22,7 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Version:** -run: `$ hlx --version` +The version of adobe/fetch used. **Additional context** Add any other context about the problem here. diff --git a/.renovaterc.json b/.renovaterc.json index a2852b4..1800a82 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -1,3 +1,43 @@ { - "extends": ["github>adobe/helix-shared"] + "extends": [ + "config:base", + ":semanticCommits", + ":autodetectPinVersions" + ], + "timezone": "Europe/Zurich", + "branchPrefix": "renovate-", + "packageRules": [ + { + "packageNames": ["circleci/node"], + "allowedVersions": "<15" + }, + { + "packageNames": ["cimg/node"], + "allowedVersions": "<15" + }, + { + "groupName": "external fixes", + "updateTypes": ["patch", "pin", "digest", "minor"], + "automerge": true, + "schedule": ["after 2pm on Saturday"], + "packagePatterns": ["^.+"], + "excludePackagePatterns": ["^@adobe/"] + }, + { + "groupName": "external major", + "updateTypes": ["major"], + "automerge": false, + "packagePatterns": ["^.+"], + "excludePackagePatterns": ["^@adobe/"], + "schedule": ["after 2pm on Monday"] + }, + { + "datasources": ["orb"], + "updateTypes": ["patch", "minor"], + "automerge": true + } + ], + "encrypted": { + "npmToken": "ohOXR8y4hdfHs/2go7YBdEwkhCFA+atc0qqw0UdLoAkKITfpmD538MiXVQf1ZgRFfnmVyHy9uf9KV9DH0fSHl4QDbOZ/+0Y4JgalbaC0LgpWrvZIa3JRarMhfEq8oM2ZVCZrJQehLyh2zKTnkeiTRQWMQwNPOIbByJAqhRwzwCJWjHQk8ztC6T2DyJPO6KvkOusTRY2SN19FmkccUBRyAWdR6IkHels3zlQOnKPNx+FJRp9J1RLzHMlFmJ7878wrAoFBrSKRq6fSWfCro4q5iPe7xih2JvRzZmPX2vi/7KBktzBVr+1Pjr8C4XPX9I6NNztDEGlAJNLLQX2da6ZTjg==" + } } diff --git a/README.md b/README.md index 08ca18b..2d5e174 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
- Helix Fetch + adobe/fetch

Light-weight Fetch API implementation transparently supporting both HTTP/1(.1) and HTTP/2

codecov @@ -364,7 +364,7 @@ Using `AbortController`: const { createUrl, fetch } = require('@adobe/fetch'); const qs = { - helix: 'dummy', + fake: 'dummy', foo: 'bar', rumple: "stiltskin", }; @@ -378,7 +378,7 @@ or using `URLSearchParams`: const { fetch } = require('@adobe/fetch'); const body = new URLSearchParams({ - helix: 'dummy', + fake: 'dummy', foo: 'bar', rumple: "stiltskin", }); diff --git a/package-lock.json b/package-lock.json index b80f480..a42a756 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "lru-cache": "7.14.0" }, "devDependencies": { - "@adobe/eslint-config-helix": "1.3.2", "@semantic-release/changelog": "6.0.1", "@semantic-release/git": "10.0.1", "chai": "4.3.6", @@ -22,6 +21,7 @@ "chai-bytes": "0.1.2", "chai-iterator": "3.0.2", "eslint": "8.23.1", + "eslint-config-airbnb-base": "15.0.0", "eslint-plugin-header": "3.1.1", "eslint-plugin-import": "2.26.0", "formdata-node": "4.4.1", @@ -40,21 +40,6 @@ "node": ">=12.0" } }, - "node_modules/@adobe/eslint-config-helix": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@adobe/eslint-config-helix/-/eslint-config-helix-1.3.2.tgz", - "integrity": "sha512-Q2m5NFr78JeKDLZUnN3iqPD2QoOlduAL9auMUu0EDf8e9sd/T5lyMJWRyqlybQD2jrQOp0Oh7DvoYMThQaeerg==", - "dev": true, - "dependencies": { - "eslint-config-airbnb-base": "15.0.0" - }, - "engines": { - "node": ">= 12" - }, - "peerDependencies": { - "eslint": "^8.0.0" - } - }, "node_modules/@ampproject/remapping": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", @@ -10154,15 +10139,6 @@ } }, "dependencies": { - "@adobe/eslint-config-helix": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@adobe/eslint-config-helix/-/eslint-config-helix-1.3.2.tgz", - "integrity": "sha512-Q2m5NFr78JeKDLZUnN3iqPD2QoOlduAL9auMUu0EDf8e9sd/T5lyMJWRyqlybQD2jrQOp0Oh7DvoYMThQaeerg==", - "dev": true, - "requires": { - "eslint-config-airbnb-base": "15.0.0" - } - }, "@ampproject/remapping": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", diff --git a/package.json b/package.json index 63db796..0a37c01 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ "lru-cache": "7.14.0" }, "devDependencies": { - "@adobe/eslint-config-helix": "1.3.2", "@semantic-release/changelog": "6.0.1", "@semantic-release/git": "10.0.1", "chai": "4.3.6", @@ -62,6 +61,7 @@ "chai-bytes": "0.1.2", "chai-iterator": "3.0.2", "eslint": "8.23.1", + "eslint-config-airbnb-base": "15.0.0", "eslint-plugin-header": "3.1.1", "eslint-plugin-import": "2.26.0", "formdata-node": "4.4.1", diff --git a/src/index.d.ts b/src/index.d.ts index 9988710..68007ab 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -14,7 +14,7 @@ export * from './api'; import * as api from './api.d'; import { ContextOptions } from './api'; -declare type HelixFetchAPI = typeof api; +declare type FetchAPI = typeof api; /** * This function returns an object which looks like the public API, @@ -23,7 +23,7 @@ declare type HelixFetchAPI = typeof api; * * @param {ContextOptions} options */ -export declare function context(options?: ContextOptions): HelixFetchAPI; +export declare function context(options?: ContextOptions): FetchAPI; /** * Convenience function which creates a new context with disabled caching, @@ -33,7 +33,7 @@ export declare function context(options?: ContextOptions): HelixFetchAPI; * * @param {ContextOptions} options */ -export declare function noCache(options?: ContextOptions): HelixFetchAPI; +export declare function noCache(options?: ContextOptions): FetchAPI; /** * Convenience function which creates a new context with enforced HTTP/1.1 protocol, @@ -43,7 +43,7 @@ export declare function noCache(options?: ContextOptions): HelixFetchAPI; * * @param {ContextOptions} options */ - export declare function h1(options?: ContextOptions): HelixFetchAPI; + export declare function h1(options?: ContextOptions): FetchAPI; /** * Convenience function which creates a new context with enforced HTTP/1.1 protocol @@ -54,7 +54,7 @@ export declare function noCache(options?: ContextOptions): HelixFetchAPI; * * @param {ContextOptions} options */ - export declare function keepAlive(options?: ContextOptions): HelixFetchAPI; + export declare function keepAlive(options?: ContextOptions): FetchAPI; /** * Convenience function which creates a new context with disabled caching @@ -64,7 +64,7 @@ export declare function noCache(options?: ContextOptions): HelixFetchAPI; * * @param {ContextOptions} options */ - export declare function h1NoCache(options?: ContextOptions): HelixFetchAPI; + export declare function h1NoCache(options?: ContextOptions): FetchAPI; /** * Convenience function which creates a new context with disabled caching @@ -75,5 +75,5 @@ export declare function noCache(options?: ContextOptions): HelixFetchAPI; * * @param {ContextOptions} options */ - export declare function keepAliveNoCache(options?: ContextOptions): HelixFetchAPI; + export declare function keepAliveNoCache(options?: ContextOptions): FetchAPI; \ No newline at end of file diff --git a/test/fetch/misc.test.js b/test/fetch/misc.test.js index 7456124..afa7c73 100644 --- a/test/fetch/misc.test.js +++ b/test/fetch/misc.test.js @@ -22,9 +22,9 @@ const { createUrl, timeoutSignal } = require('../../src'); describe('Misc. Tests', () => { it('createUrl encodes query paramters', async () => { - const EXPECTED = 'https://httpbin.org/json?helix=42&dummy=true&name=Andr%C3%A9+Citro%C3%ABn&rumple=stiltskin&nephews=Huey&nephews=Louie&nephews=Dewey'; + const EXPECTED = 'https://httpbin.org/json?foo=42&dummy=true&name=Andr%C3%A9+Citro%C3%ABn&rumple=stiltskin&nephews=Huey&nephews=Louie&nephews=Dewey'; const qs = { - helix: 42, + foo: 42, dummy: true, name: 'André Citroën', rumple: 'stiltskin', From 29a1d118d9be617c370d1320fd1782659fa74580 Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 09:47:32 +0200 Subject: [PATCH 03/13] chore: clean up --- .renovaterc.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.renovaterc.json b/.renovaterc.json index 1800a82..350ad6c 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -20,15 +20,13 @@ "updateTypes": ["patch", "pin", "digest", "minor"], "automerge": true, "schedule": ["after 2pm on Saturday"], - "packagePatterns": ["^.+"], - "excludePackagePatterns": ["^@adobe/"] + "packagePatterns": ["^.+"] }, { "groupName": "external major", "updateTypes": ["major"], "automerge": false, "packagePatterns": ["^.+"], - "excludePackagePatterns": ["^@adobe/"], "schedule": ["after 2pm on Monday"] }, { From aa6ba27169f92c1f792d9917af12897e221c168d Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 09:54:10 +0200 Subject: [PATCH 04/13] chore: clean up --- package.json | 8 -------- 1 file changed, 8 deletions(-) diff --git a/package.json b/package.json index 0a37c01..99a9848 100644 --- a/package.json +++ b/package.json @@ -78,13 +78,5 @@ }, "lint-staged": { "*.js": "eslint" - }, - "config": { - "commitizen": { - "path": "node_modules/cz-conventional-changelog" - }, - "ghooks": { - "pre-commit": "npx lint-staged" - } } } From a6fab270a9c4c763d00ae0c3176c2bac9ebe9a90 Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 13:58:14 +0200 Subject: [PATCH 05/13] chore: doc cleanup --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8511d6c..77e40a9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -# Contributing to @adobe/fetch +# Contributing to adobe/fetch -This project (like almost all of @adobe/fetch) is an Open Development project and welcomes contributions from everyone who finds it useful or lacking. +This project is an Open Development project and welcomes contributions from everyone who finds it useful or lacking. ## Code Of Conduct From de6448b73bb9c50e10afcd60df28728effc10694 Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:12:24 +0200 Subject: [PATCH 06/13] Update src/core/index.js Co-authored-by: Lars Trieloff --- src/core/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/index.js b/src/core/index.js index 0602b95..6782764 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -49,7 +49,7 @@ class RequestContext { request: async (url, options) => this.request(url, options), /** - * This function returns an object which looks like the global `adobe/fetch` API, + * This function returns an object which looks like the global `@adobe/fetch` API, * i.e. it will have the functions `request`, `reset`, etc. and provide its * own isolated caches. * From d236041d770afc3ab6de1a7d5d4f92ad9d799ab4 Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:12:51 +0200 Subject: [PATCH 07/13] Update .github/ISSUE_TEMPLATE/bug_report.md Co-authored-by: Lars Trieloff --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c9a7ea4..7cc420e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -22,7 +22,7 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Version:** -The version of adobe/fetch used. +The version of @adobe/fetch used. **Additional context** Add any other context about the problem here. From 46eea7e8356821f330d9579c9c4abd51f57f75a4 Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:13:07 +0200 Subject: [PATCH 08/13] Update CONTRIBUTING.md Co-authored-by: Lars Trieloff --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 77e40a9..5914ff8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to adobe/fetch +# Contributing to `@adobe/fetch` This project is an Open Development project and welcomes contributions from everyone who finds it useful or lacking. From aa7b7f23c772af4727ec3658aab8f8ce83aa89f5 Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:13:26 +0200 Subject: [PATCH 09/13] Update README.md Co-authored-by: Lars Trieloff --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ab659a..81f0cec 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ ## About -`adobe/fetch` in general adheres to the [Fetch API Specification](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), implementing a subset of the API. However, there are some notable deviations: +`@adobe/fetch` in general adheres to the [Fetch API Specification](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), implementing a subset of the API. However, there are some notable deviations: * `Response.body` returns a Node.js [Readable stream](https://nodejs.org/api/stream.html#stream_readable_streams). * `Response.blob()` is not implemented. Use `Response.buffer()` instead. From 3c2cf65ac35998b55c423a8c100538f0ba6f9bda Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:13:49 +0200 Subject: [PATCH 10/13] Update README.md Co-authored-by: Lars Trieloff --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81f0cec..78a4f36 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ * `Response.formData()` is not implemented. * Cookies are not stored by default. However, cookies can be extracted and passed by manipulating request and response headers. * The following values of the `fetch()` option `cache` are supported: `'default'` (the implicit default) and `'no-store'`. All other values are currently ignored. -* The following `fetch()` options are ignored due to the nature of Node.js and since `adobe/fetch` doesn't have the concept of web pages: `mode`, `referrer`, `referrerPolicy`, `integrity` and `credentials`. +* The following `fetch()` options are ignored due to the nature of Node.js and since `@adobe/fetch` doesn't have the concept of web pages: `mode`, `referrer`, `referrerPolicy`, `integrity` and `credentials`. * The `fetch()` option `keepalive` is not supported. But you can use the `h1.keepAlive` context option, as demonstrated [here](#http11-keep-alive). `adobe/fetch` also supports the following extensions: From aba745aec5e19ab32929a643f233fdf2ffa25f4a Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:14:04 +0200 Subject: [PATCH 11/13] Update README.md Co-authored-by: Lars Trieloff --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78a4f36..9ca8f7d 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ * The following `fetch()` options are ignored due to the nature of Node.js and since `@adobe/fetch` doesn't have the concept of web pages: `mode`, `referrer`, `referrerPolicy`, `integrity` and `credentials`. * The `fetch()` option `keepalive` is not supported. But you can use the `h1.keepAlive` context option, as demonstrated [here](#http11-keep-alive). -`adobe/fetch` also supports the following extensions: +`@adobe/fetch` also supports the following extensions: * `Response.buffer()` returns a Node.js `Buffer`. * `Response.url` contains the final url when following redirects. From 1d32389c89cfb8aad5059eaadd4c5430b97ccc1d Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:14:17 +0200 Subject: [PATCH 12/13] Update README.md Co-authored-by: Lars Trieloff --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ca8f7d..7f9c915 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Apart from the standard Fetch API * `Headers` * `Body` -`adobe/fetch` exposes the following extensions: +`@adobe/fetch` exposes the following extensions: * `context()` - creates a new customized API context * `reset()` - resets the current API context, i.e. closes pending sessions/sockets, clears internal caches, etc ... From 3716c7da460f2b342ae5c4321dca4504ca24ae7d Mon Sep 17 00:00:00 2001 From: Stefan Guggisberg Date: Tue, 20 Sep 2022 15:14:29 +0200 Subject: [PATCH 13/13] Update README.md Co-authored-by: Lars Trieloff --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f9c915..3b06042 100644 --- a/README.md +++ b/README.md @@ -524,7 +524,7 @@ $ npm run lint ### Troubleshooting -You can enable `adobe/fetch` low-level debug console output by setting the `DEBUG` environment variable to `adobe/fetch*`, e.g.: +You can enable `@adobe/fetch` low-level debug console output by setting the `DEBUG` environment variable to `adobe/fetch*`, e.g.: ```bash $ DEBUG=adobe/fetch* node test.js