diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0b6072c..c1870cf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,11 +10,9 @@ jobs: fail-fast: false matrix: node-version: - # Uncomment when using Got v10 - # - 14 - # - 12 + - 14 + - 12 - 10 - - 8 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 diff --git a/index.js b/index.js index 072dc59..eb5c794 100644 --- a/index.js +++ b/index.js @@ -110,7 +110,6 @@ alfy.cache = new CacheConf({ alfy.fetch = async (url, options) => { options = { - json: true, ...options }; @@ -132,7 +131,7 @@ alfy.fetch = async (url, options) => { let response; try { - response = await got(url, options); + response = await got(url, {searchParams: options.query}).json(); } catch (error) { if (cachedResponse) { return cachedResponse; @@ -141,7 +140,7 @@ alfy.fetch = async (url, options) => { throw error; } - const data = options.transform ? options.transform(response.body) : response.body; + const data = options.transform ? options.transform(response) : response; if (options.maxAge) { alfy.cache.set(key, data, {maxAge: options.maxAge}); diff --git a/package.json b/package.json index f0913e5..50d7c88 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "alfy-cleanup": "cleanup.js" }, "engines": { - "node": ">=8" + "node": ">=10" }, "scripts": { "test": "xo && ava" @@ -43,7 +43,7 @@ "dot-prop": "^5.1.0", "esm": "^3.2.18", "execa": "^2.0.4", - "got": "^9.3.2", + "got": "^11.8.2", "hook-std": "^2.0.0", "loud-rejection": "^2.1.0", "read-pkg-up": "^6.0.0" diff --git a/test/fetch.js b/test/fetch.js index a1b5fe7..e13f980 100644 --- a/test/fetch.js +++ b/test/fetch.js @@ -56,7 +56,7 @@ test('cache key', async t => { const alfy = createAlfy(); t.deepEqual(await alfy.fetch(`${URL}/cache-key`, {query: {unicorn: 'rainbow'}, maxAge: 5000}), {unicorn: 'rainbow'}); - t.truthy(alfy.cache.store['https://foo.bar/cache-key{"json":true,"query":{"unicorn":"rainbow"},"maxAge":5000}']); + t.truthy(alfy.cache.store['https://foo.bar/cache-key{"query":{"unicorn":"rainbow"},"maxAge":5000}']); }); test('invalid version', async t => { @@ -65,12 +65,12 @@ test('invalid version', async t => { const alfy = createAlfy({cache, version: '1.0.0'}); t.deepEqual(await alfy.fetch(`${URL}/cache-version`, {maxAge: 5000}), {foo: 'bar'}); t.deepEqual(await alfy.fetch(`${URL}/cache-version`, {maxAge: 5000}), {foo: 'bar'}); - t.deepEqual(alfy.cache.store['https://foo.bar/cache-version{"json":true,"maxAge":5000}'].data, {foo: 'bar'}); + t.deepEqual(alfy.cache.store['https://foo.bar/cache-version{"maxAge":5000}'].data, {foo: 'bar'}); const alfy2 = createAlfy({cache, version: '1.0.0'}); t.deepEqual(await alfy2.fetch(`${URL}/cache-version`, {maxAge: 5000}), {foo: 'bar'}); const alfy3 = createAlfy({cache, version: '1.0.1'}); t.deepEqual(await alfy3.fetch(`${URL}/cache-version`, {maxAge: 5000}), {unicorn: 'rainbow'}); - t.deepEqual(alfy.cache.store['https://foo.bar/cache-version{"json":true,"maxAge":5000}'].data, {unicorn: 'rainbow'}); + t.deepEqual(alfy.cache.store['https://foo.bar/cache-version{"maxAge":5000}'].data, {unicorn: 'rainbow'}); });