next-sanity 5.4.4 → 5.4.5

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.
Files changed (2) hide show
  1. package/README.md +53 -6
  2. package/package.json +11 -12
package/README.md CHANGED
@@ -161,6 +161,16 @@ async function HomePageLayout() {
161
161
 
162
162
  [Checkout our Personal website template to see a feature complete example of how `revalidateTag` is used together with Live Previews.](https://github.com/sanity-io/sanity-template-nextjs-app-router-personal-website)
163
163
 
164
+ To aid in debugging and understanding what's in the cache, revalidated, skipped and more, add this to your `next.config.js`:
165
+
166
+ ```js
167
+ module.exports = {
168
+ experimental: {
169
+ logging: 'verbose',
170
+ },
171
+ }
172
+ ```
173
+
164
174
  ## `next-sanity` Visual Editing with Content Source Maps
165
175
 
166
176
  > **Note**
@@ -359,7 +369,47 @@ function StudioPage() {
359
369
 
360
370
  Implements [`@sanity/webhook`](https://github.com/sanity-io/webhook-toolkit) to parse and verify that a [Webhook](https://www.sanity.io/docs/webhooks) is indeed coming from Sanity infrastructure.
361
371
 
362
- `pages/api/revalidate`:
372
+ ### App Router
373
+
374
+ `app/api/revalidate/route.ts`:
375
+
376
+ ```ts
377
+ import {revalidateTag} from 'next/cache'
378
+ import {type NextRequest, NextResponse} from 'next/server'
379
+ import {parseBody} from 'next-sanity/webhook'
380
+
381
+ export async function POST(req: NextRequest) {
382
+ try {
383
+ const {isValidSignature, body} = await parseBody<{_type}>(
384
+ req,
385
+ process.env.SANITY_REVALIDATE_SECRET,
386
+ )
387
+
388
+ if (!isValidSignature) {
389
+ const message = 'Invalid signature'
390
+ return new Response(JSON.stringify({message, isValidSignature, body}), {status: 401})
391
+ }
392
+
393
+ if (!body?._type) {
394
+ const message = 'Bad Request'
395
+ return new Response({message, body}, {status: 400})
396
+ }
397
+
398
+ // If the `_type` is `page`, then all `client.fetch` calls with
399
+ // `{next: {tags: ['page']}}` will be revalidated
400
+ await revalidateTag(body._type)
401
+
402
+ return NextResponse.json({body})
403
+ } catch (err) {
404
+ console.error(err)
405
+ return new Response(err.message, {status: 500})
406
+ }
407
+ }
408
+ ```
409
+
410
+ ### Pages Router
411
+
412
+ `pages/api/revalidate.ts`:
363
413
 
364
414
  ```ts
365
415
  import type {NextApiRequest, NextApiResponse} from 'next'
@@ -374,16 +424,13 @@ export default async function revalidate(req: NextApiRequest, res: NextApiRespon
374
424
 
375
425
  if (!isValidSignature) {
376
426
  const message = 'Invalid signature'
377
- console.warn(message)
378
- res.status(401).json({message})
379
- return
427
+ return res.status(401).json({message, isValidSignature, body})
380
428
  }
381
429
 
382
430
  const staleRoute = `/${body.slug.current}`
383
431
  await res.revalidate(staleRoute)
384
432
  const message = `Updated route: ${staleRoute}`
385
- console.log(message)
386
- return res.status(200).json({message})
433
+ return res.status(200).json({message, body})
387
434
  } catch (err) {
388
435
  console.error(err)
389
436
  return res.status(500).json({message: err.message})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "5.4.4",
3
+ "version": "5.4.5",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "sanity",
@@ -174,7 +174,7 @@
174
174
  "singleQuote": true
175
175
  },
176
176
  "dependencies": {
177
- "@sanity/preview-kit": "3.1.4",
177
+ "@sanity/preview-kit": "3.1.5",
178
178
  "@sanity/webhook": "3.0.1",
179
179
  "groq": "^3.0.0"
180
180
  },
@@ -185,16 +185,16 @@
185
185
  "@sanity/client": "6.4.9",
186
186
  "@sanity/eslint-config-studio": "^3.0.0",
187
187
  "@sanity/image-url": "^1.0.2",
188
- "@sanity/pkg-utils": "^2.4.6",
188
+ "@sanity/pkg-utils": "^2.4.8",
189
189
  "@sanity/semantic-release-preset": "^4.1.3",
190
- "@sanity/ui": "^1.7.8",
190
+ "@sanity/ui": "^1.7.9",
191
191
  "@sanity/vision": "3.15.1",
192
192
  "@types/eventsource": "^1.1.11",
193
- "@types/jest": "^29.5.3",
194
- "@types/react": "^18.2.20",
193
+ "@types/jest": "^29.5.4",
194
+ "@types/react": "^18.2.21",
195
195
  "@types/react-dom": "^18.2.7",
196
196
  "@types/styled-components": "^5.1.26",
197
- "@typescript-eslint/eslint-plugin": "^6.4.0",
197
+ "@typescript-eslint/eslint-plugin": "^6.4.1",
198
198
  "autoprefixer": "^10.4.15",
199
199
  "eslint": "^8.47.0",
200
200
  "eslint-config-prettier": "^9.0.0",
@@ -203,8 +203,8 @@
203
203
  "eslint-plugin-prettier": "^5.0.0",
204
204
  "eslint-plugin-simple-import-sort": "^10.0.0",
205
205
  "groqd": "^0.15.9",
206
- "jest": "^29.6.2",
207
- "jest-environment-jsdom": "^29.6.2",
206
+ "jest": "^29.6.3",
207
+ "jest-environment-jsdom": "^29.6.3",
208
208
  "ls-engines": "^0.9.0",
209
209
  "next": "13.4.19",
210
210
  "postcss": "^8.4.28",
@@ -214,7 +214,7 @@
214
214
  "react": "^18.2.0",
215
215
  "react-dom": "^18.2.0",
216
216
  "react-is": "^18.2.0",
217
- "rollup": "^3.28.0",
217
+ "rollup": "^3.28.1",
218
218
  "sanity": "3.15.1",
219
219
  "server-only": "^0.0.1",
220
220
  "styled-components": "^5.3.11",
@@ -228,11 +228,10 @@
228
228
  "@sanity/icons": "^2.0.0",
229
229
  "@sanity/types": "^3.0.0",
230
230
  "@sanity/ui": "^1.0.0",
231
- "@types/styled-components": "^5.1.0",
232
231
  "next": "^13.0.0",
233
232
  "react": "^18.0.0",
234
233
  "sanity": "^3.0.0",
235
- "styled-components": "^5.2.0"
234
+ "styled-components": "^5.2.0 || ^6.0.0"
236
235
  },
237
236
  "engines": {
238
237
  "node": ">=16.14"