@prismicio/next 2.3.1-pr.147.3d90e76 → 2.3.1-pr.147.939de68

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.
@@ -1,6 +1,4 @@
1
- require("./_virtual/_rolldown/runtime.cjs");
2
1
  const require_expiredPreviewCookies = require("./lib/expiredPreviewCookies.cjs");
3
- let _prismicio_client = require("@prismicio/client");
4
2
  //#region src/exitPreview.ts
5
3
  /**
6
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -18,12 +16,8 @@ let _prismicio_client = require("@prismicio/client");
18
16
  * ```
19
17
  */
20
18
  async function exitPreview() {
21
- const { cookies, draftMode } = await import("next/headers.js");
22
- (await draftMode()).disable();
23
- const cookieJar = await cookies();
24
- for (const options of require_expiredPreviewCookies.expiredPreviewCookieSetOptions) cookieJar.set(_prismicio_client.cookie.preview, "", options);
25
19
  const headers = new Headers({ "Cache-Control": "no-store" });
26
- for (const setCookie of require_expiredPreviewCookies.expiredPreviewCookieHeaders()) headers.append("Set-Cookie", setCookie);
20
+ for (const setCookie of [...require_expiredPreviewCookies.expiredPreviewCookieHeaders(), ...require_expiredPreviewCookies.expiredDraftModeCookieHeaders()]) headers.append("Set-Cookie", setCookie);
27
21
  return new Response(JSON.stringify({ success: true }), { headers });
28
22
  }
