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

fix(module)!: default version to v5 #436

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
## Features

- Nuxt 3 ready
- Strapi v3 + v4 compatible
- Strapi v5/v4/v3 compatible
- Authentication support
- RESTful methods
- Handle errors with hooks
Expand Down
4 changes: 2 additions & 2 deletions docs/content/1.index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ hero:
export default defineNuxtConfig({
modules: ['@nuxtjs/strapi'],
strapi: {
version: 'v4',
version: 'v5',
prefix: '/api'
}
})
Expand All @@ -32,7 +32,7 @@ features:
- title: 'Nuxt 3 Ready'
description: 'Leverage our auto-imported [composables](/usage) and our [devtools](/devtools) integration.'
icon: 'i-simple-icons-nuxtdotjs'
- title: 'Strapi v3 & v4'
- title: 'Strapi v4/v3/v5'
description: 'Works with the different versions of Strapi.'
icon: 'i-simple-icons-strapi'
- title: 'Authentication'
Expand Down
6 changes: 3 additions & 3 deletions docs/content/2.setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Defaults:
url: process.env.STRAPI_URL || 'http://localhost:1337',
prefix: '/api',
admin: '/admin',
version: 'v4',
version: 'v5',
cookie: {},
cookieName: 'strapi_jwt'
}
Expand Down Expand Up @@ -68,13 +68,13 @@ Specify admin prefix used by your Strapi.

### `prefix`

Prefix of the Strapi server. Only used when version is `v4`.
Prefix of the Strapi server. Not for version `v3`.

> Learn how to change the default [API prefix](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/api.html) in your Strapi server.

### `version`

Version of the Strapi server. Can only be `v4` or `v3`.
Version of the Strapi server. Can only be `v5`/`v4`/`v3`.

### `cookie`

Expand Down
4 changes: 2 additions & 2 deletions docs/content/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ description: Learn how to use strapi module in your Nuxt 3 application.

## `useStrapi`

Depending on which version you have in your [options](/setup#options), you will be using either the v3 or v4 client.
Depending on which version you have in your [options](/setup#options), you will be using either the version you want client.

::callout{icon="i-heroicons-light-bulb"}
All examples below are demonstrated with v4 `useStrapi()`. :br
:br
Note that v3 exposes the same methods with different options. Check out specific types for [v3](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v3.d.ts) and [v4](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts).
Note that v3 exposes the same methods with different options. Check out specific types for [v5](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v5.ts), [v4](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.ts) or [v3](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v3.ts).
::

> Learn how to handle Strapi errors globally by using [nuxt hooks](/advanced#errors-handling).
Expand Down
12 changes: 6 additions & 6 deletions docs/content/5.advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ definePageMeta({

You can use the nuxt `strapi:error` hook to display a toast for example (the following example assumes that a `$toast` plugin has been injected).

Here are examples for both `v4` and `v3` as the signature between both versions is different.
Here are examples for both `v5`/`v4` and `v3` as the signature between both versions is different.

> Learn how to change the version in the [options](/setup#options).

### `v4`
### `v5`/`v4`

```ts [plugins/strapi.client.ts]
import type { Strapi4Error } from '@nuxtjs/strapi'
import type { Strapi4Error, Strapi5Error } from '@nuxtjs/strapi'

export default defineNuxtPlugin((nuxt) => {
nuxt.hook('strapi:error' as any, (e: Strapi4Error) => {
Expand All @@ -88,7 +88,7 @@ export default defineNuxtPlugin((nuxt) => {
})
```

> Check out the [Strapi4Error](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L3) type.
> Check out the [Strapi5Error](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v5.ts#L3) or [Strapi4Error](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.ts#L3) type.

### `v3`

Expand Down Expand Up @@ -123,7 +123,7 @@ By default, when calling `/users/me` route, Strapi only returns the user populat

Here is how to override this method for both Strapi v3 and v4 by adding our own custom relation, in this example `restaurants`:

### `v4`
### `v5`/`v4`

```js [src/index.js]
module.exports = {
Expand All @@ -137,7 +137,7 @@ module.exports = {
}
```

> Note that in Strapi v4, you must enable the `restaurants.find` permission in your admin for the Authenticated role to have the data populated.
> Note that in Strapi v4 v5, you must enable the `restaurants.find` permission in your admin for the Authenticated role to have the data populated.

### `v3`

Expand Down
6 changes: 3 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export interface ModuleOptions {

/**
* Strapi Version
* @default 'v4'
* @default 'v5'
* @type string
* @example 'v3'
* @example 'v4'
*/
version?: 'v5' | 'v4' | 'v3'

Expand Down Expand Up @@ -86,7 +86,7 @@ export default defineNuxtModule<ModuleOptions>({
url: process.env.STRAPI_URL || 'http://localhost:1337',
prefix: '/api',
admin: '/admin',
version: 'v4',
version: 'v5',
cookie: {},
auth: {},
cookieName: 'strapi_jwt',
Expand Down
Loading