@prismicio/next 2.3.4-pr.174.890bc09 → 2.3.4-pr.175.5f9614e
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/PrismicPreview.cjs +5 -19
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts.map +1 -1
- package/dist/PrismicPreview.d.ts.map +1 -1
- package/dist/PrismicPreview.js +5 -17
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +11 -1
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js +9 -1
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/exitPreview.cjs +6 -0
- 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 +6 -0
- package/dist/exitPreview.js.map +1 -1
- package/dist/lib/toolbarV5.cjs +37 -0
- package/dist/lib/toolbarV5.cjs.map +1 -0
- package/dist/lib/toolbarV5.js +34 -0
- package/dist/lib/toolbarV5.js.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/PrismicPreview.cjs +2 -2
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts.map +1 -1
- package/dist/pages/PrismicPreview.d.ts.map +1 -1
- package/dist/pages/PrismicPreview.js +3 -3
- package/dist/pages/PrismicPreview.js.map +1 -1
- package/dist/pages/appendCookie.cjs +12 -0
- package/dist/pages/appendCookie.cjs.map +1 -0
- package/dist/pages/appendCookie.js +12 -0
- package/dist/pages/appendCookie.js.map +1 -0
- package/dist/pages/exitPreview.cjs +3 -0
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts.map +1 -1
- package/dist/pages/exitPreview.d.ts.map +1 -1
- package/dist/pages/exitPreview.js +3 -0
- package/dist/pages/exitPreview.js.map +1 -1
- package/dist/pages/redirectToPreviewURL.cjs +18 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.ts +1 -1
- package/dist/pages/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/pages/redirectToPreviewURL.js +18 -1
- package/dist/pages/redirectToPreviewURL.js.map +1 -1
- package/dist/pages/types.d.cts +1 -0
- package/dist/pages/types.d.cts.map +1 -1
- package/dist/pages/types.d.ts +1 -0
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.cjs +13 -3
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +1 -1
- package/dist/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/redirectToPreviewURL.d.ts +1 -1
- package/dist/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.js +13 -3
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +8 -8
- package/src/PrismicPreview.tsx +0 -7
- package/src/PrismicPreviewClient.tsx +12 -1
- package/src/exitPreview.ts +3 -0
- package/src/lib/toolbarV5.ts +54 -0
- package/src/pages/PrismicPreview.tsx +7 -4
- package/src/pages/appendCookie.ts +16 -0
- package/src/pages/exitPreview.ts +3 -0
- package/src/pages/redirectToPreviewURL.ts +24 -3
- package/src/pages/types.ts +1 -0
- package/src/redirectToPreviewURL.ts +16 -10
package/src/pages/types.ts
CHANGED
|
@@ -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
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cookie as prismicCookie, type Client, type LinkResolverFunction } from "@prismicio/client"
|
|
2
2
|
|
|
3
|
+
import { getPreviewSessionRef, getSafePath, previewSessionCookie } from "./lib/toolbarV5"
|
|
3
4
|
import type { NextRequestLike } from "./types"
|
|
4
5
|
|
|
5
6
|
export type RedirectToPreviewURLConfig = {
|
|
@@ -7,7 +8,7 @@ export type RedirectToPreviewURLConfig = {
|
|
|
7
8
|
// `Pick` is used to use the smallest possible subset of
|
|
8
9
|
// `prismic.Client`. Doing this reduces the surface area for breaking
|
|
9
10
|
// type changes.
|
|
10
|
-
client: Pick<Client, "resolvePreviewURL">
|
|
11
|
+
client: Pick<Client, "resolvePreviewURL" | "documentAPIEndpoint">
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The `request` object from a Next.js Route Handler.
|
|
@@ -44,24 +45,29 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
44
45
|
// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.
|
|
45
46
|
const { redirect } = await import("next/navigation")
|
|
46
47
|
|
|
47
|
-
const
|
|
48
|
+
const { searchParams } = request.nextUrl
|
|
49
|
+
const documentID = searchParams.get("documentId") ?? undefined
|
|
50
|
+
let previewToken = searchParams.get("token") ?? undefined
|
|
51
|
+
const cookieJar = await cookies()
|
|
52
|
+
|
|
53
|
+
// The toolbar's v5 flow follows the session. Share links only carry the session.
|
|
54
|
+
const session = searchParams.get("session")
|
|
55
|
+
if (session) {
|
|
56
|
+
previewToken ??= await getPreviewSessionRef(client, session)
|
|
57
|
+
cookieJar.set(previewSessionCookie, session, { sameSite: "none", secure: true })
|
|
58
|
+
}
|
|
48
59
|
|
|
49
60
|
// Set the initial preview cookie. Setting the cookie here is necessary
|
|
50
61
|
// to support unpublished previews. Without setting it here, the page
|
|
51
62
|
// will try to render without the preview cookie, leading to a
|
|
52
63
|
// PrismicNotFound error.
|
|
53
|
-
const cookieJar = await cookies()
|
|
54
|
-
const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
|
|
55
64
|
if (previewToken) {
|
|
56
65
|
cookieJar.set(prismicCookie.preview, previewToken, { sameSite: "none", secure: true })
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
const previewURL =
|
|
60
|
-
|
|
61
|
-
previewToken,
|
|
62
|
-
defaultURL,
|
|
63
|
-
linkResolver,
|
|
64
|
-
})
|
|
68
|
+
const previewURL =
|
|
69
|
+
(session && getSafePath(searchParams.get("path"))) ||
|
|
70
|
+
(await client.resolvePreviewURL({ documentID, previewToken, defaultURL, linkResolver }))
|
|
65
71
|
|
|
66
72
|
;(await draftMode()).enable()
|
|
67
73
|
|