@prismicio/next 2.3.1-pr.148.d5dbc1a → 2.3.1-pr.148.fb401e2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PrismicNextLink.d.cts +3 -3
- package/dist/PrismicNextLink.d.ts +3 -3
- package/dist/exitPreview.cjs +5 -7
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.cts.map +1 -1
- package/dist/exitPreview.d.ts.map +1 -1
- package/dist/exitPreview.js +5 -7
- package/dist/exitPreview.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/redirectToPreviewURL.cjs +6 -4
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.js +6 -4
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +1 -1
- package/src/exitPreview.ts +6 -11
- package/src/redirectToPreviewURL.ts +8 -7
- package/dist/lib/previewCookieAttributes.cjs +0 -20
- package/dist/lib/previewCookieAttributes.cjs.map +0 -1
- package/dist/lib/previewCookieAttributes.js +0 -20
- package/dist/lib/previewCookieAttributes.js.map +0 -1
- package/src/lib/previewCookieAttributes.ts +0 -16
|
@@ -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>, "
|
|
26
|
+
} & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
27
27
|
linkResolver?: LinkResolverFunction;
|
|
28
28
|
rel?: string | AsLinkAttrsConfig["rel"];
|
|
29
29
|
} & {
|
|
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
|
|
|
32
32
|
href?: never;
|
|
33
33
|
}, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
|
|
34
34
|
children?: React.ReactNode | undefined;
|
|
35
|
-
} & _$react.RefAttributes<HTMLAnchorElement>, "
|
|
35
|
+
} & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
36
36
|
linkResolver?: LinkResolverFunction;
|
|
37
37
|
rel?: string | AsLinkAttrsConfig["rel"];
|
|
38
38
|
} & {
|
|
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
|
|
|
41
41
|
href?: never;
|
|
42
42
|
}, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
|
|
43
43
|
children?: React.ReactNode | undefined;
|
|
44
|
-
} & _$react.RefAttributes<HTMLAnchorElement>, "
|
|
44
|
+
} & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
45
45
|
linkResolver?: LinkResolverFunction;
|
|
46
46
|
rel?: string | AsLinkAttrsConfig["rel"];
|
|
47
47
|
} & {
|
|
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
|
|
|
23
23
|
});
|
|
24
24
|
declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
|
|
25
25
|
children?: React.ReactNode | undefined;
|
|
26
|
-
} & _$react.RefAttributes<HTMLAnchorElement>, "
|
|
26
|
+
} & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
27
27
|
linkResolver?: LinkResolverFunction;
|
|
28
28
|
rel?: string | AsLinkAttrsConfig["rel"];
|
|
29
29
|
} & {
|
|
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
|
|
|
32
32
|
href?: never;
|
|
33
33
|
}, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
|
|
34
34
|
children?: React.ReactNode | undefined;
|
|
35
|
-
} & _$react.RefAttributes<HTMLAnchorElement>, "
|
|
35
|
+
} & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
36
36
|
linkResolver?: LinkResolverFunction;
|
|
37
37
|
rel?: string | AsLinkAttrsConfig["rel"];
|
|
38
38
|
} & {
|
|
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
|
|
|
41
41
|
href?: never;
|
|
42
42
|
}, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
|
|
43
43
|
children?: React.ReactNode | undefined;
|
|
44
|
-
} & _$react.RefAttributes<HTMLAnchorElement>, "
|
|
44
|
+
} & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
45
45
|
linkResolver?: LinkResolverFunction;
|
|
46
46
|
rel?: string | AsLinkAttrsConfig["rel"];
|
|
47
47
|
} & {
|
package/dist/exitPreview.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_previewCookieAttributes = require("./lib/previewCookieAttributes.cjs");
|
|
3
2
|
let _prismicio_client = require("@prismicio/client");
|
|
4
3
|
//#region src/exitPreview.ts
|
|
5
4
|
/**
|
|
@@ -18,18 +17,17 @@ let _prismicio_client = require("@prismicio/client");
|
|
|
18
17
|
* ```
|
|
19
18
|
*/
|
|
20
19
|
async function exitPreview() {
|
|
21
|
-
const { cookies
|
|
22
|
-
(await draftMode()).disable();
|
|
20
|
+
const { cookies } = await import("next/headers.js");
|
|
23
21
|
const cookieJar = await cookies();
|
|
24
|
-
const cookieAttributes = require_previewCookieAttributes.previewCookieAttributes((await headers()).get("host"));
|
|
25
22
|
cookieJar.delete({
|
|
26
23
|
name: "__prerender_bypass",
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
sameSite: "none",
|
|
25
|
+
secure: true
|
|
29
26
|
});
|
|
30
27
|
cookieJar.delete({
|
|
31
28
|
name: _prismicio_client.cookie.preview,
|
|
32
|
-
|
|
29
|
+
sameSite: "none",
|
|
30
|
+
secure: true
|
|
33
31
|
});
|
|
34
32
|
return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
|
|
35
33
|
}
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":["
|
|
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 } = await import(\"next/headers\")\n\n\t// Expire both cookies with the attributes `redirectToPreviewURL` used.\n\t// `draftMode().disable()` only expires the Draft Mode cookie, and with\n\t// `SameSite=Lax` in development, which a cross-site iframe cannot clear.\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,YAAY,MAAM,OAAO;CAKjC,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChF,WAAU,OAAO;EAAE,MAAMA,kBAAAA,OAAc;EAAS,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGjF,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
|
package/dist/exitPreview.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { previewCookieAttributes } from "./lib/previewCookieAttributes.js";
|
|
2
1
|
import { cookie } from "@prismicio/client";
|
|
3
2
|
//#region src/exitPreview.ts
|
|
4
3
|
/**
|
|
@@ -17,18 +16,17 @@ import { cookie } from "@prismicio/client";
|
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
18
|
async function exitPreview() {
|
|
20
|
-
const { cookies
|
|
21
|
-
(await draftMode()).disable();
|
|
19
|
+
const { cookies } = await import("next/headers.js");
|
|
22
20
|
const cookieJar = await cookies();
|
|
23
|
-
const cookieAttributes = previewCookieAttributes((await headers()).get("host"));
|
|
24
21
|
cookieJar.delete({
|
|
25
22
|
name: "__prerender_bypass",
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
sameSite: "none",
|
|
24
|
+
secure: true
|
|
28
25
|
});
|
|
29
26
|
cookieJar.delete({
|
|
30
27
|
name: cookie.preview,
|
|
31
|
-
|
|
28
|
+
sameSite: "none",
|
|
29
|
+
secure: true
|
|
32
30
|
});
|
|
33
31
|
return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
|
|
34
32
|
}
|
package/dist/exitPreview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\
|
|
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 } = await import(\"next/headers\")\n\n\t// Expire both cookies with the attributes `redirectToPreviewURL` used.\n\t// `draftMode().disable()` only expires the Draft Mode cookie, and with\n\t// `SameSite=Lax` in development, which a cross-site iframe cannot clear.\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,YAAY,MAAM,OAAO;CAKjC,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChF,WAAU,OAAO;EAAE,MAAMA,OAAc;EAAS,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGjF,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_previewCookieAttributes = require("./lib/previewCookieAttributes.cjs");
|
|
3
2
|
let _prismicio_client = require("@prismicio/client");
|
|
4
3
|
//#region src/redirectToPreviewURL.ts
|
|
5
4
|
async function redirectToPreviewURL(config) {
|
|
@@ -8,9 +7,11 @@ async function redirectToPreviewURL(config) {
|
|
|
8
7
|
const { redirect } = await import("next/navigation");
|
|
9
8
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
10
9
|
const cookieJar = await cookies();
|
|
11
|
-
const cookieAttributes = require_previewCookieAttributes.previewCookieAttributes(request.headers.get("host"));
|
|
12
10
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
13
|
-
if (previewToken) cookieJar.set(_prismicio_client.cookie.preview, previewToken,
|
|
11
|
+
if (previewToken) cookieJar.set(_prismicio_client.cookie.preview, previewToken, {
|
|
12
|
+
sameSite: "none",
|
|
13
|
+
secure: true
|
|
14
|
+
});
|
|
14
15
|
const previewURL = await client.resolvePreviewURL({
|
|
15
16
|
documentID,
|
|
16
17
|
previewToken,
|
|
@@ -21,7 +22,8 @@ async function redirectToPreviewURL(config) {
|
|
|
21
22
|
const draftCookie = cookieJar.get("__prerender_bypass");
|
|
22
23
|
if (draftCookie) cookieJar.set({
|
|
23
24
|
...draftCookie,
|
|
24
|
-
|
|
25
|
+
sameSite: "none",
|
|
26
|
+
secure: true
|
|
25
27
|
});
|
|
26
28
|
return redirect(previewURL);
|
|
27
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","names":["
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Browsers only send `SameSite=Lax` cookies on same-site requests, so\n\t// `SameSite=None; Secure` is needed for the site to preview inside a\n\t// cross-site iframe, like the Prismic editor.\n\tconst cookieJar = await cookies()\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.\n\t// Rewrite it like the preview cookie, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, sameSite: \"none\", secure: true })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAUrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIA,kBAAAA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;EAAM,CAAC;CAGvF,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAI7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { previewCookieAttributes } from "./lib/previewCookieAttributes.js";
|
|
2
1
|
import { cookie } from "@prismicio/client";
|
|
3
2
|
//#region src/redirectToPreviewURL.ts
|
|
4
3
|
async function redirectToPreviewURL(config) {
|
|
@@ -7,9 +6,11 @@ async function redirectToPreviewURL(config) {
|
|
|
7
6
|
const { redirect } = await import("next/navigation");
|
|
8
7
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
9
8
|
const cookieJar = await cookies();
|
|
10
|
-
const cookieAttributes = previewCookieAttributes(request.headers.get("host"));
|
|
11
9
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
12
|
-
if (previewToken) cookieJar.set(cookie.preview, previewToken,
|
|
10
|
+
if (previewToken) cookieJar.set(cookie.preview, previewToken, {
|
|
11
|
+
sameSite: "none",
|
|
12
|
+
secure: true
|
|
13
|
+
});
|
|
13
14
|
const previewURL = await client.resolvePreviewURL({
|
|
14
15
|
documentID,
|
|
15
16
|
previewToken,
|
|
@@ -20,7 +21,8 @@ async function redirectToPreviewURL(config) {
|
|
|
20
21
|
const draftCookie = cookieJar.get("__prerender_bypass");
|
|
21
22
|
if (draftCookie) cookieJar.set({
|
|
22
23
|
...draftCookie,
|
|
23
|
-
|
|
24
|
+
sameSite: "none",
|
|
25
|
+
secure: true
|
|
24
26
|
});
|
|
25
27
|
return redirect(previewURL);
|
|
26
28
|
}
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Browsers only send `SameSite=Lax` cookies on same-site requests, so\n\t// `SameSite=None; Secure` is needed for the site to preview inside a\n\t// cross-site iframe, like the Prismic editor.\n\tconst cookieJar = await cookies()\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.\n\t// Rewrite it like the preview cookie, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, sameSite: \"none\", secure: true })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAUrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;EAAM,CAAC;CAGvF,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAI7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
|
package/package.json
CHANGED
package/src/exitPreview.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { cookie as prismicCookie } from "@prismicio/client"
|
|
2
2
|
|
|
3
|
-
import { previewCookieAttributes } from "./lib/previewCookieAttributes"
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
7
5
|
* Handler.
|
|
@@ -21,17 +19,14 @@ export async function exitPreview(): Promise<Response> {
|
|
|
21
19
|
// Need this to avoid the following Next.js build-time error:
|
|
22
20
|
// You're importing a component that needs next/headers. That only works
|
|
23
21
|
// in a Server Component which is not supported in the pages/ directory.
|
|
24
|
-
const { cookies
|
|
25
|
-
|
|
26
|
-
;(await draftMode()).disable()
|
|
22
|
+
const { cookies } = await import("next/headers")
|
|
27
23
|
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
// `
|
|
24
|
+
// Expire both cookies with the attributes `redirectToPreviewURL` used.
|
|
25
|
+
// `draftMode().disable()` only expires the Draft Mode cookie, and with
|
|
26
|
+
// `SameSite=Lax` in development, which a cross-site iframe cannot clear.
|
|
31
27
|
const cookieJar = await cookies()
|
|
32
|
-
|
|
33
|
-
cookieJar.delete({ name: "
|
|
34
|
-
cookieJar.delete({ name: prismicCookie.preview, ...cookieAttributes })
|
|
28
|
+
cookieJar.delete({ name: "__prerender_bypass", sameSite: "none", secure: true })
|
|
29
|
+
cookieJar.delete({ name: prismicCookie.preview, sameSite: "none", secure: true })
|
|
35
30
|
|
|
36
31
|
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
37
32
|
return new Response(JSON.stringify({ success: true }), {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { cookie as prismicCookie, type Client, type LinkResolverFunction } from "@prismicio/client"
|
|
2
2
|
|
|
3
|
-
import { previewCookieAttributes } from "./lib/previewCookieAttributes"
|
|
4
3
|
import type { NextRequestLike } from "./types"
|
|
5
4
|
|
|
6
5
|
export type RedirectToPreviewURLConfig = {
|
|
@@ -51,11 +50,14 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
51
50
|
// to support unpublished previews. Without setting it here, the page
|
|
52
51
|
// will try to render without the preview cookie, leading to a
|
|
53
52
|
// PrismicNotFound error.
|
|
53
|
+
//
|
|
54
|
+
// Browsers only send `SameSite=Lax` cookies on same-site requests, so
|
|
55
|
+
// `SameSite=None; Secure` is needed for the site to preview inside a
|
|
56
|
+
// cross-site iframe, like the Prismic editor.
|
|
54
57
|
const cookieJar = await cookies()
|
|
55
|
-
const cookieAttributes = previewCookieAttributes(request.headers.get("host"))
|
|
56
58
|
const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
|
|
57
59
|
if (previewToken) {
|
|
58
|
-
cookieJar.set(prismicCookie.preview, previewToken,
|
|
60
|
+
cookieJar.set(prismicCookie.preview, previewToken, { sameSite: "none", secure: true })
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
const previewURL = await client.resolvePreviewURL({
|
|
@@ -67,12 +69,11 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
67
69
|
|
|
68
70
|
;(await draftMode()).enable()
|
|
69
71
|
|
|
70
|
-
// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development
|
|
71
|
-
//
|
|
72
|
-
// attributes, keeping Next.js's value.
|
|
72
|
+
// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.
|
|
73
|
+
// Rewrite it like the preview cookie, keeping Next.js's value.
|
|
73
74
|
const draftCookie = cookieJar.get("__prerender_bypass")
|
|
74
75
|
if (draftCookie) {
|
|
75
|
-
cookieJar.set({ ...draftCookie,
|
|
76
|
+
cookieJar.set({ ...draftCookie, sameSite: "none", secure: true })
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
return redirect(previewURL)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/lib/previewCookieAttributes.ts
|
|
2
|
-
/**
|
|
3
|
-
* Attributes for the preview cookie and Next.js's Draft Mode cookie.
|
|
4
|
-
*
|
|
5
|
-
* Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need
|
|
6
|
-
* `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the
|
|
7
|
-
* Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,
|
|
8
|
-
* so `next dev` on any other host keeps Next.js's `Lax` default.
|
|
9
|
-
*/
|
|
10
|
-
function previewCookieAttributes(host) {
|
|
11
|
-
const secure = process.env.NODE_ENV !== "development" || host?.split(":")[0] === "localhost";
|
|
12
|
-
return {
|
|
13
|
-
sameSite: secure ? "none" : "lax",
|
|
14
|
-
secure
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
exports.previewCookieAttributes = previewCookieAttributes;
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=previewCookieAttributes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"previewCookieAttributes.cjs","names":[],"sources":["../../src/lib/previewCookieAttributes.ts"],"sourcesContent":["/**\n * Attributes for the preview cookie and Next.js's Draft Mode cookie.\n *\n * Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need\n * `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the\n * Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,\n * so `next dev` on any other host keeps Next.js's `Lax` default.\n */\nexport function previewCookieAttributes(host: string | null | undefined): {\n\tsameSite: \"none\" | \"lax\"\n\tsecure: boolean\n} {\n\tconst secure = process.env.NODE_ENV !== \"development\" || host?.split(\":\")[0] === \"localhost\"\n\n\treturn { sameSite: secure ? \"none\" : \"lax\", secure }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,wBAAwB,MAGtC;CACD,MAAM,SAAS,QAAQ,IAAI,aAAa,iBAAiB,MAAM,MAAM,IAAI,CAAC,OAAO;AAEjF,QAAO;EAAE,UAAU,SAAS,SAAS;EAAO;EAAQ"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/lib/previewCookieAttributes.ts
|
|
2
|
-
/**
|
|
3
|
-
* Attributes for the preview cookie and Next.js's Draft Mode cookie.
|
|
4
|
-
*
|
|
5
|
-
* Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need
|
|
6
|
-
* `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the
|
|
7
|
-
* Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,
|
|
8
|
-
* so `next dev` on any other host keeps Next.js's `Lax` default.
|
|
9
|
-
*/
|
|
10
|
-
function previewCookieAttributes(host) {
|
|
11
|
-
const secure = process.env.NODE_ENV !== "development" || host?.split(":")[0] === "localhost";
|
|
12
|
-
return {
|
|
13
|
-
sameSite: secure ? "none" : "lax",
|
|
14
|
-
secure
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
export { previewCookieAttributes };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=previewCookieAttributes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"previewCookieAttributes.js","names":[],"sources":["../../src/lib/previewCookieAttributes.ts"],"sourcesContent":["/**\n * Attributes for the preview cookie and Next.js's Draft Mode cookie.\n *\n * Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need\n * `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the\n * Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,\n * so `next dev` on any other host keeps Next.js's `Lax` default.\n */\nexport function previewCookieAttributes(host: string | null | undefined): {\n\tsameSite: \"none\" | \"lax\"\n\tsecure: boolean\n} {\n\tconst secure = process.env.NODE_ENV !== \"development\" || host?.split(\":\")[0] === \"localhost\"\n\n\treturn { sameSite: secure ? \"none\" : \"lax\", secure }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,wBAAwB,MAGtC;CACD,MAAM,SAAS,QAAQ,IAAI,aAAa,iBAAiB,MAAM,MAAM,IAAI,CAAC,OAAO;AAEjF,QAAO;EAAE,UAAU,SAAS,SAAS;EAAO;EAAQ"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Attributes for the preview cookie and Next.js's Draft Mode cookie.
|
|
3
|
-
*
|
|
4
|
-
* Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need
|
|
5
|
-
* `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the
|
|
6
|
-
* Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,
|
|
7
|
-
* so `next dev` on any other host keeps Next.js's `Lax` default.
|
|
8
|
-
*/
|
|
9
|
-
export function previewCookieAttributes(host: string | null | undefined): {
|
|
10
|
-
sameSite: "none" | "lax"
|
|
11
|
-
secure: boolean
|
|
12
|
-
} {
|
|
13
|
-
const secure = process.env.NODE_ENV !== "development" || host?.split(":")[0] === "localhost"
|
|
14
|
-
|
|
15
|
-
return { sameSite: secure ? "none" : "lax", secure }
|
|
16
|
-
}
|