29
23
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.cjs","names":["expiredPreviewCookieSetOptions","prismicCookie","expiredPreviewCookieHeaders"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport {\n\texpiredPreviewCookieHeaders,\n\texpiredPreviewCookieSetOptions,\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// 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// `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may\n\t// leave SameSite=Lax (not Secure). Those are different cookies to Chrome.\n\t// Expire both. Do not use `cookies().delete()`: on Next.js 13.4.5–15 it\n\t// omits Secure/SameSite. `cookies()` is name-keyed, so also emit both\n\t// Set-Cookie headers on the Response.\n\tconst cookieJar = await cookies()\n\tfor (const options of expiredPreviewCookieSetOptions) {\n\t\tcookieJar.set(prismicCookie.preview, \"\", options)\n\t}\n\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of expiredPreviewCookieHeaders()) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;CAO9B,MAAM,YAAY,MAAM,SAAS;AACjC,MAAK,MAAM,WAAWA,8BAAAA,+BACrB,WAAU,IAAIC,kBAAAA,OAAc,SAAS,IAAI,QAAQ;CAGlD,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAaC,8BAAAA,6BAA6B,CACpD,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":["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 +1 @@
1
- {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAsBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAsBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1,5 +1,4 @@
1
- import { expiredPreviewCookieHeaders, expiredPreviewCookieSetOptions } from "./lib/expiredPreviewCookies.js";
2
- import { cookie } from "@prismicio/client";
1
+ import { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies.js";
3
2
  //#region src/exitPreview.ts
4
3
  /**
5
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -17,12 +16,8 @@ import { cookie } from "@prismicio/client";
17
16
  * ```
18
17
  */
19
18
  async function exitPreview() {
20
- const { cookies, draftMode } = await import("next/headers.js");
21
- (await draftMode()).disable();
22
- const cookieJar = await cookies();
23
- for (const options of expiredPreviewCookieSetOptions) cookieJar.set(cookie.preview, "", options);
24
19
  const headers = new Headers({ "Cache-Control": "no-store" });
25
- for (const setCookie of expiredPreviewCookieHeaders()) headers.append("Set-Cookie", setCookie);
20
+ for (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) headers.append("Set-Cookie", setCookie);
26
21
  return new Response(JSON.stringify({ success: true }), { headers });
27
22
  }
28
23
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport {\n\texpiredPreviewCookieHeaders,\n\texpiredPreviewCookieSetOptions,\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// 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// `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may\n\t// leave SameSite=Lax (not Secure). Those are different cookies to Chrome.\n\t// Expire both. Do not use `cookies().delete()`: on Next.js 13.4.5–15 it\n\t// omits Secure/SameSite. `cookies()` is name-keyed, so also emit both\n\t// Set-Cookie headers on the Response.\n\tconst cookieJar = await cookies()\n\tfor (const options of expiredPreviewCookieSetOptions) {\n\t\tcookieJar.set(prismicCookie.preview, \"\", options)\n\t}\n\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of expiredPreviewCookieHeaders()) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;CAO9B,MAAM,YAAY,MAAM,SAAS;AACjC,MAAK,MAAM,WAAW,+BACrB,WAAU,IAAIA,OAAc,SAAS,IAAI,QAAQ;CAGlD,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAa,6BAA6B,CACpD,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":[],"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,4 +1,5 @@
1
1
  require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_previewRefFromCookie = require("./lib/previewRefFromCookie.cjs");
2
3
  let _prismicio_client = require("@prismicio/client");
3
4
  //#region src/getPreviewRef.ts
4
5
  /**
@@ -29,8 +30,7 @@ async function getPreviewRef() {
29
30
  if (!isDraftModeEnabled) return;
30
31
  const cookie = (await cookies()).get(_prismicio_client.cookie.preview)?.value;
31
32
  if (!cookie) return;
32
- if (!cookie.includes("websitePreviewId=")) return;
33
- return cookie;
33
+ return require_previewRefFromCookie.previewRefFromCookie(cookie);
34
34
  }
35
35
  //#endregion
36
36
  exports.getPreviewRef = getPreviewRef;
@@ -1 +1 @@
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
+ {"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 +1 @@
1
- {"version":3,"file":"getPreviewRef.d.cts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
1
+ {"version":3,"file":"getPreviewRef.d.cts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAqBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewRef.d.ts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
1
+ {"version":3,"file":"getPreviewRef.d.ts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAqBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -1,3 +1,4 @@
1
+ import { previewRefFromCookie } from "./lib/previewRefFromCookie.js";
1
2
  import { cookie } from "@prismicio/client";
2
3
  //#region src/getPreviewRef.ts
3
4
  /**
@@ -28,8 +29,7 @@ async function getPreviewRef() {
28
29
  if (!isDraftModeEnabled) return;
29
30
  const cookie$1 = (await cookies()).get(cookie.preview)?.value;
30
31
  if (!cookie$1) return;
31
- if (!cookie$1.includes("websitePreviewId=")) return;
32
- return cookie$1;
32
+ return previewRefFromCookie(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\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"}
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"}
@@ -2,33 +2,26 @@ require("../_virtual/_rolldown/runtime.cjs");
2
2
  let _prismicio_client = require("@prismicio/client");
3
3
  //#region src/lib/expiredPreviewCookies.ts
4
4
  const epoch = /* @__PURE__ */ new Date(0);
5
- /**
6
- * `cookies().set` options that expire both leftover shapes of `io.prismic.preview`: toolbar Lax
7
- * (not Secure) and the iframe write (SameSite=None; Secure).
8
- *
9
- * `cookies()` is name-keyed, so a Route Handler must also emit both `Set-Cookie` headers from
10
- * {@link expiredPreviewCookieHeaders}.
11
- */
12
- const expiredPreviewCookieSetOptions = [{
13
- path: "/",
14
- sameSite: "lax",
15
- secure: false,
16
- httpOnly: false,
17
- expires: epoch
18
- }, {
19
- path: "/",
20
- sameSite: "none",
21
- secure: true,
22
- httpOnly: false,
23
- expires: epoch
24
- }];
5
+ function expiresAttr() {
6
+ return `Expires=${epoch.toUTCString()}`;
7
+ }
25
8
  /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
26
9
  function expiredPreviewCookieHeaders(name = _prismicio_client.cookie.preview) {
27
- const expires = `Expires=${epoch.toUTCString()}`;
10
+ const expires = expiresAttr();
28
11
  return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
29
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
+ }
30
23
  //#endregion
24
+ exports.expiredDraftModeCookieHeaders = expiredDraftModeCookieHeaders;
31
25
  exports.expiredPreviewCookieHeaders = expiredPreviewCookieHeaders;
32
- exports.expiredPreviewCookieSetOptions = expiredPreviewCookieSetOptions;
33
26
 
34
27
  //# sourceMappingURL=expiredPreviewCookies.cjs.map
@@ -1 +1 @@
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\n/**\n * `cookies().set` options that expire both leftover shapes of `io.prismic.preview`: toolbar Lax\n * (not Secure) and the iframe write (SameSite=None; Secure).\n *\n * `cookies()` is name-keyed, so a Route Handler must also emit both `Set-Cookie` headers from\n * {@link expiredPreviewCookieHeaders}.\n */\nexport const expiredPreviewCookieSetOptions = [\n\t{\n\t\tpath: \"/\",\n\t\tsameSite: \"lax\",\n\t\tsecure: false,\n\t\thttpOnly: false,\n\t\texpires: epoch,\n\t},\n\t{\n\t\tpath: \"/\",\n\t\tsameSite: \"none\",\n\t\tsecure: true,\n\t\thttpOnly: false,\n\t\texpires: epoch,\n\t},\n] as const\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = `Expires=${epoch.toUTCString()}`\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n"],"mappings":";;;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;;;;;;;;AASzB,MAAa,iCAAiC,CAC7C;CACC,MAAM;CACN,UAAU;CACV,QAAQ;CACR,UAAU;CACV,SAAS;CACT,EACD;CACC,MAAM;CACN,UAAU;CACV,QAAQ;CACR,UAAU;CACV,SAAS;CACT,CACD;;AAGD,SAAgB,4BAA4B,OAAOA,kBAAAA,OAAc,SAAmB;CACnF,MAAM,UAAU,WAAW,MAAM,aAAa;AAE9C,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B"}
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,32 +1,25 @@
1
1
  import { cookie } from "@prismicio/client";
2
2
  //#region src/lib/expiredPreviewCookies.ts
3
3
  const epoch = /* @__PURE__ */ new Date(0);
4
- /**
5
- * `cookies().set` options that expire both leftover shapes of `io.prismic.preview`: toolbar Lax
6
- * (not Secure) and the iframe write (SameSite=None; Secure).
7
- *
8
- * `cookies()` is name-keyed, so a Route Handler must also emit both `Set-Cookie` headers from
9
- * {@link expiredPreviewCookieHeaders}.
10
- */
11
- const expiredPreviewCookieSetOptions = [{
12
- path: "/",
13
- sameSite: "lax",
14
- secure: false,
15
- httpOnly: false,
16
- expires: epoch
17
- }, {
18
- path: "/",
19
- sameSite: "none",
20
- secure: true,
21
- httpOnly: false,
22
- expires: epoch
23
- }];
4
+ function expiresAttr() {
5
+ return `Expires=${epoch.toUTCString()}`;
6
+ }
24
7
  /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
25
8
  function expiredPreviewCookieHeaders(name = cookie.preview) {
26
- const expires = `Expires=${epoch.toUTCString()}`;
9
+ const expires = expiresAttr();
27
10
  return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
28
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
+ }
29
22
  //#endregion
30
- export { expiredPreviewCookieHeaders, expiredPreviewCookieSetOptions };
23
+ export { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders };
31
24
 
32
25
  //# sourceMappingURL=expiredPreviewCookies.js.map
@@ -1 +1 @@
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\n/**\n * `cookies().set` options that expire both leftover shapes of `io.prismic.preview`: toolbar Lax\n * (not Secure) and the iframe write (SameSite=None; Secure).\n *\n * `cookies()` is name-keyed, so a Route Handler must also emit both `Set-Cookie` headers from\n * {@link expiredPreviewCookieHeaders}.\n */\nexport const expiredPreviewCookieSetOptions = [\n\t{\n\t\tpath: \"/\",\n\t\tsameSite: \"lax\",\n\t\tsecure: false,\n\t\thttpOnly: false,\n\t\texpires: epoch,\n\t},\n\t{\n\t\tpath: \"/\",\n\t\tsameSite: \"none\",\n\t\tsecure: true,\n\t\thttpOnly: false,\n\t\texpires: epoch,\n\t},\n] as const\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = `Expires=${epoch.toUTCString()}`\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n"],"mappings":";;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;;;;;;;;AASzB,MAAa,iCAAiC,CAC7C;CACC,MAAM;CACN,UAAU;CACV,QAAQ;CACR,UAAU;CACV,SAAS;CACT,EACD;CACC,MAAM;CACN,UAAU;CACV,QAAQ;CACR,UAAU;CACV,SAAS;CACT,CACD;;AAGD,SAAgB,4BAA4B,OAAOA,OAAc,SAAmB;CACnF,MAAM,UAAU,WAAW,MAAM,aAAa;AAE9C,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B"}
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"}
@@ -0,0 +1,24 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,24 @@
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
@@ -0,0 +1 @@
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"}
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.147.3d90e76";
2
+ var version = "2.3.1-pr.147.939de68";
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.3d90e76";
2
+ var version = "2.3.1-pr.147.939de68";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -1,9 +1,17 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_previewRefFromCookie = require("../lib/previewRefFromCookie.cjs");
2
3
  let _prismicio_client = require("@prismicio/client");
3
4
  //#region src/pages/setPreviewData.ts
4
5
  /** Set Prismic preview data for Next.js's Preview Mode. */
5
6
  function setPreviewData({ req, res }) {
6
- const ref = req.query.token || req.cookies[_prismicio_client.cookie.preview];
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);
7
15
  if (ref) res.setPreviewData({ ref });
8
16
  }
9
17
  //#endregion
@@ -1 +1 @@
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
+ {"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 +1 @@
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
+ {"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 +1 @@
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
+ {"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,8 +1,16 @@
1
+ import { previewRefFromCookie } from "../lib/previewRefFromCookie.js";
1
2
  import { cookie } from "@prismicio/client";
2
3
  //#region src/pages/setPreviewData.ts
3
4
  /** Set Prismic preview data for Next.js's Preview Mode. */
4
5
  function setPreviewData({ req, res }) {
5
- const ref = req.query.token || req.cookies[cookie.preview];
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);
6
14
  if (ref) res.setPreviewData({ ref });
7
15
  }
8
16
  //#endregion
@@ -1 +1 @@
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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.3.1-pr.147.3d90e76",
3
+ "version": "2.3.1-pr.147.939de68",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "next",
@@ -1,8 +1,6 @@
1
- import { cookie as prismicCookie } from "@prismicio/client"
2
-
3
1
  import {
2
+ expiredDraftModeCookieHeaders,
4
3
  expiredPreviewCookieHeaders,
5
- expiredPreviewCookieSetOptions,
6
4
  } from "./lib/expiredPreviewCookies"
7
5
 
8
6
  /**
@@ -21,27 +19,15 @@ import {
21
19
  * ```
22
20
  */
23
21
  export async function exitPreview(): Promise<Response> {
24
- // Need this to avoid the following Next.js build-time error:
25
- // You're importing a component that needs next/headers. That only works
26
- // in a Server Component which is not supported in the pages/ directory.
27
- const { cookies, draftMode } = await import("next/headers")
28
-
29
- ;(await draftMode()).disable()
30
-
31
- // `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may
32
- // leave SameSite=Lax (not Secure). Those are different cookies to Chrome.
33
- // Expire both. Do not use `cookies().delete()`: on Next.js 13.4.5–15 it
34
- // omits Secure/SameSite. `cookies()` is name-keyed, so also emit both
35
- // Set-Cookie headers on the Response.
36
- const cookieJar = await cookies()
37
- for (const options of expiredPreviewCookieSetOptions) {
38
- cookieJar.set(prismicCookie.preview, "", options)
39
- }
40
-
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.
41
27
  const headers = new Headers({
42
28
  "Cache-Control": "no-store",
43
29
  })
44
- for (const setCookie of expiredPreviewCookieHeaders()) {
30
+ for (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {
45
31
  headers.append("Set-Cookie", setCookie)
46
32
  }
47
33
 
@@ -1,5 +1,7 @@
1
1
  import { cookie as prismicCookie } from "@prismicio/client"
2
2
 
3
+ import { previewRefFromCookie } from "./lib/previewRefFromCookie"
4
+
3
5
  /**
4
6
  * Reads the Prismic preview ref for the current request when an active preview session exists.
5
7
  *
@@ -42,10 +44,8 @@ export async function getPreviewRef(): Promise<string | undefined> {
42
44
  return
43
45
  }
44
46
 
45
- const isActiveCookie = cookie.includes("websitePreviewId=")
46
- if (!isActiveCookie) {
47
- return
48
- }
49
-
50
- return cookie
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)
51
51
  }
@@ -2,36 +2,31 @@ import { cookie as prismicCookie } from "@prismicio/client"
2
2
 
3
3
  const epoch = new Date(0)
4
4
 
5
- /**
6
- * `cookies().set` options that expire both leftover shapes of `io.prismic.preview`: toolbar Lax
7
- * (not Secure) and the iframe write (SameSite=None; Secure).
8
- *
9
- * `cookies()` is name-keyed, so a Route Handler must also emit both `Set-Cookie` headers from
10
- * {@link expiredPreviewCookieHeaders}.
11
- */
12
- export const expiredPreviewCookieSetOptions = [
13
- {
14
- path: "/",
15
- sameSite: "lax",
16
- secure: false,
17
- httpOnly: false,
18
- expires: epoch,
19
- },
20
- {
21
- path: "/",
22
- sameSite: "none",
23
- secure: true,
24
- httpOnly: false,
25
- expires: epoch,
26
- },
27
- ] as const
5
+ function expiresAttr(): string {
6
+ return `Expires=${epoch.toUTCString()}`
7
+ }
28
8
 
29
9
  /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
30
10
  export function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {
31
- const expires = `Expires=${epoch.toUTCString()}`
11
+ const expires = expiresAttr()
32
12
 
33
13
  return [
34
14
  `${name}=; Path=/; ${expires}; SameSite=Lax`,
35
15
  `${name}=; Path=/; ${expires}; SameSite=None; Secure`,
36
16
  ]
37
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
+ }
@@ -0,0 +1,33 @@
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
+ }
@@ -1,5 +1,6 @@
1
1
  import { cookie } from "@prismicio/client"
2
2
 
3
+ import { previewRefFromCookie } from "../lib/previewRefFromCookie"
3
4
  import type { NextApiRequestLike, NextApiResponseLike } from "./types"
4
5
 
5
6
  /** Configuration for `setPreviewData`. */
@@ -21,8 +22,19 @@ export type SetPreviewDataConfig = {
21
22
 
22
23
  /** Set Prismic preview data for Next.js's Preview Mode. */
23
24
  export function setPreviewData({ req, res }: SetPreviewDataConfig): void {
24
- const ref = req.query.token || req.cookies[cookie.preview]
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
+ }
25
36
 
37
+ const ref = previewRefFromCookie(previewCookie)
26
38
  if (ref) {
27
39
  res.setPreviewData({ ref })
28
40
  }