next-sanity 13.0.0-cache-components.41 → 13.0.0-cache-components.42
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/live/conditions/default/index.d.ts +28 -0
- package/dist/live/conditions/default/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.js +30 -2
- package/dist/live/conditions/default/index.js.map +1 -1
- package/dist/live/conditions/next-js/index.js +2 -2
- package/dist/live/conditions/next-js/index.js.map +1 -1
- package/dist/live/conditions/react-server/index.js +3 -8
- package/dist/live/conditions/react-server/index.js.map +1 -1
- package/dist/live/server-actions/index.default.d.ts +6 -5
- package/dist/live/server-actions/index.default.d.ts.map +1 -1
- package/dist/live/server-actions/index.default.js +9 -9
- package/dist/live/server-actions/index.default.js.map +1 -1
- package/dist/live/server-actions/index.next-js.d.ts +6 -5
- package/dist/live/server-actions/index.next-js.d.ts.map +1 -1
- package/dist/live/server-actions/index.next-js.js +9 -8
- package/dist/live/server-actions/index.next-js.js.map +1 -1
- package/dist/parseTags.d.ts +17 -8
- package/dist/parseTags.d.ts.map +1 -1
- package/dist/resolvePerspectiveFromCookies.js +17 -8
- package/dist/resolvePerspectiveFromCookies.js.map +1 -1
- package/dist/visual-editing/index.js +2 -2
- package/dist/visual-editing/index.js.map +1 -1
- package/dist/visual-editing/server-actions/index.d.ts +2 -2
- package/dist/visual-editing/server-actions/index.js +3 -3
- package/dist/visual-editing/server-actions/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,34 @@ declare function defineLive(config: DefineLiveOptions & {
|
|
|
21
21
|
sanityFetch: DefinedFetchType;
|
|
22
22
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),
|
|
26
|
+
* where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
|
|
27
|
+
* Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* import {cookies, draftMode} from 'next/headers'
|
|
32
|
+
* import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
|
|
33
|
+
* import {sanityFetch} from '#sanity/live'
|
|
34
|
+
*
|
|
35
|
+
* function Page() {
|
|
36
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
37
|
+
* let perspective: LivePerspective = 'published'
|
|
38
|
+
* if(isDraftMode) {
|
|
39
|
+
* perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
40
|
+
* }
|
|
41
|
+
* const {data} = await cachedFetch({query, perspective, stega: isDraftMode})
|
|
42
|
+
* }
|
|
43
|
+
* function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {
|
|
44
|
+
* 'use cache'
|
|
45
|
+
* const {data} = await sanityFetch({query, params, perspective, stega})
|
|
46
|
+
* return {data}
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
24
52
|
declare const resolvePerspectiveFromCookies: typeof resolvePerspectiveFromCookies$1;
|
|
25
53
|
export { type LivePerspective, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
|
|
26
54
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;AAsBA;;;;AAAA,iBAAgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,sBAAA;AAAA;;;;;iBAMlB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;AAsBA;;;;AAAA,iBAAgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,sBAAA;AAAA;;;;;iBAMlB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA;AAFlC;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;;;AAxCA,cAwCa,6BAAA,SAAsC,+BAAA"}
|
|
@@ -7,9 +7,37 @@ import { t as parseTags } from "../../../parseTags.js";
|
|
|
7
7
|
function defineLive(_config) {
|
|
8
8
|
throw new Error(`defineLive can't be imported by a client component`);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),
|
|
12
|
+
* where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
|
|
13
|
+
* Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import {cookies, draftMode} from 'next/headers'
|
|
18
|
+
* import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
|
|
19
|
+
* import {sanityFetch} from '#sanity/live'
|
|
20
|
+
*
|
|
21
|
+
* function Page() {
|
|
22
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
23
|
+
* let perspective: LivePerspective = 'published'
|
|
24
|
+
* if(isDraftMode) {
|
|
25
|
+
* perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
26
|
+
* }
|
|
27
|
+
* const {data} = await cachedFetch({query, perspective, stega: isDraftMode})
|
|
28
|
+
* }
|
|
29
|
+
* function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {
|
|
30
|
+
* 'use cache'
|
|
31
|
+
* const {data} = await sanityFetch({query, params, perspective, stega})
|
|
32
|
+
* return {data}
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
const resolvePerspectiveFromCookies = () => {
|
|
11
39
|
throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`);
|
|
12
|
-
}
|
|
40
|
+
};
|
|
13
41
|
export { defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
|
|
14
42
|
|
|
15
43
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["// This is the fallback export condition for `import 'next-sanity/live'`,\n// it should have the same type definitions as the other conditions so that userland don't have to worry about setting the right\n// `customCondition` in their `tsconfig.json` in order to get accurate typings.\n// The implementation here though should all throw errors, as importing this file means userland made a mistake and somehow a client component is\n// trying to pull in something it shouldn't.\n\nimport type {resolvePerspectiveFromCookies as _resolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\nexport {parseTags} from '#live/parseTags'\n\n/**\n * One\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\n/**\n * Two\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\n/**\n * Three\n * @public\n */\nexport function defineLive(_config: DefineLiveOptions): never {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["// This is the fallback export condition for `import 'next-sanity/live'`,\n// it should have the same type definitions as the other conditions so that userland don't have to worry about setting the right\n// `customCondition` in their `tsconfig.json` in order to get accurate typings.\n// The implementation here though should all throw errors, as importing this file means userland made a mistake and somehow a client component is\n// trying to pull in something it shouldn't.\n\nimport type {resolvePerspectiveFromCookies as _resolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\nexport {parseTags} from '#live/parseTags'\n\n/**\n * One\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\n/**\n * Two\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\n/**\n * Three\n * @public\n */\nexport function defineLive(_config: DefineLiveOptions): never {\n throw new Error(`defineLive can't be imported by a client component`)\n}\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 {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'\n * import {sanityFetch} from '#sanity/live'\n *\n * function Page() {\n * const {isEnabled: isDraftMode} = await draftMode()\n * let perspective: LivePerspective = 'published'\n * if(isDraftMode) {\n * perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n * }\n * const {data} = await cachedFetch({query, perspective, stega: isDraftMode})\n * }\n * function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {\n * 'use cache'\n * const {data} = await sanityFetch({query, params, perspective, stega})\n * return {data}\n * }\n * ```\n *\n * @public\n */\nexport const resolvePerspectiveFromCookies: typeof _resolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n\nexport type {LivePerspective} from '#live/types'\n"],"mappings":";;;;;;AAsCA,SAAgB,WAAW,SAAmC;AAC5D,OAAM,IAAI,MAAM,qDAAqD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BvE,MAAa,sCAA6E;AACxF,OAAM,IAAI,MAAM,wEAAwE"}
|
|
@@ -4,7 +4,7 @@ import { n as validateStrictFetchOptions, r as validateStrictSanityLiveProps, t
|
|
|
4
4
|
import { t as parseTags } from "../../../parseTags.js";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
7
|
-
import {
|
|
7
|
+
import { refreshAction, revalidateSyncTagsAction } from "next-sanity/live/server-actions";
|
|
8
8
|
import { cacheLife, cacheTag } from "next/cache";
|
|
9
9
|
import { PHASE_PRODUCTION_BUILD } from "next/constants";
|
|
10
10
|
import { preconnect } from "react-dom";
|
|
@@ -57,7 +57,7 @@ function defineLive(config) {
|
|
|
57
57
|
};
|
|
58
58
|
const SanityLive$2 = function SanityLive$1(props) {
|
|
59
59
|
if (strict) validateStrictSanityLiveProps(props);
|
|
60
|
-
const { includeDrafts = false, action =
|
|
60
|
+
const { includeDrafts = false, action = revalidateSyncTagsAction, onReconnect = refreshAction, onRestart = refreshAction, onWelcome, onError, onGoAway, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components" } = props;
|
|
61
61
|
const shouldIncludeDrafts = typeof browserToken === "string" && includeDrafts;
|
|
62
62
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
63
63
|
const { origin } = new URL(client.getUrl("", false));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {refreshAction, revalidateSyncTagsAction} from 'next-sanity/live/server-actions'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {PHASE_PRODUCTION_BUILD} from 'next/constants'\nimport {preconnect} from 'react-dom'\n\nimport {cacheTagPrefixes, revalidate} from '#live/constants'\nimport {validateStrictFetchOptions, validateStrictSanityLiveProps} from '#live/strictValidation'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\nexport function defineLive(config: DefineLiveOptions) {\n const {client: _client, serverToken, browserToken, strict = false} = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: true})\n const {token: originalToken, perspective: originalPerspective = 'published'} = client.config()\n\n const sanityFetch: DefinedFetchType = async function sanityFetch({\n query,\n params = {},\n perspective: _perspective,\n stega: _stega,\n tags: customCacheTags = [],\n requestTag = 'next-loader.fetch.cache-components',\n }) {\n if (strict) {\n validateStrictFetchOptions({perspective: _perspective, stega: _stega})\n }\n const perspective = _perspective ?? originalPerspective\n const stega = _stega ?? false\n const useCdn = perspective === 'published'\n const isBuildPhase = process.env['NEXT_PHASE'] === PHASE_PRODUCTION_BUILD\n const cacheMode = useCdn && !isBuildPhase ? 'noStale' : undefined\n\n const cacheTagPrefix =\n perspective === 'published' ? cacheTagPrefixes.published : cacheTagPrefixes.drafts\n const {result, resultSourceMap, syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n returnQuery: false,\n perspective,\n useCdn,\n stega,\n cacheMode,\n tag: requestTag,\n token: perspective === 'published' ? originalToken : serverToken || originalToken, // @TODO can pass undefined instead of config.token here?\n })\n const tags = [...customCacheTags, ...(syncTags || []).map((tag) => `${cacheTagPrefix}${tag}`)]\n /**\n * The tags used here, are expired later on in the `expireTags` Server Action with the `expireTag` function from `next/cache`\n */\n cacheTag(...tags)\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short,\n * userland can still set a shorter revalidate time by calling `cacheLife` themselves.\n */\n cacheLife({revalidate})\n\n return {data: result, sourceMap: resultSourceMap || null, tags}\n }\n\n const SanityLive: React.ComponentType<DefinedLiveProps> = function SanityLive(props) {\n if (strict) {\n validateStrictSanityLiveProps(props)\n }\n const {\n includeDrafts = false,\n action = revalidateSyncTagsAction,\n onReconnect = refreshAction,\n onRestart = refreshAction,\n\n onWelcome,\n onError,\n onGoAway,\n\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = false,\n requestTag = 'next-loader.live.cache-components',\n } = props\n\n const shouldIncludeDrafts = typeof browserToken === 'string' && includeDrafts\n\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: shouldIncludeDrafts ? browserToken : undefined,\n }}\n includeDrafts={shouldIncludeDrafts}\n action={action}\n onReconnect={onReconnect}\n onRestart={onRestart}\n onWelcome={onWelcome}\n onError={onError}\n onGoAway={onGoAway}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n />\n )\n }\n SanityLive.displayName = 'SanityLiveServerComponent'\n\n return {sanityFetch, SanityLive}\n}\n"],"mappings":";;;;;;;;;;AAwBA,SAAgB,WAAW,QAA2B;CACpD,MAAM,EAAC,QAAQ,SAAS,aAAa,cAAc,SAAS,UAAS;AAErE,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAK,CAAC;CAC1E,MAAM,EAAC,OAAO,eAAe,aAAa,sBAAsB,gBAAe,OAAO,QAAQ;CAE9F,MAAM,cAAgC,eAAe,YAAY,EAC/D,OACA,SAAS,EAAE,EACX,aAAa,cACb,OAAO,QACP,MAAM,kBAAkB,EAAE,EAC1B,aAAa,wCACZ;AACD,MAAI,OACF,4BAA2B;GAAC,aAAa;GAAc,OAAO;GAAO,CAAC;EAExE,MAAM,cAAc,gBAAgB;EACpC,MAAM,QAAQ,UAAU;EACxB,MAAM,SAAS,gBAAgB;EAC/B,MAAM,eAAe,QAAQ,IAAI,kBAAkB;EACnD,MAAM,YAAY,UAAU,CAAC,eAAe,YAAY,KAAA;EAExD,MAAM,iBACJ,gBAAgB,cAAc,iBAAiB,YAAY,iBAAiB;EAC9E,MAAM,EAAC,QAAQ,iBAAiB,aAAY,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GAClF,gBAAgB;GAChB,aAAa;GACb;GACA;GACA;GACA;GACA,KAAK;GACL,OAAO,gBAAgB,cAAc,gBAAgB,eAAe;GACrE,CAAC;EACF,MAAM,OAAO,CAAC,GAAG,iBAAiB,IAAI,YAAY,EAAE,EAAE,KAAK,QAAQ,GAAG,iBAAiB,MAAM,CAAC;;;;AAI9F,WAAS,GAAG,KAAK;;;;;AAKjB,YAAU,EAAC,YAAW,CAAC;AAEvB,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM;GAAK;;CAGjE,MAAMA,eAAoD,SAASA,aAAW,OAAO;AACnF,MAAI,OACF,+BAA8B,MAAM;EAEtC,MAAM,EACJ,gBAAgB,OAChB,SAAS,0BACT,cAAc,eACd,YAAY,eAEZ,WACA,SACA,UAEA,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,OACrB,aAAa,wCACX;EAEJ,MAAM,sBAAsB,OAAO,iBAAiB,YAAY;EAEhE,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EAGjB,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,aAAW,OAAO;AAElB,SACE,oBAACC,YAAD;GACE,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,sBAAsB,eAAe,KAAA;IAC7C;GACD,eAAe;GACP;GACK;GACF;GACA;GACF;GACC;GACE;GACI;GACA;GACI;GACpB,CAAA;;AAGN,cAAW,cAAc;AAEzB,QAAO;EAAC;EAAa,YAAA;EAAW"}
|
|
@@ -8,7 +8,7 @@ import { cookies, draftMode } from "next/headers";
|
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
import "@sanity/client";
|
|
10
10
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
11
|
-
import {
|
|
11
|
+
import { refreshAction, revalidateSyncTagsAction } from "next-sanity/live/server-actions";
|
|
12
12
|
import { PHASE_PRODUCTION_BUILD } from "next/constants";
|
|
13
13
|
import { preconnect } from "react-dom";
|
|
14
14
|
function defineLive(config) {
|
|
@@ -32,17 +32,12 @@ function defineLive(config) {
|
|
|
32
32
|
const useCdn = perspective === "published";
|
|
33
33
|
const isBuildPhase = process.env["NEXT_PHASE"] === PHASE_PRODUCTION_BUILD;
|
|
34
34
|
const cacheMode = useCdn && !isBuildPhase ? "noStale" : void 0;
|
|
35
|
-
const revalidate = false;
|
|
36
35
|
const cacheTagPrefix = perspective === "published" ? cacheTagPrefixes.published : cacheTagPrefixes.drafts;
|
|
37
36
|
const { syncTags } = await client.fetch(query, await params, {
|
|
38
37
|
filterResponse: false,
|
|
39
38
|
perspective,
|
|
40
39
|
stega: false,
|
|
41
40
|
returnQuery: false,
|
|
42
|
-
next: {
|
|
43
|
-
revalidate,
|
|
44
|
-
tags: [...tags, "fetch-sync-tags"].map((tag) => `${cacheTagPrefix}${tag}`)
|
|
45
|
-
},
|
|
46
41
|
useCdn,
|
|
47
42
|
cacheMode,
|
|
48
43
|
tag: [requestTag, "fetch-sync-tags"].filter(Boolean).join(".")
|
|
@@ -54,7 +49,7 @@ function defineLive(config) {
|
|
|
54
49
|
stega,
|
|
55
50
|
token: perspective !== "published" && serverToken ? serverToken : originalToken,
|
|
56
51
|
next: {
|
|
57
|
-
revalidate,
|
|
52
|
+
revalidate: false,
|
|
58
53
|
tags: cacheTags
|
|
59
54
|
},
|
|
60
55
|
useCdn,
|
|
@@ -69,7 +64,7 @@ function defineLive(config) {
|
|
|
69
64
|
};
|
|
70
65
|
const SanityLive$2 = async function SanityLive$1(props) {
|
|
71
66
|
if (strict) validateStrictSanityLiveProps(props);
|
|
72
|
-
const { includeDrafts = (await draftMode()).isEnabled, action =
|
|
67
|
+
const { includeDrafts = (await draftMode()).isEnabled, action = revalidateSyncTagsAction, onReconnect = refreshAction, onRestart = refreshAction, onWelcome = false, onError = false, onGoAway = false, refreshOnMount, refreshOnFocus, refreshOnReconnect, requestTag = "next-loader.live" } = props;
|
|
73
68
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
74
69
|
const shouldIncludeDrafts = typeof browserToken === "string" && includeDrafts;
|
|
75
70
|
const { origin } = new URL(client.getUrl("", false));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import {type ClientPerspective, type QueryParams} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import {type ClientPerspective, type QueryParams} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {refreshAction, revalidateSyncTagsAction} from 'next-sanity/live/server-actions'\nimport {PHASE_PRODUCTION_BUILD} from 'next/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\nimport {cacheTagPrefixes} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {validateStrictFetchOptions, validateStrictSanityLiveProps} from '#live/strictValidation'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\nexport function defineLive(config: DefineLiveOptions) {\n const {\n client: _client,\n serverToken,\n browserToken,\n stega: stegaEnabled = true,\n strict = false,\n } = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken, perspective: originalPerspective = 'published'} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = [],\n perspective: _perspective,\n tag,\n requestTag = tag ?? 'next-loader.fetch',\n }: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n tag?: string\n requestTag?: string\n }) {\n if (strict) {\n validateStrictFetchOptions({perspective: _perspective, stega: _stega})\n }\n const stega = strict\n ? _stega!\n : (_stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled))\n const perspective = strict\n ? _perspective!\n : (_perspective ??\n (await resolveCookiePerspective(\n originalPerspective === 'raw' ? 'published' : originalPerspective,\n )))\n const useCdn = perspective === 'published'\n const isBuildPhase = process.env['NEXT_PHASE'] === PHASE_PRODUCTION_BUILD\n const cacheMode = useCdn && !isBuildPhase ? 'noStale' : undefined\n const cacheTagPrefix =\n perspective === 'published' ? cacheTagPrefixes.published : cacheTagPrefixes.drafts\n\n // 1. Fetch the tags first, with an uncached request, but that does not count towards the Sanity API quota\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n useCdn,\n cacheMode,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `${cacheTagPrefix}${tag}`) || [])]\n\n // 2. Then fetch the data, using the fetch cache with specified tags\n const {result, resultSourceMap} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega,\n token: perspective !== 'published' && serverToken ? serverToken : originalToken,\n next: {revalidate: false, tags: cacheTags},\n useCdn,\n cacheMode,\n tag: requestTag,\n })\n return {data: result, sourceMap: resultSourceMap || null, tags: cacheTags}\n }\n\n const SanityLive: React.ComponentType<DefinedLiveProps> = async function SanityLive(props) {\n if (strict) {\n validateStrictSanityLiveProps(props)\n }\n const {\n includeDrafts = (await draftMode()).isEnabled,\n action = revalidateSyncTagsAction,\n onReconnect = refreshAction,\n onRestart = refreshAction,\n\n onWelcome = false,\n onError = false,\n onGoAway = false,\n\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag = 'next-loader.live',\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const shouldIncludeDrafts = typeof browserToken === 'string' && includeDrafts\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: shouldIncludeDrafts ? browserToken : undefined,\n }}\n includeDrafts={shouldIncludeDrafts}\n action={action}\n onReconnect={onReconnect}\n onRestart={onRestart}\n onWelcome={onWelcome}\n onError={onError}\n onGoAway={onGoAway}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n />\n )\n }\n SanityLive.displayName = 'SanityLiveServerComponent'\n\n return {sanityFetch, SanityLive}\n}\n\nasync function resolveCookiePerspective(\n fallback: Exclude<ClientPerspective, 'raw'>,\n): Promise<Exclude<ClientPerspective, 'raw'>> {\n return (await draftMode()).isEnabled\n ? (await cookies()).has(perspectiveCookieName)\n ? sanitizePerspective((await cookies()).get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n : fallback\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,SAAgB,WAAW,QAA2B;CACpD,MAAM,EACJ,QAAQ,SACR,aACA,cACA,OAAO,eAAe,MACtB,SAAS,UACP;AAEJ,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAM,CAAC;CAC3E,MAAM,EAAC,OAAO,eAAe,aAAa,sBAAsB,gBAAe,OAAO,QAAQ;CAC9F,MAAM,mBAAmB,OAAO,OAAO,QAAQ,CAAC,MAAM,cAAc;CAEpE,MAAM,cAAgC,eAAe,YAEnD,EACA,OACA,SAAS,EAAE,EACX,OAAO,QACP,OAAO,EAAE,EACT,aAAa,cACb,KACA,aAAa,OAAO,uBASnB;AACD,MAAI,OACF,4BAA2B;GAAC,aAAa;GAAc,OAAO;GAAO,CAAC;EAExE,MAAM,QAAQ,SACV,SACC,WAAW,gBAAgB,qBAAqB,MAAM,WAAW,EAAE;EACxE,MAAM,cAAc,SAChB,eACC,gBACA,MAAM,yBACL,wBAAwB,QAAQ,cAAc,oBAC/C;EACL,MAAM,SAAS,gBAAgB;EAC/B,MAAM,eAAe,QAAQ,IAAI,kBAAkB;EACnD,MAAM,YAAY,UAAU,CAAC,eAAe,YAAY,KAAA;EACxD,MAAM,iBACJ,gBAAgB,cAAc,iBAAiB,YAAY,iBAAiB;EAG9E,MAAM,EAAC,aAAY,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACzD,gBAAgB;GACH;GACb,OAAO;GACP,aAAa;GACb;GACA;GACA,KAAK,CAAC,YAAY,kBAAkB,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;GAC/D,CAAC;EAEF,MAAM,YAAY,CAAC,GAAG,MAAM,GAAI,UAAU,KAAK,QAAQ,GAAG,iBAAiB,MAAM,IAAI,EAAE,CAAE;EAGzF,MAAM,EAAC,QAAQ,oBAAmB,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACxE,gBAAgB;GACH;GACb;GACA,OAAO,gBAAgB,eAAe,cAAc,cAAc;GAClE,MAAM;IAAC,YAAY;IAAO,MAAM;IAAU;GAC1C;GACA;GACA,KAAK;GACN,CAAC;AACF,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM,MAAM;GAAU;;CAG5E,MAAMA,eAAoD,eAAeA,aAAW,OAAO;AACzF,MAAI,OACF,+BAA8B,MAAM;EAEtC,MAAM,EACJ,iBAAiB,MAAM,WAAW,EAAE,WACpC,SAAS,0BACT,cAAc,eACd,YAAY,eAEZ,YAAY,OACZ,UAAU,OACV,WAAW,OAEX,gBACA,gBACA,oBACA,aAAa,uBACX;EACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EACjB,MAAM,sBAAsB,OAAO,iBAAiB,YAAY;EAGhE,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,aAAW,OAAO;AAElB,SACE,oBAACC,YAAD;GACE,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,sBAAsB,eAAe,KAAA;IAC7C;GACD,eAAe;GACP;GACK;GACF;GACA;GACF;GACC;GACE;GACI;GACA;GACI;GACpB,CAAA;;AAGN,cAAW,cAAc;AAEzB,QAAO;EAAC;EAAa,YAAA;EAAW;;AAGlC,eAAe,yBACb,UAC4C;AAC5C,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @alpha CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
3
3
|
*/
|
|
4
|
-
declare function
|
|
4
|
+
declare function revalidateSyncTagsAction(unsafeTags: unknown): Promise<void>;
|
|
5
5
|
/**
|
|
6
|
-
* Used by `<SanityLive onReconnect={
|
|
6
|
+
* Used by `<SanityLive onReconnect={refreshAction} onRestart={refreshAction} />`
|
|
7
|
+
* @deprecated - refactor `onReconnect` and `onRestart` to support `() => 'refresh'`
|
|
7
8
|
*/
|
|
8
|
-
declare function
|
|
9
|
-
export {
|
|
9
|
+
declare function refreshAction(): Promise<void>;
|
|
10
|
+
export { refreshAction, revalidateSyncTagsAction };
|
|
10
11
|
//# sourceMappingURL=index.default.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"mappings":"AAUA;;;AAAA,iBAAsB,
|
|
1
|
+
{"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"mappings":"AAUA;;;AAAA,iBAAsB,wBAAA,CAAyB,UAAA,YAAsB,OAAA;;AAyBrE;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { t as parseTags } from "../../parseTags.js";
|
|
3
3
|
import { draftMode } from "next/headers";
|
|
4
|
-
import { refresh, revalidateTag
|
|
4
|
+
import { refresh, revalidateTag } from "next/cache";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* @alpha CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
7
7
|
*/
|
|
8
|
-
async function
|
|
8
|
+
async function revalidateSyncTagsAction(unsafeTags) {
|
|
9
9
|
const { tags, prefixType } = parseTags(unsafeTags);
|
|
10
10
|
if ((await draftMode()).isEnabled) {
|
|
11
11
|
console.warn(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`, { tags });
|
|
12
12
|
refresh();
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
for (const tag of tags)
|
|
16
|
-
|
|
17
|
-
console.log(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> updated tags: ${tags.join(", ")} and revalidated tag: "sanity:fetch-sync-tags" with cache profile "max"`);
|
|
15
|
+
for (const tag of tags) revalidateTag(tag, "max");
|
|
16
|
+
console.log(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> revalidated tags: ${tags.join(", ")} with cache profile "max" `);
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
|
-
* Used by `<SanityLive onReconnect={
|
|
19
|
+
* Used by `<SanityLive onReconnect={refreshAction} onRestart={refreshAction} />`
|
|
20
|
+
* @deprecated - refactor `onReconnect` and `onRestart` to support `() => 'refresh'`
|
|
21
21
|
*/
|
|
22
|
-
async function
|
|
22
|
+
async function refreshAction() {
|
|
23
23
|
refresh();
|
|
24
24
|
}
|
|
25
|
-
export {
|
|
25
|
+
export { refreshAction, revalidateSyncTagsAction };
|
|
26
26
|
|
|
27
27
|
//# sourceMappingURL=index.default.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.default.js","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":["'use server'\n\nimport {refresh, revalidateTag
|
|
1
|
+
{"version":3,"file":"index.default.js","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":["'use server'\n\nimport {refresh, revalidateTag} from 'next/cache'\nimport {draftMode} from 'next/headers'\n\nimport {parseTags} from '#live/parseTags'\n\n/**\n * @alpha CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function revalidateSyncTagsAction(unsafeTags: unknown): Promise<void> {\n const {tags, prefixType} = parseTags(unsafeTags)\n if ((await draftMode()).isEnabled) {\n console.warn(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`,\n {tags},\n )\n refresh()\n return undefined\n }\n\n for (const tag of tags) {\n revalidateTag(tag, 'max')\n }\n\n // oxlint-disable-next-line no-console\n console.log(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> revalidated tags: ${tags.join(', ')} with cache profile \"max\" `,\n )\n}\n\n/**\n * Used by `<SanityLive onReconnect={refreshAction} onRestart={refreshAction} />`\n * @deprecated - refactor `onReconnect` and `onRestart` to support `() => 'refresh'`\n */\nexport async function refreshAction(): Promise<void> {\n refresh()\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,yBAAyB,YAAoC;CACjF,MAAM,EAAC,MAAM,eAAc,UAAU,WAAW;AAChD,MAAK,MAAM,WAAW,EAAE,WAAW;AACjC,UAAQ,KACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,6HAC/D,EAAC,MAAK,CACP;AACD,WAAS;AACT;;AAGF,MAAK,MAAM,OAAO,KAChB,eAAc,KAAK,MAAM;AAI3B,SAAQ,IACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,uBAAuB,KAAK,KAAK,KAAK,CAAC,4BACvG;;;;;;AAOH,eAAsB,gBAA+B;AACnD,UAAS"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @alpha CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
3
3
|
*/
|
|
4
|
-
declare function
|
|
4
|
+
declare function revalidateSyncTagsAction(unsafeTags: unknown): Promise<void>;
|
|
5
5
|
/**
|
|
6
|
-
* Used by `<SanityLive onReconnect={
|
|
6
|
+
* Used by `<SanityLive onReconnect={refreshAction} onRestart={refreshAction} />`
|
|
7
|
+
* @deprecated - refactor `onReconnect` and `onRestart` to support `() => 'refresh'`
|
|
7
8
|
*/
|
|
8
|
-
declare function
|
|
9
|
-
export {
|
|
9
|
+
declare function refreshAction(): Promise<void>;
|
|
10
|
+
export { refreshAction, revalidateSyncTagsAction };
|
|
10
11
|
//# sourceMappingURL=index.next-js.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"mappings":"AAUA;;;AAAA,iBAAsB,
|
|
1
|
+
{"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"mappings":"AAUA;;;AAAA,iBAAsB,wBAAA,CAAyB,UAAA,YAAsB,OAAA;;AAyBrE;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { t as parseTags } from "../../parseTags.js";
|
|
3
3
|
import { draftMode } from "next/headers";
|
|
4
|
-
import { refresh,
|
|
4
|
+
import { refresh, revalidateTag } from "next/cache";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* @alpha CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
7
7
|
*/
|
|
8
|
-
async function
|
|
8
|
+
async function revalidateSyncTagsAction(unsafeTags) {
|
|
9
9
|
const { tags, prefixType } = parseTags(unsafeTags);
|
|
10
10
|
if ((await draftMode()).isEnabled) {
|
|
11
11
|
console.warn(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`, { tags });
|
|
12
12
|
refresh();
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
for (const tag of tags)
|
|
16
|
-
console.log(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/>
|
|
15
|
+
for (const tag of tags) revalidateTag(tag, "max");
|
|
16
|
+
console.log(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> revalidated tags: ${tags.join(", ")} with cache profile "max" `);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Used by `<SanityLive onReconnect={
|
|
19
|
+
* Used by `<SanityLive onReconnect={refreshAction} onRestart={refreshAction} />`
|
|
20
|
+
* @deprecated - refactor `onReconnect` and `onRestart` to support `() => 'refresh'`
|
|
20
21
|
*/
|
|
21
|
-
async function
|
|
22
|
+
async function refreshAction() {
|
|
22
23
|
refresh();
|
|
23
24
|
}
|
|
24
|
-
export {
|
|
25
|
+
export { refreshAction, revalidateSyncTagsAction };
|
|
25
26
|
|
|
26
27
|
//# sourceMappingURL=index.next-js.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.next-js.js","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":["'use server'\n\nimport {refresh,
|
|
1
|
+
{"version":3,"file":"index.next-js.js","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":["'use server'\n\nimport {refresh, revalidateTag} from 'next/cache'\nimport {draftMode} from 'next/headers'\n\nimport {parseTags} from '#live/parseTags'\n\n/**\n * @alpha CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function revalidateSyncTagsAction(unsafeTags: unknown): Promise<void> {\n const {tags, prefixType} = parseTags(unsafeTags)\n if ((await draftMode()).isEnabled) {\n console.warn(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`,\n {tags},\n )\n refresh()\n return undefined\n }\n\n for (const tag of tags) {\n revalidateTag(tag, 'max')\n }\n\n // oxlint-disable-next-line no-console\n console.log(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> revalidated tags: ${tags.join(', ')} with cache profile \"max\" `,\n )\n}\n\n/**\n * Used by `<SanityLive onReconnect={refreshAction} onRestart={refreshAction} />`\n * @deprecated - refactor `onReconnect` and `onRestart` to support `() => 'refresh'`\n */\nexport async function refreshAction(): Promise<void> {\n refresh()\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,yBAAyB,YAAoC;CACjF,MAAM,EAAC,MAAM,eAAc,UAAU,WAAW;AAChD,MAAK,MAAM,WAAW,EAAE,WAAW;AACjC,UAAQ,KACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,6HAC/D,EAAC,MAAK,CACP;AACD,WAAS;AACT;;AAGF,MAAK,MAAM,OAAO,KAChB,eAAc,KAAK,MAAM;AAI3B,SAAQ,IACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,uBAAuB,KAAK,KAAK,KAAK,CAAC,4BACvG;;;;;;AAOH,eAAsB,gBAA+B;AACnD,UAAS"}
|
package/dist/parseTags.d.ts
CHANGED
|
@@ -5,16 +5,25 @@ import { ClientPerspective, SyncTag } from "@sanity/client";
|
|
|
5
5
|
* where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
|
|
6
6
|
* Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.
|
|
7
7
|
*
|
|
8
|
-
* The caller is responsible for awaiting `cookies()` from `next/headers` and passing the
|
|
9
|
-
* resulting cookie store as the `cookies` option — this keeps the helper free of dynamic APIs
|
|
10
|
-
* so it can be invoked from anywhere a `ReadonlyRequestCookies` instance is available.
|
|
11
|
-
*
|
|
12
8
|
* @example
|
|
13
|
-
* ```
|
|
14
|
-
* import {cookies} from 'next/headers'
|
|
15
|
-
* import {resolvePerspectiveFromCookies} from 'next-sanity/live'
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import {cookies, draftMode} from 'next/headers'
|
|
11
|
+
* import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
|
|
12
|
+
* import {sanityFetch} from '#sanity/live'
|
|
16
13
|
*
|
|
17
|
-
*
|
|
14
|
+
* function Page() {
|
|
15
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
16
|
+
* let perspective: LivePerspective = 'published'
|
|
17
|
+
* if(isDraftMode) {
|
|
18
|
+
* perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
19
|
+
* }
|
|
20
|
+
* const {data} = await cachedFetch({query, perspective, stega: isDraftMode})
|
|
21
|
+
* }
|
|
22
|
+
* function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {
|
|
23
|
+
* 'use cache'
|
|
24
|
+
* const {data} = await sanityFetch({query, params, perspective, stega})
|
|
25
|
+
* return {data}
|
|
26
|
+
* }
|
|
18
27
|
* ```
|
|
19
28
|
*
|
|
20
29
|
* @public
|
package/dist/parseTags.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseTags.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/shared/constants.ts","../src/live/shared/parseTags.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"parseTags.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/shared/constants.ts","../src/live/shared/parseTags.ts"],"mappings":";;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;AC3BA;;;iBD2BsB,6BAAA,CAAA;EACpB,OAAA,EAAS;AAAA;EAET,OAAA,EAAS,OAAA,CAAQ,UAAA,QAAkB,OAAA;AAAA,IACjC,OAAA,CAAQ,OAAA,CAAQ,iBAAA;AAAA,cC/BP,gBAAA;EACX,SAAA;EACA,MAAA;AAAA;AAAA,UCLQ,mBAAA;EACR,IAAA,YAAgB,gBAAA,CAAiB,SAAA,GAAY,OAAA;EAC7C,MAAA,SAAe,gBAAA,CAAiB,SAAA;EAChC,UAAA;AAAA;AAAA,UAEQ,eAAA;EACR,IAAA,YAAgB,gBAAA,CAAiB,MAAA,GAAS,OAAA;EAC1C,MAAA,SAAe,gBAAA,CAAiB,MAAA;EAChC,UAAA;AAAA;AAAA,KAEG,UAAA,GAAa,mBAAA,GAAsB,eAAA;;;;;;;;;;;;;;;ADPxC;;;;;;ACL+B;iBAmCf,SAAA,CAAU,UAAA,YAAsB,UAAA"}
|
|
@@ -13,16 +13,25 @@ function validateStrictFetchOptions(options) {
|
|
|
13
13
|
* where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
|
|
14
14
|
* Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.
|
|
15
15
|
*
|
|
16
|
-
* The caller is responsible for awaiting `cookies()` from `next/headers` and passing the
|
|
17
|
-
* resulting cookie store as the `cookies` option — this keeps the helper free of dynamic APIs
|
|
18
|
-
* so it can be invoked from anywhere a `ReadonlyRequestCookies` instance is available.
|
|
19
|
-
*
|
|
20
16
|
* @example
|
|
21
|
-
* ```
|
|
22
|
-
* import {cookies} from 'next/headers'
|
|
23
|
-
* import {resolvePerspectiveFromCookies} from 'next-sanity/live'
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import {cookies, draftMode} from 'next/headers'
|
|
19
|
+
* import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
|
|
20
|
+
* import {sanityFetch} from '#sanity/live'
|
|
24
21
|
*
|
|
25
|
-
*
|
|
22
|
+
* function Page() {
|
|
23
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
24
|
+
* let perspective: LivePerspective = 'published'
|
|
25
|
+
* if(isDraftMode) {
|
|
26
|
+
* perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
27
|
+
* }
|
|
28
|
+
* const {data} = await cachedFetch({query, perspective, stega: isDraftMode})
|
|
29
|
+
* }
|
|
30
|
+
* function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {
|
|
31
|
+
* 'use cache'
|
|
32
|
+
* const {data} = await sanityFetch({query, params, perspective, stega})
|
|
33
|
+
* return {data}
|
|
34
|
+
* }
|
|
26
35
|
* ```
|
|
27
36
|
*
|
|
28
37
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePerspectiveFromCookies.js","names":[],"sources":["../src/live/shared/strictValidation.ts","../src/live/shared/resolvePerspectiveFromCookies.ts"],"sourcesContent":["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 type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport type {cookies} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\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 *
|
|
1
|
+
{"version":3,"file":"resolvePerspectiveFromCookies.js","names":[],"sources":["../src/live/shared/strictValidation.ts","../src/live/shared/resolvePerspectiveFromCookies.ts"],"sourcesContent":["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 type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport type {cookies} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\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 {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'\n * import {sanityFetch} from '#sanity/live'\n *\n * function Page() {\n * const {isEnabled: isDraftMode} = await draftMode()\n * let perspective: LivePerspective = 'published'\n * if(isDraftMode) {\n * perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n * }\n * const {data} = await cachedFetch({query, perspective, stega: isDraftMode})\n * }\n * function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {\n * 'use cache'\n * const {data} = await sanityFetch({query, params, perspective, stega})\n * return {data}\n * }\n * ```\n *\n * @public\n */\nexport async function resolvePerspectiveFromCookies({\n cookies: jar,\n}: {\n cookies: Awaited<ReturnType<typeof cookies>>\n}): Promise<Exclude<ClientPerspective, 'raw'>> {\n return jar.has(perspectiveCookieName)\n ? sanitizePerspective(jar.get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n}\n"],"mappings":";;;AAEA,SAAgB,8BAA8B,OAAwC;AACpF,KAAI,OAAO,MAAM,kBAAkB,UACjC,OAAM,IAAI,MACR,iJAAiJ,gBAAgB,0BAA0B,IAC3L,EAAC,OAAO,OAAM,CACf;;AAIL,SAAgB,2BAA2B,SAGlC;AACP,KAAI,OAAO,QAAQ,gBAAgB,eAAe,QAAQ,gBAAgB,KACxE,OAAM,IAAI,MACR,kIAAkI,gBAAgB,2BAA2B,IAC7K,EAAC,OAAO,SAAQ,CACjB;AAEH,KAAI,OAAO,QAAQ,UAAU,UAC3B,OAAM,IAAI,MACR,4IAA4I,gBAAgB,2BAA2B,IACvL,EAAC,OAAO,SAAQ,CACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACSL,eAAsB,8BAA8B,EAClD,SAAS,OAGoC;AAC7C,QAAO,IAAI,IAAI,sBAAsB,GACjC,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,OAAO,SAAS,GACpE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { VisualEditing as VisualEditing$1 } from "next-sanity/visual-editing/client-component";
|
|
3
|
-
import {
|
|
3
|
+
import { perspectiveChangeAction } from "next-sanity/visual-editing/server-actions";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
@@ -20,7 +20,7 @@ function VisualEditing(props) {
|
|
|
20
20
|
console.error("Failed detecting trailingSlash", err);
|
|
21
21
|
}
|
|
22
22
|
return /* @__PURE__ */ jsx(VisualEditing$1, {
|
|
23
|
-
onPerspectiveChange:
|
|
23
|
+
onPerspectiveChange: perspectiveChangeAction,
|
|
24
24
|
...props,
|
|
25
25
|
basePath: props.basePath ?? autoBasePath,
|
|
26
26
|
trailingSlash: props.trailingSlash ?? autoTrailingSlash
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["VisualEditingComponent"],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport {VisualEditing as VisualEditingComponent} from 'next-sanity/visual-editing/client-component'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["VisualEditingComponent"],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport {VisualEditing as VisualEditingComponent} from 'next-sanity/visual-editing/client-component'\nimport {perspectiveChangeAction} from 'next-sanity/visual-editing/server-actions'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n onPerspectiveChange={perspectiveChangeAction}\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"mappings":";;;;;;AAOA,SAAgB,cAAc,OAA+C;CAC3E,IAAI;AACJ,KAAI,OAAO,MAAM,aAAa,SAC5B,KAAI;AACF,iBAAe,QAAQ,IAAI;AAC3B,MAAI,aAEF,SAAQ,IACN,6BAA6B,KAAK,UAAU,aAAa,CAAC,gKAC3D;UAEI,KAAK;AACZ,UAAQ,MAAM,6BAA6B,IAAI;;CAGnD,IAAI;AACJ,KAAI,OAAO,MAAM,kBAAkB,UACjC,KAAI;AACF,sBAAoB,QAAQ,QAAQ,IAAI,yBAAyB;AACjE,MAAI,kBAEF,SAAQ,IACN,kCAAkC,KAAK,UAAU,kBAAkB,CAAC,oKACrE;UAEI,KAAK;AACZ,UAAQ,MAAM,kCAAkC,IAAI;;AAGxD,QACE,oBAACA,iBAAD;EACE,qBAAqB;EACrB,GAAI;EACJ,UAAU,MAAM,YAAY;EAC5B,eAAe,MAAM,iBAAiB;EACtC,CAAA"}
|
|
@@ -2,6 +2,6 @@ import { ClientPerspective } from "@sanity/client";
|
|
|
2
2
|
/**
|
|
3
3
|
* @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
4
4
|
*/
|
|
5
|
-
declare function
|
|
6
|
-
export {
|
|
5
|
+
declare function perspectiveChangeAction(perspective: ClientPerspective): Promise<void>;
|
|
6
|
+
export { perspectiveChangeAction };
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -6,13 +6,13 @@ import { refresh } from "next/cache";
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
8
8
|
*/
|
|
9
|
-
async function
|
|
9
|
+
async function perspectiveChangeAction(perspective) {
|
|
10
10
|
const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
|
|
11
11
|
if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
|
|
12
12
|
const nextPerspective = Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective;
|
|
13
13
|
const jar = await cookies();
|
|
14
14
|
if (nextPerspective === jar.get(perspectiveCookieName)?.value && process.env.NODE_ENV !== "production") {
|
|
15
|
-
console.debug("
|
|
15
|
+
console.debug("perspectiveChangeAction", "Perspective is the same, skipping", nextPerspective);
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
jar.set(perspectiveCookieName, nextPerspective, {
|
|
@@ -23,6 +23,6 @@ async function actionPerspectiveChange(perspective) {
|
|
|
23
23
|
});
|
|
24
24
|
refresh();
|
|
25
25
|
}
|
|
26
|
-
export {
|
|
26
|
+
export { perspectiveChangeAction };
|
|
27
27
|
|
|
28
28
|
//# 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 {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
|
|
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 {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 jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n refresh()\n}\n"],"mappings":";;;;;;;;AAYA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KACE,CAAC,wBACA,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAExE,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;CAG9D,MAAM,kBAAkB,MAAM,QAAQ,qBAAqB,GACvD,qBAAqB,KAAK,IAAI,GAC9B;CACJ,MAAM,MAAM,MAAM,SAAS;AAC3B,KACE,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,SACpD,QAAQ,IAAI,aAAa,cACzB;AAEA,UAAQ,MAAM,2BAA2B,qCAAqC,gBAAgB;AAC9F;;AAEF,KAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CAAC;AAEF,UAAS"}
|