next-sanity 13.1.7 → 13.2.0
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/VisualEditing.js +2 -1
- package/dist/VisualEditing.js.map +1 -1
- package/dist/draft-mode/index.js +19 -2
- package/dist/draft-mode/index.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -0
- package/dist/live/conditions/default/index.d.ts +77 -5
- package/dist/live/conditions/default/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.js +70 -1
- package/dist/live/conditions/default/index.js.map +1 -1
- package/dist/live/conditions/next-js/index.d.ts +10 -5
- package/dist/live/conditions/next-js/index.d.ts.map +1 -1
- package/dist/live/conditions/next-js/index.js +4 -3
- package/dist/live/conditions/next-js/index.js.map +1 -1
- package/dist/live/conditions/react-server/index.d.ts +10 -5
- package/dist/live/conditions/react-server/index.d.ts.map +1 -1
- package/dist/live/conditions/react-server/index.js +9 -3
- package/dist/live/conditions/react-server/index.js.map +1 -1
- package/dist/parseTags.d.ts +70 -1
- package/dist/parseTags.d.ts.map +1 -1
- package/dist/{resolvePerspectiveFromCookies.js → resolveVariantFromCookies.js} +73 -4
- package/dist/resolveVariantFromCookies.js.map +1 -0
- package/dist/sanitizeVariant.js +37 -0
- package/dist/sanitizeVariant.js.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/visual-editing/index.d.ts.map +1 -1
- package/dist/visual-editing/index.js +2 -1
- package/dist/visual-editing/index.js.map +1 -1
- package/dist/visual-editing/server-actions/index.d.ts +5 -1
- package/dist/visual-editing/server-actions/index.d.ts.map +1 -1
- package/dist/visual-editing/server-actions/index.js +36 -3
- package/dist/visual-editing/server-actions/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/resolvePerspectiveFromCookies.js.map +0 -1
- package/dist/sanitizePerspective.js +0 -14
- package/dist/sanitizePerspective.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { r as partitionedCookieName } from "../../constants.js";
|
|
3
|
-
import {
|
|
4
|
-
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
3
|
+
import { n as sanitizePerspective, t as sanitizeVariant } from "../../sanitizeVariant.js";
|
|
4
|
+
import { perspectiveCookieName, variantCookieName } from "@sanity/preview-url-secret/constants";
|
|
5
5
|
import { cookies } from "next/headers";
|
|
6
6
|
import { refresh } from "next/cache";
|
|
7
7
|
/**
|
|
@@ -25,6 +25,39 @@ async function perspectiveChangeAction(perspective) {
|
|
|
25
25
|
});
|
|
26
26
|
refresh();
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
30
|
+
*/
|
|
31
|
+
async function variantChangeAction(variant) {
|
|
32
|
+
const sanitizedVariant = sanitizeVariant(variant);
|
|
33
|
+
const jar = await cookies();
|
|
34
|
+
const currentVariant = jar.get(variantCookieName)?.value;
|
|
35
|
+
if (!sanitizedVariant) {
|
|
36
|
+
if (!currentVariant) return;
|
|
37
|
+
jar.delete({
|
|
38
|
+
name: variantCookieName,
|
|
39
|
+
httpOnly: true,
|
|
40
|
+
path: "/",
|
|
41
|
+
secure: true,
|
|
42
|
+
sameSite: "none",
|
|
43
|
+
partitioned: jar.has(partitionedCookieName)
|
|
44
|
+
});
|
|
45
|
+
refresh();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (sanitizedVariant === currentVariant && process.env.NODE_ENV !== "production") {
|
|
49
|
+
console.debug("variantChangeAction", "Variant is the same, skipping", sanitizedVariant);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
jar.set(variantCookieName, sanitizedVariant, {
|
|
53
|
+
httpOnly: true,
|
|
54
|
+
path: "/",
|
|
55
|
+
secure: true,
|
|
56
|
+
sameSite: "none",
|
|
57
|
+
partitioned: jar.has(partitionedCookieName)
|
|
58
|
+
});
|
|
59
|
+
refresh();
|
|
60
|
+
}
|
|
61
|
+
export { perspectiveChangeAction, variantChangeAction };
|
|
29
62
|
|
|
30
63
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\nimport {partitionedCookieName} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function perspectiveChangeAction(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (\n nextPerspective === jar.get(perspectiveCookieName)?.value &&\n process.env.NODE_ENV !== 'production'\n ) {\n // oxlint-disable-next-line no-console\n console.debug('perspectiveChangeAction', 'Perspective is the same, skipping', nextPerspective)\n return\n }\n // Mirror the CHIPS partitioning decision from defineEnableDraftMode. Server\n // actions do not receive Sec-Fetch iframe headers, so we rely on the companion\n // flag cookie set during enable.\n // https://github.com/sanity-io/sanity/issues/12806\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n partitioned: jar.has(partitionedCookieName),\n })\n\n refresh()\n}\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName, variantCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\nimport {partitionedCookieName} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {sanitizeVariant} from '#live/sanitizeVariant'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function perspectiveChangeAction(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (\n nextPerspective === jar.get(perspectiveCookieName)?.value &&\n process.env.NODE_ENV !== 'production'\n ) {\n // oxlint-disable-next-line no-console\n console.debug('perspectiveChangeAction', 'Perspective is the same, skipping', nextPerspective)\n return\n }\n // Mirror the CHIPS partitioning decision from defineEnableDraftMode. Server\n // actions do not receive Sec-Fetch iframe headers, so we rely on the companion\n // flag cookie set during enable.\n // https://github.com/sanity-io/sanity/issues/12806\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n partitioned: jar.has(partitionedCookieName),\n })\n\n refresh()\n}\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function variantChangeAction(variant: string | undefined): Promise<void> {\n const sanitizedVariant = sanitizeVariant(variant)\n const jar = await cookies()\n const currentVariant = jar.get(variantCookieName)?.value\n\n // Unlike perspective, an empty/undefined variant is not an error: it means the\n // variant was cleared and any stale cookie must be removed.\n if (!sanitizedVariant) {\n if (!currentVariant) {\n return\n }\n jar.delete({\n name: variantCookieName,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n partitioned: jar.has(partitionedCookieName),\n })\n refresh()\n return\n }\n\n if (sanitizedVariant === currentVariant && process.env.NODE_ENV !== 'production') {\n // oxlint-disable-next-line no-console\n console.debug('variantChangeAction', 'Variant is the same, skipping', sanitizedVariant)\n return\n }\n // Mirror the CHIPS partitioning decision from defineEnableDraftMode. Server\n // actions do not receive Sec-Fetch iframe headers, so we rely on the companion\n // flag cookie set during enable.\n // https://github.com/sanity-io/sanity/issues/12806\n jar.set(variantCookieName, sanitizedVariant, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n partitioned: jar.has(partitionedCookieName),\n })\n\n refresh()\n}\n"],"mappings":";;;;;;;;;AAcA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,QAAQ;CACtE,IACE,CAAC,wBACA,MAAM,QAAQ,oBAAoB,KAAK,qBAAqB,WAAW,GAExE,MAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,YAAW,CAAC;CAG7D,MAAM,kBAAkB,MAAM,QAAQ,oBAAoB,IACtD,qBAAqB,KAAK,GAAG,IAC7B;CACJ,MAAM,MAAM,MAAM,QAAQ;CAC1B,IACE,oBAAoB,IAAI,IAAI,qBAAqB,CAAC,EAAE,SACpD,QAAQ,IAAI,aAAa,cACzB;EAEA,QAAQ,MAAM,2BAA2B,qCAAqC,eAAe;EAC7F;CACF;CAKA,IAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACV,aAAa,IAAI,IAAI,qBAAqB;CAC5C,CAAC;CAED,QAAQ;AACV;;;;AAKA,eAAsB,oBAAoB,SAA4C;CACpF,MAAM,mBAAmB,gBAAgB,OAAO;CAChD,MAAM,MAAM,MAAM,QAAQ;CAC1B,MAAM,iBAAiB,IAAI,IAAI,iBAAiB,CAAC,EAAE;CAInD,IAAI,CAAC,kBAAkB;EACrB,IAAI,CAAC,gBACH;EAEF,IAAI,OAAO;GACT,MAAM;GACN,UAAU;GACV,MAAM;GACN,QAAQ;GACR,UAAU;GACV,aAAa,IAAI,IAAI,qBAAqB;EAC5C,CAAC;EACD,QAAQ;EACR;CACF;CAEA,IAAI,qBAAqB,kBAAkB,QAAQ,IAAI,aAAa,cAAc;EAEhF,QAAQ,MAAM,uBAAuB,iCAAiC,gBAAgB;EACtF;CACF;CAKA,IAAI,IAAI,mBAAmB,kBAAkB;EAC3C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACV,aAAa,IAAI,IAAI,qBAAqB;CAC5C,CAAC;CAED,QAAQ;AACV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"live",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@sanity/client": "^7.24.0",
|
|
63
63
|
"@sanity/generate-help-url": "^4.0.0",
|
|
64
64
|
"@sanity/preview-url-secret": "^4.1.1",
|
|
65
|
-
"@sanity/visual-editing": "^5.7.
|
|
65
|
+
"@sanity/visual-editing": "^5.7.2",
|
|
66
66
|
"@sanity/webhook": "^4.0.4",
|
|
67
67
|
"groq": "^6.6.0",
|
|
68
68
|
"history": "^5.3.0"
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"@vitest/coverage-v8": "^4.1.10",
|
|
79
79
|
"js-yaml": "^5.2.1",
|
|
80
80
|
"msw": "^2.15.0",
|
|
81
|
-
"next": "16.3.0-canary.
|
|
82
|
-
"publint": "^0.3.
|
|
81
|
+
"next": "16.3.0-canary.94",
|
|
82
|
+
"publint": "^0.3.22",
|
|
83
83
|
"react": "^19.2.8",
|
|
84
84
|
"react-dom": "^19.2.8",
|
|
85
85
|
"styled-components": "^6.4.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePerspectiveFromCookies.js","names":["preconnect"],"sources":["../src/live/shared/preconnect.ts","../src/live/shared/strictValidation.ts","../src/live/shared/resolvePerspectiveFromCookies.ts"],"sourcesContent":["import type {SanityClient} from 'next-sanity'\nimport {preconnect as reactDomPreconnect} from 'react-dom'\n\n/**\n * Uses the React DOM `preconnect` function to preconnect to the Live Event API origin early, Next.js will set the right headers and meta tags to speed up the connection.\n */\nexport function preconnect(client: SanityClient): void {\n const {origin} = new URL(client.getUrl('', false))\n reactDomPreconnect(origin)\n}\n","import {generateHelpUrl} from '@sanity/generate-help-url'\n\nexport function validateStrictSanityLiveProps(props: {includeDrafts?: unknown}): void {\n if (typeof props.includeDrafts !== 'boolean') {\n throw new Error(\n `<SanityLive> requires an explicit \\`includeDrafts\\` prop (true or false) when \\`strict: true\\` is set on \\`defineLive\\`.\\n\\nMore information: ${generateHelpUrl('next-sanity-live-strict')}`,\n {cause: props},\n )\n }\n}\n\nexport function validateStrictFetchOptions(options: {\n perspective?: unknown\n stega?: unknown\n}): void {\n if (typeof options.perspective === 'undefined' || options.perspective === null) {\n throw new Error(\n `sanityFetch() requires an explicit \\`perspective\\` option when \\`strict: true\\` is set on \\`defineLive\\`.\\n\\nMore information: ${generateHelpUrl('next-sanity-fetch-strict')}`,\n {cause: options},\n )\n }\n if (typeof options.stega !== 'boolean') {\n throw new Error(\n `sanityFetch() requires an explicit \\`stega\\` option (true or false) when \\`strict: true\\` is set on \\`defineLive\\`.\\n\\nMore information: ${generateHelpUrl('next-sanity-fetch-strict')}`,\n {cause: options},\n )\n }\n}\n","import {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport type {cookies} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport type {LivePerspective} from '#live/types'\n\n/**\n * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),\n * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.\n * Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.\n *\n * @example\n * ```tsx\n * import {cookies, draftMode} from 'next/headers'\n * import {defineQuery} from 'next-sanity'\n * import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'\n * import {sanityFetch, sanityFetchStaticParams} from '#sanity/live'\n *\n * export async function generateStaticParams() {\n * const query = defineQuery(`*[_type == \"page\" && defined(slug.current)]{\"slug\": slug.current}`)\n * return await sanityFetchStaticParams({query})\n * }\n *\n * export default async function Page({params}: PageProps<'/[slug]'>) {\n * const {isEnabled: isDraftMode} = await draftMode()\n *\n * if (isDraftMode) {\n * return (\n * <Suspense>\n * <DynamicPage params={params} />\n * </Suspense>\n * )\n * }\n *\n * const {slug} = await params\n *\n * return <CachedPage slug={slug} perspective=\"published\" stega={false} />\n * }\n *\n * async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {\n * const {slug} = await params\n * const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n *\n * return <CachedPage slug={slug} perspective={perspective} stega />\n * }\n *\n * async function CachedPage({\n * slug,\n * perspective,\n * stega,\n * }: Awaited<PageProps<'/[slug]'>['params']> & {\n * perspective: LivePerspective\n * stega: boolean\n * }) {\n * 'use cache'\n *\n * const query = defineQuery(`*[_type == \"page\" && slug.current == $slug][0]`)\n * const {data} = await sanityFetch({query, params: {slug}, perspective, stega})\n *\n * return <article>...</article>\n * }\n * ```\n *\n * @public\n */\nexport async function resolvePerspectiveFromCookies({\n cookies: jar,\n}: {\n cookies: Awaited<ReturnType<typeof cookies>>\n}): Promise<LivePerspective> {\n return jar.has(perspectiveCookieName)\n ? sanitizePerspective(jar.get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n}\n"],"mappings":";;;;;;;AAMA,SAAgBA,aAAW,QAA4B;CACrD,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,KAAK,CAAC;CACjD,WAAmB,MAAM;AAC3B;ACPA,SAAgB,8BAA8B,OAAwC;CACpF,IAAI,OAAO,MAAM,kBAAkB,WACjC,MAAM,IAAI,MACR,iJAAiJ,gBAAgB,yBAAyB,KAC1L,EAAC,OAAO,MAAK,CACf;AAEJ;AAEA,SAAgB,2BAA2B,SAGlC;CACP,IAAI,OAAO,QAAQ,gBAAgB,eAAe,QAAQ,gBAAgB,MACxE,MAAM,IAAI,MACR,kIAAkI,gBAAgB,0BAA0B,KAC5K,EAAC,OAAO,QAAO,CACjB;CAEF,IAAI,OAAO,QAAQ,UAAU,WAC3B,MAAM,IAAI,MACR,4IAA4I,gBAAgB,0BAA0B,KACtL,EAAC,OAAO,QAAO,CACjB;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACsCA,eAAsB,8BAA8B,EAClD,SAAS,OAGkB;CAC3B,OAAO,IAAI,IAAI,qBAAqB,IAChC,oBAAoB,IAAI,IAAI,qBAAqB,CAAC,EAAE,OAAO,QAAQ,IACnE;AACN"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { validateApiPerspective } from "@sanity/client";
|
|
2
|
-
function sanitizePerspective(_perspective, fallback) {
|
|
3
|
-
const perspective = typeof _perspective === "string" && _perspective.includes(",") ? _perspective.split(",") : _perspective;
|
|
4
|
-
try {
|
|
5
|
-
validateApiPerspective(perspective);
|
|
6
|
-
return perspective === "raw" ? fallback : perspective;
|
|
7
|
-
} catch (err) {
|
|
8
|
-
console.warn(`Invalid perspective:`, _perspective, perspective, err);
|
|
9
|
-
return fallback;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export { sanitizePerspective as t };
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=sanitizePerspective.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizePerspective.js","names":[],"sources":["../src/live/shared/sanitizePerspective.ts"],"sourcesContent":["import {validateApiPerspective} from '@sanity/client'\n\nimport type {LivePerspective} from '#live/types'\n\nexport function sanitizePerspective(\n _perspective: unknown,\n fallback: 'drafts' | 'published',\n): LivePerspective {\n const perspective =\n typeof _perspective === 'string' && _perspective.includes(',')\n ? _perspective.split(',')\n : _perspective\n try {\n validateApiPerspective(perspective)\n return perspective === 'raw' ? fallback : perspective\n } catch (err) {\n console.warn(`Invalid perspective:`, _perspective, perspective, err)\n return fallback\n }\n}\n"],"mappings":";AAIA,SAAgB,oBACd,cACA,UACiB;CACjB,MAAM,cACJ,OAAO,iBAAiB,YAAY,aAAa,SAAS,GAAG,IACzD,aAAa,MAAM,GAAG,IACtB;CACN,IAAI;EACF,uBAAuB,WAAW;EAClC,OAAO,gBAAgB,QAAQ,WAAW;CAC5C,SAAS,KAAK;EACZ,QAAQ,KAAK,wBAAwB,cAAc,aAAa,GAAG;EACnE,OAAO;CACT;AACF"}
|