@prismicio/next 2.3.4-pr.175.5f9614e → 2.3.4-pr.176.2b93539

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/PrismicPreview.cjs +19 -5
  2. package/dist/PrismicPreview.cjs.map +1 -1
  3. package/dist/PrismicPreview.d.cts.map +1 -1
  4. package/dist/PrismicPreview.d.ts.map +1 -1
  5. package/dist/PrismicPreview.js +17 -5
  6. package/dist/PrismicPreview.js.map +1 -1
  7. package/dist/PrismicPreviewClient.cjs +1 -11
  8. package/dist/PrismicPreviewClient.cjs.map +1 -1
  9. package/dist/PrismicPreviewClient.js +1 -9
  10. package/dist/PrismicPreviewClient.js.map +1 -1
  11. package/dist/exitPreview.cjs +0 -6
  12. package/dist/exitPreview.cjs.map +1 -1
  13. package/dist/exitPreview.d.cts.map +1 -1
  14. package/dist/exitPreview.d.ts.map +1 -1
  15. package/dist/exitPreview.js +0 -6
  16. package/dist/exitPreview.js.map +1 -1
  17. package/dist/package.cjs +1 -1
  18. package/dist/package.js +1 -1
  19. package/dist/pages/PrismicPreview.cjs +2 -2
  20. package/dist/pages/PrismicPreview.cjs.map +1 -1
  21. package/dist/pages/PrismicPreview.d.cts.map +1 -1
  22. package/dist/pages/PrismicPreview.d.ts.map +1 -1
  23. package/dist/pages/PrismicPreview.js +3 -3
  24. package/dist/pages/PrismicPreview.js.map +1 -1
  25. package/dist/pages/exitPreview.cjs +0 -3
  26. package/dist/pages/exitPreview.cjs.map +1 -1
  27. package/dist/pages/exitPreview.d.cts.map +1 -1
  28. package/dist/pages/exitPreview.d.ts.map +1 -1
  29. package/dist/pages/exitPreview.js +0 -3
  30. package/dist/pages/exitPreview.js.map +1 -1
  31. package/dist/pages/redirectToPreviewURL.cjs +1 -18
  32. package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
  33. package/dist/pages/redirectToPreviewURL.d.cts +1 -1
  34. package/dist/pages/redirectToPreviewURL.d.cts.map +1 -1
  35. package/dist/pages/redirectToPreviewURL.d.ts +1 -1
  36. package/dist/pages/redirectToPreviewURL.d.ts.map +1 -1
  37. package/dist/pages/redirectToPreviewURL.js +1 -18
  38. package/dist/pages/redirectToPreviewURL.js.map +1 -1
  39. package/dist/pages/types.d.cts +0 -1
  40. package/dist/pages/types.d.cts.map +1 -1
  41. package/dist/pages/types.d.ts +0 -1
  42. package/dist/pages/types.d.ts.map +1 -1
  43. package/dist/redirectToPreviewURL.cjs +3 -13
  44. package/dist/redirectToPreviewURL.cjs.map +1 -1
  45. package/dist/redirectToPreviewURL.d.cts +1 -1
  46. package/dist/redirectToPreviewURL.d.cts.map +1 -1
  47. package/dist/redirectToPreviewURL.d.ts +1 -1
  48. package/dist/redirectToPreviewURL.d.ts.map +1 -1
  49. package/dist/redirectToPreviewURL.js +3 -13
  50. package/dist/redirectToPreviewURL.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/PrismicPreview.tsx +7 -0
  53. package/src/PrismicPreviewClient.tsx +1 -12
  54. package/src/exitPreview.ts +0 -3
  55. package/src/pages/PrismicPreview.tsx +4 -7
  56. package/src/pages/exitPreview.ts +0 -3
  57. package/src/pages/redirectToPreviewURL.ts +3 -24
  58. package/src/pages/types.ts +0 -1
  59. package/src/redirectToPreviewURL.ts +10 -16
  60. package/dist/lib/toolbarV5.cjs +0 -37
  61. package/dist/lib/toolbarV5.cjs.map +0 -1
  62. package/dist/lib/toolbarV5.js +0 -34
  63. package/dist/lib/toolbarV5.js.map +0 -1
  64. package/dist/pages/appendCookie.cjs +0 -12
  65. package/dist/pages/appendCookie.cjs.map +0 -1
  66. package/dist/pages/appendCookie.js +0 -12
  67. package/dist/pages/appendCookie.js.map +0 -1
  68. package/src/lib/toolbarV5.ts +0 -54
  69. package/src/pages/appendCookie.ts +0 -16
@@ -1,54 +0,0 @@
1
- import { getToolbarSrc, PreviewTokenExpiredError, type Client } from "@prismicio/client"
2
-
3
- /** The cookie storing the preview session ID. The toolbar's v5 flow follows this session. */
4
- export const previewSessionCookie = "io.prismic.previewSession"
5
-
6
- /**
7
- * Props for the toolbar's `<script>`, opting into its v5 flow.
8
- *
9
- * @param previewURL - The app's preview route, as passed to `fetch()`.
10
- */
11
- export function getToolbarScriptProps(
12
- repositoryName: string,
13
- previewURL: string,
14
- ): { src: string; "data-preview-url"?: string } {
15
- return {
16
- // TODO: Use `getToolbarSrc()` once `@prismicio/client` adds `v=5`.
17
- src: `${getToolbarSrc(repositoryName)}&v=5`,
18
- // The toolbar builds share links with this URL. `next/script` adds `lazyOnload` scripts in
19
- // the browser, where the URL is known.
20
- "data-preview-url":
21
- typeof window === "undefined" ? undefined : new URL(previewURL, document.baseURI).href,
22
- }
23
- }
24
-
25
- /** Fetches the current ref of a preview session, for share links that only carry the session. */
26
- export async function getPreviewSessionRef(
27
- client: Pick<Client, "documentAPIEndpoint">,
28
- session: string,
29
- ): Promise<string> {
30
- const url = new URL(`/previews/token/${encodeURIComponent(session)}`, client.documentAPIEndpoint)
31
- // The endpoint is on the repository host, not on its CDN.
32
- url.hostname = url.hostname.replace(".cdn.", ".")
33
- const res = await fetch(url, { cache: "no-store" })
34
- const json = await res.json()
35
- if (!json.ref) {
36
- // Like the Content API's response to an expired preview token.
37
- throw new PreviewTokenExpiredError("This preview session has expired", url.href, json)
38
- }
39
-
40
- return json.ref
41
- }
42
-
43
- /** Returns `path` if it is a path on the same origin, like `/blog?page=2`. */
44
- export function getSafePath(path: string | undefined | null): string | undefined {
45
- if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) {
46
- return
47
- }
48
-
49
- const origin = "https://placeholder.invalid"
50
- const url = new URL(path, origin)
51
- if (url.origin === origin) {
52
- return url.href.slice(origin.length)
53
- }
54
- }
@@ -1,16 +0,0 @@
1
- import type { NextApiResponseLike } from "./types"
2
-
3
- /** Adds a cookie like the App Router's preview cookie, keeping Next.js's preview data cookies. */
4
- export function appendCookie(
5
- res: NextApiResponseLike,
6
- name: string,
7
- value: string,
8
- expires?: Date,
9
- ): void {
10
- const previous = res.getHeader("Set-Cookie") ?? []
11
- let cookie = `${name}=${encodeURIComponent(value)}; Path=/; SameSite=None; Secure`
12
- if (expires) {
13
- cookie += `; Expires=${expires.toUTCString()}`
14
- }
15
- res.setHeader("Set-Cookie", [...[previous].flat().map(String), cookie])
16
- }