next-sanity 13.0.0-cache-components.20 → 13.0.0-cache-components.22
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/README.md +3 -1
- package/dist/NextStudio.js +1 -1
- package/dist/SanityLive.js +3 -4
- package/dist/SanityLive.js.map +1 -1
- package/dist/VisualEditing.js +1 -1
- package/dist/defineLive.d.ts +4 -44
- package/dist/defineLive.d.ts.map +1 -1
- package/dist/draft-mode/index.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +3 -33
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +5 -108
- package/dist/hooks/index.js.map +1 -1
- package/dist/image/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/isCorsOriginError.d.ts.map +1 -1
- package/dist/live/cache-life.d.ts.map +1 -0
- package/dist/live/cache-life.js.map +1 -0
- package/dist/live/client-components/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.d.ts +3 -3
- 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 +3 -3
- package/dist/live/conditions/next-js/index.d.ts.map +1 -1
- package/dist/live/conditions/next-js/index.js +3 -3
- package/dist/live/conditions/next-js/index.js.map +1 -1
- package/dist/live/conditions/react-server/index.d.ts +1 -1
- package/dist/live/conditions/react-server/index.js +7 -7
- package/dist/live/conditions/react-server/index.js.map +1 -1
- package/dist/live/server-actions/index.default.d.ts.map +1 -1
- package/dist/live/server-actions/index.next-js.d.ts.map +1 -1
- package/dist/resolvePerspectiveFromCookies.js +1 -1
- package/dist/resolvePerspectiveFromCookies.js.map +1 -1
- package/dist/studio/client-component/index.d.ts.map +1 -1
- package/dist/studio/client-component/index.js +1 -1
- package/dist/studio/index.d.ts.map +1 -1
- package/dist/types.d.ts +8 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/visual-editing/client-component/index.d.ts.map +1 -1
- package/dist/visual-editing/index.d.ts.map +1 -1
- package/dist/visual-editing/server-actions/index.d.ts.map +1 -1
- package/dist/webhook/index.d.ts.map +1 -1
- package/dist/webhook/index.js +1 -48
- package/dist/webhook/index.js.map +1 -1
- package/package.json +20 -22
- package/dist/cache-life.d.ts.map +0 -1
- package/dist/cache-life.js.map +0 -1
- /package/dist/{cache-life.d.ts → live/cache-life.d.ts} +0 -0
- /package/dist/{cache-life.js → live/cache-life.js} +0 -0
package/README.md
CHANGED
|
@@ -641,10 +641,11 @@ The same token can be used as both `browserToken` and `serverToken`, as the `bro
|
|
|
641
641
|
```tsx
|
|
642
642
|
// src/app/layout.tsx
|
|
643
643
|
|
|
644
|
+
import {draftMode} from 'next/headers'
|
|
644
645
|
import {VisualEditing} from 'next-sanity/visual-editing'
|
|
645
646
|
import {SanityLive} from '@/sanity/lib/live'
|
|
646
647
|
|
|
647
|
-
export default function RootLayout({children}: {children: React.ReactNode}) {
|
|
648
|
+
export default async function RootLayout({children}: {children: React.ReactNode}) {
|
|
648
649
|
return (
|
|
649
650
|
<html lang="en">
|
|
650
651
|
<body>
|
|
@@ -832,6 +833,7 @@ import {
|
|
|
832
833
|
useIsPresentationTool,
|
|
833
834
|
useDraftModeEnvironment,
|
|
834
835
|
useDraftModePerspective,
|
|
836
|
+
useVisualEditingEnvironment,
|
|
835
837
|
} from 'next-sanity/hooks'
|
|
836
838
|
```
|
|
837
839
|
|
package/dist/NextStudio.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as NextStudioLayout, t as NextStudioNoScript } from "./NextStudioNoScript.js";
|
|
2
|
-
import { useMemo, useSyncExternalStore } from "react";
|
|
3
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useSyncExternalStore } from "react";
|
|
4
4
|
import { Studio } from "sanity";
|
|
5
5
|
import { createHashHistory } from "history";
|
|
6
6
|
function createHashHistoryForStudio() {
|
package/dist/SanityLive.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { startTransition, useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
3
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
3
|
import { createClient } from "@sanity/client";
|
|
5
4
|
import dynamic from "next/dynamic";
|
|
5
|
+
import { startTransition, useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
6
6
|
const RefreshOnFocus = dynamic(() => import("./RefreshOnFocus.js"));
|
|
7
7
|
const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"));
|
|
8
8
|
const RefreshOnInterval = dynamic(() => import("./RefreshOnInterval.js"));
|
|
@@ -71,7 +71,7 @@ function SanityLive(props) {
|
|
|
71
71
|
tag: requestTag
|
|
72
72
|
}).subscribe({
|
|
73
73
|
next: (event) => startTransition(() => handleLiveEvent(event)),
|
|
74
|
-
error: (error
|
|
74
|
+
error: (error) => startTransition(() => setError(error))
|
|
75
75
|
});
|
|
76
76
|
return () => subscription.unsubscribe();
|
|
77
77
|
}, [
|
|
@@ -87,7 +87,6 @@ function SanityLive(props) {
|
|
|
87
87
|
] });
|
|
88
88
|
}
|
|
89
89
|
SanityLive.displayName = "SanityLiveClientComponent";
|
|
90
|
-
|
|
91
|
-
export { SanityLive_default as default };
|
|
90
|
+
export { SanityLive as default };
|
|
92
91
|
|
|
93
92
|
//# sourceMappingURL=SanityLive.js.map
|
package/dist/SanityLive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SanityLive.js","names":[
|
|
1
|
+
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import type {SanityLiveActionContext} from '#live/types'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {createClient, type InitializedClientConfig, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {startTransition, useEffect, useEffectEvent, useMemo, useState} from 'react'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n includeAllDocuments?: boolean\n requestTag: string\n\n action: (\n event: Extract<LiveEvent, {type: 'message'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n reconnectAction?: (\n event: Extract<LiveEvent, {type: 'reconnect'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n restartAction?: (\n event: Extract<LiveEvent, {type: 'restart'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n welcomeAction?:\n | ((\n event: Extract<LiveEvent, {type: 'welcome'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>)\n | false\n goAwayAction?:\n | ((\n event: Extract<LiveEvent, {type: 'goaway'}>,\n context: SanityLiveActionContext,\n ) => Promise<number | false>)\n | false\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeAllDocuments = false,\n action,\n goAwayAction,\n reconnectAction,\n restartAction,\n welcomeAction,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n requestTag,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeAllDocuments} satisfies SanityLiveActionContext\n const [error, setError] = useState<unknown>(null)\n if (error) {\n if (isCorsOriginError(error)) {\n throw new Error(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n } else {\n throw error\n }\n }\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n const handleLiveEvent = useEffectEvent(async (event: LiveEvent) => {\n switch (event.type) {\n case 'welcome': {\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setRefreshOnInterval(false)\n\n if (welcomeAction) {\n await welcomeAction(event, actionContext)\n } else if (welcomeAction !== false && process.env.NODE_ENV !== 'production') {\n // oxlint-disable-next-line no-console\n console.info(\n `<SanityLive> is connected and listening for live events to ${includeAllDocuments ? 'all content including drafts and version documents in content releases' : 'published content'}`,\n )\n }\n break\n }\n case 'message': {\n await action(event, actionContext)\n break\n }\n case 'restart': {\n await restartAction?.(event, actionContext)\n break\n }\n case 'reconnect': {\n await reconnectAction?.(event, actionContext)\n break\n }\n case 'goaway': {\n if (goAwayAction !== false) {\n let interval = goAwayAction ? await goAwayAction(event, actionContext) : 30_000\n if (interval === false) return\n if (Number.isFinite(interval) && interval > 0) {\n startTransition(() => setRefreshOnInterval(interval))\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n interval / 1_000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n }\n }\n } else {\n setError(\n new Error(\n `Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`,\n {cause: event},\n ),\n )\n }\n break\n }\n default:\n setError(new Error(`Unknown live event type`, {cause: event}))\n break\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts: includeAllDocuments, tag: requestTag})\n .subscribe({\n next: (event) => startTransition(() => handleLiveEvent(event)),\n error: (error) => startTransition(() => setError(error)),\n })\n return () => subscription.unsubscribe()\n }, [client.live, requestTag, includeAllDocuments])\n\n return (\n <>\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnInterval && <RefreshOnInterval interval={refreshOnInterval} />}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n"],"mappings":";;;;;AAOA,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,oBAAoB,cAAc,OAAO,0BAAuB;AACtE,MAAM,qBAAqB,cAAc,OAAO,2BAAwB;AAgDxE,SAAS,WAAW,OAAkD;CACpE,MAAM,EACJ,QACA,sBAAsB,OACtB,QACA,cACA,iBACA,eACA,eACA,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,MACrB,eACE;CACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,OAAO,qBACzE;CACF,MAAM,gBAAgB,EAAC,qBAAoB;CAC3C,MAAM,CAAC,OAAO,YAAY,SAAkB,KAAK;AACjD,KAAI,MACF,KAAI,kBAAkB,MAAM,CAC1B,OAAM,IAAI,MACR,8EAA8E,OAAO,OAAO,wEAAwE,MAAM,eAAe,iBAAiB,MAAM,iBAAiB,MACjO,EAAC,OAAO,OAAM,CACf;KAED,OAAM;CAIV,MAAM,SAAS,cAEX,aAAa;EACX;EACA;EACA;EACA;EACA;EACA,2BAA2B;EAC3B;EACA,QAAQ;EACR;EACD,CAAC,EACJ;EAAC;EAAS;EAAY;EAAS;EAAW;EAAkB;EAAO;EAAmB,CACvF;CAED,MAAM,CAAC,mBAAmB,wBAAwB,SAAyB,MAAM;CAEjF,MAAM,kBAAkB,eAAe,OAAO,UAAqB;AACjE,UAAQ,MAAM,MAAd;GACE,KAAK;AAEH,yBAAqB,MAAM;AAE3B,QAAI,cACF,OAAM,cAAc,OAAO,cAAc;aAChC,kBAAkB,SAAS,QAAQ,IAAI,aAAa,aAE7D,SAAQ,KACN,8DAA8D,sBAAsB,2EAA2E,sBAChK;AAEH;GAEF,KAAK;AACH,UAAM,OAAO,OAAO,cAAc;AAClC;GAEF,KAAK;AACH,UAAM,gBAAgB,OAAO,cAAc;AAC3C;GAEF,KAAK;AACH,UAAM,kBAAkB,OAAO,cAAc;AAC7C;GAEF,KAAK;AACH,QAAI,iBAAiB,OAAO;KAC1B,IAAI,WAAW,eAAe,MAAM,aAAa,OAAO,cAAc,GAAG;AACzE,SAAI,aAAa,MAAO;AACxB,SAAI,OAAO,SAAS,SAAS,IAAI,WAAW,GAAG;AAC7C,4BAAsB,qBAAqB,SAAS,CAAC;AACrD,UAAI,QAAQ,IAAI,aAAa,aAC3B,SAAQ,KACN,iFACA,WAAW,KACX,4CACA,MAAM,OACP;;UAIL,UACE,IAAI,MACF,mGAAmG,MAAM,UACzG,EAAC,OAAO,OAAM,CACf,CACF;AAEH;GAEF;AACE,aAAS,IAAI,MAAM,2BAA2B,EAAC,OAAO,OAAM,CAAC,CAAC;AAC9D;;GAEJ;AACF,iBAAgB;EACd,MAAM,eAAe,OAAO,KACzB,OAAO;GAAC,eAAe;GAAqB,KAAK;GAAW,CAAC,CAC7D,UAAU;GACT,OAAO,UAAU,sBAAsB,gBAAgB,MAAM,CAAC;GAC9D,QAAQ,UAAU,sBAAsB,SAAS,MAAM,CAAC;GACzD,CAAC;AACJ,eAAa,aAAa,aAAa;IACtC;EAAC,OAAO;EAAM;EAAY;EAAoB,CAAC;AAElD,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,qBAAqB,oBAAC,mBAAA,EAAkB,UAAU,mBAAA,CAAqB;EACvE,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc"}
|
package/dist/VisualEditing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
2
|
import { VisualEditing as VisualEditing$1 } from "@sanity/visual-editing/react";
|
|
4
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { actionRefresh } from "next-sanity/visual-editing/server-actions";
|
|
6
6
|
function pathHasPrefix(path, prefix) {
|
|
7
7
|
if (typeof path !== "string") return false;
|
package/dist/defineLive.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as DefinedLiveProps, t as DefineLiveOptions } from "./types.js";
|
|
2
2
|
import { cookies } from "next/headers";
|
|
3
|
-
import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams
|
|
3
|
+
import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams } from "@sanity/client";
|
|
4
4
|
type ResolvePerspectiveFromCookies = (options: {
|
|
5
5
|
/**
|
|
6
6
|
* You must await the cookies() function from next/headers
|
|
@@ -49,49 +49,9 @@ type DefinedSanityFetchType = <const QueryString extends string>(options: {
|
|
|
49
49
|
sourceMap: ContentSourceMap | null;
|
|
50
50
|
tags: string[];
|
|
51
51
|
}>;
|
|
52
|
-
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
interface DefineSanityLiveOptions {
|
|
56
|
-
/**
|
|
57
|
-
* Required for `sanityFetch` and `SanityLive` to work
|
|
58
|
-
*/
|
|
59
|
-
client: SanityClient;
|
|
60
|
-
/**
|
|
61
|
-
* Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.
|
|
62
|
-
* This token is not shared with the browser.
|
|
63
|
-
*/
|
|
64
|
-
serverToken?: string | false;
|
|
65
|
-
/**
|
|
66
|
-
* Optional. This token is shared with the browser, and should only have access to query published documents.
|
|
67
|
-
* It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.
|
|
68
|
-
*/
|
|
69
|
-
browserToken?: string | false;
|
|
70
|
-
/**
|
|
71
|
-
* Fetch options used by `sanityFetch`
|
|
72
|
-
*/
|
|
73
|
-
fetchOptions?: {
|
|
74
|
-
/**
|
|
75
|
-
* Optional, enables time based revalidation in addition to the EventSource connection.
|
|
76
|
-
* @defaultValue `false`
|
|
77
|
-
*/
|
|
78
|
-
revalidate?: number | false;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Optional. Include stega encoding when draft mode is enabled.
|
|
82
|
-
* @defaultValue `true`
|
|
83
|
-
*/
|
|
84
|
-
stega?: boolean;
|
|
85
|
-
}
|
|
86
|
-
declare function defineLive(config: DefineSanityLiveOptions): {
|
|
87
|
-
/**
|
|
88
|
-
* @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`
|
|
89
|
-
*/
|
|
52
|
+
declare function defineLive(config: DefineLiveOptions): {
|
|
90
53
|
sanityFetch: DefinedSanityFetchType;
|
|
91
|
-
/**
|
|
92
|
-
* @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`
|
|
93
|
-
*/
|
|
94
54
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
95
55
|
};
|
|
96
|
-
export { resolvePerspectiveFromCookies as
|
|
56
|
+
export { resolvePerspectiveFromCookies as i, defineLive as n, ResolvePerspectiveFromCookies as r, DefinedSanityFetchType as t };
|
|
97
57
|
//# sourceMappingURL=defineLive.d.ts.map
|
package/dist/defineLive.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/conditions/react-server/defineLive.tsx"],"
|
|
1
|
+
{"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/conditions/react-server/defineLive.tsx"],"mappings":";;;KAOY,6BAAA,IAAiC,OAAA;;AAA7C;;;;;;;;;EAWE,OAAA,EAAS,OAAA,CAAQ,UAAA,QAAkB,OAAA;AAAA,MAC/B,OAAA,CAAQ,OAAA,CAAQ,iBAAA;;;;;cAMT,6BAAA;EACX,OAAA,EAAS;AAAA;EAET,OAAA,EAAS,OAAA,CAAQ,UAAA,QAAkB,OAAA;AAAA,MACjC,OAAA,CAAQ,OAAA,CAAQ,iBAAA;;;AAtBpB;KCWY,sBAAA,sCAA4D,OAAA;EACtE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;;;;;;;EAO/B,IAAA;EACA,WAAA,GAAc,OAAA,CAAQ,iBAAA;EACtB,KAAA;;;;;;EAMA,UAAA;AAAA,MACI,OAAA;EACJ,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,IAAA;AAAA;AAAA,iBAGc,UAAA,CAAW,MAAA,EAAQ,iBAAA;EACjC,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/draft-mode/define-enable-draft-mode.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/draft-mode/define-enable-draft-mode.ts"],"mappings":";;AAUA;;UAAiB,4BAAA;EACf,MAAA,EAAQ,YAAA;;;;;;AAaV;EANE,aAAA;AAAA;;;;UAMe,eAAA;EACf,GAAA,GAAM,OAAA,EAAS,OAAA,KAAY,OAAA,CAAQ,QAAA;AAAA;;;;;;;AAoBrC;;;;;;;;;;;iBAAgB,qBAAA,CAAsB,OAAA,EAAS,4BAAA,GAA+B,eAAA"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import { useOptimistic } from "@sanity/visual-editing/react";
|
|
1
|
+
import { useIsPresentationTool, useOptimistic, useVisualEditingEnvironment } from "@sanity/visual-editing/react";
|
|
2
2
|
import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams } from "@sanity/client";
|
|
3
|
-
/**
|
|
4
|
-
* Detects if the application is considered to be in a "Live Preview" mode.
|
|
5
|
-
* Live Preview means that the application is either:
|
|
6
|
-
* - being previewed inside Sanity Presentation Tool
|
|
7
|
-
* - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as "Standalone Live Preview'"
|
|
8
|
-
* When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention.
|
|
9
|
-
* This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts,
|
|
10
|
-
* to avoid interrupting the user that is consuming your content.
|
|
11
|
-
* This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX,
|
|
12
|
-
* while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time.
|
|
13
|
-
*
|
|
14
|
-
* The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not.
|
|
15
|
-
* Then `true` if it is, and `false` otherwise.
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
declare function useIsLivePreview(): boolean | null;
|
|
19
|
-
declare function useLiveEnvironment(): null;
|
|
20
3
|
/** @alpha */
|
|
21
4
|
type UsePresentationQueryReturnsInactive = {
|
|
22
5
|
data: null;
|
|
@@ -38,23 +21,10 @@ type UsePresentationQueryReturns<QueryString extends string> = UsePresentationQu
|
|
|
38
21
|
* Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.
|
|
39
22
|
* @alpha
|
|
40
23
|
*/
|
|
41
|
-
declare function usePresentationQuery<const QueryString extends string>(
|
|
24
|
+
declare function usePresentationQuery<const QueryString extends string>(_: {
|
|
42
25
|
query: QueryString;
|
|
43
26
|
params?: QueryParams | Promise<QueryParams>;
|
|
44
27
|
stega?: boolean;
|
|
45
28
|
}): UsePresentationQueryReturns<QueryString>;
|
|
46
|
-
|
|
47
|
-
* Detects if the application is being previewed inside Sanity Presentation Tool.
|
|
48
|
-
* Presentation Tool can open the application in an iframe, or in a new window.
|
|
49
|
-
* When in this context there are some UI you usually don't want to show,
|
|
50
|
-
* for example a Draft Mode toggle, or a "Viewing draft content" indicators, these are unnecessary and add clutter to
|
|
51
|
-
* the editorial experience.
|
|
52
|
-
* The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,
|
|
53
|
-
* then `true` if it is, and `false` otherwise.
|
|
54
|
-
* @public
|
|
55
|
-
*/
|
|
56
|
-
declare function useIsPresentationTool(): boolean | null;
|
|
57
|
-
type VisualEditingEnvironment = null | "unknown" | "presentation-iframe" | "presentation-window" | "standalone";
|
|
58
|
-
declare function useVisualEditingEnvironment(): VisualEditingEnvironment;
|
|
59
|
-
export { UsePresentationQueryReturns, UsePresentationQueryReturnsActive, UsePresentationQueryReturnsInactive, useIsLivePreview, useIsPresentationTool, useLiveEnvironment, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
|
|
29
|
+
export { useIsPresentationTool, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
|
|
60
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/hooks/usePresentationQuery.ts"],"mappings":";;;KAIY,mCAAA;EACV,IAAA;EACA,SAAA;EACA,WAAA;AAAA;;KAIU,iCAAA;EACV,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,WAAA,EAAa,iBAAA;AAAA;AAAA,KAGH,2BAAA,+BACR,mCAAA,GACA,iCAAA,CAAkC,WAAA;;;;;;;;;iBAmBtB,oBAAA,kCAAA,CAAuD,CAAA;EACrE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;EAC/B,KAAA;AAAA,IACE,2BAAA,CAA4B,WAAA"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,117 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { dequal } from "dequal/lite";
|
|
4
|
-
import { useEffect, useEffectEvent, useMemo, useReducer, useSyncExternalStore } from "react";
|
|
5
|
-
import { useOptimistic } from "@sanity/visual-editing/react";
|
|
6
|
-
function useIsLivePreview() {
|
|
7
|
-
console.log("TODO: Implement useIsLivePreview");
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
function useLiveEnvironment() {
|
|
11
|
-
console.log("TODO: Implement useLiveEnvironment");
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const comlinkListeners = /* @__PURE__ */ new Set();
|
|
15
|
-
let comlink = null;
|
|
16
|
-
let comlinkProjectId = null;
|
|
17
|
-
let comlinkDataset = null;
|
|
18
|
-
let comlinkPerspective = null;
|
|
19
|
-
function reducer(state, { type, payload }) {
|
|
20
|
-
switch (type) {
|
|
21
|
-
case "query-change": return dequal(state, payload) ? state : {
|
|
22
|
-
...state,
|
|
23
|
-
data: dequal(state.data, payload.data) ? state.data : payload.data,
|
|
24
|
-
sourceMap: dequal(state.sourceMap, payload.sourceMap) ? state.sourceMap : payload.sourceMap,
|
|
25
|
-
perspective: dequal(state.perspective, payload.perspective) ? state.perspective : payload.perspective
|
|
26
|
-
};
|
|
27
|
-
default: return state;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
2
|
+
import { useIsPresentationTool, useOptimistic, useVisualEditingEnvironment } from "@sanity/visual-editing/react";
|
|
30
3
|
const initialState = {
|
|
31
4
|
data: null,
|
|
32
5
|
sourceMap: null,
|
|
33
6
|
perspective: null
|
|
34
7
|
};
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
const EMPTY_QUERY_PARAMS = {};
|
|
40
|
-
const LISTEN_HEARTBEAT_INTERVAL = 1e4;
|
|
41
|
-
function usePresentationQuery(props) {
|
|
42
|
-
const [state, dispatch] = useReducer(reducer, initialState);
|
|
43
|
-
const { query, params = EMPTY_QUERY_PARAMS, stega = true } = props;
|
|
44
|
-
const comlink$1 = useSyncExternalStore(subscribe, () => comlink, () => null);
|
|
45
|
-
const projectId = useSyncExternalStore(subscribe, () => comlinkProjectId, () => null);
|
|
46
|
-
const dataset = useSyncExternalStore(subscribe, () => comlinkDataset, () => null);
|
|
47
|
-
const perspective = useSyncExternalStore(subscribe, () => comlinkPerspective, () => null);
|
|
48
|
-
const handleQueryHeartbeat = useEffectEvent((comlink$2) => {
|
|
49
|
-
if (!projectId || !dataset || !perspective) {
|
|
50
|
-
console.warn("usePresentationQuery: projectId, dataset and perspective must be set", {
|
|
51
|
-
projectId,
|
|
52
|
-
dataset,
|
|
53
|
-
perspective
|
|
54
|
-
});
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (perspective === null) return;
|
|
58
|
-
comlink$2.post("loader/query-listen", {
|
|
59
|
-
projectId,
|
|
60
|
-
dataset,
|
|
61
|
-
perspective,
|
|
62
|
-
query,
|
|
63
|
-
params,
|
|
64
|
-
heartbeat: LISTEN_HEARTBEAT_INTERVAL
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
const handleQueryChange = useEffectEvent((event) => {
|
|
68
|
-
if (dequal({
|
|
69
|
-
projectId,
|
|
70
|
-
dataset,
|
|
71
|
-
query,
|
|
72
|
-
params
|
|
73
|
-
}, {
|
|
74
|
-
projectId: event.projectId,
|
|
75
|
-
dataset: event.dataset,
|
|
76
|
-
query: event.query,
|
|
77
|
-
params: event.params
|
|
78
|
-
})) dispatch({
|
|
79
|
-
type: "query-change",
|
|
80
|
-
payload: {
|
|
81
|
-
data: event.result,
|
|
82
|
-
sourceMap: event.resultSourceMap || null,
|
|
83
|
-
perspective: event.perspective
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
if (!comlink$1) return;
|
|
89
|
-
const unsubscribe = comlink$1.on("loader/query-change", handleQueryChange);
|
|
90
|
-
const interval = setInterval(() => handleQueryHeartbeat(comlink$1), LISTEN_HEARTBEAT_INTERVAL);
|
|
91
|
-
return () => {
|
|
92
|
-
clearInterval(interval);
|
|
93
|
-
unsubscribe();
|
|
94
|
-
};
|
|
95
|
-
}, [comlink$1]);
|
|
96
|
-
return useMemo(() => {
|
|
97
|
-
if (stega && state.sourceMap) return {
|
|
98
|
-
...state,
|
|
99
|
-
data: stegaEncodeSourceMap(state.data, state.sourceMap, {
|
|
100
|
-
enabled: true,
|
|
101
|
-
studioUrl: "/"
|
|
102
|
-
})
|
|
103
|
-
};
|
|
104
|
-
return state;
|
|
105
|
-
}, [state, stega]);
|
|
106
|
-
}
|
|
107
|
-
function useIsPresentationTool() {
|
|
108
|
-
console.log("TODO: Implement useIsPresentationTool");
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
function useVisualEditingEnvironment() {
|
|
112
|
-
console.log("TODO: Implement useVisualEditingEnvironment");
|
|
113
|
-
return null;
|
|
8
|
+
function usePresentationQuery(_) {
|
|
9
|
+
console.log("TODO: Implement usePresentationQuery");
|
|
10
|
+
return initialState;
|
|
114
11
|
}
|
|
115
|
-
export {
|
|
12
|
+
export { useIsPresentationTool, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
|
|
116
13
|
|
|
117
14
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["comlink","comlinkSnapshot"],"sources":["../../src/hooks/useIsLivePreview.ts","../../src/live/hooks/useLiveEnvironment.ts","../../src/live/shared/context.ts","../../src/live/hooks/usePresentationQuery.ts","../../src/visual-editing/hooks/useIsPresentationTool.ts","../../src/visual-editing/hooks/useVisualEditingEnvironment.ts"],"sourcesContent":["/**\n * Detects if the application is considered to be in a \"Live Preview\" mode.\n * Live Preview means that the application is either:\n * - being previewed inside Sanity Presentation Tool\n * - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as \"Standalone Live Preview'\"\n * When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention.\n * This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts,\n * to avoid interrupting the user that is consuming your content.\n * This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX,\n * while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time.\n *\n * The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not.\n * Then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsLivePreview(): boolean | null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useIsLivePreview')\n\n return null\n}\n","export function useLiveEnvironment(): null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useLiveEnvironment')\n\n return null\n}\n","import type {ClientPerspective} from '@sanity/client'\nimport type {Node} from '@sanity/comlink'\nimport type {LoaderControllerMsg, LoaderNodeMsg} from '@sanity/presentation-comlink'\n\nexport const comlinkListeners: Set<() => void> = new Set()\nexport let comlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null = null\nexport let comlinkProjectId: string | null = null\nexport let comlinkDataset: string | null = null\nexport let comlinkPerspective: ClientPerspective | null = null\nexport function setComlink(nextComlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null): void {\n comlink = nextComlink\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\nexport function setComlinkClientConfig(\n nextComlinkProjectId: string | null,\n nextComlinkDataset: string | null,\n): void {\n comlinkProjectId = nextComlinkProjectId\n comlinkDataset = nextComlinkDataset\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\nexport function setComlinkPerspective(nextComlinkPerspective: ClientPerspective | null): void {\n if (comlinkPerspective?.toString() === nextComlinkPerspective?.toString()) return\n comlinkPerspective = nextComlinkPerspective\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\n","import type {ClientPerspective, ClientReturn, ContentSourceMap, QueryParams} from '@sanity/client'\nimport type {LoaderControllerMsg} from '@sanity/presentation-comlink'\n\nimport {\n comlinkDataset,\n comlinkListeners,\n comlinkProjectId,\n comlinkPerspective,\n comlink as comlinkSnapshot,\n} from '#live/context'\nimport {stegaEncodeSourceMap} from '@sanity/client/stega'\nimport {dequal} from 'dequal/lite'\nimport {useEffect, useMemo, useReducer, useSyncExternalStore, useEffectEvent} from 'react'\n\n/** @alpha */\nexport type UsePresentationQueryReturnsInactive = {\n data: null\n sourceMap: null\n perspective: null\n}\n\n/** @alpha */\nexport type UsePresentationQueryReturnsActive<QueryString extends string> = {\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n perspective: ClientPerspective\n}\n\nexport type UsePresentationQueryReturns<QueryString extends string> =\n | UsePresentationQueryReturnsInactive\n | UsePresentationQueryReturnsActive<QueryString>\n\ntype Action<QueryString extends string> = {\n type: 'query-change'\n payload: UsePresentationQueryReturnsActive<QueryString>\n}\n\nfunction reducer<QueryString extends string>(\n state: UsePresentationQueryReturns<QueryString>,\n {type, payload}: Action<QueryString>,\n): UsePresentationQueryReturns<QueryString> {\n switch (type) {\n case 'query-change':\n return dequal(state, payload)\n ? state\n : {\n ...state,\n data: dequal(state.data, payload.data)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.data as ClientReturn<QueryString>)\n : payload.data,\n sourceMap: dequal(state.sourceMap, payload.sourceMap)\n ? state.sourceMap\n : payload.sourceMap,\n perspective: dequal(state.perspective, payload.perspective)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.perspective as Exclude<ClientPerspective, 'raw'>)\n : payload.perspective,\n }\n default:\n return state\n }\n}\nconst initialState: UsePresentationQueryReturnsInactive = {\n data: null,\n sourceMap: null,\n perspective: null,\n}\n\nfunction subscribe(listener: () => void) {\n comlinkListeners.add(listener)\n return () => comlinkListeners.delete(listener)\n}\n\nconst EMPTY_QUERY_PARAMS: QueryParams = {}\nconst LISTEN_HEARTBEAT_INTERVAL = 10_000\n\n/**\n * Experimental hook that can run queries in Presentation Tool.\n * Query results are sent back over postMessage whenever the query results change.\n * It also works with optimistic updates in the studio itself, offering low latency updates.\n * It's not as low latency as the `useOptimistic` hook, but it's a good compromise for some use cases.\n * Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.\n * @alpha\n */\nexport function usePresentationQuery<const QueryString extends string>(props: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n}): UsePresentationQueryReturns<QueryString> {\n const [state, dispatch] = useReducer(reducer, initialState)\n const {query, params = EMPTY_QUERY_PARAMS, stega = true} = props\n\n /**\n * Comlink forwards queries we want to run to the parent window where Presentation Tool handles it for us\n */\n const comlink = useSyncExternalStore(\n subscribe,\n () => comlinkSnapshot,\n () => null,\n )\n /**\n * The comlink events requires projectId and dataset, Presentation Tool uses it to protect against project and dataset mismatch errors.\n * We don't want to force the consumers of the `usePresentationQuery` hook to provide these,\n * so we set them in the component that establishes the comlink connection and propagates it to all the subscribes.\n */\n const projectId = useSyncExternalStore(\n subscribe,\n () => comlinkProjectId,\n () => null,\n )\n const dataset = useSyncExternalStore(\n subscribe,\n () => comlinkDataset,\n () => null,\n )\n /**\n * The perspective is kept in sync with Presentation Tool's perspective, and even knows what perspective the page loaded with initially and can forward it to the Sanity Studio.\n */\n const perspective = useSyncExternalStore(\n subscribe,\n () => comlinkPerspective,\n () => null,\n )\n\n const handleQueryHeartbeat = useEffectEvent((comlink: NonNullable<typeof comlinkSnapshot>) => {\n // Handle odd case where the comlink can take events but some data is missing\n if (!projectId || !dataset || !perspective) {\n console.warn('usePresentationQuery: projectId, dataset and perspective must be set', {\n projectId,\n dataset,\n perspective,\n })\n return\n }\n // Another odd case where the initial perspective states haven't resolved to the actual perspective state\n if (perspective === null) {\n return\n }\n comlink.post('loader/query-listen', {\n projectId,\n dataset,\n perspective,\n query,\n params,\n heartbeat: LISTEN_HEARTBEAT_INTERVAL,\n })\n })\n const handleQueryChange = useEffectEvent(\n (event: Extract<LoaderControllerMsg, {type: 'loader/query-change'}>['data']) => {\n if (\n dequal(\n {\n projectId,\n dataset,\n query,\n params,\n },\n {\n projectId: event.projectId,\n dataset: event.dataset,\n query: event.query,\n params: event.params,\n },\n )\n ) {\n dispatch({\n type: 'query-change',\n payload: {\n data: event.result,\n sourceMap: event.resultSourceMap || null,\n perspective: event.perspective,\n },\n })\n }\n },\n )\n useEffect(() => {\n if (!comlink) return\n\n const unsubscribe = comlink.on('loader/query-change', handleQueryChange)\n const interval = setInterval(() => handleQueryHeartbeat(comlink), LISTEN_HEARTBEAT_INTERVAL)\n return () => {\n clearInterval(interval)\n unsubscribe()\n }\n }, [comlink])\n\n return useMemo(() => {\n if (stega && state.sourceMap) {\n return {\n ...state,\n data: stegaEncodeSourceMap(state.data, state.sourceMap, {enabled: true, studioUrl: '/'}),\n }\n }\n return state\n }, [state, stega])\n}\n","/**\n * Detects if the application is being previewed inside Sanity Presentation Tool.\n * Presentation Tool can open the application in an iframe, or in a new window.\n * When in this context there are some UI you usually don't want to show,\n * for example a Draft Mode toggle, or a \"Viewing draft content\" indicators, these are unnecessary and add clutter to\n * the editorial experience.\n * The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,\n * then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsPresentationTool(): boolean | null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useIsPresentationTool')\n\n return null\n}\n","type VisualEditingEnvironment =\n | null\n | 'unknown'\n | 'presentation-iframe'\n | 'presentation-window'\n | 'standalone'\n\nexport function useVisualEditingEnvironment(): VisualEditingEnvironment {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useVisualEditingEnvironment')\n\n return null\n}\n"],"mappings":";;;;;AAeA,SAAgB,mBAAmC;AAEjD,SAAQ,IAAI,mCAAmC;AAE/C,QAAO;;ACnBT,SAAgB,qBAA2B;AAEzC,SAAQ,IAAI,qCAAqC;AAEjD,QAAO;;ACAT,MAAa,mCAAoC,IAAI,KAAK;AAC1D,IAAW,UAA2D;AACtE,IAAW,mBAAkC;AAC7C,IAAW,iBAAgC;AAC3C,IAAW,qBAA+C;AC6B1D,SAAS,QACP,OACA,EAAC,MAAM,WACmC;AAC1C,SAAQ,MAAR;EACE,KAAK,eACH,QAAO,OAAO,OAAO,QAAQ,GACzB,QACA;GACE,GAAG;GACH,MAAM,OAAO,MAAM,MAAM,QAAQ,KAAK,GAEjC,MAAM,OACP,QAAQ;GACZ,WAAW,OAAO,MAAM,WAAW,QAAQ,UAAU,GACjD,MAAM,YACN,QAAQ;GACZ,aAAa,OAAO,MAAM,aAAa,QAAQ,YAAY,GAEtD,MAAM,cACP,QAAQ;GACb;EACP,QACE,QAAO;;;AAGb,MAAM,eAAoD;CACxD,MAAM;CACN,WAAW;CACX,aAAa;CACd;AAED,SAAS,UAAU,UAAsB;AACvC,kBAAiB,IAAI,SAAS;AAC9B,cAAa,iBAAiB,OAAO,SAAS;;AAGhD,MAAM,qBAAkC,EAAE;AAC1C,MAAM,4BAA4B;AAUlC,SAAgB,qBAAuD,OAI1B;CAC3C,MAAM,CAAC,OAAO,YAAY,WAAW,SAAS,aAAa;CAC3D,MAAM,EAAC,OAAO,SAAS,oBAAoB,QAAQ,SAAQ;CAK3D,MAAMA,YAAU,qBACd,iBACMC,eACA,KACP;CAMD,MAAM,YAAY,qBAChB,iBACM,wBACA,KACP;CACD,MAAM,UAAU,qBACd,iBACM,sBACA,KACP;CAID,MAAM,cAAc,qBAClB,iBACM,0BACA,KACP;CAED,MAAM,uBAAuB,gBAAgB,cAAiD;AAE5F,MAAI,CAAC,aAAa,CAAC,WAAW,CAAC,aAAa;AAC1C,WAAQ,KAAK,wEAAwE;IACnF;IACA;IACA;IACD,CAAC;AACF;;AAGF,MAAI,gBAAgB,KAClB;AAEF,YAAQ,KAAK,uBAAuB;GAClC;GACA;GACA;GACA;GACA;GACA,WAAW;GACZ,CAAC;GACF;CACF,MAAM,oBAAoB,gBACvB,UAA+E;AAC9E,MACE,OACE;GACE;GACA;GACA;GACA;GACD,EACD;GACE,WAAW,MAAM;GACjB,SAAS,MAAM;GACf,OAAO,MAAM;GACb,QAAQ,MAAM;GACf,CACF,CAED,UAAS;GACP,MAAM;GACN,SAAS;IACP,MAAM,MAAM;IACZ,WAAW,MAAM,mBAAmB;IACpC,aAAa,MAAM;IACpB;GACF,CAAC;GAGP;AACD,iBAAgB;AACd,MAAI,CAACD,UAAS;EAEd,MAAM,cAAcA,UAAQ,GAAG,uBAAuB,kBAAkB;EACxE,MAAM,WAAW,kBAAkB,qBAAqBA,UAAQ,EAAE,0BAA0B;AAC5F,eAAa;AACX,iBAAc,SAAS;AACvB,gBAAa;;IAEd,CAACA,UAAQ,CAAC;AAEb,QAAO,cAAc;AACnB,MAAI,SAAS,MAAM,UACjB,QAAO;GACL,GAAG;GACH,MAAM,qBAAqB,MAAM,MAAM,MAAM,WAAW;IAAC,SAAS;IAAM,WAAW;IAAI,CAAC;GACzF;AAEH,SAAO;IACN,CAAC,OAAO,MAAM,CAAC;;AC1LpB,SAAgB,wBAAwC;AAEtD,SAAQ,IAAI,wCAAwC;AAEpD,QAAO;;ACPT,SAAgB,8BAAwD;AAEtE,SAAQ,IAAI,8CAA8C;AAE1D,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/visual-editing/hooks/usePresentationQuery.ts"],"sourcesContent":["import type {ClientPerspective, ClientReturn, ContentSourceMap, QueryParams} from '@sanity/client'\n\n\n/** @alpha */\nexport type UsePresentationQueryReturnsInactive = {\n data: null\n sourceMap: null\n perspective: null\n}\n\n/** @alpha */\nexport type UsePresentationQueryReturnsActive<QueryString extends string> = {\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n perspective: ClientPerspective\n}\n\nexport type UsePresentationQueryReturns<QueryString extends string> =\n | UsePresentationQueryReturnsInactive\n | UsePresentationQueryReturnsActive<QueryString>\n\n\nconst initialState: UsePresentationQueryReturnsInactive = {\n data: null,\n sourceMap: null,\n perspective: null,\n}\n\n\n\n/**\n * Experimental hook that can run queries in Presentation Tool.\n * Query results are sent back over postMessage whenever the query results change.\n * It also works with optimistic updates in the studio itself, offering low latency updates.\n * It's not as low latency as the `useOptimistic` hook, but it's a good compromise for some use cases.\n * Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.\n * @alpha\n */\nexport function usePresentationQuery<const QueryString extends string>(_: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n}): UsePresentationQueryReturns<QueryString> {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement usePresentationQuery')\n\n return initialState\n}\n"],"mappings":";;AAsBA,MAAM,eAAoD;CACxD,MAAM;CACN,WAAW;CACX,aAAa;CACd;AAYD,SAAgB,qBAAuD,GAI1B;AAE3C,SAAQ,IAAI,uCAAuC;AAEnD,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/image/Image.tsx","../../src/image/imageLoader.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/image/Image.tsx","../../src/image/imageLoader.ts"],"mappings":";;AAOA;;UAAiB,UAAA,SAAmB,IAAA,CAAK,YAAA;EAAL;;;EAIlC,MAAA;;;;EAIA,GAAA;AAAA;;;;iBAMc,KAAA,CAAM,KAAA,EAAO,UAAA,GAAa,KAAA,CAAM,GAAA,CAAI,OAAA;;AAdpD;;cCFa,WAAA,EAAa,WAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { stegaClean } from "@sanity/client/stega";
|
|
3
2
|
import { createClient, unstable__adapter, unstable__environment } from "@sanity/client";
|
|
3
|
+
import { stegaClean } from "@sanity/client/stega";
|
|
4
4
|
import { CreateDataAttribute, CreateDataAttributeProps, createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
|
|
5
5
|
import groq, { defineQuery } from "groq";
|
|
6
6
|
export * from "@sanity/client";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { stegaClean } from "@sanity/client/stega";
|
|
3
2
|
import { createClient, unstable__adapter, unstable__environment } from "@sanity/client";
|
|
3
|
+
import { stegaClean } from "@sanity/client/stega";
|
|
4
4
|
import { createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
|
|
5
5
|
import groq, { defineQuery } from "groq";
|
|
6
6
|
export * from "@portabletext/react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isCorsOriginError.d.ts","names":[],"sources":["../src/live/shared/isCorsOriginError.ts"],"
|
|
1
|
+
{"version":3,"file":"isCorsOriginError.d.ts","names":[],"sources":["../src/live/shared/isCorsOriginError.ts"],"mappings":";;iBAGgB,iBAAA,CAAkB,KAAA,YAAiB,KAAA,IAAS,eAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-life.d.ts","names":[],"sources":["../../src/live/cache-life.ts"],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAa,MAAA;;;;WAIX,UAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-life.js","names":[],"sources":["../../src/live/cache-life.ts"],"sourcesContent":["import {revalidate} from '#live/constants'\n\n/**\n * For usage with `cacheComponents: true`, and `defineLive`:\n * ```ts\n * // next.config.ts\n *\n * import type {NextConfig} from 'next'\n * import {sanity} from 'next-sanity/cache-life'\n *\n * const nextConfig: NextConfig = {\n * cacheComponents: true,\n * cacheLife: {\n * sanity\n * }\n * }\n *\n * export default nextConfig\n * ```\n *\n * ```ts\n *\n * async function sanityFetch() {\n * 'use cache'\n * cacheLife('sanity')\n * const {data} = await fetch({query, params})\n * return data\n * }\n */\nexport const sanity = {\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short\n */\n revalidate: 31_536_000, // 365 days\n} as const satisfies {\n /**\n * This cache may be stale on clients for ... seconds before checking with the server.\n */\n stale?: number\n /**\n * If the server receives a new request after ... seconds, start revalidating new values in the background.\n */\n revalidate?: typeof revalidate\n /**\n * If this entry has no traffic for ... seconds it will expire. The next request will recompute it.\n */\n expire?: number\n}\n"],"mappings":"AA6BA,MAAa,SAAS,EAIpB,YAAY,SACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"mappings":";;UAYU,kBAAA,SAA2B,IAAA,CACnC,uBAAA;AAAA,UAUe,eAAA;EACf,MAAA,EAAQ,kBAAA;EACR,mBAAA;EACA,UAAA;EAEA,MAAA,GACE,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EACL,eAAA,IACE,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EACL,aAAA,IACE,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EACL,aAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAET,YAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAGT,cAAA;EACA,cAAA;EACA,kBAAA;AAAA;;;AApDuE;cCK5D,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,eAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import { r as PerspectiveType, t as
|
|
3
|
-
import {
|
|
2
|
+
import { n as DefinedLiveProps, r as PerspectiveType, t as DefineLiveOptions } from "../../../types.js";
|
|
3
|
+
import { r as ResolvePerspectiveFromCookies, t as DefinedSanityFetchType } from "../../../defineLive.js";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
declare function defineLive(_config:
|
|
7
|
+
declare function defineLive(_config: DefineLiveOptions): {
|
|
8
8
|
sanityFetch: DefinedSanityFetchType;
|
|
9
9
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;AAgBA;;;AAAA,iBAAgB,UAAA,CAAW,OAAA,EAAS,iBAAA;EAClC,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA;;;;;cASrB,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 {DefinedLiveProps} from '#live/types'\n\nimport type {
|
|
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 {DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nimport type {DefinedSanityFetchType} from '../react-server/defineLive'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\n\n/**\n * @public\n */\nexport function defineLive(_config: DefineLiveOptions): {\n sanityFetch: DefinedSanityFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n} {\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":";AAgBA,SAAgB,WAAW,SAGzB;AACA,OAAM,IAAI,MAAM,qDAAqD;;AAOvE,MAAa,sCAAqE;AAChF,OAAM,IAAI,MAAM,wEAAwE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
declare function defineLive(config:
|
|
2
|
+
import { n as DefinedLiveProps, r as PerspectiveType, t as DefineLiveOptions } from "../../../types.js";
|
|
3
|
+
import { i as resolvePerspectiveFromCookies, t as DefinedSanityFetchType } from "../../../defineLive.js";
|
|
4
|
+
declare function defineLive(config: DefineLiveOptions): {
|
|
5
5
|
sanityFetch: DefinedSanityFetchType;
|
|
6
6
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
7
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"mappings":";;;iBAUgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EACjC,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as PUBLISHED_SYNC_TAG_PREFIX, r as revalidate, t as DRAFT_SYNC_TAG_PREFIX } from "../../../constants.js";
|
|
2
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
+
import { n as PUBLISHED_SYNC_TAG_PREFIX, r as revalidate, t as DRAFT_SYNC_TAG_PREFIX } from "../../../constants.js";
|
|
3
3
|
import { t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
@@ -16,7 +16,7 @@ function defineLive(config) {
|
|
|
16
16
|
useCdn: true
|
|
17
17
|
});
|
|
18
18
|
const { token: originalToken } = client.config();
|
|
19
|
-
const fetch = async function fetch
|
|
19
|
+
const fetch = async function fetch({ query, params = {}, perspective = "published", stega = false, tags: customCacheTags = [], requestTag = "next-loader.fetch.cache-components" }) {
|
|
20
20
|
const useCdn = perspective === "published";
|
|
21
21
|
const { result, resultSourceMap, syncTags } = await client.fetch(query, params, {
|
|
22
22
|
filterResponse: false,
|
|
@@ -37,7 +37,7 @@ function defineLive(config) {
|
|
|
37
37
|
tags
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
-
const Live = function Live
|
|
40
|
+
const Live = function Live(props) {
|
|
41
41
|
const { includeAllDocuments = false, action = actionUpdateTags, restartAction = actionRefresh, reconnectAction = actionRefresh, goAwayAction, welcomeAction, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components" } = props;
|
|
42
42
|
const shouldIncludeDrafts = typeof browserToken === "string" && includeAllDocuments;
|
|
43
43
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX, revalidate} from '#live/constants'\nimport {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 type {DefinedSanityFetchType} from '../react-server/defineLive'\n\nexport function defineLive(config: DefineLiveOptions): {\n sanityFetch: DefinedSanityFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n} {\n const {client: _client, serverToken, browserToken} = 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} = client.config()\n\n const fetch: DefinedFetchType = async function fetch({\n query,\n params = {},\n perspective = 'published',\n stega = false,\n tags: customCacheTags = [],\n requestTag = 'next-loader.fetch.cache-components',\n }) {\n const useCdn = perspective === 'published'\n\n const {result, resultSourceMap, syncTags} = await client.fetch(query, params, {\n filterResponse: false,\n returnQuery: false,\n perspective,\n useCdn,\n stega,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n token: perspective === 'published' ? originalToken : serverToken || originalToken, // @TODO can pass undefined instead of config.token here?\n })\n const tags = [\n ...customCacheTags,\n ...(syncTags || []).map(\n (tag) =>\n `${perspective === 'published' ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX}${tag}`,\n ),\n ]\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 Live: React.ComponentType<DefinedLiveProps> = function Live(props) {\n const {\n includeAllDocuments = false,\n action = actionUpdateTags,\n restartAction = actionRefresh,\n reconnectAction = actionRefresh,\n goAwayAction,\n welcomeAction,\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' && includeAllDocuments\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 includeAllDocuments={shouldIncludeDrafts}\n action={action}\n reconnectAction={reconnectAction === false ? undefined : reconnectAction}\n restartAction={restartAction === false ? undefined : restartAction}\n welcomeAction={welcomeAction}\n goAwayAction={goAwayAction}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n />\n )\n }\n Live.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch: fetch,\n SanityLive: Live,\n }\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,WAAW,QAGzB;CACA,MAAM,EAAC,QAAQ,SAAS,aAAa,iBAAgB;AAErD,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,kBAAiB,OAAO,QAAQ;CAE9C,MAAM,QAA0B,eAAe,MAAM,EACnD,OACA,SAAS,EAAE,EACX,cAAc,aACd,QAAQ,OACR,MAAM,kBAAkB,EAAE,EAC1B,aAAa,wCACZ;EACD,MAAM,SAAS,gBAAgB;EAE/B,MAAM,EAAC,QAAQ,iBAAiB,aAAY,MAAM,OAAO,MAAM,OAAO,QAAQ;GAC5E,gBAAgB;GAChB,aAAa;GACb;GACA;GACA;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK;GACL,OAAO,gBAAgB,cAAc,gBAAgB,eAAe;GACrE,CAAC;EACF,MAAM,OAAO,CACX,GAAG,iBACH,IAAI,YAAY,EAAE,EAAE,KACjB,QACC,GAAG,gBAAgB,cAAc,4BAA4B,wBAAwB,MACxF,CACF;AAID,WAAS,GAAG,KAAK;AAKjB,YAAU,EAAC,YAAW,CAAC;AAEvB,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM;GAAK;;CAGjE,MAAM,OAA8C,SAAS,KAAK,OAAO;EACvE,MAAM,EACJ,sBAAsB,OACtB,SAAS,kBACT,gBAAgB,eAChB,kBAAkB,eAClB,cACA,eACA,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,oBAACA,YAAAA;GACC,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,sBAAsB,eAAe,KAAA;IAC7C;GACD,qBAAqB;GACb;GACR,iBAAiB,oBAAoB,QAAQ,KAAA,IAAY;GACzD,eAAe,kBAAkB,QAAQ,KAAA,IAAY;GACtC;GACD;GACF;GACI;GACA;GACI;IACpB;;AAGN,MAAK,cAAc;AAEnB,QAAO;EACL,aAAa;EACb,YAAY;EACb"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
2
|
import { r as PerspectiveType } from "../../../types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { i as resolvePerspectiveFromCookies, n as defineLive } from "../../../defineLive.js";
|
|
4
4
|
export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
@@ -8,7 +8,7 @@ import { SanityLive } from "next-sanity/live/client-components";
|
|
|
8
8
|
import { actionRefresh, actionUpdateTags } from "next-sanity/live/server-actions";
|
|
9
9
|
import { preconnect } from "react-dom";
|
|
10
10
|
function defineLive(config) {
|
|
11
|
-
const { client: _client, serverToken, browserToken,
|
|
11
|
+
const { client: _client, serverToken, browserToken, stega: stegaEnabled = true } = config;
|
|
12
12
|
if (!_client) throw new Error("`client` is required for `defineLive` to function");
|
|
13
13
|
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
14
|
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`.");
|
|
@@ -18,11 +18,11 @@ function defineLive(config) {
|
|
|
18
18
|
});
|
|
19
19
|
const { token: originalToken } = client.config();
|
|
20
20
|
const studioUrlDefined = typeof client.config().stega.studioUrl !== "undefined";
|
|
21
|
-
const sanityFetch = async function sanityFetch
|
|
21
|
+
const sanityFetch = async function sanityFetch({ query, params = {}, stega: _stega, tags = ["sanity"], perspective: _perspective, tag, requestTag = tag ?? "next-loader.fetch" }) {
|
|
22
22
|
const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled);
|
|
23
23
|
const perspective = _perspective ?? await resolveCookiePerspective();
|
|
24
24
|
const useCdn = perspective === "published";
|
|
25
|
-
const revalidate =
|
|
25
|
+
const revalidate = false;
|
|
26
26
|
const { syncTags } = await client.fetch(query, await params, {
|
|
27
27
|
filterResponse: false,
|
|
28
28
|
perspective,
|
|
@@ -36,7 +36,7 @@ function defineLive(config) {
|
|
|
36
36
|
cacheMode: useCdn ? "noStale" : void 0,
|
|
37
37
|
tag: [requestTag, "fetch-sync-tags"].filter(Boolean).join(".")
|
|
38
38
|
});
|
|
39
|
-
const cacheTags = [...tags, ...syncTags?.map((tag
|
|
39
|
+
const cacheTags = [...tags, ...syncTags?.map((tag) => `sanity:${tag}`) || []];
|
|
40
40
|
const { result, resultSourceMap } = await client.fetch(query, await params, {
|
|
41
41
|
filterResponse: false,
|
|
42
42
|
perspective,
|
|
@@ -56,7 +56,7 @@ function defineLive(config) {
|
|
|
56
56
|
tags: cacheTags
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
|
-
const SanityLive$
|
|
59
|
+
const SanityLive$2 = async function SanityLive$1(props) {
|
|
60
60
|
const { includeAllDocuments = (await draftMode()).isEnabled, action = actionUpdateTags, restartAction = actionRefresh, reconnectAction = actionRefresh, goAwayAction, welcomeAction, refreshOnMount, refreshOnFocus, refreshOnReconnect, requestTag = "next-loader.live" } = props;
|
|
61
61
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
62
62
|
const shouldIncludeAllDocuments = typeof browserToken === "string" && includeAllDocuments;
|
|
@@ -84,10 +84,10 @@ function defineLive(config) {
|
|
|
84
84
|
refreshOnReconnect
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
|
-
SanityLive$
|
|
87
|
+
SanityLive$2.displayName = "SanityLiveServerComponent";
|
|
88
88
|
return {
|
|
89
89
|
sanityFetch,
|
|
90
|
-
SanityLive: SanityLive$
|
|
90
|
+
SanityLive: SanityLive$2
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
async function resolveCookiePerspective() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["sanityFetch","tag","SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedLiveProps} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {\n type ClientPerspective,\n type ClientReturn,\n type ContentSourceMap,\n type QueryParams,\n type SanityClient,\n} 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\n/**\n * @public\n */\nexport type DefinedSanityFetchType = <const QueryString extends string>(options: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n /**\n * Add custom `next.tags` to the underlying fetch request.\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags\n * This can be used in conjunction with custom fallback revalidation strategies, as well as with custom Server Actions that mutate data and want to render with fresh data right away (faster than the Live Event latency).\n * @defaultValue `['sanity']`\n */\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n stega?: boolean\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.fetch'\n */\n requestTag?: string\n}) => Promise<{\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n tags: string[]\n}>\n\n/**\n * @public\n */\nexport interface DefineSanityLiveOptions {\n /**\n * Required for `sanityFetch` and `SanityLive` to work\n */\n client: SanityClient\n /**\n * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.\n * This token is not shared with the browser.\n */\n serverToken?: string | false\n /**\n * Optional. This token is shared with the browser, and should only have access to query published documents.\n * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.\n */\n browserToken?: string | false\n /**\n * Fetch options used by `sanityFetch`\n */\n fetchOptions?: {\n /**\n * Optional, enables time based revalidation in addition to the EventSource connection.\n * @defaultValue `false`\n */\n revalidate?: number | false\n }\n /**\n * Optional. Include stega encoding when draft mode is enabled.\n * @defaultValue `true`\n */\n stega?: boolean\n}\n\nexport function defineLive(config: DefineSanityLiveOptions): {\n /**\n * @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`\n */\n sanityFetch: DefinedSanityFetchType\n /**\n * @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`\n */\n SanityLive: React.ComponentType<DefinedLiveProps>\n // fetch: DefinedFetchType\n // Live: React.ComponentType<DefinedLiveProps>\n} {\n const {\n client: _client,\n serverToken,\n browserToken,\n fetchOptions,\n stega: stegaEnabled = true,\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} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedSanityFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = ['sanity'],\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 const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const useCdn = perspective === 'published'\n const revalidate =\n fetchOptions?.revalidate !== undefined\n ? fetchOptions.revalidate\n : process.env.NODE_ENV === 'production'\n ? false\n : undefined\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: {revalidate, tags: [...tags, 'sanity:fetch-sync-tags']},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `sanity:${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: useCdn ? 'noStale' : undefined,\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 const {\n includeAllDocuments = (await draftMode()).isEnabled,\n action = actionUpdateTags,\n restartAction = actionRefresh,\n reconnectAction = actionRefresh,\n goAwayAction,\n welcomeAction,\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 shouldIncludeAllDocuments = typeof browserToken === 'string' && includeAllDocuments\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: shouldIncludeAllDocuments ? browserToken : undefined,\n }}\n includeAllDocuments={shouldIncludeAllDocuments}\n action={action}\n reconnectAction={reconnectAction === false ? undefined : reconnectAction}\n restartAction={restartAction === false ? undefined : restartAction}\n welcomeAction={welcomeAction}\n goAwayAction={goAwayAction}\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(): 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 : 'published'\n}\n"],"mappings":";;;;;;;;;AA8EA,SAAgB,WAAW,QAWzB;CACA,MAAM,EACJ,QAAQ,SACR,aACA,cACA,cACA,OAAO,eAAe,SACpB;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,kBAAiB,OAAO,QAAQ;CAC9C,MAAM,mBAAmB,OAAO,OAAO,QAAQ,CAAC,MAAM,cAAc;CAEpE,MAAM,cAAsC,eAAeA,cAEzD,EACA,OACA,SAAS,EAAE,EACX,OAAO,QACP,OAAO,CAAC,SAAS,EACjB,aAAa,cACb,KACA,aAAa,OAAO,uBASnB;EACD,MAAM,QAAQ,WAAW,gBAAgB,qBAAqB,MAAM,WAAW,EAAE;EACjF,MAAM,cAAc,gBAAiB,MAAM,0BAA0B;EACrE,MAAM,SAAS,gBAAgB;EAC/B,MAAM,aACJ,cAAc,eAAe,KAAA,IACzB,aAAa,aACb,QAAQ,IAAI,aAAa,eACvB,QACA,KAAA;EAGR,MAAM,EAAC,aAAY,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACzD,gBAAgB;GACH;GACb,OAAO;GACP,aAAa;GACb,MAAM;IAAC;IAAY,MAAM,CAAC,GAAG,MAAM,yBAAyB;IAAC;GAC7D;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK,CAAC,YAAY,kBAAkB,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;GAC/D,CAAC;EAEF,MAAM,YAAY,CAAC,GAAG,MAAM,GAAI,UAAU,KAAK,UAAQ,UAAUC,QAAM,IAAI,EAAE,CAAE;EAE/E,MAAM,EAAC,QAAQ,oBAAmB,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACxE,gBAAgB;GACH;GACb;GACA,OAAO,gBAAgB,eAAe,cAAc,cAAc;GAClE,MAAM;IAAC;IAAY,MAAM;IAAU;GACnC;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK;GACN,CAAC;AACF,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM,MAAM;GAAU;;CAG5E,MAAMC,eAAoD,eAAeA,aAAW,OAAO;EACzF,MAAM,EACJ,uBAAuB,MAAM,WAAW,EAAE,WAC1C,SAAS,kBACT,gBAAgB,eAChB,kBAAkB,eAClB,cACA,eACA,gBACA,gBACA,oBACA,aAAa,uBACX;EACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EACjB,MAAM,4BAA4B,OAAO,iBAAiB,YAAY;EAGtE,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,4BAA4B,eAAe,KAAA;IACnD;GACD,qBAAqB;GACb;GACR,iBAAiB,oBAAoB,QAAQ,KAAA,IAAY;GACzD,eAAe,kBAAkB,QAAQ,KAAA,IAAY;GACtC;GACD;GACF;GACI;GACA;GACI;IACpB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACL;EACA,YAAA;EACD;;AAGH,eAAe,2BAAuE;AACpF,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {\n type ClientPerspective,\n type ClientReturn,\n type ContentSourceMap,\n type QueryParams,\n} 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\n/**\n * @public\n */\nexport type DefinedSanityFetchType = <const QueryString extends string>(options: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n /**\n * Add custom `next.tags` to the underlying fetch request.\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags\n * This can be used in conjunction with custom fallback revalidation strategies, as well as with custom Server Actions that mutate data and want to render with fresh data right away (faster than the Live Event latency).\n * @defaultValue `['sanity']`\n */\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n stega?: boolean\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.fetch'\n */\n requestTag?: string\n}) => Promise<{\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n tags: string[]\n}>\n\nexport function defineLive(config: DefineLiveOptions): {\n sanityFetch: DefinedSanityFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n} {\n const {client: _client, serverToken, browserToken, stega: stegaEnabled = true} = 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} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedSanityFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = ['sanity'],\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 const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const useCdn = perspective === 'published'\n const revalidate = false\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: {revalidate, tags: [...tags, 'sanity:fetch-sync-tags']},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `sanity:${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: useCdn ? 'noStale' : undefined,\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 const {\n includeAllDocuments = (await draftMode()).isEnabled,\n action = actionUpdateTags,\n restartAction = actionRefresh,\n reconnectAction = actionRefresh,\n goAwayAction,\n welcomeAction,\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 shouldIncludeAllDocuments = typeof browserToken === 'string' && includeAllDocuments\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: shouldIncludeAllDocuments ? browserToken : undefined,\n }}\n includeAllDocuments={shouldIncludeAllDocuments}\n action={action}\n reconnectAction={reconnectAction === false ? undefined : reconnectAction}\n restartAction={restartAction === false ? undefined : restartAction}\n welcomeAction={welcomeAction}\n goAwayAction={goAwayAction}\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(): 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 : 'published'\n}\n"],"mappings":";;;;;;;;;AA0CA,SAAgB,WAAW,QAGzB;CACA,MAAM,EAAC,QAAQ,SAAS,aAAa,cAAc,OAAO,eAAe,SAAQ;AAEjF,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,kBAAiB,OAAO,QAAQ;CAC9C,MAAM,mBAAmB,OAAO,OAAO,QAAQ,CAAC,MAAM,cAAc;CAEpE,MAAM,cAAsC,eAAe,YAEzD,EACA,OACA,SAAS,EAAE,EACX,OAAO,QACP,OAAO,CAAC,SAAS,EACjB,aAAa,cACb,KACA,aAAa,OAAO,uBASnB;EACD,MAAM,QAAQ,WAAW,gBAAgB,qBAAqB,MAAM,WAAW,EAAE;EACjF,MAAM,cAAc,gBAAiB,MAAM,0BAA0B;EACrE,MAAM,SAAS,gBAAgB;EAC/B,MAAM,aAAa;EAGnB,MAAM,EAAC,aAAY,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACzD,gBAAgB;GACH;GACb,OAAO;GACP,aAAa;GACb,MAAM;IAAC;IAAY,MAAM,CAAC,GAAG,MAAM,yBAAyB;IAAC;GAC7D;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK,CAAC,YAAY,kBAAkB,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;GAC/D,CAAC;EAEF,MAAM,YAAY,CAAC,GAAG,MAAM,GAAI,UAAU,KAAK,QAAQ,UAAU,MAAM,IAAI,EAAE,CAAE;EAE/E,MAAM,EAAC,QAAQ,oBAAmB,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACxE,gBAAgB;GACH;GACb;GACA,OAAO,gBAAgB,eAAe,cAAc,cAAc;GAClE,MAAM;IAAC;IAAY,MAAM;IAAU;GACnC;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK;GACN,CAAC;AACF,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM,MAAM;GAAU;;CAG5E,MAAMA,eAAoD,eAAeA,aAAW,OAAO;EACzF,MAAM,EACJ,uBAAuB,MAAM,WAAW,EAAE,WAC1C,SAAS,kBACT,gBAAgB,eAChB,kBAAkB,eAClB,cACA,eACA,gBACA,gBACA,oBACA,aAAa,uBACX;EACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EACjB,MAAM,4BAA4B,OAAO,iBAAiB,YAAY;EAGtE,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,4BAA4B,eAAe,KAAA;IACnD;GACD,qBAAqB;GACb;GACR,iBAAiB,oBAAoB,QAAQ,KAAA,IAAY;GACzD,eAAe,kBAAkB,QAAQ,KAAA,IAAY;GACtC;GACD;GACF;GACI;GACA;GACI;IACpB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACL;EACA,YAAA;EACD;;AAGH,eAAe,2BAAuE;AACpF,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"
|
|
1
|
+
{"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"mappings":";;;AAYA;;iBAAsB,gBAAA,CACpB,KAAA,EAAO,OAAA,CAAQ,SAAA;EAAY,IAAA;AAAA,IAC3B,OAAA,EAAS,uBAAA,GACR,OAAA;;;;iBAsCmB,aAAA,CAAA,GAAiB,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"
|
|
1
|
+
{"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"mappings":";;;AAYA;;iBAAsB,gBAAA,CACpB,KAAA,EAAO,OAAA,CAAQ,SAAA;EAAY,IAAA;AAAA,IAC3B,OAAA,EAAS,uBAAA,GACR,OAAA;;;;iBAiCmB,aAAA,CAAA,GAAiB,OAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as sanitizePerspective } from "./sanitizePerspective.js";
|
|
2
2
|
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
3
|
-
const resolvePerspectiveFromCookies = async function resolvePerspectiveFromCookies
|
|
3
|
+
const resolvePerspectiveFromCookies = async function resolvePerspectiveFromCookies({ cookies: jar }) {
|
|
4
4
|
return jar.has(perspectiveCookieName) ? sanitizePerspective(jar.get(perspectiveCookieName)?.value, "drafts") : "drafts";
|
|
5
5
|
};
|
|
6
6
|
export { resolvePerspectiveFromCookies as t };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePerspectiveFromCookies.js","names":[
|
|
1
|
+
{"version":3,"file":"resolvePerspectiveFromCookies.js","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\nimport type {cookies} from 'next/headers'\n\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\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":";;AAyBA,MAAa,gCAAgC,eAAe,8BAA8B,EACxF,SAAS,OAGoC;AAC7C,QAAO,IAAI,IAAI,sBAAsB,GACjC,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,OAAO,SAAS,GACpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/studio/client-component/NextStudio.tsx","../../../src/studio/client-component/NextStudioLazy.tsx"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/studio/client-component/NextStudio.tsx","../../../src/studio/client-component/NextStudioLazy.tsx"],"mappings":";;UASiB,eAAA,SAAwB,WAAA;EACvC,QAAA,GAAW,KAAA,CAAM,SAAA;;;;;;EAMjB,kBAAA;;;;;;ACFF;EDSE,OAAA;AAAA;AAAA,iBCTc,6BAAA,CAA8B,KAAA,EAAO,eAAA,GAAkB,KAAA,CAAM,SAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Suspense, lazy } from "react";
|
|
3
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Suspense, lazy } from "react";
|
|
4
4
|
const NextStudioClientComponent = lazy(() => import("../../NextStudio.js"));
|
|
5
5
|
function NextStudioLazyClientComponent(props) {
|
|
6
6
|
return /* @__PURE__ */ jsx(Suspense, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/studio/head.tsx","../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx","../../src/studio/NextStudioWithBridge.tsx"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/studio/head.tsx","../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx","../../src/studio/NextStudioWithBridge.tsx"],"mappings":";;;AAoBA;;;;;;;;;AAyBA;;;;;;AC5CA;cDmBa,QAAA;EACX,KAAA;EACA,YAAA;EAEA,WAAA;AAAA;;;;ACVF;;;;;;;;;;;;;;;cD+Ba,QAAA;EACX,QAAA;EACA,MAAA;AAAA;;UC9Ce,qBAAA;EACf,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA;;cAYL,gBAAA;EAAqB;AAAA,GAAW,qBAAA,KAAwB,KAAA,CAAM,GAAA,CAAI,OAAA;;cCOlE,kBAAA,QAAyB,KAAA,CAAM,GAAA,CAAI,OAAA;AAAA,iBCXhC,oBAAA,CAAqB,KAAA,EAAO,iBAAA,GAAkB,KAAA,CAAM,GAAA,CAAI,OAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ interface DefinedLiveProps {
|
|
|
55
55
|
*/
|
|
56
56
|
requestTag?: string;
|
|
57
57
|
}
|
|
58
|
-
interface
|
|
58
|
+
interface DefineLiveOptions {
|
|
59
59
|
/**
|
|
60
60
|
* Required for `fetch()` and `<Live>` to work
|
|
61
61
|
*/
|
|
@@ -70,6 +70,12 @@ interface LiveOptions {
|
|
|
70
70
|
* It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.
|
|
71
71
|
*/
|
|
72
72
|
browserToken?: string | false;
|
|
73
|
+
/**
|
|
74
|
+
* Optional. Include stega encoding when draft mode is enabled.
|
|
75
|
+
* @deprecated This option is deprecated, as it does not have an effect when `cacheComponents: true`
|
|
76
|
+
* @defaultValue `true`
|
|
77
|
+
*/
|
|
78
|
+
stega?: boolean;
|
|
73
79
|
}
|
|
74
|
-
export { SanityLiveActionContext as i,
|
|
80
|
+
export { SanityLiveActionContext as i, DefinedLiveProps as n, PerspectiveType as r, DefineLiveOptions as t };
|
|
75
81
|
//# 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"],"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/live/shared/types.ts"],"mappings":";;AAcA;;;KAAY,eAAA,GAAkB,OAAA,CAAQ,iBAAA;;;;UAqCrB,uBAAA;EACf,mBAAA;AAAA;AAAA,UAQe,gBAAA;;;;EAIf,mBAAA;;;;EAIA,MAAA,IACE,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EACL,aAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAET,YAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAET,eAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAET,aAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;;;;;EAOT,cAAA;;;;;EAKA,cAAA;;;;;EAKA,kBAAA;EAUe;;;;;EAHf,UAAA;AAAA;AAAA,UAGe,iBAAA;;;;EAIf,MAAA,EAAQ,YAAA;;;;;EAKR,WAAA;;;;;EAKA,YAAA;;;;;;EAMA,KAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/client-component/VisualEditing.tsx","../../../src/visual-editing/client-component/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/client-component/VisualEditing.tsx","../../../src/visual-editing/client-component/index.ts"],"mappings":";;AAgBA;;UAAiB,kBAAA,SAA2B,IAAA,CAAK,oBAAA;EAAL;;;EAI1C,OAAA;;;;;;ACdF;;EDsBE,QAAA;ECtBgC;;;;;;;ED8BhC,aAAA;AAAA;AAAA,cC9BW,aAAA,EAAe,KAAA,CAAM,aAAA,CAAc,kBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"mappings":";;AAQA;;iBAAgB,aAAA,CAAc,KAAA,EAAO,oBAAA,GAAqB,KAAA,CAAM,YAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"mappings":";;;AAaA;;iBAAsB,aAAA,CAAc,QAAA,EAAU,cAAA,GAAiB,OAAA;;;;iBAOzC,uBAAA,CAAwB,WAAA,EAAa,iBAAA,GAAoB,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/webhook/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/webhook/index.ts"],"mappings":";;KAKY,UAAA;EAAA;;;EAIV,gBAAA;EACA,IAAA,EAAM,CAAA;AAAA;;UAIE,cAAA;EACR,GAAA;EACA,KAAA;EACA,UAAA;EACA,UAAA;EACA,IAAA;EAAA;;;;;;;iBASoB,SAAA,QAAiB,cAAA,CAAA,CACrC,GAAA,EAAK,WAAA,EACL,MAAA,WACA,qCAAA,aACC,OAAA,CAAQ,UAAA,CAAW,IAAA"}
|
package/dist/webhook/index.js
CHANGED
|
@@ -1,51 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type = "WebhookSignatureValueError";
|
|
3
|
-
statusCode = 401;
|
|
4
|
-
};
|
|
5
|
-
var WebhookSignatureFormatError = class extends Error {
|
|
6
|
-
type = "WebhookSignatureFormatError";
|
|
7
|
-
statusCode = 400;
|
|
8
|
-
};
|
|
9
|
-
function isSignatureError(error) {
|
|
10
|
-
return typeof error == "object" && error !== null && "type" in error && ["WebhookSignatureValueError", "WebhookSignatureFormatError"].includes(error.type);
|
|
11
|
-
}
|
|
12
|
-
const MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = "sanity-webhook-signature";
|
|
13
|
-
async function assertValidSignature(stringifiedPayload, signature, secret) {
|
|
14
|
-
const { timestamp } = decodeSignatureHeader(signature);
|
|
15
|
-
if (signature !== await encodeSignatureHeader(stringifiedPayload, timestamp, secret)) throw new WebhookSignatureValueError("Signature is invalid");
|
|
16
|
-
}
|
|
17
|
-
async function isValidSignature(stringifiedPayload, signature, secret) {
|
|
18
|
-
try {
|
|
19
|
-
return await assertValidSignature(stringifiedPayload, signature, secret), !0;
|
|
20
|
-
} catch (err) {
|
|
21
|
-
if (isSignatureError(err)) return !1;
|
|
22
|
-
throw err;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {
|
|
26
|
-
return `t=${timestamp},v1=${await createHS256Signature(stringifiedPayload, timestamp, secret)}`;
|
|
27
|
-
}
|
|
28
|
-
function decodeSignatureHeader(signaturePayload) {
|
|
29
|
-
if (!signaturePayload) throw new WebhookSignatureFormatError("Missing or empty signature header");
|
|
30
|
-
const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];
|
|
31
|
-
if (!timestamp || !hashedPayload) throw new WebhookSignatureFormatError("Invalid signature payload format");
|
|
32
|
-
return {
|
|
33
|
-
timestamp: parseInt(timestamp, 10),
|
|
34
|
-
hashedPayload
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async function createHS256Signature(stringifiedPayload, timestamp, secret) {
|
|
38
|
-
if (typeof crypto > "u") throw new TypeError("The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.");
|
|
39
|
-
if (!secret || typeof secret != "string") throw new WebhookSignatureFormatError("Invalid secret provided");
|
|
40
|
-
if (!stringifiedPayload) throw new WebhookSignatureFormatError("Can not create signature for empty payload");
|
|
41
|
-
if (typeof stringifiedPayload != "string") throw new WebhookSignatureFormatError("Payload must be a JSON-encoded string");
|
|
42
|
-
if (typeof timestamp != "number" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP) throw new WebhookSignatureFormatError("Invalid signature timestamp, must be a unix timestamp with millisecond precision");
|
|
43
|
-
const enc = new TextEncoder(), key = await crypto.subtle.importKey("raw", enc.encode(secret), {
|
|
44
|
-
name: "HMAC",
|
|
45
|
-
hash: "SHA-256"
|
|
46
|
-
}, !1, ["sign"]), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign("HMAC", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));
|
|
47
|
-
return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
48
|
-
}
|
|
1
|
+
import { SIGNATURE_HEADER_NAME, isValidSignature } from "@sanity/webhook";
|
|
49
2
|
async function parseBody(req, secret, waitForContentLakeEventualConsistency = true) {
|
|
50
3
|
const signature = req.headers.get(SIGNATURE_HEADER_NAME);
|
|
51
4
|
if (!signature) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/webhook/index.ts"],"sourcesContent":["import type {NextRequest} from 'next/server'\n\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/** @public */\ninterface SanityDocument {\n _id: string\n _type: string\n _createdAt: string\n _updatedAt: string\n _rev: string\n [key: string]: unknown\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"mappings":";AA4BA,eAAsB,UACpB,KACA,QACA,wCAAwC,MACb;CAC3B,MAAM,YAAY,IAAI,QAAQ,IAAI,sBAAsB;AACxD,KAAI,CAAC,WAAW;AACd,UAAQ,MAAM,2BAA2B;AACzC,SAAO;GAAC,MAAM;GAAM,kBAAkB;GAAK;;CAG7C,MAAM,OAAO,MAAM,IAAI,MAAM;CAC7B,MAAM,iBAAiB,SAAS,MAAM,iBAAiB,MAAM,WAAW,OAAO,MAAM,CAAC,GAAG;AAEzF,KAAI,mBAAmB,SAAS,sCAC9B,OAAM,IAAI,SAAS,YAAY,WAAW,SAAS,IAAK,CAAC;AAG3D,QAAO;EACL,MAAM,KAAK,MAAM,GAAG,KAAK,MAAM,KAAK,GAAG;EACvC,kBAAkB;EACnB"}
|
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.22",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"live",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"exports": {
|
|
40
40
|
".": "./dist/index.js",
|
|
41
|
-
"./cache-life": "./dist/cache-life.js",
|
|
42
41
|
"./draft-mode": "./dist/draft-mode/index.js",
|
|
43
42
|
"./hooks": "./dist/hooks/index.js",
|
|
44
43
|
"./image": "./dist/image/index.js",
|
|
@@ -47,6 +46,7 @@
|
|
|
47
46
|
"react-server": "./dist/live/conditions/react-server/index.js",
|
|
48
47
|
"default": "./dist/live/conditions/default/index.js"
|
|
49
48
|
},
|
|
49
|
+
"./live/cache-life": "./dist/live/cache-life.js",
|
|
50
50
|
"./live/client-components": "./dist/live/client-components/index.js",
|
|
51
51
|
"./live/server-actions": {
|
|
52
52
|
"next-js": "./dist/live/server-actions/index.next-js.js",
|
|
@@ -62,45 +62,43 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@portabletext/react": "^6.0.2",
|
|
65
|
-
"@sanity/client": "^7.14.
|
|
65
|
+
"@sanity/client": "^7.14.1",
|
|
66
66
|
"@sanity/comlink": "^4.0.1",
|
|
67
67
|
"@sanity/presentation-comlink": "^2.0.1",
|
|
68
|
-
"@sanity/preview-url-secret": "^4.0.
|
|
69
|
-
"@sanity/visual-editing": "^5.1
|
|
68
|
+
"@sanity/preview-url-secret": "^4.0.3",
|
|
69
|
+
"@sanity/visual-editing": "^5.2.1",
|
|
70
|
+
"@sanity/webhook": "^4.0.4",
|
|
70
71
|
"dequal": "^2.0.3",
|
|
71
|
-
"groq": "^5.
|
|
72
|
+
"groq": "^5.8.1",
|
|
72
73
|
"history": "^5.3.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@sanity/browserslist-config": "^1.0.5",
|
|
76
76
|
"@sanity/tsconfig": "^2.1.0",
|
|
77
|
-
"@sanity/webhook": "4.0.4",
|
|
78
77
|
"@types/js-yaml": "^4.0.9",
|
|
79
|
-
"@types/node": "^24.10.
|
|
80
|
-
"@types/react": "^19.2.
|
|
78
|
+
"@types/node": "^24.10.11",
|
|
79
|
+
"@types/react": "^19.2.13",
|
|
81
80
|
"@types/react-dom": "^19.2.3",
|
|
82
|
-
"@vitejs/plugin-react": "^5.1.
|
|
83
|
-
"@vitest/coverage-v8": "^4.0.
|
|
81
|
+
"@vitejs/plugin-react": "^5.1.3",
|
|
82
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
84
83
|
"js-yaml": "^4.1.1",
|
|
85
|
-
"next": "16.
|
|
86
|
-
"publint": "^0.3.
|
|
87
|
-
"react": "^19.2.
|
|
88
|
-
"react-dom": "^19.2.
|
|
84
|
+
"next": "16.2.0-canary.29",
|
|
85
|
+
"publint": "^0.3.17",
|
|
86
|
+
"react": "^19.2.4",
|
|
87
|
+
"react-dom": "^19.2.4",
|
|
89
88
|
"styled-components": "^6.3.8",
|
|
90
|
-
"tsdown": "0.
|
|
89
|
+
"tsdown": "0.20.3",
|
|
91
90
|
"typescript": "5.9.3",
|
|
92
|
-
"vitest": "^4.0.
|
|
93
|
-
"vitest-package-exports": "^1.
|
|
91
|
+
"vitest": "^4.0.18",
|
|
92
|
+
"vitest-package-exports": "^1.2.0"
|
|
94
93
|
},
|
|
95
94
|
"peerDependencies": {
|
|
96
|
-
"@sanity/client": "^7.14.
|
|
95
|
+
"@sanity/client": "^7.14.1",
|
|
97
96
|
"next": "^16.0.0-0",
|
|
98
97
|
"react": "^19.2.3",
|
|
99
98
|
"react-dom": "^19.2.3",
|
|
100
|
-
"sanity": "^5.
|
|
99
|
+
"sanity": "^5.8.1",
|
|
101
100
|
"styled-components": "^6.1"
|
|
102
101
|
},
|
|
103
|
-
"browserslist": "extends @sanity/browserslist-config",
|
|
104
102
|
"engines": {
|
|
105
103
|
"node": ">=20.19 <22 || >=22.12"
|
|
106
104
|
},
|
package/dist/cache-life.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-life.d.ts","names":[],"sources":["../src/cache-life.ts"],"sourcesContent":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa"}
|
package/dist/cache-life.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-life.js","names":[],"sources":["../src/cache-life.ts"],"sourcesContent":["import {revalidate} from '#live/constants'\n\n/**\n * For usage with `cacheComponents: true`, and `defineLive`:\n * ```ts\n * // next.config.ts\n *\n * import type {NextConfig} from 'next'\n * import {sanity} from 'next-sanity/cache-life'\n *\n * const nextConfig: NextConfig = {\n * cacheComponents: true,\n * cacheLife: {\n * sanity\n * }\n * }\n *\n * export default nextConfig\n * ```\n *\n * ```ts\n *\n * async function sanityFetch() {\n * 'use cache'\n * cacheLife('sanity')\n * const {data} = await fetch({query, params})\n * return data\n * }\n */\nexport const sanity = {\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short\n */\n revalidate: 31_536_000, // 365 days\n} as const satisfies {\n /**\n * This cache may be stale on clients for ... seconds before checking with the server.\n */\n stale?: number\n /**\n * If the server receives a new request after ... seconds, start revalidating new values in the background.\n */\n revalidate?: typeof revalidate\n /**\n * If this entry has no traffic for ... seconds it will expire. The next request will recompute it.\n */\n expire?: number\n}\n"],"mappings":"AA6BA,MAAa,SAAS,EAIpB,YAAY,SACb"}
|
|
File without changes
|
|
File without changes
|