@prismicio/next 2.3.1-pr.147.f16ccf2 → 2.3.1-pr.148.3e4f6ec

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.
Files changed (53) hide show
  1. package/dist/PrismicNextLink.d.cts +3 -3
  2. package/dist/PrismicNextLink.d.ts +3 -3
  3. package/dist/exitPreview.cjs +16 -4
  4. package/dist/exitPreview.cjs.map +1 -1
  5. package/dist/exitPreview.d.cts.map +1 -1
  6. package/dist/exitPreview.d.ts.map +1 -1
  7. package/dist/exitPreview.js +15 -4
  8. package/dist/exitPreview.js.map +1 -1
  9. package/dist/getPreviewRef.cjs +2 -2
  10. package/dist/getPreviewRef.cjs.map +1 -1
  11. package/dist/getPreviewRef.d.cts.map +1 -1
  12. package/dist/getPreviewRef.d.ts.map +1 -1
  13. package/dist/getPreviewRef.js +2 -2
  14. package/dist/getPreviewRef.js.map +1 -1
  15. package/dist/package.cjs +1 -1
  16. package/dist/package.js +1 -1
  17. package/dist/pages/exitPreview.cjs +0 -4
  18. package/dist/pages/exitPreview.cjs.map +1 -1
  19. package/dist/pages/exitPreview.d.cts.map +1 -1
  20. package/dist/pages/exitPreview.d.ts.map +1 -1
  21. package/dist/pages/exitPreview.js +0 -4
  22. package/dist/pages/exitPreview.js.map +1 -1
  23. package/dist/pages/setPreviewData.cjs +1 -9
  24. package/dist/pages/setPreviewData.cjs.map +1 -1
  25. package/dist/pages/setPreviewData.d.cts.map +1 -1
  26. package/dist/pages/setPreviewData.d.ts.map +1 -1
  27. package/dist/pages/setPreviewData.js +1 -9
  28. package/dist/pages/setPreviewData.js.map +1 -1
  29. package/dist/pages/types.d.cts +0 -1
  30. package/dist/pages/types.d.cts.map +1 -1
  31. package/dist/pages/types.d.ts +0 -1
  32. package/dist/pages/types.d.ts.map +1 -1
  33. package/dist/redirectToPreviewURL.cjs +9 -4
  34. package/dist/redirectToPreviewURL.cjs.map +1 -1
  35. package/dist/redirectToPreviewURL.js +9 -4
  36. package/dist/redirectToPreviewURL.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/exitPreview.ts +20 -16
  39. package/src/getPreviewRef.ts +6 -6
  40. package/src/pages/exitPreview.ts +0 -21
  41. package/src/pages/setPreviewData.ts +1 -13
  42. package/src/pages/types.ts +0 -1
  43. package/src/redirectToPreviewURL.ts +12 -11
  44. package/dist/lib/expiredPreviewCookies.cjs +0 -27
  45. package/dist/lib/expiredPreviewCookies.cjs.map +0 -1
  46. package/dist/lib/expiredPreviewCookies.js +0 -25
  47. package/dist/lib/expiredPreviewCookies.js.map +0 -1
  48. package/dist/lib/previewRefFromCookie.cjs +0 -24
  49. package/dist/lib/previewRefFromCookie.cjs.map +0 -1
  50. package/dist/lib/previewRefFromCookie.js +0 -24
  51. package/dist/lib/previewRefFromCookie.js.map +0 -1
  52. package/src/lib/expiredPreviewCookies.ts +0 -32
  53. package/src/lib/previewRefFromCookie.ts +0 -33
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -1,4 +1,5 @@
1
- const require_expiredPreviewCookies = require("./lib/expiredPreviewCookies.cjs");
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
+ let _prismicio_client = require("@prismicio/client");
2
3
  //#region src/exitPreview.ts
3
4
  /**
4
5
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -16,9 +17,20 @@ const require_expiredPreviewCookies = require("./lib/expiredPreviewCookies.cjs")
16
17
  * ```
17
18
  */
18
19
  async function exitPreview() {
19
- const headers = new Headers({ "Cache-Control": "no-store" });
20
- for (const setCookie of [...require_expiredPreviewCookies.expiredPreviewCookieHeaders(), ...require_expiredPreviewCookies.expiredDraftModeCookieHeaders()]) headers.append("Set-Cookie", setCookie);
21
- return new Response(JSON.stringify({ success: true }), { headers });
20
+ const { cookies, draftMode } = await import("next/headers.js");
21
+ (await draftMode()).disable();
22
+ const cookieJar = await cookies();
23
+ cookieJar.delete({
24
+ name: "__prerender_bypass",
25
+ sameSite: "none",
26
+ secure: true
27
+ });
28
+ cookieJar.delete({
29
+ name: _prismicio_client.cookie.preview,
30
+ sameSite: "none",
31
+ secure: true
32
+ });
33
+ return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
22
34
  }
23
35
  //#endregion
