next-sanity 4.3.0 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
  - [Installation](#installation)
15
15
  - [`next-sanity` Running groq queries](#next-sanity-running-groq-queries)
16
16
  - [`appDir`, React Server Components and caching](#appdir-react-server-components-and-caching)
17
+ - [`next-sanity` Visual Editing with Content Source Maps](#next-sanity-visual-editing-with-content-source-maps)
17
18
  - [`next-sanity/preview` Live real-time preview](#next-sanitypreview-live-real-time-preview)
18
19
  - [Examples](#examples)
19
20
  - [Built-in Sanity auth](#built-in-sanity-auth)
@@ -64,22 +65,12 @@ pnpm install next-sanity @portabletext/react @sanity/image-url
64
65
 
65
66
  ### `next-sanity/studio` peer dependencies
66
67
 
67
- When using `npm` newer than `v7` you should end up with needed dependencies like `sanity` and `styled-components` when you `npm install next-sanity`. For other package managers you may need to do some extra steps.
68
-
69
- #### Yarn
68
+ When using `npm` newer than `v7`, or `pnpm` newer than `v8`, you should end up with needed dependencies like `sanity` and `styled-components` when you `npm install next-sanity`. It also works in `yarn` `v1` using `install-peerdeps`:
70
69
 
71
70
  ```bash
72
71
  npx install-peerdeps --yarn next-sanity
73
72
  ```
74
73
 
75
- #### pnpm
76
-
77
- You can either setup [`auto-install-peers`](https://stackoverflow.com/questions/72468635/pnpm-peer-dependencies-auto-install/74835069#74835069) and `pnpm install next-sanity` is enough, or:
78
-
79
- ```bash
80
- npx install-peerdeps --pnpm next-sanity
81
- ```
82
-
83
74
  ## `next-sanity` Running groq queries
84
75
 
85
76
  ```ts
@@ -87,7 +78,7 @@ import {createClient, groq} from 'next-sanity'
87
78
 
88
79
  const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
89
80
  const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
90
- const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2022-11-16"
81
+ const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
91
82
 
92
83
  const client = createClient({
93
84
  projectId,
@@ -109,7 +100,7 @@ import {cache} from 'react'
109
100
 
110
101
  const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
111
102
  const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
112
- const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2022-11-16"
103
+ const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
113
104
 
114
105
  const client = createClient({
115
106
  projectId,
@@ -127,6 +118,33 @@ const data = await clientFetch(groq`*[]`)
127
118
  const total = await clientFetch<number>(groq`count*()`)
128
119
  ```
129
120
 
121
+ ## `next-sanity` Visual Editing with Content Source Maps
122
+
123
+ > **Note**
124
+ >
125
+ > [Content Source Maps][content-source-maps-intro] are available [as an API][content-source-maps] for select [Sanity enterprise customers][enterprise-cta]. [Contact our sales team for more information.][sales-cta]
126
+
127
+ The `createClient` method in `next-sanity` supports [visual editing][visual-editing-intro], it supports all the same options as [`@sanity/preview-kit/client`][preview-kit-client]. Add `studioUrl` to your client configuration and it'll automatically show up on Vercel Preview Deployments:
128
+
129
+ ```tsx
130
+ import {createClient, groq} from 'next-sanity'
131
+
132
+ const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
133
+ const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
134
+ const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
135
+
136
+ const client = createClient({
137
+ projectId,
138
+ dataset,
139
+ apiVersion, // https://www.sanity.io/docs/api-versioning
140
+ useCdn: true, // if you're using ISR or only static generation at build time then you can set this to `false` to guarantee no stale content
141
+ studioUrl: '/studio', // Or: 'https://my-cool-project.sanity.studio'
142
+ encodeSourceMap: true, // Optional. Default to: process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview',
143
+ })
144
+ ```
145
+
146
+ [Our setup guide walks you through how to customize the experience.][visual-editing]
147
+
130
148
  ## `next-sanity/preview` Live real-time preview
131
149
 
132
150
  You can implement real-time client side preview using `definePreview`. It works by streaming the whole dataset to the browser, which it keeps updated using [listeners](https://www.sanity.io/docs/realtime-updates) and Mendoza patches. When it receives updates, then the query is run against the client-side datastore using [groq-js](https://github.com/sanity-io/groq-js).
@@ -195,7 +213,7 @@ import {createClient} from 'next-sanity'
195
213
 
196
214
  const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
197
215
  const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
198
- const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2022-11-16"
216
+ const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
199
217
 
200
218
  export const client = createClient({projectId, dataset, apiVersion})
201
219
  ```
@@ -372,7 +390,7 @@ import {createClient} from 'next-sanity'
372
390
 
373
391
  const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
374
392
  const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
375
- const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2022-11-16"
393
+ const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
376
394
 
377
395
  export const client = createClient({projectId, dataset, apiVersion})
378
396
  ```
@@ -897,3 +915,11 @@ Semantic release will only release on configured branches, so it is safe to run
897
915
  ## License
898
916
 
899
917
  MIT-licensed. See [LICENSE](LICENSE).
918
+
919
+ [visual-editing]: https://www.sanity.io/docs/vercel-visual-editing?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
920
+ [visual-editing-intro]: https://www.sanity.io/blog/visual-editing-sanity-vercel?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
921
+ [content-source-maps]: https://www.sanity.io/docs/content-source-maps?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
922
+ [content-source-maps-intro]: https://www.sanity.io/blog/content-source-maps-announce?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
923
+ [preview-kit-client]: https://github.com/sanity-io/preview-kit#sanitypreview-kitclient
924
+ [sales-cta]: https://www.sanity.io/contact/sales?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
925
+ [enterprise-cta]: https://www.sanity.io/enterprise?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/client.ts"],"sourcesContent":["import {\n type ClientConfig as _ClientConfig,\n createClient as _createClient,\n} from '@sanity/preview-kit/client'\n\nexport type * from '@sanity/preview-kit/client'\n\n/** @public */\nexport interface ClientConfig extends Omit<_ClientConfig, 'studioUrl' | 'encodeSourceMap'> {\n /**\n * Where the Studio is hosted.\n * If it's embedded in the app, use the base path for example `/studio`.\n * Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.\n * @defaultValue process.env.NEXT_PUBLIC_SANITY_STUDIO_URL\n * @alpha\n */\n studioUrl?: _ClientConfig['studioUrl']\n /**\n * If there's no `studioUrl` then the default value is `none` and the normal `@sanity/client` will be used. If `studioUrl` is set, then it's `auto` by default.\n * @defaultValue process.env.MEXT_PUBLIC_SANITY_SOURCE_MAP || studioUrl ? 'auto' : 'none'\n * @alpha\n */\n encodeSourceMap?: _ClientConfig['encodeSourceMap']\n}\n\n/**\n * @public\n */\nexport function createClient(config: ClientConfig): ReturnType<typeof _createClient> {\n let {\n // eslint-disable-next-line prefer-const, no-process-env\n studioUrl = process.env.NEXT_PUBLIC_SANITY_STUDIO_URL! as _ClientConfig['studioUrl'],\n encodeSourceMap = (studioUrl ? 'auto' : false) satisfies _ClientConfig['encodeSourceMap'],\n } = config\n // eslint-disable-next-line no-process-env\n if (encodeSourceMap === 'auto' && process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {\n encodeSourceMap = true\n }\n return _createClient({...config, studioUrl, encodeSourceMap})\n}\n"],"names":["createClient","config","studioUrl","process","env","NEXT_PUBLIC_SANITY_STUDIO_URL","encodeSourceMap","NEXT_PUBLIC_VERCEL_ENV","_createClient"],"mappings":";;;;;;;;;;;;;AA4BO,SAASA,aAAaC,MAAwD,EAAA;EAC/E,IAAA;IAAA;IAEFC,SAAA,GAAYC,QAAQC,GAAI,CAAAC,6BAAA;IACxBC,eAAA,GAAmBJ,YAAY,MAAS,GAAA;EACtC,CAAA,GAAAD,MAAA;EAEJ,IAAIK,eAAoB,KAAA,MAAA,IAAUH,OAAQ,CAAAC,GAAA,CAAIG,2BAA2B,SAAW,EAAA;IAChED,eAAA,GAAA,IAAA;EACpB;EACA,OAAOE,MAAAA,CAAAA,aAAc;IAAC,GAAGP,MAAQ;IAAAC,SAAA;IAAWI;EAAgB,CAAA,CAAA;AAC9D;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/client.ts"],"sourcesContent":["import {\n type ClientConfig as _ClientConfig,\n createClient as _createClient,\n} from '@sanity/preview-kit/client'\n\nexport type * from '@sanity/preview-kit/client'\n\n/** @public */\nexport interface ClientConfig extends Omit<_ClientConfig, 'studioUrl' | 'encodeSourceMap'> {\n /**\n * Where the Studio is hosted.\n * If it's embedded in the app, use the base path for example `/studio`.\n * Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.\n * @defaultValue process.env.NEXT_PUBLIC_SANITY_STUDIO_URL\n * @alpha\n */\n studioUrl?: _ClientConfig['studioUrl']\n /**\n * If there's no `studioUrl` then the default value is `none` and the normal `@sanity/client` will be used. If `studioUrl` is set, then it's `auto` by default.\n * @defaultValue process.env.MEXT_PUBLIC_SANITY_SOURCE_MAP || studioUrl ? 'auto' : 'none'\n * @alpha\n */\n encodeSourceMap?: _ClientConfig['encodeSourceMap']\n}\n\n/** @public */\nexport type SanityClient = ReturnType<typeof _createClient>\n\n/**\n * @public\n */\nexport function createClient(config: ClientConfig): SanityClient {\n let {\n // eslint-disable-next-line prefer-const, no-process-env\n studioUrl = process.env.NEXT_PUBLIC_SANITY_STUDIO_URL! as _ClientConfig['studioUrl'],\n encodeSourceMap = (studioUrl ? 'auto' : false) satisfies _ClientConfig['encodeSourceMap'],\n } = config\n // eslint-disable-next-line no-process-env\n if (encodeSourceMap === 'auto' && process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {\n encodeSourceMap = true\n }\n return _createClient({...config, studioUrl, encodeSourceMap})\n}\n"],"names":["createClient","config","studioUrl","process","env","NEXT_PUBLIC_SANITY_STUDIO_URL","encodeSourceMap","NEXT_PUBLIC_VERCEL_ENV","_createClient"],"mappings":";;;;;;;;;;;;;AA+BO,SAASA,aAAaC,MAAoC,EAAA;EAC3D,IAAA;IAAA;IAEFC,SAAA,GAAYC,QAAQC,GAAI,CAAAC,6BAAA;IACxBC,eAAA,GAAmBJ,YAAY,MAAS,GAAA;EACtC,CAAA,GAAAD,MAAA;EAEJ,IAAIK,eAAoB,KAAA,MAAA,IAAUH,OAAQ,CAAAC,GAAA,CAAIG,2BAA2B,SAAW,EAAA;IAChED,eAAA,GAAA,IAAA;EACpB;EACA,OAAOE,MAAAA,CAAAA,aAAc;IAAC,GAAGP,MAAQ;IAAAC,SAAA;IAAWI;EAAgB,CAAA,CAAA;AAC9D;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -24,10 +24,13 @@ export declare interface ClientConfig
24
24
  /**
25
25
  * @public
26
26
  */
27
- export declare function createClient(config: ClientConfig): ReturnType<typeof createClient_2>
27
+ export declare function createClient(config: ClientConfig): SanityClient
28
28
 
29
29
  export {groq}
30
30
 
31
+ /** @public */
32
+ export declare type SanityClient = ReturnType<typeof createClient_2>
33
+
31
34
  export * from '@sanity/preview-kit/client'
32
35
 
33
36
  export {}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/client.ts"],"sourcesContent":["import {\n type ClientConfig as _ClientConfig,\n createClient as _createClient,\n} from '@sanity/preview-kit/client'\n\nexport type * from '@sanity/preview-kit/client'\n\n/** @public */\nexport interface ClientConfig extends Omit<_ClientConfig, 'studioUrl' | 'encodeSourceMap'> {\n /**\n * Where the Studio is hosted.\n * If it's embedded in the app, use the base path for example `/studio`.\n * Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.\n * @defaultValue process.env.NEXT_PUBLIC_SANITY_STUDIO_URL\n * @alpha\n */\n studioUrl?: _ClientConfig['studioUrl']\n /**\n * If there's no `studioUrl` then the default value is `none` and the normal `@sanity/client` will be used. If `studioUrl` is set, then it's `auto` by default.\n * @defaultValue process.env.MEXT_PUBLIC_SANITY_SOURCE_MAP || studioUrl ? 'auto' : 'none'\n * @alpha\n */\n encodeSourceMap?: _ClientConfig['encodeSourceMap']\n}\n\n/**\n * @public\n */\nexport function createClient(config: ClientConfig): ReturnType<typeof _createClient> {\n let {\n // eslint-disable-next-line prefer-const, no-process-env\n studioUrl = process.env.NEXT_PUBLIC_SANITY_STUDIO_URL! as _ClientConfig['studioUrl'],\n encodeSourceMap = (studioUrl ? 'auto' : false) satisfies _ClientConfig['encodeSourceMap'],\n } = config\n // eslint-disable-next-line no-process-env\n if (encodeSourceMap === 'auto' && process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {\n encodeSourceMap = true\n }\n return _createClient({...config, studioUrl, encodeSourceMap})\n}\n"],"names":["createClient","config","studioUrl","process","env","NEXT_PUBLIC_SANITY_STUDIO_URL","encodeSourceMap","NEXT_PUBLIC_VERCEL_ENV","_createClient"],"mappings":";;AA4BO,SAASA,aAAaC,MAAwD,EAAA;EAC/E,IAAA;IAAA;IAEFC,SAAA,GAAYC,QAAQC,GAAI,CAAAC,6BAAA;IACxBC,eAAA,GAAmBJ,YAAY,MAAS,GAAA;EACtC,CAAA,GAAAD,MAAA;EAEJ,IAAIK,eAAoB,KAAA,MAAA,IAAUH,OAAQ,CAAAC,GAAA,CAAIG,2BAA2B,SAAW,EAAA;IAChED,eAAA,GAAA,IAAA;EACpB;EACA,OAAOE,eAAc;IAAC,GAAGP,MAAQ;IAAAC,SAAA;IAAWI;EAAgB,CAAA,CAAA;AAC9D;"}
1
+ {"version":3,"file":"index.js","sources":["../src/client.ts"],"sourcesContent":["import {\n type ClientConfig as _ClientConfig,\n createClient as _createClient,\n} from '@sanity/preview-kit/client'\n\nexport type * from '@sanity/preview-kit/client'\n\n/** @public */\nexport interface ClientConfig extends Omit<_ClientConfig, 'studioUrl' | 'encodeSourceMap'> {\n /**\n * Where the Studio is hosted.\n * If it's embedded in the app, use the base path for example `/studio`.\n * Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.\n * @defaultValue process.env.NEXT_PUBLIC_SANITY_STUDIO_URL\n * @alpha\n */\n studioUrl?: _ClientConfig['studioUrl']\n /**\n * If there's no `studioUrl` then the default value is `none` and the normal `@sanity/client` will be used. If `studioUrl` is set, then it's `auto` by default.\n * @defaultValue process.env.MEXT_PUBLIC_SANITY_SOURCE_MAP || studioUrl ? 'auto' : 'none'\n * @alpha\n */\n encodeSourceMap?: _ClientConfig['encodeSourceMap']\n}\n\n/** @public */\nexport type SanityClient = ReturnType<typeof _createClient>\n\n/**\n * @public\n */\nexport function createClient(config: ClientConfig): SanityClient {\n let {\n // eslint-disable-next-line prefer-const, no-process-env\n studioUrl = process.env.NEXT_PUBLIC_SANITY_STUDIO_URL! as _ClientConfig['studioUrl'],\n encodeSourceMap = (studioUrl ? 'auto' : false) satisfies _ClientConfig['encodeSourceMap'],\n } = config\n // eslint-disable-next-line no-process-env\n if (encodeSourceMap === 'auto' && process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {\n encodeSourceMap = true\n }\n return _createClient({...config, studioUrl, encodeSourceMap})\n}\n"],"names":["createClient","config","studioUrl","process","env","NEXT_PUBLIC_SANITY_STUDIO_URL","encodeSourceMap","NEXT_PUBLIC_VERCEL_ENV","_createClient"],"mappings":";;AA+BO,SAASA,aAAaC,MAAoC,EAAA;EAC3D,IAAA;IAAA;IAEFC,SAAA,GAAYC,QAAQC,GAAI,CAAAC,6BAAA;IACxBC,eAAA,GAAmBJ,YAAY,MAAS,GAAA;EACtC,CAAA,GAAAD,MAAA;EAEJ,IAAIK,eAAoB,KAAA,MAAA,IAAUH,OAAQ,CAAAC,GAAA,CAAIG,2BAA2B,SAAW,EAAA;IAChED,eAAA,GAAA,IAAA;EACpB;EACA,OAAOE,eAAc;IAAC,GAAGP,MAAQ;IAAAC,SAAA;IAAWI;EAAgB,CAAA,CAAA;AAC9D;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "sanity",
@@ -181,7 +181,7 @@
181
181
  "@typescript-eslint/eslint-plugin": "^5.59.2",
182
182
  "autoprefixer": "^10.4.14",
183
183
  "eslint": "^8.39.0",
184
- "eslint-config-next": "13.3.5-canary.5",
184
+ "eslint-config-next": "13.3.5-canary.6",
185
185
  "eslint-config-prettier": "^8.8.0",
186
186
  "eslint-config-sanity": "^6.0.0",
187
187
  "eslint-gitignore": "^0.1.0",
@@ -191,7 +191,7 @@
191
191
  "jest": "^29.5.0",
192
192
  "jest-environment-jsdom": "^29.5.0",
193
193
  "ls-engines": "^0.9.0",
194
- "next": "13.3.5-canary.5",
194
+ "next": "13.3.5-canary.6",
195
195
  "postcss": "^8.4.23",
196
196
  "prettier": "^2.8.8",
197
197
  "prettier-plugin-packagejson": "^2.4.3",
package/src/client.ts CHANGED
@@ -23,10 +23,13 @@ export interface ClientConfig extends Omit<_ClientConfig, 'studioUrl' | 'encodeS
23
23
  encodeSourceMap?: _ClientConfig['encodeSourceMap']
24
24
  }
25
25
 
26
+ /** @public */
27
+ export type SanityClient = ReturnType<typeof _createClient>
28
+
26
29
  /**
27
30
  * @public
28
31
  */
29
- export function createClient(config: ClientConfig): ReturnType<typeof _createClient> {
32
+ export function createClient(config: ClientConfig): SanityClient {
30
33
  let {
31
34
  // eslint-disable-next-line prefer-const, no-process-env
32
35
  studioUrl = process.env.NEXT_PUBLIC_SANITY_STUDIO_URL! as _ClientConfig['studioUrl'],