@prismicio/next 2.3.1-pr.146.a87f9e7 → 2.3.1-pr.147.05dde81

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.
@@ -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>, "rel" | "field" | "href" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "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>, "rel" | "field" | "href" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "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>, "rel" | "field" | "href" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "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>, "rel" | "field" | "href" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "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>, "rel" | "field" | "href" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "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>, "rel" | "field" | "href" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -1,5 +1,4 @@
1
- require("./_virtual/_rolldown/runtime.cjs");
2
- let _prismicio_client = require("@prismicio/client");
1
+ const require_expiredPreviewCookies = require("./lib/expiredPreviewCookies.cjs");
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,10 +16,9 @@ let _prismicio_client = require("@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
- (await cookies()).delete(_prismicio_client.cookie.preview);
23
- return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
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 });
24
22
  }
25
23
  //#endregion
26
24
  exports.exitPreview = exitPreview;
@@ -1 +1 @@
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// `redirectToPreviewURL` writes the preview cookie, so `exitPreview`\n\t// clears it to close the preview-cookie loop.\n\t;(await cookies()).delete(prismicCookie.preview)\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;AAI7B,EAAC,MAAM,SAAS,EAAE,OAAOA,kBAAAA,OAAc,QAAQ;AAGhD,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,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":";;AAiBA;;;;;;;;;;;;;;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":";;AAiBA;;;;;;;;;;;;;;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,4 +1,4 @@
1
- import { cookie } from "@prismicio/client";
1
+ import { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies.js";
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,10 +16,9 @@ import { cookie } from "@prismicio/client";
16
16
  * ```
17
17
  */
18
18
  async function exitPreview() {
19
- const { cookies, draftMode } = await import("next/headers.js");
20
- (await draftMode()).disable();
21
- (await cookies()).delete(cookie.preview);
22
- return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
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 });
23
22
  }
24
23
  //#endregion
25
24
  export { exitPreview };
@@ -1 +1 @@
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// `redirectToPreviewURL` writes the preview cookie, so `exitPreview`\n\t// clears it to close the preview-cookie loop.\n\t;(await cookies()).delete(prismicCookie.preview)\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;AAI7B,EAAC,MAAM,SAAS,EAAE,OAAOA,OAAc,QAAQ;AAGhD,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,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"}
@@ -0,0 +1,27 @@
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
@@ -0,0 +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\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"}
@@ -0,0 +1,25 @@
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
@@ -0,0 +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\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"}
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.146.a87f9e7";
2
+ var version = "2.3.1-pr.147.05dde81";
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.146.a87f9e7";
2
+ var version = "2.3.1-pr.147.05dde81";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -1,3 +1,4 @@
1
+ const require_expiredPreviewCookies = require("../lib/expiredPreviewCookies.cjs");
1
2
  //#region src/pages/exitPreview.ts
2
3
  /**
3
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in an API
@@ -16,6 +17,9 @@
16
17
  */
17
18
  function exitPreview(config) {
18
19
  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]);
19
23
  config.res.setHeader("Cache-Control", "no-store");
20
24
  config.res.json({ success: true });
21
25
  }
@@ -1 +1 @@
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
+ {"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 +1 @@
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
+ {"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 +1 @@
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
+ {"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,3 +1,4 @@
1
+ import { expiredPreviewCookieHeaders } from "../lib/expiredPreviewCookies.js";
1
2
  //#region src/pages/exitPreview.ts
2
3
  /**
3
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in an API
@@ -16,6 +17,9 @@
16
17
  */
17
18
  function exitPreview(config) {
18
19
  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]);
19
23
  config.res.setHeader("Cache-Control", "no-store");
20
24
  config.res.json({ success: true });
21
25
  }
@@ -1 +1 @@
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
+ {"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"}
@@ -21,6 +21,7 @@ type NextApiRequestLike = {
21
21
  type NextApiResponseLike = {
22
22
  redirect(url: string): NextApiResponseLike;
23
23
  clearPreviewData(): NextApiResponseLike;
24
+ getHeader(name: string): number | string | string[] | undefined;
24
25
  setHeader(name: string, value: string | string[]): NextApiResponseLike;
25
26
  json(body: any): void;
26
27
  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,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;EACV,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
@@ -21,6 +21,7 @@ type NextApiRequestLike = {
21
21
  type NextApiResponseLike = {
22
22
  redirect(url: string): NextApiResponseLike;
23
23
  clearPreviewData(): NextApiResponseLike;
24
+ getHeader(name: string): number | string | string[] | undefined;
24
25
  setHeader(name: string, value: string | string[]): NextApiResponseLike;
25
26
  json(body: any): void;
26
27
  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,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;EACV,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
@@ -7,7 +7,12 @@ async function redirectToPreviewURL(config) {
7
7
  const { redirect } = await import("next/navigation");
8
8
  const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
9
9
  const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
10
- if (previewToken) (await cookies()).set(_prismicio_client.cookie.preview, previewToken);
10
+ if (previewToken) (await cookies()).set(_prismicio_client.cookie.preview, previewToken, {
11
+ path: "/",
12
+ sameSite: "none",
13
+ secure: true,
14
+ httpOnly: false
15
+ });
11
16
  const previewURL = await client.resolvePreviewURL({
12
17
  documentID,
13
18
  previewToken,
@@ -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\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}\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;CAMrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,kBAAAA,OAAc,SAAS,aAAa;CAGnD,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// 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"}
@@ -6,7 +6,12 @@ async function redirectToPreviewURL(config) {
6
6
  const { redirect } = await import("next/navigation");
7
7
  const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
8
8
  const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
9
- if (previewToken) (await cookies()).set(cookie.preview, previewToken);
9
+ if (previewToken) (await cookies()).set(cookie.preview, previewToken, {
10
+ path: "/",
11
+ sameSite: "none",
12
+ secure: true,
13
+ httpOnly: false
14
+ });
10
15
  const previewURL = await client.resolvePreviewURL({
11
16
  documentID,
12
17
  previewToken,
@@ -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\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}\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;CAMrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,aAAa;CAGnD,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// 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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.3.1-pr.146.a87f9e7",
3
+ "version": "2.3.1-pr.147.05dde81",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "next",
@@ -1,4 +1,7 @@
1
- import { cookie as prismicCookie } from "@prismicio/client"
1
+ import {
2
+ expiredDraftModeCookieHeaders,
3
+ expiredPreviewCookieHeaders,
4
+ } from "./lib/expiredPreviewCookies"
2
5
 
3
6
  /**
4
7
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -16,21 +19,17 @@ import { cookie as prismicCookie } from "@prismicio/client"
16
19
  * ```
17
20
  */
18
21
  export async function exitPreview(): Promise<Response> {
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()
25
-
26
- // `redirectToPreviewURL` writes the preview cookie, so `exitPreview`
27
- // clears it to close the preview-cookie loop.
28
- ;(await cookies()).delete(prismicCookie.preview)
29
-
30
- // `Cache-Control` header is used to prevent CDN-level caching.
31
- return new Response(JSON.stringify({ success: true }), {
32
- headers: {
33
- "Cache-Control": "no-store",
34
- },
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",
35
29
  })
30
+ for (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {
31
+ headers.append("Set-Cookie", setCookie)
32
+ }
33
+
34
+ return new Response(JSON.stringify({ success: true }), { headers })
36
35
  }
@@ -0,0 +1,32 @@
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,3 +1,4 @@
1
+ import { expiredPreviewCookieHeaders } from "../lib/expiredPreviewCookies"
1
2
  import type { NextApiRequestLike, NextApiResponseLike } from "./types"
2
3
 
3
4
  /** Configuration for `exitPreview()`. */
@@ -35,6 +36,26 @@ export type ExitPreviewAPIRouteConfig = {
35
36
  export function exitPreview(config: ExitPreviewAPIRouteConfig): void {
36
37
  config.res.clearPreviewData()
37
38
 
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
+
38
59
  // `Cache-Control` header is used to prevent CDN-level caching.
39
60
  config.res.setHeader("Cache-Control", "no-store")
40
61
 
@@ -24,6 +24,7 @@ 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
27
28
  setHeader(name: string, value: string | string[]): NextApiResponseLike
28
29
  // oxlint-disable-next-line no-explicit-any explicit-module-boundary-types
29
30
  json(body: any): void
@@ -50,10 +50,20 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
50
50
  // to support unpublished previews. Without setting it here, the page
51
51
  // will try to render without the preview cookie, leading to a
52
52
  // PrismicNotFound error.
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`.
53
58
  const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
54
59
  if (previewToken) {
55
60
  const cookieJar = await cookies()
56
- cookieJar.set(prismicCookie.preview, previewToken)
61
+ cookieJar.set(prismicCookie.preview, previewToken, {
62
+ path: "/",
63
+ sameSite: "none",
64
+ secure: true,
65
+ httpOnly: false,
66
+ })
57
67
  }
58
68
 
59
69
  const previewURL = await client.resolvePreviewURL({