next-sanity 10.0.1 → 10.0.3
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/dist/draft-mode.cjs
CHANGED
|
@@ -14,21 +14,21 @@ function defineEnableDraftMode(options) {
|
|
|
14
14
|
return new Response("Invalid secret", { status: 401 });
|
|
15
15
|
const draftModeStore = await headers.draftMode();
|
|
16
16
|
draftModeStore.isEnabled || draftModeStore.enable();
|
|
17
|
-
const
|
|
17
|
+
const isSecure = process.env.NODE_ENV === "production" || (options.secureDevMode ?? !1), cookieStore = await headers.cookies(), cookie = cookieStore.get("__prerender_bypass");
|
|
18
18
|
return cookieStore.set({
|
|
19
19
|
name: "__prerender_bypass",
|
|
20
20
|
value: cookie?.value,
|
|
21
21
|
httpOnly: !0,
|
|
22
22
|
path: "/",
|
|
23
|
-
secure:
|
|
24
|
-
sameSite:
|
|
23
|
+
secure: isSecure,
|
|
24
|
+
sameSite: isSecure ? "none" : "lax"
|
|
25
25
|
}), studioPreviewPerspective && cookieStore.set({
|
|
26
26
|
name: constants.perspectiveCookieName,
|
|
27
27
|
value: studioPreviewPerspective,
|
|
28
28
|
httpOnly: !0,
|
|
29
29
|
path: "/",
|
|
30
|
-
secure:
|
|
31
|
-
sameSite:
|
|
30
|
+
secure: isSecure,
|
|
31
|
+
sameSite: isSecure ? "none" : "lax"
|
|
32
32
|
}), navigation.redirect(redirectTo);
|
|
33
33
|
}
|
|
34
34
|
};
|
package/dist/draft-mode.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-mode.cjs","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const
|
|
1
|
+
{"version":3,"file":"draft-mode.cjs","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n /**\n * Force secure cookies in development mode.\n * Enable this when using Next.js --experimental-https flag.\n * This option has no effect in production (cookies are always secure).\n * @defaultValue false\n */\n secureDevMode?: boolean\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n // We can't auto-detect HTTPS in dev due to Next.js limitations,\n // so we need an explicit option\n const isSecure = isProduction || (options.secureDevMode ?? false)\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":["validatePreviewUrl","draftMode","cookies","perspectiveCookieName","redirect"],"mappings":";;;AA6CO,SAAS,sBAAsB,SAAwD;AAC5F,QAAM,EAAC,WAAU;AACjB,SAAO;AAAA,IACL,KAAK,OAAO,YAAqB;AAI/B,YAAM;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MAAA,IACE,MAAMA,iBAAAA,mBAAmB,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,KAAI;AAGrD,YAAM,iBAAiB,MAAMC,kBAAA;AAGxB,qBAAe,aAClB,eAAe,OAAA;AAOjB,YAAM,WAJe,QAAQ,IAAI,aAAa,iBAIZ,QAAQ,iBAAiB,KAIrD,cAAc,MAAMC,gBAAA,GACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU,WAAW,SAAS;AAAA,MAAA,CAC/B,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAMC,UAAAA;AAAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU,WAAW,SAAS;AAAA,MAAA,CAC/B,GAIIC,WAAAA,SAAS,UAAU;AAAA,IAC5B;AAAA,EAAA;AAEJ;;"}
|
package/dist/draft-mode.d.cts
CHANGED
|
@@ -26,6 +26,13 @@ export declare function defineEnableDraftMode(
|
|
|
26
26
|
*/
|
|
27
27
|
export declare interface DefineEnableDraftModeOptions {
|
|
28
28
|
client: SanityClient
|
|
29
|
+
/**
|
|
30
|
+
* Force secure cookies in development mode.
|
|
31
|
+
* Enable this when using Next.js --experimental-https flag.
|
|
32
|
+
* This option has no effect in production (cookies are always secure).
|
|
33
|
+
* @defaultValue false
|
|
34
|
+
*/
|
|
35
|
+
secureDevMode?: boolean
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
/**
|
package/dist/draft-mode.d.ts
CHANGED
|
@@ -26,6 +26,13 @@ export declare function defineEnableDraftMode(
|
|
|
26
26
|
*/
|
|
27
27
|
export declare interface DefineEnableDraftModeOptions {
|
|
28
28
|
client: SanityClient
|
|
29
|
+
/**
|
|
30
|
+
* Force secure cookies in development mode.
|
|
31
|
+
* Enable this when using Next.js --experimental-https flag.
|
|
32
|
+
* This option has no effect in production (cookies are always secure).
|
|
33
|
+
* @defaultValue false
|
|
34
|
+
*/
|
|
35
|
+
secureDevMode?: boolean
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
/**
|
package/dist/draft-mode.js
CHANGED
|
@@ -15,21 +15,21 @@ function defineEnableDraftMode(options) {
|
|
|
15
15
|
return new Response("Invalid secret", { status: 401 });
|
|
16
16
|
const draftModeStore = await draftMode();
|
|
17
17
|
draftModeStore.isEnabled || draftModeStore.enable();
|
|
18
|
-
const
|
|
18
|
+
const isSecure = process.env.NODE_ENV === "production" || (options.secureDevMode ?? !1), cookieStore = await cookies(), cookie = cookieStore.get("__prerender_bypass");
|
|
19
19
|
return cookieStore.set({
|
|
20
20
|
name: "__prerender_bypass",
|
|
21
21
|
value: cookie?.value,
|
|
22
22
|
httpOnly: !0,
|
|
23
23
|
path: "/",
|
|
24
|
-
secure:
|
|
25
|
-
sameSite:
|
|
24
|
+
secure: isSecure,
|
|
25
|
+
sameSite: isSecure ? "none" : "lax"
|
|
26
26
|
}), studioPreviewPerspective && cookieStore.set({
|
|
27
27
|
name: perspectiveCookieName,
|
|
28
28
|
value: studioPreviewPerspective,
|
|
29
29
|
httpOnly: !0,
|
|
30
30
|
path: "/",
|
|
31
|
-
secure:
|
|
32
|
-
sameSite:
|
|
31
|
+
secure: isSecure,
|
|
32
|
+
sameSite: isSecure ? "none" : "lax"
|
|
33
33
|
}), redirect(redirectTo);
|
|
34
34
|
}
|
|
35
35
|
};
|
package/dist/draft-mode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-mode.js","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const
|
|
1
|
+
{"version":3,"file":"draft-mode.js","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n /**\n * Force secure cookies in development mode.\n * Enable this when using Next.js --experimental-https flag.\n * This option has no effect in production (cookies are always secure).\n * @defaultValue false\n */\n secureDevMode?: boolean\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n // We can't auto-detect HTTPS in dev due to Next.js limitations,\n // so we need an explicit option\n const isSecure = isProduction || (options.secureDevMode ?? false)\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":[],"mappings":";;;;AA6CO,SAAS,sBAAsB,SAAwD;AAC5F,QAAM,EAAC,WAAU;AACjB,SAAO;AAAA,IACL,KAAK,OAAO,YAAqB;AAI/B,YAAM;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MAAA,IACE,MAAM,mBAAmB,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,KAAI;AAGrD,YAAM,iBAAiB,MAAM,UAAA;AAGxB,qBAAe,aAClB,eAAe,OAAA;AAOjB,YAAM,WAJe,QAAQ,IAAI,aAAa,iBAIZ,QAAQ,iBAAiB,KAIrD,cAAc,MAAM,QAAA,GACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU,WAAW,SAAS;AAAA,MAAA,CAC/B,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU,WAAW,SAAS;AAAA,MAAA,CAC/B,GAII,SAAS,UAAU;AAAA,IAC5B;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.3",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -121,16 +121,16 @@
|
|
|
121
121
|
"dependencies": {
|
|
122
122
|
"@portabletext/react": "^3.2.1",
|
|
123
123
|
"@sanity/client": "^7.8.0",
|
|
124
|
-
"@sanity/next-loader": "^1.7.
|
|
125
|
-
"@sanity/preview-url-secret": "^2.1.
|
|
126
|
-
"@sanity/visual-editing": "^2.15.
|
|
127
|
-
"groq": "^4.
|
|
124
|
+
"@sanity/next-loader": "^1.7.2",
|
|
125
|
+
"@sanity/preview-url-secret": "^2.1.14",
|
|
126
|
+
"@sanity/visual-editing": "^2.15.4",
|
|
127
|
+
"groq": "^4.1.1",
|
|
128
128
|
"history": "^5.3.0"
|
|
129
129
|
},
|
|
130
130
|
"devDependencies": {
|
|
131
131
|
"@sanity/browserslist-config": "^1.0.5",
|
|
132
|
-
"@sanity/pkg-utils": "^7.9.
|
|
133
|
-
"@sanity/types": "^4.
|
|
132
|
+
"@sanity/pkg-utils": "^7.9.9",
|
|
133
|
+
"@sanity/types": "^4.1.1",
|
|
134
134
|
"@sanity/webhook": "4.0.4",
|
|
135
135
|
"@types/react": "^19.1.8",
|
|
136
136
|
"@types/react-dom": "^19.1.6",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"next": "^15.1",
|
|
150
150
|
"react": "^19",
|
|
151
151
|
"react-dom": "^19",
|
|
152
|
-
"sanity": "^4.
|
|
152
|
+
"sanity": "^4.1.1",
|
|
153
153
|
"styled-components": "^6.1"
|
|
154
154
|
},
|
|
155
155
|
"engines": {
|
|
@@ -10,6 +10,13 @@ import type {SanityClient} from '../client'
|
|
|
10
10
|
*/
|
|
11
11
|
export interface DefineEnableDraftModeOptions {
|
|
12
12
|
client: SanityClient
|
|
13
|
+
/**
|
|
14
|
+
* Force secure cookies in development mode.
|
|
15
|
+
* Enable this when using Next.js --experimental-https flag.
|
|
16
|
+
* This option has no effect in production (cookies are always secure).
|
|
17
|
+
* @defaultValue false
|
|
18
|
+
*/
|
|
19
|
+
secureDevMode?: boolean
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
/**
|
|
@@ -59,7 +66,11 @@ export function defineEnableDraftMode(options: DefineEnableDraftModeOptions): En
|
|
|
59
66
|
draftModeStore.enable()
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
const
|
|
69
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
70
|
+
|
|
71
|
+
// We can't auto-detect HTTPS in dev due to Next.js limitations,
|
|
72
|
+
// so we need an explicit option
|
|
73
|
+
const isSecure = isProduction || (options.secureDevMode ?? false)
|
|
63
74
|
|
|
64
75
|
// Override cookie header for draft mode for usage in live-preview
|
|
65
76
|
// https://github.com/vercel/next.js/issues/49927
|
|
@@ -70,8 +81,8 @@ export function defineEnableDraftMode(options: DefineEnableDraftModeOptions): En
|
|
|
70
81
|
value: cookie?.value,
|
|
71
82
|
httpOnly: true,
|
|
72
83
|
path: '/',
|
|
73
|
-
secure:
|
|
74
|
-
sameSite:
|
|
84
|
+
secure: isSecure,
|
|
85
|
+
sameSite: isSecure ? 'none' : 'lax',
|
|
75
86
|
})
|
|
76
87
|
|
|
77
88
|
if (studioPreviewPerspective) {
|
|
@@ -80,8 +91,8 @@ export function defineEnableDraftMode(options: DefineEnableDraftModeOptions): En
|
|
|
80
91
|
value: studioPreviewPerspective,
|
|
81
92
|
httpOnly: true,
|
|
82
93
|
path: '/',
|
|
83
|
-
secure:
|
|
84
|
-
sameSite:
|
|
94
|
+
secure: isSecure,
|
|
95
|
+
sameSite: isSecure ? 'none' : 'lax',
|
|
85
96
|
})
|
|
86
97
|
}
|
|
87
98
|
|