24
36
  exports.exitPreview = exitPreview;
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.cjs","names":["expiredPreviewCookieHeaders","expiredDraftModeCookieHeaders"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import {\n\texpiredDraftModeCookieHeaders,\n\texpiredPreviewCookieHeaders,\n} from \"./lib/expiredPreviewCookies\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Do not call `cookies()` or `draftMode().disable()`. ResponseCookies is\n\t// name-keyed: `appendMutableCookies` rebuilds Set-Cookie by name and drops\n\t// the extra Lax expire. Emit every expire on the Response instead:\n\t// toolbar Lax + iframe None; Secure for `io.prismic.preview`, and both\n\t// shapes of `__prerender_bypass` that `disable()` would have cleared.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,eAAsB,cAAiC;CAMtD,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAa,CAAC,GAAGA,8BAAAA,6BAA6B,EAAE,GAAGC,8BAAAA,+BAA+B,CAAC,CAC7F,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
1
+ {"version":3,"file":"exitPreview.cjs","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// Expire both cookies with the attributes `redirectToPreviewURL` used.\n\t// `draftMode().disable()` uses `SameSite=Lax` in development, which a\n\t// cross-site iframe cannot clear.\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;CAK9B,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChF,WAAU,OAAO;EAAE,MAAMA,kBAAAA,OAAc;EAAS,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGjF,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1,4 +1,4 @@
1
- import { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies.js";
1
+ import { cookie } from "@prismicio/client";
2
2
  //#region src/exitPreview.ts
3
3
  /**
4
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -16,9 +16,20 @@ import { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders } from "./li
16
16
  * ```
17
17
  */
18
18
  async function exitPreview() {
19
- const headers = new Headers({ "Cache-Control": "no-store" });
20
- for (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) headers.append("Set-Cookie", setCookie);
21
- return new Response(JSON.stringify({ success: true }), { headers });
19
+ const { cookies, draftMode } = await import("next/headers.js");
20
+ (await draftMode()).disable();
21
+ const cookieJar = await cookies();
22
+ cookieJar.delete({
23
+ name: "__prerender_bypass",
24
+ sameSite: "none",
25
+ secure: true
26
+ });
27
+ cookieJar.delete({
28
+ name: cookie.preview,
29
+ sameSite: "none",
30
+ secure: true
31
+ });
32
+ return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
22
33
  }
23
34
  //#endregion
24
35
  export { exitPreview };
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["import {\n\texpiredDraftModeCookieHeaders,\n\texpiredPreviewCookieHeaders,\n} from \"./lib/expiredPreviewCookies\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Do not call `cookies()` or `draftMode().disable()`. ResponseCookies is\n\t// name-keyed: `appendMutableCookies` rebuilds Set-Cookie by name and drops\n\t// the extra Lax expire. Emit every expire on the Response instead:\n\t// toolbar Lax + iframe None; Secure for `io.prismic.preview`, and both\n\t// shapes of `__prerender_bypass` that `disable()` would have cleared.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,eAAsB,cAAiC;CAMtD,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAa,CAAC,GAAG,6BAA6B,EAAE,GAAG,+BAA+B,CAAC,CAC7F,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
1
+ {"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// Expire both cookies with the attributes `redirectToPreviewURL` used.\n\t// `draftMode().disable()` uses `SameSite=Lax` in development, which a\n\t// cross-site iframe cannot clear.\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;CAK9B,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChF,WAAU,OAAO;EAAE,MAAMA,OAAc;EAAS,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGjF,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
@@ -1,5 +1,4 @@
1
1
  require("./_virtual/_rolldown/runtime.cjs");
2
- const require_previewRefFromCookie = require("./lib/previewRefFromCookie.cjs");
3
2
  let _prismicio_client = require("@prismicio/client");
4
3
  //#region src/getPreviewRef.ts
5
4
  /**
@@ -30,7 +29,8 @@ async function getPreviewRef() {
30
29
  if (!isDraftModeEnabled) return;
31
30
  const cookie = (await cookies()).get(_prismicio_client.cookie.preview)?.value;
32
31
  if (!cookie) return;
33
- return require_previewRefFromCookie.previewRefFromCookie(cookie);
32
+ if (!cookie.includes("websitePreviewId=")) return;
33
+ return cookie;
34
34
  }
35
35
  //#endregion
36
36
  exports.getPreviewRef = getPreviewRef;
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewRef.cjs","names":["prismicCookie","previewRefFromCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { previewRefFromCookie } from \"./lib/previewRefFromCookie\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\t// Draft Mode gates preview reads. The cookie may be a raw token or the\n\t// toolbar jar (`{ \"<repo>.prismic.io\": { preview } }`). Only `preview` is a\n\t// Content API ref; the jar string is not.\n\treturn previewRefFromCookie(cookie)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAM,UAAU,MAAM,SAAS,EAAE,IAAIA,kBAAAA,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAAC,OACJ;AAMD,QAAOC,6BAAAA,qBAAqB,OAAO"}
1
+ {"version":3,"file":"getPreviewRef.cjs","names":["prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\tif (!isActiveCookie) {\n\t\treturn\n\t}\n\n\treturn cookie\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAM,UAAU,MAAM,SAAS,EAAE,IAAIA,kBAAAA,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAAC,OACJ;AAID,KAAI,CADmB,OAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewRef.d.cts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAqBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
1
+ {"version":3,"file":"getPreviewRef.d.cts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewRef.d.ts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAqBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
1
+ {"version":3,"file":"getPreviewRef.d.ts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -1,4 +1,3 @@
1
- import { previewRefFromCookie } from "./lib/previewRefFromCookie.js";
2
1
  import { cookie } from "@prismicio/client";
3
2
  //#region src/getPreviewRef.ts
4
3
  /**
@@ -29,7 +28,8 @@ async function getPreviewRef() {
29
28
  if (!isDraftModeEnabled) return;
30
29
  const cookie$1 = (await cookies()).get(cookie.preview)?.value;
31
30
  if (!cookie$1) return;
32
- return previewRefFromCookie(cookie$1);
31
+ if (!cookie$1.includes("websitePreviewId=")) return;
32
+ return cookie$1;
33
33
  }
34
34
  //#endregion
35
35
  export { getPreviewRef };
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewRef.js","names":["cookie","prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { previewRefFromCookie } from \"./lib/previewRefFromCookie\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\t// Draft Mode gates preview reads. The cookie may be a raw token or the\n\t// toolbar jar (`{ \"<repo>.prismic.io\": { preview } }`). Only `preview` is a\n\t// Content API ref; the jar string is not.\n\treturn previewRefFromCookie(cookie)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAMA,YAAU,MAAM,SAAS,EAAE,IAAIC,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAACD,SACJ;AAMD,QAAO,qBAAqBA,SAAO"}
1
+ {"version":3,"file":"getPreviewRef.js","names":["cookie","prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\tif (!isActiveCookie) {\n\t\treturn\n\t}\n\n\treturn cookie\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAMA,YAAU,MAAM,SAAS,EAAE,IAAIC,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAACD,SACJ;AAID,KAAI,CADmBA,SAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAOA"}
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.147.f16ccf2";
2
+ var version = "2.3.1-pr.148.3e4f6ec";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.147.f16ccf2";
2
+ var version = "2.3.1-pr.148.3e4f6ec";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -1,4 +1,3 @@
1
- const require_expiredPreviewCookies = require("../lib/expiredPreviewCookies.cjs");
2
1
  //#region src/pages/exitPreview.ts
3
2
  /**
4
3
  * Ends a Prismic preview session within a Next.js app. This function should be used in an API
@@ -17,9 +16,6 @@ const require_expiredPreviewCookies = require("../lib/expiredPreviewCookies.cjs"
17
16
  */
18
17
  function exitPreview(config) {
19
18
  config.res.clearPreviewData();
20
- const existingSetCookie = config.res.getHeader("Set-Cookie");
21
- const expiredPreviewCookies = require_expiredPreviewCookies.expiredPreviewCookieHeaders();
22
- config.res.setHeader("Set-Cookie", existingSetCookie == null ? expiredPreviewCookies : [...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(String), ...expiredPreviewCookies]);
23
19
  config.res.setHeader("Cache-Control", "no-store");
24
20
  config.res.json({ success: true });
25
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.cjs","names":["expiredPreviewCookieHeaders"],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"../lib/expiredPreviewCookies\"\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in an API\n * route.\n *\n * @example\n * \t;```typescript\n * \t// src/pages/api/exit-preview.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport default function handler(_req, res) {\n * \t\treturn exitPreview({ res })\n * \t}\n * \t```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData()\n\n\t// `clearPreviewData()` only clears Next.js preview cookies. Expire both\n\t// leftover `io.prismic.preview` shapes (toolbar Lax, not Secure; and the\n\t// iframe SameSite=None; Secure write). If either survives,\n\t// `<PrismicPreview>` calls `start()` → `/api/preview` and preview returns.\n\t// Do not use `cookies().set` — that is the App Router helper. Do not\n\t// replace the existing Set-Cookie header from `clearPreviewData()`.\n\tconst existingSetCookie = config.res.getHeader(\"Set-Cookie\")\n\tconst expiredPreviewCookies = expiredPreviewCookieHeaders()\n\tconfig.res.setHeader(\n\t\t\"Set-Cookie\",\n\t\texistingSetCookie == null\n\t\t\t? expiredPreviewCookies\n\t\t\t: [\n\t\t\t\t\t...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(\n\t\t\t\t\t\tString,\n\t\t\t\t\t),\n\t\t\t\t\t...expiredPreviewCookies,\n\t\t\t\t],\n\t)\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\")\n\n\tconfig.res.json({ success: true })\n\n\treturn\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;CAQ7B,MAAM,oBAAoB,OAAO,IAAI,UAAU,aAAa;CAC5D,MAAM,wBAAwBA,8BAAAA,6BAA6B;AAC3D,QAAO,IAAI,UACV,cACA,qBAAqB,OAClB,wBACA,CACA,IAAI,MAAM,QAAQ,kBAAkB,GAAG,oBAAoB,CAAC,kBAAkB,EAAE,IAC/E,OACA,EACD,GAAG,sBACH,CACH;AAGD,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
1
+ {"version":3,"file":"exitPreview.cjs","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in an API\n * route.\n *\n * @example\n * \t;```typescript\n * \t// src/pages/api/exit-preview.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport default function handler(_req, res) {\n * \t\treturn exitPreview({ res })\n * \t}\n * \t```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData()\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\")\n\n\tconfig.res.json({ success: true })\n\n\treturn\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;AAG7B,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;KAIY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
1
+ {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;KAGY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;KAIY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
1
+ {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;KAGY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
@@ -1,4 +1,3 @@
1
- import { expiredPreviewCookieHeaders } from "../lib/expiredPreviewCookies.js";
2
1
  //#region src/pages/exitPreview.ts
3
2
  /**
4
3
  * Ends a Prismic preview session within a Next.js app. This function should be used in an API
@@ -17,9 +16,6 @@ import { expiredPreviewCookieHeaders } from "../lib/expiredPreviewCookies.js";
17
16
  */
18
17
  function exitPreview(config) {
19
18
  config.res.clearPreviewData();
20
- const existingSetCookie = config.res.getHeader("Set-Cookie");
21
- const expiredPreviewCookies = expiredPreviewCookieHeaders();
22
- config.res.setHeader("Set-Cookie", existingSetCookie == null ? expiredPreviewCookies : [...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(String), ...expiredPreviewCookies]);
23
19
  config.res.setHeader("Cache-Control", "no-store");
24
20
  config.res.json({ success: true });
25
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"../lib/expiredPreviewCookies\"\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in an API\n * route.\n *\n * @example\n * \t;```typescript\n * \t// src/pages/api/exit-preview.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport default function handler(_req, res) {\n * \t\treturn exitPreview({ res })\n * \t}\n * \t```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData()\n\n\t// `clearPreviewData()` only clears Next.js preview cookies. Expire both\n\t// leftover `io.prismic.preview` shapes (toolbar Lax, not Secure; and the\n\t// iframe SameSite=None; Secure write). If either survives,\n\t// `<PrismicPreview>` calls `start()` → `/api/preview` and preview returns.\n\t// Do not use `cookies().set` — that is the App Router helper. Do not\n\t// replace the existing Set-Cookie header from `clearPreviewData()`.\n\tconst existingSetCookie = config.res.getHeader(\"Set-Cookie\")\n\tconst expiredPreviewCookies = expiredPreviewCookieHeaders()\n\tconfig.res.setHeader(\n\t\t\"Set-Cookie\",\n\t\texistingSetCookie == null\n\t\t\t? expiredPreviewCookies\n\t\t\t: [\n\t\t\t\t\t...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(\n\t\t\t\t\t\tString,\n\t\t\t\t\t),\n\t\t\t\t\t...expiredPreviewCookies,\n\t\t\t\t],\n\t)\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\")\n\n\tconfig.res.json({ success: true })\n\n\treturn\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;CAQ7B,MAAM,oBAAoB,OAAO,IAAI,UAAU,aAAa;CAC5D,MAAM,wBAAwB,6BAA6B;AAC3D,QAAO,IAAI,UACV,cACA,qBAAqB,OAClB,wBACA,CACA,IAAI,MAAM,QAAQ,kBAAkB,GAAG,oBAAoB,CAAC,kBAAkB,EAAE,IAC/E,OACA,EACD,GAAG,sBACH,CACH;AAGD,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
1
+ {"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in an API\n * route.\n *\n * @example\n * \t;```typescript\n * \t// src/pages/api/exit-preview.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport default function handler(_req, res) {\n * \t\treturn exitPreview({ res })\n * \t}\n * \t```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData()\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\")\n\n\tconfig.res.json({ success: true })\n\n\treturn\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;AAG7B,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
@@ -1,17 +1,9 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
- const require_previewRefFromCookie = require("../lib/previewRefFromCookie.cjs");
3
2
  let _prismicio_client = require("@prismicio/client");
4
3
  //#region src/pages/setPreviewData.ts
5
4
  /** Set Prismic preview data for Next.js's Preview Mode. */
6
5
  function setPreviewData({ req, res }) {
7
- const token = req.query.token;
8
- if (token) {
9
- res.setPreviewData({ ref: token });
10
- return;
11
- }
12
- const previewCookie = req.cookies[_prismicio_client.cookie.preview];
13
- if (!previewCookie) return;
14
- const ref = require_previewRefFromCookie.previewRefFromCookie(previewCookie);
6
+ const ref = req.query.token || req.cookies[_prismicio_client.cookie.preview];
15
7
  if (ref) res.setPreviewData({ ref });
16
8
  }
17
9
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"setPreviewData.cjs","names":["cookie","previewRefFromCookie"],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport { previewRefFromCookie } from \"../lib/previewRefFromCookie\"\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst token = req.query.token\n\tif (token) {\n\t\tres.setPreviewData({ ref: token })\n\t\treturn\n\t}\n\n\t// Cookie-only path: unwrap the toolbar jar. `token` stays as-is above.\n\tconst previewCookie = req.cookies[cookie.preview]\n\tif (!previewCookie) {\n\t\treturn\n\t}\n\n\tconst ref = previewRefFromCookie(previewCookie)\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;;;AAuBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,QAAQ,IAAI,MAAM;AACxB,KAAI,OAAO;AACV,MAAI,eAAe,EAAE,KAAK,OAAO,CAAC;AAClC;;CAID,MAAM,gBAAgB,IAAI,QAAQA,kBAAAA,OAAO;AACzC,KAAI,CAAC,cACJ;CAGD,MAAM,MAAMC,6BAAAA,qBAAqB,cAAc;AAC/C,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
1
+ {"version":3,"file":"setPreviewData.cjs","names":["cookie"],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview]\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,kBAAAA,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"setPreviewData.d.cts","names":[],"sources":["../../src/pages/setPreviewData.ts"],"mappings":";;;;KAMY,oBAAA;EAAA;;;;;EAMX,GAAA,EAAK,kBAAA;EAOL;;;;AAID;EAJC,GAAA,EAAK,mBAAA;AAAA;;iBAIU,cAAA,CAAA;EAAiB,GAAA;EAAK;AAAA,GAAO,oBAAA"}
1
+ {"version":3,"file":"setPreviewData.d.cts","names":[],"sources":["../../src/pages/setPreviewData.ts"],"mappings":";;;;KAKY,oBAAA;EAAA;;;;;EAMX,GAAA,EAAK,kBAAA;EAOL;;;;AAID;EAJC,GAAA,EAAK,mBAAA;AAAA;;iBAIU,cAAA,CAAA;EAAiB,GAAA;EAAK;AAAA,GAAO,oBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"setPreviewData.d.ts","names":[],"sources":["../../src/pages/setPreviewData.ts"],"mappings":";;;;KAMY,oBAAA;EAAA;;;;;EAMX,GAAA,EAAK,kBAAA;EAOL;;;;AAID;EAJC,GAAA,EAAK,mBAAA;AAAA;;iBAIU,cAAA,CAAA;EAAiB,GAAA;EAAK;AAAA,GAAO,oBAAA"}
1
+ {"version":3,"file":"setPreviewData.d.ts","names":[],"sources":["../../src/pages/setPreviewData.ts"],"mappings":";;;;KAKY,oBAAA;EAAA;;;;;EAMX,GAAA,EAAK,kBAAA;EAOL;;;;AAID;EAJC,GAAA,EAAK,mBAAA;AAAA;;iBAIU,cAAA,CAAA;EAAiB,GAAA;EAAK;AAAA,GAAO,oBAAA"}
@@ -1,16 +1,8 @@
1
- import { previewRefFromCookie } from "../lib/previewRefFromCookie.js";
2
1
  import { cookie } from "@prismicio/client";
3
2
  //#region src/pages/setPreviewData.ts
4
3
  /** Set Prismic preview data for Next.js's Preview Mode. */
5
4
  function setPreviewData({ req, res }) {
6
- const token = req.query.token;
7
- if (token) {
8
- res.setPreviewData({ ref: token });
9
- return;
10
- }
11
- const previewCookie = req.cookies[cookie.preview];
12
- if (!previewCookie) return;
13
- const ref = previewRefFromCookie(previewCookie);
5
+ const ref = req.query.token || req.cookies[cookie.preview];
14
6
  if (ref) res.setPreviewData({ ref });
15
7
  }
16
8
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport { previewRefFromCookie } from \"../lib/previewRefFromCookie\"\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst token = req.query.token\n\tif (token) {\n\t\tres.setPreviewData({ ref: token })\n\t\treturn\n\t}\n\n\t// Cookie-only path: unwrap the toolbar jar. `token` stays as-is above.\n\tconst previewCookie = req.cookies[cookie.preview]\n\tif (!previewCookie) {\n\t\treturn\n\t}\n\n\tconst ref = previewRefFromCookie(previewCookie)\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;;AAuBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,QAAQ,IAAI,MAAM;AACxB,KAAI,OAAO;AACV,MAAI,eAAe,EAAE,KAAK,OAAO,CAAC;AAClC;;CAID,MAAM,gBAAgB,IAAI,QAAQ,OAAO;AACzC,KAAI,CAAC,cACJ;CAGD,MAAM,MAAM,qBAAqB,cAAc;AAC/C,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
1
+ {"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview]\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
@@ -21,7 +21,6 @@ type NextApiRequestLike = {
21
21
  type NextApiResponseLike = {
22
22
  redirect(url: string): NextApiResponseLike;
23
23
  clearPreviewData(): NextApiResponseLike;
24
- getHeader(name: string): number | string | string[] | undefined;
25
24
  setHeader(name: string, value: string | string[]): NextApiResponseLike;
26
25
  json(body: any): void;
27
26
  setPreviewData(data: object | string): NextApiResponseLike;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA;EACV,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
@@ -21,7 +21,6 @@ type NextApiRequestLike = {
21
21
  type NextApiResponseLike = {
22
22
  redirect(url: string): NextApiResponseLike;
23
23
  clearPreviewData(): NextApiResponseLike;
24
- getHeader(name: string): number | string | string[] | undefined;
25
24
  setHeader(name: string, value: string | string[]): NextApiResponseLike;
26
25
  json(body: any): void;
27
26
  setPreviewData(data: object | string): NextApiResponseLike;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA;EACV,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
@@ -6,12 +6,11 @@ async function redirectToPreviewURL(config) {
6
6
  const { cookies, draftMode } = await import("next/headers.js");
7
7
  const { redirect } = await import("next/navigation");
8
8
  const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
9
+ const cookieJar = await cookies();
9
10
  const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
10
- if (previewToken) (await cookies()).set(_prismicio_client.cookie.preview, previewToken, {
11
- path: "/",
11
+ if (previewToken) cookieJar.set(_prismicio_client.cookie.preview, previewToken, {
12
12
  sameSite: "none",
13
- secure: true,
14
- httpOnly: false
13
+ secure: true
15
14
  });
16
15
  const previewURL = await client.resolvePreviewURL({
17
16
  documentID,
@@ -20,6 +19,12 @@ async function redirectToPreviewURL(config) {
20
19
  linkResolver
21
20
  });
22
21
  (await draftMode()).enable();
22
+ const draftCookie = cookieJar.get("__prerender_bypass");
23
+ if (draftCookie) cookieJar.set({
24
+ ...draftCookie,
25
+ sameSite: "none",
26
+ secure: true
27
+ });
23
28
  return redirect(previewURL);
24
29
  }
25
30
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Path=/; SameSite=None; Secure so the cookie is sent when the site is\n\t// embedded in a cross-site iframe (e.g. the Platform editor). Chrome\n\t// defaults omitted SameSite to Lax and strips the cookie from those\n\t// requests. Do not set HttpOnly: the toolbar reads `document.cookie`.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies()\n\t\tcookieJar.set(prismicCookie.preview, previewToken, {\n\t\t\tpath: \"/\",\n\t\t\tsameSite: \"none\",\n\t\t\tsecure: true,\n\t\t\thttpOnly: false,\n\t\t})\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAWrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,kBAAAA,OAAc,SAAS,cAAc;EAClD,MAAM;EACN,UAAU;EACV,QAAQ;EACR,UAAU;EACV,CAAC;CAGH,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,QAAO,SAAS,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Browsers only send `SameSite=Lax` cookies on same-site requests, so\n\t// `SameSite=None; Secure` is needed for the site to preview inside a\n\t// cross-site iframe, like the Prismic editor.\n\tconst cookieJar = await cookies()\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.\n\t// Rewrite it like the preview cookie, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, sameSite: \"none\", secure: true })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAUrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIA,kBAAAA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;EAAM,CAAC;CAGvF,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAI7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
@@ -5,12 +5,11 @@ async function redirectToPreviewURL(config) {
5
5
  const { cookies, draftMode } = await import("next/headers.js");
6
6
  const { redirect } = await import("next/navigation");
7
7
  const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
8
+ const cookieJar = await cookies();
8
9
  const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
9
- if (previewToken) (await cookies()).set(cookie.preview, previewToken, {
10
- path: "/",
10
+ if (previewToken) cookieJar.set(cookie.preview, previewToken, {
11
11
  sameSite: "none",
12
- secure: true,
13
- httpOnly: false
12
+ secure: true
14
13
  });
15
14
  const previewURL = await client.resolvePreviewURL({
16
15
  documentID,
@@ -19,6 +18,12 @@ async function redirectToPreviewURL(config) {
19
18
  linkResolver
20
19
  });
21
20
  (await draftMode()).enable();
21
+ const draftCookie = cookieJar.get("__prerender_bypass");
22
+ if (draftCookie) cookieJar.set({
23
+ ...draftCookie,
24
+ sameSite: "none",
25
+ secure: true
26
+ });
22
27
  return redirect(previewURL);
23
28
  }
24
29
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Path=/; SameSite=None; Secure so the cookie is sent when the site is\n\t// embedded in a cross-site iframe (e.g. the Platform editor). Chrome\n\t// defaults omitted SameSite to Lax and strips the cookie from those\n\t// requests. Do not set HttpOnly: the toolbar reads `document.cookie`.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies()\n\t\tcookieJar.set(prismicCookie.preview, previewToken, {\n\t\t\tpath: \"/\",\n\t\t\tsameSite: \"none\",\n\t\t\tsecure: true,\n\t\t\thttpOnly: false,\n\t\t})\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAWrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,cAAc;EAClD,MAAM;EACN,UAAU;EACV,QAAQ;EACR,UAAU;EACV,CAAC;CAGH,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,QAAO,SAAS,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Browsers only send `SameSite=Lax` cookies on same-site requests, so\n\t// `SameSite=None; Secure` is needed for the site to preview inside a\n\t// cross-site iframe, like the Prismic editor.\n\tconst cookieJar = await cookies()\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.\n\t// Rewrite it like the preview cookie, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, sameSite: \"none\", secure: true })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAUrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;EAAM,CAAC;CAGvF,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAI7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.3.1-pr.147.f16ccf2",
3
+ "version": "2.3.1-pr.148.3e4f6ec",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "next",
@@ -1,7 +1,4 @@
1
- import {
2
- expiredDraftModeCookieHeaders,
3
- expiredPreviewCookieHeaders,
4
- } from "./lib/expiredPreviewCookies"
1
+ import { cookie as prismicCookie } from "@prismicio/client"
5
2
 
6
3
  /**
7
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -19,17 +16,24 @@ import {
19
16
  * ```
20
17
  */
21
18
  export async function exitPreview(): Promise<Response> {
22
- // Do not call `cookies()` or `draftMode().disable()`. ResponseCookies is
23
- // name-keyed: `appendMutableCookies` rebuilds Set-Cookie by name and drops
24
- // the extra Lax expire. Emit every expire on the Response instead:
25
- // toolbar Lax + iframe None; Secure for `io.prismic.preview`, and both
26
- // shapes of `__prerender_bypass` that `disable()` would have cleared.
27
- const headers = new Headers({
28
- "Cache-Control": "no-store",
29
- })
30
- for (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {
31
- headers.append("Set-Cookie", setCookie)
32
- }
19
+ // Need this to avoid the following Next.js build-time error:
20
+ // You're importing a component that needs next/headers. That only works
21
+ // in a Server Component which is not supported in the pages/ directory.
22
+ const { cookies, draftMode } = await import("next/headers")
23
+
24
+ ;(await draftMode()).disable()
33
25
 
34
- return new Response(JSON.stringify({ success: true }), { headers })
26
+ // Expire both cookies with the attributes `redirectToPreviewURL` used.
27
+ // `draftMode().disable()` uses `SameSite=Lax` in development, which a
28
+ // cross-site iframe cannot clear.
29
+ const cookieJar = await cookies()
30
+ cookieJar.delete({ name: "__prerender_bypass", sameSite: "none", secure: true })
31
+ cookieJar.delete({ name: prismicCookie.preview, sameSite: "none", secure: true })
32
+
33
+ // `Cache-Control` header is used to prevent CDN-level caching.
34
+ return new Response(JSON.stringify({ success: true }), {
35
+ headers: {
36
+ "Cache-Control": "no-store",
37
+ },
38
+ })
35
39
  }
@@ -1,7 +1,5 @@
1
1
  import { cookie as prismicCookie } from "@prismicio/client"
2
2
 
3
- import { previewRefFromCookie } from "./lib/previewRefFromCookie"
4
-
5
3
  /**
6
4
  * Reads the Prismic preview ref for the current request when an active preview session exists.
7
5
  *
@@ -44,8 +42,10 @@ export async function getPreviewRef(): Promise<string | undefined> {
44
42
  return
45
43
  }
46
44
 
47
- // Draft Mode gates preview reads. The cookie may be a raw token or the
48
- // toolbar jar (`{ "<repo>.prismic.io": { preview } }`). Only `preview` is a
49
- // Content API ref; the jar string is not.
50
- return previewRefFromCookie(cookie)
45
+ const isActiveCookie = cookie.includes("websitePreviewId=")
46
+ if (!isActiveCookie) {
47
+ return
48
+ }
49
+
50
+ return cookie
51
51
  }
@@ -1,4 +1,3 @@
1
- import { expiredPreviewCookieHeaders } from "../lib/expiredPreviewCookies"
2
1
  import type { NextApiRequestLike, NextApiResponseLike } from "./types"
3
2
 
4
3
  /** Configuration for `exitPreview()`. */
@@ -36,26 +35,6 @@ export type ExitPreviewAPIRouteConfig = {
36
35
  export function exitPreview(config: ExitPreviewAPIRouteConfig): void {
37
36
  config.res.clearPreviewData()
38
37
 
39
- // `clearPreviewData()` only clears Next.js preview cookies. Expire both
40
- // leftover `io.prismic.preview` shapes (toolbar Lax, not Secure; and the
41
- // iframe SameSite=None; Secure write). If either survives,
42
- // `<PrismicPreview>` calls `start()` → `/api/preview` and preview returns.
43
- // Do not use `cookies().set` — that is the App Router helper. Do not
44
- // replace the existing Set-Cookie header from `clearPreviewData()`.
45
- const existingSetCookie = config.res.getHeader("Set-Cookie")
46
- const expiredPreviewCookies = expiredPreviewCookieHeaders()
47
- config.res.setHeader(
48
- "Set-Cookie",
49
- existingSetCookie == null
50
- ? expiredPreviewCookies
51
- : [
52
- ...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(
53
- String,
54
- ),
55
- ...expiredPreviewCookies,
56
- ],
57
- )
58
-
59
38
  // `Cache-Control` header is used to prevent CDN-level caching.
60
39
  config.res.setHeader("Cache-Control", "no-store")
61
40
 
@@ -1,6 +1,5 @@
1
1
  import { cookie } from "@prismicio/client"
2
2
 
3
- import { previewRefFromCookie } from "../lib/previewRefFromCookie"
4
3
  import type { NextApiRequestLike, NextApiResponseLike } from "./types"
5
4
 
6
5
  /** Configuration for `setPreviewData`. */
@@ -22,19 +21,8 @@ export type SetPreviewDataConfig = {
22
21
 
23
22
  /** Set Prismic preview data for Next.js's Preview Mode. */
24
23
  export function setPreviewData({ req, res }: SetPreviewDataConfig): void {
25
- const token = req.query.token
26
- if (token) {
27
- res.setPreviewData({ ref: token })
28
- return
29
- }
30
-
31
- // Cookie-only path: unwrap the toolbar jar. `token` stays as-is above.
32
- const previewCookie = req.cookies[cookie.preview]
33
- if (!previewCookie) {
34
- return
35
- }
24
+ const ref = req.query.token || req.cookies[cookie.preview]
36
25
 
37
- const ref = previewRefFromCookie(previewCookie)
38
26
  if (ref) {
39
27
  res.setPreviewData({ ref })
40
28
  }
@@ -24,7 +24,6 @@ export type NextApiRequestLike = {
24
24
  export type NextApiResponseLike = {
25
25
  redirect(url: string): NextApiResponseLike
26
26
  clearPreviewData(): NextApiResponseLike
27
- getHeader(name: string): number | string | string[] | undefined
28
27
  setHeader(name: string, value: string | string[]): NextApiResponseLike
29
28
  // oxlint-disable-next-line no-explicit-any explicit-module-boundary-types
30
29
  json(body: any): void
@@ -51,19 +51,13 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
51
51
  // will try to render without the preview cookie, leading to a
52
52
  // PrismicNotFound error.
53
53
  //
54
- // Path=/; SameSite=None; Secure so the cookie is sent when the site is
55
- // embedded in a cross-site iframe (e.g. the Platform editor). Chrome
56
- // defaults omitted SameSite to Lax and strips the cookie from those
57
- // requests. Do not set HttpOnly: the toolbar reads `document.cookie`.
54
+ // Browsers only send `SameSite=Lax` cookies on same-site requests, so
55
+ // `SameSite=None; Secure` is needed for the site to preview inside a
56
+ // cross-site iframe, like the Prismic editor.
57
+ const cookieJar = await cookies()
58
58
  const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
59
59
  if (previewToken) {
60
- const cookieJar = await cookies()
61
- cookieJar.set(prismicCookie.preview, previewToken, {
62
- path: "/",
63
- sameSite: "none",
64
- secure: true,
65
- httpOnly: false,
66
- })
60
+ cookieJar.set(prismicCookie.preview, previewToken, { sameSite: "none", secure: true })
67
61
  }
68
62
 
69
63
  const previewURL = await client.resolvePreviewURL({
@@ -75,5 +69,12 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
75
69
 
76
70
  ;(await draftMode()).enable()
77
71
 
72
+ // Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.
73
+ // Rewrite it like the preview cookie, keeping Next.js's value.
74
+ const draftCookie = cookieJar.get("__prerender_bypass")
75
+ if (draftCookie) {
76
+ cookieJar.set({ ...draftCookie, sameSite: "none", secure: true })
77
+ }
78
+
78
79
  return redirect(previewURL)
79
80
  }
@@ -1,27 +0,0 @@
1
- require("../_virtual/_rolldown/runtime.cjs");
2
- let _prismicio_client = require("@prismicio/client");
3
- //#region src/lib/expiredPreviewCookies.ts
4
- const epoch = /* @__PURE__ */ new Date(0);
5
- function expiresAttr() {
6
- return `Expires=${epoch.toUTCString()}`;
7
- }
8
- /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
9
- function expiredPreviewCookieHeaders(name = _prismicio_client.cookie.preview) {
10
- const expires = expiresAttr();
11
- return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
12
- }
13
- /**
14
- * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`
15
- * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;
16
- * Secure in production.
17
- */
18
- function expiredDraftModeCookieHeaders() {
19
- const expires = expiresAttr();
20
- const name = "__prerender_bypass";
21
- return [`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`, `${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`];
22
- }
23
- //#endregion
24
- exports.expiredDraftModeCookieHeaders = expiredDraftModeCookieHeaders;
25
- exports.expiredPreviewCookieHeaders = expiredPreviewCookieHeaders;
26
-
27
- //# sourceMappingURL=expiredPreviewCookies.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"expiredPreviewCookies.cjs","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\nfunction expiresAttr(): string {\n\treturn `Expires=${epoch.toUTCString()}`\n}\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = expiresAttr()\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n\n/**\n * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`\n * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;\n * Secure in production.\n */\nexport function expiredDraftModeCookieHeaders(): string[] {\n\tconst expires = expiresAttr()\n\tconst name = \"__prerender_bypass\"\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`,\n\t]\n}\n"],"mappings":";;;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;AAEzB,SAAS,cAAsB;AAC9B,QAAO,WAAW,MAAM,aAAa;;;AAItC,SAAgB,4BAA4B,OAAOA,kBAAAA,OAAc,SAAmB;CACnF,MAAM,UAAU,aAAa;AAE7B,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B;;;;;;;AAQF,SAAgB,gCAA0C;CACzD,MAAM,UAAU,aAAa;CAC7B,MAAM,OAAO;AAEb,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,2BAC7B,GAAG,KAAK,aAAa,QAAQ,mCAC7B"}
@@ -1,25 +0,0 @@
1
- import { cookie } from "@prismicio/client";
2
- //#region src/lib/expiredPreviewCookies.ts
3
- const epoch = /* @__PURE__ */ new Date(0);
4
- function expiresAttr() {
5
- return `Expires=${epoch.toUTCString()}`;
6
- }
7
- /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
8
- function expiredPreviewCookieHeaders(name = cookie.preview) {
9
- const expires = expiresAttr();
10
- return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
11
- }
12
- /**
13
- * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`
14
- * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;
15
- * Secure in production.
16
- */
17
- function expiredDraftModeCookieHeaders() {
18
- const expires = expiresAttr();
19
- const name = "__prerender_bypass";
20
- return [`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`, `${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`];
21
- }
22
- //#endregion
23
- export { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders };
24
-
25
- //# sourceMappingURL=expiredPreviewCookies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"expiredPreviewCookies.js","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\nfunction expiresAttr(): string {\n\treturn `Expires=${epoch.toUTCString()}`\n}\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = expiresAttr()\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n\n/**\n * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`\n * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;\n * Secure in production.\n */\nexport function expiredDraftModeCookieHeaders(): string[] {\n\tconst expires = expiresAttr()\n\tconst name = \"__prerender_bypass\"\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`,\n\t]\n}\n"],"mappings":";;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;AAEzB,SAAS,cAAsB;AAC9B,QAAO,WAAW,MAAM,aAAa;;;AAItC,SAAgB,4BAA4B,OAAOA,OAAc,SAAmB;CACnF,MAAM,UAAU,aAAa;AAE7B,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B;;;;;;;AAQF,SAAgB,gCAA0C;CACzD,MAAM,UAAU,aAAa;CAC7B,MAAM,OAAO;AAEb,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,2BAC7B,GAAG,KAAK,aAAa,QAAQ,mCAC7B"}
@@ -1,24 +0,0 @@
1
- //#region src/lib/previewRefFromCookie.ts
2
- /**
3
- * Unwraps `io.prismic.preview` to a Content API ref.
4
- *
5
- * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is
6
- * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`
7
- * / Cache Components send a non-ref (ParsingError / 404). A jar with more than one
8
- * repository `preview` is ambiguous and is ignored.
9
- */
10
- function previewRefFromCookie(cookie) {
11
- try {
12
- const parsed = JSON.parse(cookie);
13
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return;
14
- const previewRefs = [];
15
- for (const value of Object.values(parsed)) if (value !== null && typeof value === "object" && !Array.isArray(value) && "preview" in value && typeof value.preview === "string") previewRefs.push(value.preview);
16
- return previewRefs.length === 1 ? previewRefs[0] : void 0;
17
- } catch {
18
- return cookie;
19
- }
20
- }
21
- //#endregion
22
- exports.previewRefFromCookie = previewRefFromCookie;
23
-
24
- //# sourceMappingURL=previewRefFromCookie.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"previewRefFromCookie.cjs","names":[],"sources":["../../src/lib/previewRefFromCookie.ts"],"sourcesContent":["/**\n * Unwraps `io.prismic.preview` to a Content API ref.\n *\n * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is\n * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`\n * / Cache Components send a non-ref (ParsingError / 404). A jar with more than one\n * repository `preview` is ambiguous and is ignored.\n */\nexport function previewRefFromCookie(cookie: string): string | undefined {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(cookie)\n\t\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\t\treturn\n\t\t}\n\n\t\tconst previewRefs: string[] = []\n\t\tfor (const value of Object.values(parsed)) {\n\t\t\tif (\n\t\t\t\tvalue !== null &&\n\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t!Array.isArray(value) &&\n\t\t\t\t\"preview\" in value &&\n\t\t\t\ttypeof value.preview === \"string\"\n\t\t\t) {\n\t\t\t\tpreviewRefs.push(value.preview)\n\t\t\t}\n\t\t}\n\n\t\treturn previewRefs.length === 1 ? previewRefs[0] : undefined\n\t} catch {\n\t\treturn cookie\n\t}\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,qBAAqB,QAAoC;AACxE,KAAI;EACH,MAAM,SAAkB,KAAK,MAAM,OAAO;AAC1C,MAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,CACzE;EAGD,MAAM,cAAwB,EAAE;AAChC,OAAK,MAAM,SAAS,OAAO,OAAO,OAAO,CACxC,KACC,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,MAAM,IACrB,aAAa,SACb,OAAO,MAAM,YAAY,SAEzB,aAAY,KAAK,MAAM,QAAQ;AAIjC,SAAO,YAAY,WAAW,IAAI,YAAY,KAAK,KAAA;SAC5C;AACP,SAAO"}
@@ -1,24 +0,0 @@
1
- //#region src/lib/previewRefFromCookie.ts
2
- /**
3
- * Unwraps `io.prismic.preview` to a Content API ref.
4
- *
5
- * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is
6
- * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`
7
- * / Cache Components send a non-ref (ParsingError / 404). A jar with more than one
8
- * repository `preview` is ambiguous and is ignored.
9
- */
10
- function previewRefFromCookie(cookie) {
11
- try {
12
- const parsed = JSON.parse(cookie);
13
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return;
14
- const previewRefs = [];
15
- for (const value of Object.values(parsed)) if (value !== null && typeof value === "object" && !Array.isArray(value) && "preview" in value && typeof value.preview === "string") previewRefs.push(value.preview);
16
- return previewRefs.length === 1 ? previewRefs[0] : void 0;
17
- } catch {
18
- return cookie;
19
- }
20
- }
21
- //#endregion
22
- export { previewRefFromCookie };
23
-
24
- //# sourceMappingURL=previewRefFromCookie.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"previewRefFromCookie.js","names":[],"sources":["../../src/lib/previewRefFromCookie.ts"],"sourcesContent":["/**\n * Unwraps `io.prismic.preview` to a Content API ref.\n *\n * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is\n * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`\n * / Cache Components send a non-ref (ParsingError / 404). A jar with more than one\n * repository `preview` is ambiguous and is ignored.\n */\nexport function previewRefFromCookie(cookie: string): string | undefined {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(cookie)\n\t\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\t\treturn\n\t\t}\n\n\t\tconst previewRefs: string[] = []\n\t\tfor (const value of Object.values(parsed)) {\n\t\t\tif (\n\t\t\t\tvalue !== null &&\n\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t!Array.isArray(value) &&\n\t\t\t\t\"preview\" in value &&\n\t\t\t\ttypeof value.preview === \"string\"\n\t\t\t) {\n\t\t\t\tpreviewRefs.push(value.preview)\n\t\t\t}\n\t\t}\n\n\t\treturn previewRefs.length === 1 ? previewRefs[0] : undefined\n\t} catch {\n\t\treturn cookie\n\t}\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,qBAAqB,QAAoC;AACxE,KAAI;EACH,MAAM,SAAkB,KAAK,MAAM,OAAO;AAC1C,MAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,CACzE;EAGD,MAAM,cAAwB,EAAE;AAChC,OAAK,MAAM,SAAS,OAAO,OAAO,OAAO,CACxC,KACC,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,MAAM,IACrB,aAAa,SACb,OAAO,MAAM,YAAY,SAEzB,aAAY,KAAK,MAAM,QAAQ;AAIjC,SAAO,YAAY,WAAW,IAAI,YAAY,KAAK,KAAA;SAC5C;AACP,SAAO"}
@@ -1,32 +0,0 @@
1
- import { cookie as prismicCookie } from "@prismicio/client"
2
-
3
- const epoch = new Date(0)
4
-
5
- function expiresAttr(): string {
6
- return `Expires=${epoch.toUTCString()}`
7
- }
8
-
9
- /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
10
- export function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {
11
- const expires = expiresAttr()
12
-
13
- return [
14
- `${name}=; Path=/; ${expires}; SameSite=Lax`,
15
- `${name}=; Path=/; ${expires}; SameSite=None; Secure`,
16
- ]
17
- }
18
-
19
- /**
20
- * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`
21
- * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;
22
- * Secure in production.
23
- */
24
- export function expiredDraftModeCookieHeaders(): string[] {
25
- const expires = expiresAttr()
26
- const name = "__prerender_bypass"
27
-
28
- return [
29
- `${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`,
30
- `${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`,
31
- ]
32
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Unwraps `io.prismic.preview` to a Content API ref.
3
- *
4
- * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is
5
- * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`
6
- * / Cache Components send a non-ref (ParsingError / 404). A jar with more than one
7
- * repository `preview` is ambiguous and is ignored.
8
- */
9
- export function previewRefFromCookie(cookie: string): string | undefined {
10
- try {
11
- const parsed: unknown = JSON.parse(cookie)
12
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
13
- return
14
- }
15
-
16
- const previewRefs: string[] = []
17
- for (const value of Object.values(parsed)) {
18
- if (
19
- value !== null &&
20
- typeof value === "object" &&
21
- !Array.isArray(value) &&
22
- "preview" in value &&
23
- typeof value.preview === "string"
24
- ) {
25
- previewRefs.push(value.preview)
26
- }
27
- }
28
-
29
- return previewRefs.length === 1 ? previewRefs[0] : undefined
30
- } catch {
31
- return cookie
32
- }
33
- }