From ad084061bba5921cf757438deeaff4b9187465fc Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 26 Sep 2023 03:04:19 +0200 Subject: [PATCH 1/2] feat(fetch): allow fetch options to be passed through for find & findOne --- src/runtime/composables-v4/useStrapi4.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/runtime/composables-v4/useStrapi4.ts b/src/runtime/composables-v4/useStrapi4.ts index ca569223..4a0caa32 100644 --- a/src/runtime/composables-v4/useStrapi4.ts +++ b/src/runtime/composables-v4/useStrapi4.ts @@ -1,4 +1,5 @@ import type { Strapi4RequestParams } from '../types/v4' +import type { FetchOptions } from 'ofetch' import { useStrapiVersion, useStrapiClient } from '#imports' /** @@ -19,8 +20,8 @@ export const useStrapi4 = () => { * @param {Strapi4RequestParams} params? - Query parameters * @returns Promise */ - const find = (contentType: string, params?: Strapi4RequestParams): Promise => { - return client(`/${contentType}`, { method: 'GET', params }) + const find = (contentType: string, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise => { + return client(`/${contentType}`, { method: 'GET', params, ...fetchOptions }) } /** @@ -31,7 +32,7 @@ export const useStrapi4 = () => { * @param {Strapi4RequestParams} params? - Query parameters * @returns Promise */ - const findOne = (contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams): Promise => { + const findOne = (contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise => { if (typeof id === 'object') { params = id // @ts-ignore @@ -40,7 +41,7 @@ export const useStrapi4 = () => { const path = [contentType, id].filter(Boolean).join('/') - return client(path, { method: 'GET', params }) + return client(path, { method: 'GET', params, ...fetchOptions }) } /** From bce22aef9c2b4d75409a108267f0e1a38c920188 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 26 Sep 2023 03:07:29 +0200 Subject: [PATCH 2/2] docs: add fetch options argument to docs --- docs/content/3.usage.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/content/3.usage.md b/docs/content/3.usage.md index 43cb32b0..7648f3ee 100644 --- a/docs/content/3.usage.md +++ b/docs/content/3.usage.md @@ -47,6 +47,7 @@ Get entries. Returns entries matching the query filters (see [parameters](https: - **Arguments:** - contentType: `string` - params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24) + - fetchOptions?: [`FetchOptions`](https://github.com/unjs/ohmyfetch/blob/main/src/fetch.ts#L26) - **Returns:** `Promise` ```vue @@ -69,6 +70,7 @@ Returns an entry by `id`. - contentType: `string` - id?: `string | number | Strapi4RequestParams` - params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24) + - fetchOptions?: [`FetchOptions`](https://github.com/unjs/ohmyfetch/blob/main/src/fetch.ts#L26) - **Returns:** `Promise` ```vue