next-sanity 13.0.0-cache-components.33 → 13.0.0-cache-components.35
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 +10 -2
- package/dist/live/conditions/default/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.js.map +1 -1
- package/dist/live/conditions/next-js/index.d.ts +10 -2
- package/dist/live/conditions/next-js/index.d.ts.map +1 -1
- package/dist/live/conditions/next-js/index.js +14 -4
- package/dist/live/conditions/next-js/index.js.map +1 -1
- package/dist/live/conditions/react-server/index.d.ts +10 -2
- package/dist/live/conditions/react-server/index.d.ts.map +1 -1
- package/dist/live/conditions/react-server/index.js +15 -6
- package/dist/live/conditions/react-server/index.js.map +1 -1
- package/dist/resolvePerspectiveFromCookies.js +9 -1
- package/dist/resolvePerspectiveFromCookies.js.map +1 -1
- package/dist/types.d.ts +30 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -5
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import { i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
2
|
+
import { d as StrictDefinedFetchType, f as StrictDefinedLiveProps, i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
3
3
|
import { n as ResolvePerspectiveFromCookies, t as parseTags } from "../../../parseTags.js";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
declare function defineLive(
|
|
7
|
+
declare function defineLive(config: DefineLiveOptions & {
|
|
8
|
+
strict: true;
|
|
9
|
+
}): {
|
|
10
|
+
sanityFetch: StrictDefinedFetchType;
|
|
11
|
+
SanityLive: React.ComponentType<StrictDefinedLiveProps>;
|
|
12
|
+
};
|
|
13
|
+
declare function defineLive(config: DefineLiveOptions & {
|
|
14
|
+
strict?: false;
|
|
15
|
+
}): {
|
|
8
16
|
sanityFetch: DefinedFetchType;
|
|
9
17
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
10
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;AAqBA;;;AAAA,iBAAgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,sBAAA;AAAA;AAAA,iBAElB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA;;;;;cAUrB,6BAAA,EAA+B,6BAAA"}
|
|
@@ -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} from '#live/resolvePerspectiveFromCookies'\nimport type {DefinedFetchType
|
|
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} 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 * @public\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): never {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\n/**\n * Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from \"next-sanity/draft-mode\"`\n * @public\n */\nexport const resolvePerspectiveFromCookies: ResolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n\nexport type {PerspectiveType as LivePerspective} from '#live/types'\n"],"mappings":";;AA6BA,SAAgB,WAAW,SAAmC;AAC5D,OAAM,IAAI,MAAM,qDAAqD;;AAOvE,MAAa,sCAAqE;AAChF,OAAM,IAAI,MAAM,wEAAwE"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import { i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
2
|
+
import { d as StrictDefinedFetchType, f as StrictDefinedLiveProps, i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
3
3
|
import { r as resolvePerspectiveFromCookies, t as parseTags } from "../../../parseTags.js";
|
|
4
|
-
declare function defineLive(config: DefineLiveOptions
|
|
4
|
+
declare function defineLive(config: DefineLiveOptions & {
|
|
5
|
+
strict: true;
|
|
6
|
+
}): {
|
|
7
|
+
sanityFetch: StrictDefinedFetchType;
|
|
8
|
+
SanityLive: React.ComponentType<StrictDefinedLiveProps>;
|
|
9
|
+
};
|
|
10
|
+
declare function defineLive(config: DefineLiveOptions & {
|
|
11
|
+
strict?: false;
|
|
12
|
+
}): {
|
|
5
13
|
sanityFetch: DefinedFetchType;
|
|
6
14
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
7
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"mappings":";;;iBAgBgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,sBAAA;AAAA;AAAA,iBAElB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
2
|
import { n as revalidate, t as cacheTagPrefixes } from "../../../constants.js";
|
|
3
3
|
import { t as parseTags } from "../../../parseTags.js";
|
|
4
|
-
import { t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
|
+
import { n as validateStrictFetchOptions, r as validateStrictSanityLiveProps, t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
7
7
|
import { actionRefresh, actionUpdateTags } from "next-sanity/live/server-actions";
|
|
8
8
|
import { cacheLife, cacheTag } from "next/cache";
|
|
9
|
+
import { PHASE_PRODUCTION_BUILD } from "next/constants";
|
|
9
10
|
import { preconnect } from "react-dom";
|
|
10
11
|
function defineLive(config) {
|
|
11
|
-
const { client: _client, serverToken, browserToken } = config;
|
|
12
|
+
const { client: _client, serverToken, browserToken, strict = false } = config;
|
|
12
13
|
if (!_client) throw new Error("`client` is required for `defineLive` to function");
|
|
13
14
|
if (process.env.NODE_ENV !== "production" && !serverToken && serverToken !== false) console.warn("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`.");
|
|
14
15
|
if (process.env.NODE_ENV !== "production" && !browserToken && browserToken !== false) console.warn("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`.");
|
|
@@ -17,8 +18,16 @@ function defineLive(config) {
|
|
|
17
18
|
useCdn: true
|
|
18
19
|
});
|
|
19
20
|
const { token: originalToken, perspective: originalPerspective = "published" } = client.config();
|
|
20
|
-
const sanityFetch = async function sanityFetch({ query, params = {}, perspective
|
|
21
|
+
const sanityFetch = async function sanityFetch({ query, params = {}, perspective: _perspective, stega: _stega, tags: customCacheTags = [], requestTag = "next-loader.fetch.cache-components" }) {
|
|
22
|
+
if (strict) validateStrictFetchOptions({
|
|
23
|
+
perspective: _perspective,
|
|
24
|
+
stega: _stega
|
|
25
|
+
});
|
|
26
|
+
const perspective = _perspective ?? originalPerspective;
|
|
27
|
+
const stega = _stega ?? false;
|
|
21
28
|
const useCdn = perspective === "published";
|
|
29
|
+
const isBuildPhase = process.env["NEXT_PHASE"] === PHASE_PRODUCTION_BUILD;
|
|
30
|
+
const cacheMode = useCdn && !isBuildPhase ? "noStale" : void 0;
|
|
22
31
|
const cacheTagPrefix = perspective === "published" ? cacheTagPrefixes.published : cacheTagPrefixes.drafts;
|
|
23
32
|
const { result, resultSourceMap, syncTags } = await client.fetch(query, await params, {
|
|
24
33
|
filterResponse: false,
|
|
@@ -26,7 +35,7 @@ function defineLive(config) {
|
|
|
26
35
|
perspective,
|
|
27
36
|
useCdn,
|
|
28
37
|
stega,
|
|
29
|
-
cacheMode
|
|
38
|
+
cacheMode,
|
|
30
39
|
tag: requestTag,
|
|
31
40
|
token: perspective === "published" ? originalToken : serverToken || originalToken
|
|
32
41
|
});
|
|
@@ -40,6 +49,7 @@ function defineLive(config) {
|
|
|
40
49
|
};
|
|
41
50
|
};
|
|
42
51
|
const SanityLive$2 = function SanityLive$1(props) {
|
|
52
|
+
if (strict) validateStrictSanityLiveProps(props);
|
|
43
53
|
const { includeDrafts = false, action = actionUpdateTags, onReconnect = actionRefresh, onRestart = actionRefresh, onWelcome, onError, onGoAway, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components" } = props;
|
|
44
54
|
const shouldIncludeDrafts = typeof browserToken === "string" && includeDrafts;
|
|
45
55
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
@@ -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 {actionRefresh, actionUpdateTags} from 'next-sanity/live/server-actions'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {preconnect} from 'react-dom'\n\nimport {cacheTagPrefixes, revalidate} from '#live/constants'\nimport type {DefinedFetchType
|
|
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 {actionRefresh, actionUpdateTags} 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 = actionUpdateTags,\n onReconnect = actionRefresh,\n onRestart = actionRefresh,\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 {\n sanityFetch: sanityFetch,\n SanityLive: SanityLive,\n }\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,kBACT,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,YAAAA;GACC,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;IACpB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACQ;EACb,YAAYD;EACb"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import { i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
2
|
+
import { d as StrictDefinedFetchType, f as StrictDefinedLiveProps, i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
3
3
|
import { r as resolvePerspectiveFromCookies, t as parseTags } from "../../../parseTags.js";
|
|
4
|
-
declare function defineLive(config: DefineLiveOptions
|
|
4
|
+
declare function defineLive(config: DefineLiveOptions & {
|
|
5
|
+
strict: true;
|
|
6
|
+
}): {
|
|
7
|
+
sanityFetch: StrictDefinedFetchType;
|
|
8
|
+
SanityLive: React.ComponentType<StrictDefinedLiveProps>;
|
|
9
|
+
};
|
|
10
|
+
declare function defineLive(config: DefineLiveOptions & {
|
|
11
|
+
strict?: false;
|
|
12
|
+
}): {
|
|
5
13
|
sanityFetch: DefinedFetchType;
|
|
6
14
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
7
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"mappings":";;;iBAmBgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,sBAAA;AAAA;AAAA,iBAElB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
2
|
import { t as cacheTagPrefixes } from "../../../constants.js";
|
|
3
3
|
import { t as parseTags } from "../../../parseTags.js";
|
|
4
|
+
import { n as validateStrictFetchOptions, r as validateStrictSanityLiveProps, t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
5
|
import { t as sanitizePerspective } from "../../../sanitizePerspective.js";
|
|
5
|
-
import { t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
6
6
|
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
7
7
|
import { cookies, draftMode } from "next/headers";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import "@sanity/client";
|
|
9
10
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
10
11
|
import { actionRefresh, actionUpdateTags } from "next-sanity/live/server-actions";
|
|
12
|
+
import { PHASE_PRODUCTION_BUILD } from "next/constants";
|
|
11
13
|
import { preconnect } from "react-dom";
|
|
12
14
|
function defineLive(config) {
|
|
13
|
-
const { client: _client, serverToken, browserToken, stega: stegaEnabled = true } = config;
|
|
15
|
+
const { client: _client, serverToken, browserToken, stega: stegaEnabled = true, strict = false } = config;
|
|
14
16
|
if (!_client) throw new Error("`client` is required for `defineLive` to function");
|
|
15
17
|
if (process.env.NODE_ENV !== "production" && !serverToken && serverToken !== false) console.warn("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`.");
|
|
16
18
|
if (process.env.NODE_ENV !== "production" && !browserToken && browserToken !== false) console.warn("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`.");
|
|
@@ -21,9 +23,15 @@ function defineLive(config) {
|
|
|
21
23
|
const { token: originalToken, perspective: originalPerspective = "published" } = client.config();
|
|
22
24
|
const studioUrlDefined = typeof client.config().stega.studioUrl !== "undefined";
|
|
23
25
|
const sanityFetch = async function sanityFetch({ query, params = {}, stega: _stega, tags = [], perspective: _perspective, tag, requestTag = tag ?? "next-loader.fetch" }) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
if (strict) validateStrictFetchOptions({
|
|
27
|
+
perspective: _perspective,
|
|
28
|
+
stega: _stega
|
|
29
|
+
});
|
|
30
|
+
const stega = strict ? _stega : _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled);
|
|
31
|
+
const perspective = strict ? _perspective : _perspective ?? await resolveCookiePerspective(originalPerspective === "raw" ? "published" : originalPerspective);
|
|
26
32
|
const useCdn = perspective === "published";
|
|
33
|
+
const isBuildPhase = process.env["NEXT_PHASE"] === PHASE_PRODUCTION_BUILD;
|
|
34
|
+
const cacheMode = useCdn && !isBuildPhase ? "noStale" : void 0;
|
|
27
35
|
const revalidate = false;
|
|
28
36
|
const cacheTagPrefix = perspective === "published" ? cacheTagPrefixes.published : cacheTagPrefixes.drafts;
|
|
29
37
|
const { syncTags } = await client.fetch(query, await params, {
|
|
@@ -36,7 +44,7 @@ function defineLive(config) {
|
|
|
36
44
|
tags: [...tags, "fetch-sync-tags"].map((tag) => `${cacheTagPrefix}${tag}`)
|
|
37
45
|
},
|
|
38
46
|
useCdn,
|
|
39
|
-
cacheMode
|
|
47
|
+
cacheMode,
|
|
40
48
|
tag: [requestTag, "fetch-sync-tags"].filter(Boolean).join(".")
|
|
41
49
|
});
|
|
42
50
|
const cacheTags = [...tags, ...syncTags?.map((tag) => `${cacheTagPrefix}${tag}`) || []];
|
|
@@ -50,7 +58,7 @@ function defineLive(config) {
|
|
|
50
58
|
tags: cacheTags
|
|
51
59
|
},
|
|
52
60
|
useCdn,
|
|
53
|
-
cacheMode
|
|
61
|
+
cacheMode,
|
|
54
62
|
tag: requestTag
|
|
55
63
|
});
|
|
56
64
|
return {
|
|
@@ -60,6 +68,7 @@ function defineLive(config) {
|
|
|
60
68
|
};
|
|
61
69
|
};
|
|
62
70
|
const SanityLive$2 = async function SanityLive$1(props) {
|
|
71
|
+
if (strict) validateStrictSanityLiveProps(props);
|
|
63
72
|
const { includeDrafts = (await draftMode()).isEnabled, action = actionUpdateTags, onReconnect = actionRefresh, onRestart = actionRefresh, onWelcome = false, onError = false, onGoAway = false, refreshOnMount, refreshOnFocus, refreshOnReconnect, requestTag = "next-loader.live" } = props;
|
|
64
73
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
65
74
|
const shouldIncludeDrafts = typeof browserToken === "string" && includeDrafts;
|
|
@@ -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 {actionRefresh, actionUpdateTags} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\nimport {cacheTagPrefixes} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport type {DefinedFetchType
|
|
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 {actionRefresh, actionUpdateTags} 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 revalidate = false\n const cacheTagPrefix =\n perspective === 'published' ? cacheTagPrefixes.published : cacheTagPrefixes.drafts\n\n // fetch the tags first, with revalidate to 1s to ensure we get the latest tags, eventually\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n next: {\n revalidate,\n tags: [...tags, 'fetch-sync-tags'].map((tag) => `${cacheTagPrefix}${tag}`),\n },\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 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, 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 = actionUpdateTags,\n onReconnect = actionRefresh,\n onRestart = actionRefresh,\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 {\n sanityFetch,\n SanityLive,\n }\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,gBA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C;AAClD,aAAW,OAAO;AAElB,SACE,oBAACC,YAAAA;GACC,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;IACpB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACL;EACA,YAAA;EACD;;AAGH,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,8 +1,16 @@
|
|
|
1
1
|
import { t as sanitizePerspective } from "./sanitizePerspective.js";
|
|
2
2
|
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
3
|
+
import { generateHelpUrl } from "@sanity/generate-help-url";
|
|
4
|
+
function validateStrictSanityLiveProps(props) {
|
|
5
|
+
if (typeof props.includeDrafts !== "boolean") throw new Error(`<SanityLive> requires an explicit \`includeDrafts\` prop (true or false) when \`strict: true\` is set on \`defineLive\`.\n\nMore information: ${generateHelpUrl("next-sanity-live-strict")}`, { cause: props });
|
|
6
|
+
}
|
|
7
|
+
function validateStrictFetchOptions(options) {
|
|
8
|
+
if (typeof options.perspective === "undefined" || options.perspective === null) throw new Error(`sanityFetch() requires an explicit \`perspective\` option when \`strict: true\` is set on \`defineLive\`.\n\nMore information: ${generateHelpUrl("next-sanity-fetch-strict")}`, { cause: options });
|
|
9
|
+
if (typeof options.stega !== "boolean") throw new Error(`sanityFetch() requires an explicit \`stega\` option (true or false) when \`strict: true\` is set on \`defineLive\`.\n\nMore information: ${generateHelpUrl("next-sanity-fetch-strict")}`, { cause: options });
|
|
10
|
+
}
|
|
3
11
|
const resolvePerspectiveFromCookies = async function resolvePerspectiveFromCookies({ cookies: jar }) {
|
|
4
12
|
return jar.has(perspectiveCookieName) ? sanitizePerspective(jar.get(perspectiveCookieName)?.value, "drafts") : "drafts";
|
|
5
13
|
};
|
|
6
|
-
export { resolvePerspectiveFromCookies as t };
|
|
14
|
+
export { validateStrictFetchOptions as n, validateStrictSanityLiveProps as r, resolvePerspectiveFromCookies as t };
|
|
7
15
|
|
|
8
16
|
//# sourceMappingURL=resolvePerspectiveFromCookies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePerspectiveFromCookies.js","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport type {cookies} from 'next/headers'\n\nimport {sanitizePerspective} from './sanitizePerspective'\n\nexport type ResolvePerspectiveFromCookies = (options: {\n /**\n * You must await the cookies() function from next/headers\n * and pass it here.\n * Example:\n * ```ts\n * import { cookies } from 'next/headers'\n *\n * const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n * ```\n */\n cookies: Awaited<ReturnType<typeof cookies>>\n}) => Promise<Exclude<ClientPerspective, 'raw'>>\n\n/**\n * Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from \"next-sanity/draft-mode\"`\n * @public\n */\nexport const resolvePerspectiveFromCookies = 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":";;
|
|
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 './sanitizePerspective'\n\nexport type ResolvePerspectiveFromCookies = (options: {\n /**\n * You must await the cookies() function from next/headers\n * and pass it here.\n * Example:\n * ```ts\n * import { cookies } from 'next/headers'\n *\n * const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n * ```\n */\n cookies: Awaited<ReturnType<typeof cookies>>\n}) => Promise<Exclude<ClientPerspective, 'raw'>>\n\n/**\n * Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from \"next-sanity/draft-mode\"`\n * @public\n */\nexport const resolvePerspectiveFromCookies = 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;;ACDL,MAAa,gCAAgC,eAAe,8BAA8B,EACxF,SAAS,OAGoC;AAC7C,QAAO,IAAI,IAAI,sBAAsB,GACjC,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,OAAO,SAAS,GACpE"}
|
package/dist/types.d.ts
CHANGED
|
@@ -152,6 +152,35 @@ interface DefineLiveOptions {
|
|
|
152
152
|
* @defaultValue `true`
|
|
153
153
|
*/
|
|
154
154
|
stega?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* When `true`, requires explicit `includeDrafts` on `<SanityLive>` and explicit `perspective`/`stega` on `sanityFetch`.
|
|
157
|
+
* Use this to prepare for migrating to `cacheComponents: true` while still using `cacheComponents: false`.
|
|
158
|
+
* @defaultValue `false`
|
|
159
|
+
*/
|
|
160
|
+
strict?: boolean;
|
|
155
161
|
}
|
|
156
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Like {@link DefinedLiveProps} but with `includeDrafts` required.
|
|
164
|
+
* Returned by `defineLive({strict: true})`.
|
|
165
|
+
*/
|
|
166
|
+
interface StrictDefinedLiveProps extends Omit<DefinedLiveProps, "includeDrafts"> {
|
|
167
|
+
includeDrafts: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Like {@link DefinedFetchType} but with `perspective` and `stega` required.
|
|
171
|
+
* Returned by `defineLive({strict: true})`.
|
|
172
|
+
*/
|
|
173
|
+
type StrictDefinedFetchType = <const QueryString extends string>(options: {
|
|
174
|
+
query: QueryString;
|
|
175
|
+
params?: QueryParams | Promise<QueryParams>;
|
|
176
|
+
perspective: PerspectiveType;
|
|
177
|
+
stega: boolean;
|
|
178
|
+
tags?: string[];
|
|
179
|
+
requestTag?: string;
|
|
180
|
+
}) => Promise<{
|
|
181
|
+
data: ClientReturn<QueryString, unknown>;
|
|
182
|
+
sourceMap: ContentSourceMap | null;
|
|
183
|
+
tags: string[];
|
|
184
|
+
}>;
|
|
185
|
+
export { SanityLiveAction as a, SanityLiveOnReconnect as c, StrictDefinedFetchType as d, StrictDefinedLiveProps as f, PerspectiveType as i, SanityLiveOnRestart as l, DefinedFetchType as n, SanityLiveOnError as o, DefinedLiveProps as r, SanityLiveOnGoaway as s, DefineLiveOptions as t, SanityLiveOnWelcome as u };
|
|
157
186
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/live/shared/types.ts"],"mappings":";;AAcA;;;KAAY,eAAA,GAAkB,OAAA,CAAQ,iBAAA;;AAKtC;;KAAY,gBAAA,sCAAsD,OAAA;EAChE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;;;;EAI/B,WAAA,GAAc,eAAA;;;;;EAKd,KAAA;;;;;EAKA,IAAA;;;;;;EAMA,UAAA;AAAA,MACI,OAAA;EACJ,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,IAAA;AAAA;;;;UAMe,uBAAA;EACf,aAAA;AAAA;AADF;;;;AAAA,KAQY,gBAAA,IAAoB,UAAA,cAAwB,OAAA;AAAxD;;;;;AAAA,KAMY,iBAAA,IACV,KAAA,WACA,OAAA,EAAS,uBAAA,YACC,OAAA;;;;;KAKA,mBAAA,IACV,KAAA,EAAO,OAAA,CAAQ,SAAA;EAAY,IAAA;AAAA,IAC3B,OAAA,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AAA,GAAc,OAAA,CAAQ,WAAA;EAC/B,WAAA,EAAa,eAAA;EACb,KAAA;EACA,IAAA;EACA,UAAA;AAAA,MACI,OAAA;EACJ,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,IAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "13.0.0-cache-components.
|
|
3
|
+
"version": "13.0.0-cache-components.35",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"live",
|
|
@@ -64,12 +64,13 @@
|
|
|
64
64
|
"@portabletext/react": "^6.0.3",
|
|
65
65
|
"@sanity/client": "^7.20.0",
|
|
66
66
|
"@sanity/comlink": "^4.0.1",
|
|
67
|
+
"@sanity/generate-help-url": "^4.0.0",
|
|
67
68
|
"@sanity/presentation-comlink": "^2.0.1",
|
|
68
69
|
"@sanity/preview-url-secret": "^4.0.4",
|
|
69
70
|
"@sanity/visual-editing": "^5.3.3",
|
|
70
71
|
"@sanity/webhook": "^4.0.4",
|
|
71
72
|
"dequal": "^2.0.3",
|
|
72
|
-
"groq": "^5.
|
|
73
|
+
"groq": "^5.18.0",
|
|
73
74
|
"history": "^5.3.0"
|
|
74
75
|
},
|
|
75
76
|
"devDependencies": {
|
|
@@ -81,11 +82,11 @@
|
|
|
81
82
|
"@vitejs/plugin-react": "^5.2.0",
|
|
82
83
|
"@vitest/coverage-v8": "^4.1.0",
|
|
83
84
|
"js-yaml": "^4.1.1",
|
|
84
|
-
"next": "16.2.1-canary.
|
|
85
|
+
"next": "16.2.1-canary.10",
|
|
85
86
|
"publint": "^0.3.18",
|
|
86
87
|
"react": "^19.2.4",
|
|
87
88
|
"react-dom": "^19.2.4",
|
|
88
|
-
"styled-components": "
|
|
89
|
+
"styled-components": "^6.3.12",
|
|
89
90
|
"tsdown": "0.20.3",
|
|
90
91
|
"typedoc": "^0.28.17",
|
|
91
92
|
"typescript": "5.9.3",
|
|
@@ -97,7 +98,7 @@
|
|
|
97
98
|
"next": "^16.0.0-0",
|
|
98
99
|
"react": "^19.2.3",
|
|
99
100
|
"react-dom": "^19.2.3",
|
|
100
|
-
"sanity": "^5.
|
|
101
|
+
"sanity": "^5.18.0",
|
|
101
102
|
"styled-components": "^6.1"
|
|
102
103
|
},
|
|
103
104
|
"engines": {
|