From 075744f49ed62f91a2c870d75d7b419b988f5dd5 Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Wed, 5 Apr 2023 22:56:02 +0200 Subject: [PATCH 01/17] nuxt(docs): use custon fetch init example #14736 --- examples/other/custom-fetch-composable/app.vue | 5 +++++ .../composables/useCustomFetch.ts | 16 ++++++++++++++++ .../other/custom-fetch-composable/nuxt.config.ts | 4 ++++ .../other/custom-fetch-composable/package.json | 14 ++++++++++++++ .../other/custom-fetch-composable/tsconfig.json | 4 ++++ 5 files changed, 43 insertions(+) create mode 100644 examples/other/custom-fetch-composable/app.vue create mode 100644 examples/other/custom-fetch-composable/composables/useCustomFetch.ts create mode 100644 examples/other/custom-fetch-composable/nuxt.config.ts create mode 100644 examples/other/custom-fetch-composable/package.json create mode 100644 examples/other/custom-fetch-composable/tsconfig.json diff --git a/examples/other/custom-fetch-composable/app.vue b/examples/other/custom-fetch-composable/app.vue new file mode 100644 index 000000000000..a495b7573290 --- /dev/null +++ b/examples/other/custom-fetch-composable/app.vue @@ -0,0 +1,5 @@ + diff --git a/examples/other/custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/custom-fetch-composable/composables/useCustomFetch.ts new file mode 100644 index 000000000000..de49edd9b01f --- /dev/null +++ b/examples/other/custom-fetch-composable/composables/useCustomFetch.ts @@ -0,0 +1,16 @@ +import type { FetchOptions } from 'ofetch' +type method = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace' + +type UseFetchOptions = FetchOptions & { method?: method } + +export async function useCustomFetch (url: string, options: UseFetchOptions = {}) { + const defaults: UseFetchOptions = { + baseURL: 'https://api.nuxtjs.dev' + } + + const params = Object.assign(defaults, options) + + const { data, p, error, refresh } = await useFetch(url, { + ...params + }) +} diff --git a/examples/other/custom-fetch-composable/nuxt.config.ts b/examples/other/custom-fetch-composable/nuxt.config.ts new file mode 100644 index 000000000000..5e7d9c6fd733 --- /dev/null +++ b/examples/other/custom-fetch-composable/nuxt.config.ts @@ -0,0 +1,4 @@ +// https://nuxt.com/docs/api/configuration/nuxt-config +export default defineNuxtConfig({ + +}) diff --git a/examples/other/custom-fetch-composable/package.json b/examples/other/custom-fetch-composable/package.json new file mode 100644 index 000000000000..ffa6db68e102 --- /dev/null +++ b/examples/other/custom-fetch-composable/package.json @@ -0,0 +1,14 @@ +{ + "name": "nuxt-app", + "private": true, + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "generate": "nuxt generate", + "preview": "nuxt preview", + "postinstall": "nuxt prepare" + }, + "devDependencies": { + "nuxt": "^3.3.3" + } +} diff --git a/examples/other/custom-fetch-composable/tsconfig.json b/examples/other/custom-fetch-composable/tsconfig.json new file mode 100644 index 000000000000..a746f2a70c28 --- /dev/null +++ b/examples/other/custom-fetch-composable/tsconfig.json @@ -0,0 +1,4 @@ +{ + // https://nuxt.com/docs/guide/concepts/typescript + "extends": "./.nuxt/tsconfig.json" +} From a9a8f7ea308ffeb615e467a6dcf2bfc463d78b27 Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Thu, 6 Apr 2023 19:38:53 +0200 Subject: [PATCH 02/17] nuxt(docs): better defaults in useCustomFetch --- .../composables/useCustomFetch.ts | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/examples/other/custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/custom-fetch-composable/composables/useCustomFetch.ts index de49edd9b01f..0b93d03ee4f9 100644 --- a/examples/other/custom-fetch-composable/composables/useCustomFetch.ts +++ b/examples/other/custom-fetch-composable/composables/useCustomFetch.ts @@ -1,16 +1,35 @@ -import type { FetchOptions } from 'ofetch' -type method = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace' +import type { UseFetchOptions } from 'nuxt/app' -type UseFetchOptions = FetchOptions & { method?: method } +export async function useCustomFetch(url: string, options: UseFetchOptions = {}) { + const userAuth = useCookie('token') + const config = useRuntimeConfig() -export async function useCustomFetch (url: string, options: UseFetchOptions = {}) { - const defaults: UseFetchOptions = { - baseURL: 'https://api.nuxtjs.dev' + const defaults: UseFetchOptions = { + baseURL: config.baseUrl ?? 'https://api.nuxtjs.dev', + // cache request + key: url, + + onRequest({ options }) { + options.headers = options.headers ?? new Headers() + + // set user token if connected + if (userAuth.value) { + options.headers['Authorization'] = `Bearer ${userAuth.value}` + } + }, + + onResponse({ response }) { + // return new myBusinessResponse(response._data)ß + }, + + onResponseError({ error }) { + // add you error logic here + // return new myBusinessError(error) + }, } + // for nice deep defaults, please unjs/defu const params = Object.assign(defaults, options) - const { data, p, error, refresh } = await useFetch(url, { - ...params - }) + return await useFetch(url, params) } From 5f1328966db6bc883a8cb7870dda041eb72d47de Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Thu, 6 Apr 2023 19:59:42 +0200 Subject: [PATCH 03/17] nuxt(docs): example in docs --- docs/3.api/1.composables/use-fetch.md | 3 +++ .../8.other/use-custom-fetch-composable.md | 9 +++++++++ examples/other/custom-fetch-composable/app.vue | 5 ----- .../other/use-custom-fetch-composable/app.vue | 16 ++++++++++++++++ .../composables/useCustomFetch.ts | 0 .../nuxt.config.ts | 4 +++- .../package.json | 0 .../tsconfig.json | 0 8 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 docs/4.examples/8.other/use-custom-fetch-composable.md delete mode 100644 examples/other/custom-fetch-composable/app.vue create mode 100644 examples/other/use-custom-fetch-composable/app.vue rename examples/other/{custom-fetch-composable => use-custom-fetch-composable}/composables/useCustomFetch.ts (100%) rename examples/other/{custom-fetch-composable => use-custom-fetch-composable}/nuxt.config.ts (74%) rename examples/other/{custom-fetch-composable => use-custom-fetch-composable}/package.json (100%) rename examples/other/{custom-fetch-composable => use-custom-fetch-composable}/tsconfig.json (100%) diff --git a/docs/3.api/1.composables/use-fetch.md b/docs/3.api/1.composables/use-fetch.md index 6a4f03963641..06ba5e8c1b0b 100644 --- a/docs/3.api/1.composables/use-fetch.md +++ b/docs/3.api/1.composables/use-fetch.md @@ -126,6 +126,9 @@ const { data, pending, error, refresh } = await useFetch('/api/auth/login', { `useFetch` is a reserved function name transformed by the compiler, so you should not name your own function `useFetch`. :: +::LinkExample{link="/docs/examples/other/use-custom-fetch-composable"} +:: + :ReadMore{link="/docs/getting-started/data-fetching"} ::LinkExample{link="/docs/examples/composables/use-fetch"} diff --git a/docs/4.examples/8.other/use-custom-fetch-composable.md b/docs/4.examples/8.other/use-custom-fetch-composable.md new file mode 100644 index 000000000000..939bf9e50d3f --- /dev/null +++ b/docs/4.examples/8.other/use-custom-fetch-composable.md @@ -0,0 +1,9 @@ +--- +toc: false +--- + +# Use custom fetch composable + +This example shows a convenient wrapper for the useFetch composable from nuxt. It allows you to customize the fetch request with default values and user authentication token. + +::sandbox{repo="nuxt/nuxt" branch="main" dir="examples/other/use-custom-fetch-composable" file="composables/useCustomFetch.ts"} diff --git a/examples/other/custom-fetch-composable/app.vue b/examples/other/custom-fetch-composable/app.vue deleted file mode 100644 index a495b7573290..000000000000 --- a/examples/other/custom-fetch-composable/app.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/examples/other/use-custom-fetch-composable/app.vue b/examples/other/use-custom-fetch-composable/app.vue new file mode 100644 index 000000000000..a4b3d6d4a9e5 --- /dev/null +++ b/examples/other/use-custom-fetch-composable/app.vue @@ -0,0 +1,16 @@ + + + + diff --git a/examples/other/custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts similarity index 100% rename from examples/other/custom-fetch-composable/composables/useCustomFetch.ts rename to examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts diff --git a/examples/other/custom-fetch-composable/nuxt.config.ts b/examples/other/use-custom-fetch-composable/nuxt.config.ts similarity index 74% rename from examples/other/custom-fetch-composable/nuxt.config.ts rename to examples/other/use-custom-fetch-composable/nuxt.config.ts index 5e7d9c6fd733..1ede6806b692 100644 --- a/examples/other/custom-fetch-composable/nuxt.config.ts +++ b/examples/other/use-custom-fetch-composable/nuxt.config.ts @@ -1,4 +1,6 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ - + modules: [ + '@nuxt/ui' + ] }) diff --git a/examples/other/custom-fetch-composable/package.json b/examples/other/use-custom-fetch-composable/package.json similarity index 100% rename from examples/other/custom-fetch-composable/package.json rename to examples/other/use-custom-fetch-composable/package.json diff --git a/examples/other/custom-fetch-composable/tsconfig.json b/examples/other/use-custom-fetch-composable/tsconfig.json similarity index 100% rename from examples/other/custom-fetch-composable/tsconfig.json rename to examples/other/use-custom-fetch-composable/tsconfig.json From 0342e59cd8bc97c1471bd95805fc07f18989104e Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Thu, 6 Apr 2023 20:25:26 +0200 Subject: [PATCH 04/17] nuxt(docs): fix build ? --- examples/other/use-custom-fetch-composable/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/other/use-custom-fetch-composable/package.json b/examples/other/use-custom-fetch-composable/package.json index ffa6db68e102..fce61f7e3508 100644 --- a/examples/other/use-custom-fetch-composable/package.json +++ b/examples/other/use-custom-fetch-composable/package.json @@ -9,6 +9,7 @@ "postinstall": "nuxt prepare" }, "devDependencies": { + "@nuxt/ui": "^0.3.3", "nuxt": "^3.3.3" } } From 9baf8419a7c04bb320c0631937efef737aa11fef Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 7 Apr 2023 09:34:03 +0100 Subject: [PATCH 05/17] chore: update lockfile --- pnpm-lock.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bafd147a2045..93f9847338b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,6 +304,15 @@ importers: specifier: workspace:* version: link:../../../packages/nuxt + examples/other/use-custom-fetch-composable: + devDependencies: + '@nuxt/ui': + specifier: ^0.3.3 + version: 0.3.3(nuxt@packages+nuxt)(rollup@3.20.2)(vite@3.2.5)(vue@3.2.47)(webpack@5.78.0) + nuxt: + specifier: workspace:* + version: link:../../../packages/nuxt + examples/routing/layouts: devDependencies: '@nuxt/ui': From c718c990469d5be7332ec6ada271cfba1eeb4ef5 Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Sat, 22 Apr 2023 00:16:18 +0200 Subject: [PATCH 06/17] nuxt(docs): fix package lock ? --- pnpm-lock.yaml | 152 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 720a1638176f..9276e6f67f46 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -167,7 +167,7 @@ importers: version: link:../../../packages/nuxt vitest: specifier: latest - version: 0.30.1(playwright@1.32.3) + version: 0.29.8(playwright@1.32.3) examples/app-config: devDependencies: @@ -314,7 +314,7 @@ importers: devDependencies: '@nuxt/ui': specifier: ^0.3.3 - version: 0.3.3(nuxt@packages+nuxt)(rollup@3.20.2)(vite@3.2.5)(vue@3.2.47)(webpack@5.78.0) + version: 0.3.3(nuxt@packages+nuxt)(rollup@3.20.2)(vite@3.2.5)(vue@3.2.47)(webpack@5.80.0) nuxt: specifier: workspace:* version: link:../../../packages/nuxt @@ -2987,6 +2987,14 @@ packages: vite: 4.3.0(@types/node@18.15.12) vue: 3.2.47 + /@vitest/expect@0.29.8: + resolution: {integrity: sha512-xlcVXn5I5oTq6NiZSY3ykyWixBxr5mG8HYtjvpgg6KaqHm0mvhX18xuwl5YGxIRNt/A5jidd7CWcNHrSvgaQqQ==} + dependencies: + '@vitest/spy': 0.29.8 + '@vitest/utils': 0.29.8 + chai: 4.3.7 + dev: true + /@vitest/expect@0.30.1: resolution: {integrity: sha512-c3kbEtN8XXJSeN81iDGq29bUzSjQhjES2WR3aColsS4lPGbivwLtas4DNUe0jD9gg/FYGIteqOenfU95EFituw==} dependencies: @@ -2995,6 +3003,14 @@ packages: chai: 4.3.7 dev: true + /@vitest/runner@0.29.8: + resolution: {integrity: sha512-FzdhnRDwEr/A3Oo1jtIk/B952BBvP32n1ObMEb23oEJNO+qO5cBet6M2XWIDQmA7BDKGKvmhUf2naXyp/2JEwQ==} + dependencies: + '@vitest/utils': 0.29.8 + p-limit: 4.0.0 + pathe: 1.1.0 + dev: true + /@vitest/runner@0.30.1: resolution: {integrity: sha512-W62kT/8i0TF1UBCNMRtRMOBWJKRnNyv9RrjIgdUryEe0wNpGZvvwPDLuzYdxvgSckzjp54DSpv1xUbv4BQ0qVA==} dependencies: @@ -3012,12 +3028,27 @@ packages: pretty-format: 27.5.1 dev: true + /@vitest/spy@0.29.8: + resolution: {integrity: sha512-VdjBe9w34vOMl5I5mYEzNX8inTxrZ+tYUVk9jxaZJmHFwmDFC/GV3KBFTA/JKswr3XHvZL+FE/yq5EVhb6pSAw==} + dependencies: + tinyspy: 1.1.1 + dev: true + /@vitest/spy@0.30.1: resolution: {integrity: sha512-YfJeIf37GvTZe04ZKxzJfnNNuNSmTEGnla2OdL60C8od16f3zOfv9q9K0nNii0NfjDJRt/CVN/POuY5/zTS+BA==} dependencies: tinyspy: 2.1.0 dev: true + /@vitest/utils@0.29.8: + resolution: {integrity: sha512-qGzuf3vrTbnoY+RjjVVIBYfuWMjn3UMUqyQtdGNZ6ZIIyte7B37exj6LaVkrZiUTvzSadVvO/tJm8AEgbGCBPg==} + dependencies: + cli-truncate: 3.1.0 + diff: 5.1.0 + loupe: 2.3.6 + pretty-format: 27.5.1 + dev: true + /@vitest/utils@0.30.1: resolution: {integrity: sha512-/c8Xv2zUVc+rnNt84QF0Y0zkfxnaGhp87K2dYJMLtLOIckPzuxLVzAtFCicGFdB4NeBHNzTRr1tNn7rCtQcWFA==} dependencies: @@ -3989,6 +4020,14 @@ packages: resolution: {integrity: sha512-qu3pN8Y3qHNgE2AFweciB1IfMnmZ/fsNTEE+NOFjmGB2F/7rLhnhzppvpCnN4FovtP26k8lHyy9ptEbNwWFLzw==} engines: {node: '>=6'} + /cli-truncate@3.1.0: + resolution: {integrity: sha512-wfOBkjXteqSnI59oPcJkcPl/ZmwvMMOj340qUIY1SKZCv0B9Cf4D4fAucRkIKQmsIuYK3x1rrgU7MeGRruiuiA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + slice-ansi: 5.0.0 + string-width: 5.1.2 + dev: true + /cli-width@4.0.0: resolution: {integrity: sha512-ZksGS2xpa/bYkNzN3BAw1wEjsLV/ZKOf/CCrJ/QOBsxx6fOARIkwTutxp1XIOIohi6HKmOFjMoK/XaqDVUpEEw==} engines: {node: '>= 12'} @@ -4544,6 +4583,11 @@ packages: engines: {node: '>=0.3.1'} dev: false + /diff@5.1.0: + resolution: {integrity: sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==} + engines: {node: '>=0.3.1'} + dev: true + /dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -6295,6 +6339,11 @@ packages: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} engines: {node: '>=8'} + /is-fullwidth-code-point@4.0.0: + resolution: {integrity: sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==} + engines: {node: '>=12'} + dev: true + /is-glob@4.0.3: resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} engines: {node: '>=0.10.0'} @@ -8572,6 +8621,14 @@ packages: resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==} engines: {node: '>=12'} + /slice-ansi@5.0.0: + resolution: {integrity: sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==} + engines: {node: '>=12'} + dependencies: + ansi-styles: 6.2.1 + is-fullwidth-code-point: 4.0.0 + dev: true + /smob@0.0.6: resolution: {integrity: sha512-V21+XeNni+tTyiST1MHsa84AQhT1aFZipzPpOFAVB8DkHzwJyjjAmt9bgwnuZiZWnIbMo2duE29wybxv/7HWUw==} @@ -8933,6 +8990,11 @@ packages: engines: {node: '>=14.0.0'} dev: true + /tinyspy@1.1.1: + resolution: {integrity: sha512-UVq5AXt/gQlti7oxoIg5oi/9r0WpF7DGEVwXgqWSMmyN16+e3tl5lIvTaOpJ3TAtu5xFzWccFRM4R5NaWHF+4g==} + engines: {node: '>=14.0.0'} + dev: true + /tinyspy@2.1.0: resolution: {integrity: sha512-7eORpyqImoOvkQJCSkL0d0mB4NHHIFAy4b1u8PHdDa7SjGS2njzl6/lyGoZLm+eyYEtlUmFGE0rFj66SWxZgQQ==} engines: {node: '>=14.0.0'} @@ -9412,6 +9474,27 @@ packages: extsprintf: 1.3.0 dev: true + /vite-node@0.29.8(@types/node@18.15.12): + resolution: {integrity: sha512-b6OtCXfk65L6SElVM20q5G546yu10/kNrhg08afEoWlFRJXFq9/6glsvSVY+aI6YeC1tu2TtAqI2jHEQmOmsFw==} + engines: {node: '>=v14.16.0'} + hasBin: true + dependencies: + cac: 6.7.14 + debug: 4.3.4 + mlly: 1.2.0 + pathe: 1.1.0 + picocolors: 1.0.0 + vite: 4.3.0(@types/node@18.15.12) + transitivePeerDependencies: + - '@types/node' + - less + - sass + - stylus + - sugarss + - supports-color + - terser + dev: true + /vite-node@0.30.1(@types/node@18.15.12): resolution: {integrity: sha512-vTikpU/J7e6LU/8iM3dzBo8ZhEiKZEKRznEMm+mJh95XhWaPrJQraT/QsT2NWmuEf+zgAoMe64PKT7hfZ1Njmg==} engines: {node: '>=v14.18.0'} @@ -9551,6 +9634,71 @@ packages: optionalDependencies: fsevents: 2.3.2 + /vitest@0.29.8(playwright@1.32.3): + resolution: {integrity: sha512-JIAVi2GK5cvA6awGpH0HvH/gEG9PZ0a/WoxdiV3PmqK+3CjQMf8c+J/Vhv4mdZ2nRyXFw66sAg6qz7VNkaHfDQ==} + engines: {node: '>=v14.16.0'} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@vitest/browser': '*' + '@vitest/ui': '*' + happy-dom: '*' + jsdom: '*' + playwright: '*' + safaridriver: '*' + webdriverio: '*' + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@vitest/browser': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + playwright: + optional: true + safaridriver: + optional: true + webdriverio: + optional: true + dependencies: + '@types/chai': 4.3.4 + '@types/chai-subset': 1.3.3 + '@types/node': 18.15.12 + '@vitest/expect': 0.29.8 + '@vitest/runner': 0.29.8 + '@vitest/spy': 0.29.8 + '@vitest/utils': 0.29.8 + acorn: 8.8.2 + acorn-walk: 8.2.0 + cac: 6.7.14 + chai: 4.3.7 + debug: 4.3.4 + local-pkg: 0.4.3 + pathe: 1.1.0 + picocolors: 1.0.0 + playwright: 1.32.3 + source-map: 0.6.1 + std-env: 3.3.2 + strip-literal: 1.0.1 + tinybench: 2.4.0 + tinypool: 0.4.0 + tinyspy: 1.1.1 + vite: 4.3.0(@types/node@18.15.12) + vite-node: 0.29.8(@types/node@18.15.12) + why-is-node-running: 2.2.2 + transitivePeerDependencies: + - less + - sass + - stylus + - sugarss + - supports-color + - terser + dev: true + /vitest@0.30.1(playwright@1.32.3): resolution: {integrity: sha512-y35WTrSTlTxfMLttgQk4rHcaDkbHQwDP++SNwPb+7H8yb13Q3cu2EixrtHzF27iZ8v0XCciSsLg00RkPAzB/aA==} engines: {node: '>=v14.18.0'} From a4f4b384d70ca6ea714c789337b3bb2f4125b45a Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Sat, 22 Apr 2023 00:20:16 +0200 Subject: [PATCH 07/17] nuxt(docs): other attempt to fix the lock --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2670f7448058..cf8ebe4b9d73 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9482,7 +9482,7 @@ packages: mlly: 1.2.0 pathe: 1.1.0 picocolors: 1.0.0 - vite: 4.3.0(@types/node@18.15.12) + vite: 4.3.1(@types/node@18.15.12) transitivePeerDependencies: - '@types/node' - less @@ -9685,7 +9685,7 @@ packages: tinybench: 2.4.0 tinypool: 0.4.0 tinyspy: 1.1.1 - vite: 4.3.0(@types/node@18.15.12) + vite: 4.3.1(@types/node@18.15.12) vite-node: 0.29.8(@types/node@18.15.12) why-is-node-running: 2.2.2 transitivePeerDependencies: From 66ca3f8adeee6414f0224fc47730ba154b55c1c5 Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Sat, 22 Apr 2023 00:41:37 +0200 Subject: [PATCH 08/17] nuxt(docs): align with other examples --- examples/other/use-custom-fetch-composable/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/other/use-custom-fetch-composable/package.json b/examples/other/use-custom-fetch-composable/package.json index fce61f7e3508..83ad8c42bdcc 100644 --- a/examples/other/use-custom-fetch-composable/package.json +++ b/examples/other/use-custom-fetch-composable/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@nuxt/ui": "^0.3.3", - "nuxt": "^3.3.3" + "nuxt": "^3.0.0" } } From f18e3867625c3cf7716b37228e28738742dd36e4 Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Sat, 22 Apr 2023 00:49:29 +0200 Subject: [PATCH 09/17] nuxt(docs): fix package.json --- .../other/use-custom-fetch-composable/package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/other/use-custom-fetch-composable/package.json b/examples/other/use-custom-fetch-composable/package.json index 83ad8c42bdcc..e010f02188a9 100644 --- a/examples/other/use-custom-fetch-composable/package.json +++ b/examples/other/use-custom-fetch-composable/package.json @@ -1,12 +1,12 @@ { - "name": "nuxt-app", + "name": "example-use-custom-fetch-composable", "private": true, "scripts": { - "build": "nuxt build", - "dev": "nuxt dev", - "generate": "nuxt generate", - "preview": "nuxt preview", - "postinstall": "nuxt prepare" + "build": "nuxi build", + "dev": "nuxi dev", + "generate": "nuxi generate", + "preview": "nuxi preview", + "postinstall": "nuxi prepare" }, "devDependencies": { "@nuxt/ui": "^0.3.3", From ae079e68c42f730846c5d3a21e6bb1777f55e45e Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Sat, 22 Apr 2023 00:51:22 +0200 Subject: [PATCH 10/17] nuxt(docs): remove post install --- examples/other/use-custom-fetch-composable/package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/other/use-custom-fetch-composable/package.json b/examples/other/use-custom-fetch-composable/package.json index e010f02188a9..ae4d6000981f 100644 --- a/examples/other/use-custom-fetch-composable/package.json +++ b/examples/other/use-custom-fetch-composable/package.json @@ -4,9 +4,7 @@ "scripts": { "build": "nuxi build", "dev": "nuxi dev", - "generate": "nuxi generate", - "preview": "nuxi preview", - "postinstall": "nuxi prepare" + "start": "nuxi preview" }, "devDependencies": { "@nuxt/ui": "^0.3.3", From 3f842e4e590dc8e20382887378b2f9c60d58f9ec Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Sat, 22 Apr 2023 01:01:15 +0200 Subject: [PATCH 11/17] nuxt(docs): fix lint --- .../composables/useCustomFetch.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts index 0b93d03ee4f9..68430e983967 100644 --- a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts +++ b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts @@ -1,6 +1,6 @@ import type { UseFetchOptions } from 'nuxt/app' -export async function useCustomFetch(url: string, options: UseFetchOptions = {}) { +export async function useCustomFetch (url: string, options: UseFetchOptions = {}) { const userAuth = useCookie('token') const config = useRuntimeConfig() @@ -9,23 +9,23 @@ export async function useCustomFetch(url: string, options: UseFetchOptions // cache request key: url, - onRequest({ options }) { + onRequest ({ options }) { options.headers = options.headers ?? new Headers() // set user token if connected if (userAuth.value) { - options.headers['Authorization'] = `Bearer ${userAuth.value}` + options.headers.Authorization = `Bearer ${userAuth.value}` } }, - onResponse({ response }) { + onResponse (__ctx) { // return new myBusinessResponse(response._data)ß }, - onResponseError({ error }) { + onResponseError (__ctx) { // add you error logic here // return new myBusinessError(error) - }, + } } // for nice deep defaults, please unjs/defu From 30ec3469ec6fa98bfe2aaafcd5d8bf4707836fe2 Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Sat, 22 Apr 2023 01:14:34 +0200 Subject: [PATCH 12/17] nuxt(docs): fix typos --- .../composables/useCustomFetch.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts index 68430e983967..c921262879c3 100644 --- a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts +++ b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts @@ -19,16 +19,15 @@ export async function useCustomFetch (url: string, options: UseFetchOptions Date: Tue, 25 Apr 2023 21:59:36 +0200 Subject: [PATCH 13/17] using defu --- .../use-custom-fetch-composable/composables/useCustomFetch.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts index c921262879c3..ac49a3d9423c 100644 --- a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts +++ b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts @@ -1,4 +1,5 @@ import type { UseFetchOptions } from 'nuxt/app' +import { defu } from 'defu' export async function useCustomFetch (url: string, options: UseFetchOptions = {}) { const userAuth = useCookie('token') @@ -28,7 +29,7 @@ export async function useCustomFetch (url: string, options: UseFetchOptions Date: Tue, 25 Apr 2023 22:10:04 +0200 Subject: [PATCH 14/17] simpler default header --- .../composables/useCustomFetch.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts index ac49a3d9423c..e2e486e8d2c1 100644 --- a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts +++ b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts @@ -10,14 +10,11 @@ export async function useCustomFetch (url: string, options: UseFetchOptions Date: Wed, 26 Apr 2023 10:00:51 +0100 Subject: [PATCH 15/17] refactor: use plain object for headers --- .../composables/useCustomFetch.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts index e2e486e8d2c1..8722e7cee266 100644 --- a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts +++ b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts @@ -10,11 +10,10 @@ export async function useCustomFetch (url: string, options: UseFetchOptions Date: Wed, 26 Apr 2023 10:01:53 +0100 Subject: [PATCH 16/17] refactor: use sync function --- .../use-custom-fetch-composable/composables/useCustomFetch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts index 8722e7cee266..56365292b7b8 100644 --- a/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts +++ b/examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts @@ -1,7 +1,7 @@ import type { UseFetchOptions } from 'nuxt/app' import { defu } from 'defu' -export async function useCustomFetch (url: string, options: UseFetchOptions = {}) { +export function useCustomFetch (url: string, options: UseFetchOptions = {}) { const userAuth = useCookie('token') const config = useRuntimeConfig() @@ -27,5 +27,5 @@ export async function useCustomFetch (url: string, options: UseFetchOptions Date: Wed, 26 Apr 2023 10:08:37 +0100 Subject: [PATCH 17/17] chore: update lockfile --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2f301bf27a6..2ad71d386788 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -314,7 +314,7 @@ importers: devDependencies: '@nuxt/ui': specifier: ^0.3.3 - version: 0.3.3(nuxt@packages+nuxt)(rollup@3.20.2)(vite@3.2.5)(vue@3.2.47)(webpack@5.80.0) + version: 0.3.3(nuxt@packages+nuxt)(rollup@3.21.0)(vite@3.2.5)(vue@3.2.47)(webpack@5.80.0) nuxt: specifier: workspace:* version: link:../../../packages/nuxt