@prismicio/next 2.2.2 → 2.2.3-canary.1abb259

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 (178) hide show
  1. package/dist/PrismicNextImage.cjs +16 -20
  2. package/dist/PrismicNextImage.cjs.map +1 -1
  3. package/dist/PrismicNextImage.d.cts +14 -23
  4. package/dist/PrismicNextImage.d.cts.map +1 -0
  5. package/dist/PrismicNextImage.d.ts +14 -23
  6. package/dist/PrismicNextImage.d.ts.map +1 -0
  7. package/dist/PrismicNextImage.js +11 -15
  8. package/dist/PrismicNextImage.js.map +1 -1
  9. package/dist/PrismicNextLink.cjs +7 -8
  10. package/dist/PrismicNextLink.cjs.map +1 -1
  11. package/dist/PrismicNextLink.d.cts +10 -10
  12. package/dist/PrismicNextLink.d.cts.map +1 -0
  13. package/dist/PrismicNextLink.d.ts +10 -10
  14. package/dist/PrismicNextLink.d.ts.map +1 -0
  15. package/dist/PrismicNextLink.js +3 -4
  16. package/dist/PrismicNextLink.js.map +1 -1
  17. package/dist/PrismicPreview.cjs +13 -15
  18. package/dist/PrismicPreview.cjs.map +1 -1
  19. package/dist/PrismicPreview.d.cts +12 -14
  20. package/dist/PrismicPreview.d.cts.map +1 -0
  21. package/dist/PrismicPreview.d.ts +12 -14
  22. package/dist/PrismicPreview.d.ts.map +1 -0
  23. package/dist/PrismicPreview.js +8 -10
  24. package/dist/PrismicPreview.js.map +1 -1
  25. package/dist/PrismicPreviewClient.cjs +5 -9
  26. package/dist/PrismicPreviewClient.cjs.map +1 -1
  27. package/dist/PrismicPreviewClient.js +6 -10
  28. package/dist/PrismicPreviewClient.js.map +1 -1
  29. package/dist/SliceSimulator.cjs +6 -8
  30. package/dist/SliceSimulator.cjs.map +1 -1
  31. package/dist/SliceSimulator.d.cts +3 -6
  32. package/dist/SliceSimulator.d.cts.map +1 -0
  33. package/dist/SliceSimulator.d.ts +3 -6
  34. package/dist/SliceSimulator.d.ts.map +1 -0
  35. package/dist/SliceSimulator.js +4 -6
  36. package/dist/SliceSimulator.js.map +1 -1
  37. package/dist/SliceSimulatorWrapper.cjs +3 -7
  38. package/dist/SliceSimulatorWrapper.cjs.map +1 -1
  39. package/dist/SliceSimulatorWrapper.js +2 -6
  40. package/dist/SliceSimulatorWrapper.js.map +1 -1
  41. package/dist/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.cjs} +8 -14
  42. package/dist/createLocaleRedirect.cjs +2 -3
  43. package/dist/createLocaleRedirect.cjs.map +1 -1
  44. package/dist/createLocaleRedirect.d.cts.map +1 -0
  45. package/dist/createLocaleRedirect.d.ts.map +1 -0
  46. package/dist/createLocaleRedirect.js +1 -2
  47. package/dist/createLocaleRedirect.js.map +1 -1
  48. package/dist/enableAutoPreviews.cjs +4 -6
  49. package/dist/enableAutoPreviews.cjs.map +1 -1
  50. package/dist/enableAutoPreviews.d.cts +2 -4
  51. package/dist/enableAutoPreviews.d.cts.map +1 -0
  52. package/dist/enableAutoPreviews.d.ts +2 -4
  53. package/dist/enableAutoPreviews.d.ts.map +1 -0
  54. package/dist/enableAutoPreviews.js +3 -5
  55. package/dist/enableAutoPreviews.js.map +1 -1
  56. package/dist/exitPreview.cjs +11 -13
  57. package/dist/exitPreview.cjs.map +1 -1
  58. package/dist/exitPreview.d.cts +9 -10
  59. package/dist/exitPreview.d.cts.map +1 -0
  60. package/dist/exitPreview.d.ts +9 -10
  61. package/dist/exitPreview.d.ts.map +1 -0
  62. package/dist/exitPreview.js +11 -12
  63. package/dist/exitPreview.js.map +1 -1
  64. package/dist/getSlices.cjs +2 -3
  65. package/dist/getSlices.cjs.map +1 -1
  66. package/dist/getSlices.d.cts.map +1 -0
  67. package/dist/getSlices.d.ts.map +1 -0
  68. package/dist/getSlices.js +1 -2
  69. package/dist/getSlices.js.map +1 -1
  70. package/dist/imgixLoader.cjs +4 -5
  71. package/dist/imgixLoader.cjs.map +1 -1
  72. package/dist/imgixLoader.d.cts +3 -4
  73. package/dist/imgixLoader.d.cts.map +1 -0
  74. package/dist/imgixLoader.d.ts +3 -4
  75. package/dist/imgixLoader.d.ts.map +1 -0
  76. package/dist/imgixLoader.js +3 -4
  77. package/dist/imgixLoader.js.map +1 -1
  78. package/dist/index.cjs +12 -12
  79. package/dist/index.js +1 -2
  80. package/dist/lib/devMsg.cjs +8 -11
  81. package/dist/lib/devMsg.cjs.map +1 -1
  82. package/dist/lib/devMsg.js +7 -10
  83. package/dist/lib/devMsg.js.map +1 -1
  84. package/dist/lib/resolveDefaultExport.cjs +9 -14
  85. package/dist/lib/resolveDefaultExport.cjs.map +1 -1
  86. package/dist/lib/resolveDefaultExport.js +9 -13
  87. package/dist/lib/resolveDefaultExport.js.map +1 -1
  88. package/dist/package.cjs +7 -8
  89. package/dist/package.js +2 -2
  90. package/dist/pages/PrismicPreview.cjs +12 -14
  91. package/dist/pages/PrismicPreview.cjs.map +1 -1
  92. package/dist/pages/PrismicPreview.d.cts +12 -14
  93. package/dist/pages/PrismicPreview.d.cts.map +1 -0
  94. package/dist/pages/PrismicPreview.d.ts +12 -14
  95. package/dist/pages/PrismicPreview.d.ts.map +1 -0
  96. package/dist/pages/PrismicPreview.js +8 -10
  97. package/dist/pages/PrismicPreview.js.map +1 -1
  98. package/dist/pages/SliceSimulator.cjs +5 -6
  99. package/dist/pages/SliceSimulator.cjs.map +1 -1
  100. package/dist/pages/SliceSimulator.d.cts +10 -13
  101. package/dist/pages/SliceSimulator.d.cts.map +1 -0
  102. package/dist/pages/SliceSimulator.d.ts +10 -13
  103. package/dist/pages/SliceSimulator.d.ts.map +1 -0
  104. package/dist/pages/SliceSimulator.js +3 -4
  105. package/dist/pages/SliceSimulator.js.map +1 -1
  106. package/dist/pages/enableAutoPreviews.cjs +4 -5
  107. package/dist/pages/enableAutoPreviews.cjs.map +1 -1
  108. package/dist/pages/enableAutoPreviews.d.cts +6 -8
  109. package/dist/pages/enableAutoPreviews.d.cts.map +1 -0
  110. package/dist/pages/enableAutoPreviews.d.ts +6 -8
  111. package/dist/pages/enableAutoPreviews.d.ts.map +1 -0
  112. package/dist/pages/enableAutoPreviews.js +4 -4
  113. package/dist/pages/enableAutoPreviews.js.map +1 -1
  114. package/dist/pages/exitPreview.cjs +10 -12
  115. package/dist/pages/exitPreview.cjs.map +1 -1
  116. package/dist/pages/exitPreview.d.cts +9 -10
  117. package/dist/pages/exitPreview.d.cts.map +1 -0
  118. package/dist/pages/exitPreview.d.ts +9 -10
  119. package/dist/pages/exitPreview.d.ts.map +1 -0
  120. package/dist/pages/exitPreview.js +10 -11
  121. package/dist/pages/exitPreview.js.map +1 -1
  122. package/dist/pages/redirectToPreviewURL.cjs +1 -2
  123. package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
  124. package/dist/pages/redirectToPreviewURL.d.cts +8 -11
  125. package/dist/pages/redirectToPreviewURL.d.cts.map +1 -0
  126. package/dist/pages/redirectToPreviewURL.d.ts +8 -11
  127. package/dist/pages/redirectToPreviewURL.d.ts.map +1 -0
  128. package/dist/pages/redirectToPreviewURL.js +1 -1
  129. package/dist/pages/redirectToPreviewURL.js.map +1 -1
  130. package/dist/pages/setPreviewData.cjs +2 -3
  131. package/dist/pages/setPreviewData.cjs.map +1 -1
  132. package/dist/pages/setPreviewData.d.cts.map +1 -0
  133. package/dist/pages/setPreviewData.d.ts.map +1 -0
  134. package/dist/pages/setPreviewData.js +1 -2
  135. package/dist/pages/setPreviewData.js.map +1 -1
  136. package/dist/pages/types.d.cts +3 -9
  137. package/dist/pages/types.d.cts.map +1 -0
  138. package/dist/pages/types.d.ts +3 -9
  139. package/dist/pages/types.d.ts.map +1 -0
  140. package/dist/pages.cjs +12 -12
  141. package/dist/pages.js +1 -2
  142. package/dist/redirectToPreviewURL.cjs +3 -4
  143. package/dist/redirectToPreviewURL.cjs.map +1 -1
  144. package/dist/redirectToPreviewURL.d.cts +4 -7
  145. package/dist/redirectToPreviewURL.d.cts.map +1 -0
  146. package/dist/redirectToPreviewURL.d.ts +4 -7
  147. package/dist/redirectToPreviewURL.d.ts.map +1 -0
  148. package/dist/redirectToPreviewURL.js +2 -3
  149. package/dist/redirectToPreviewURL.js.map +1 -1
  150. package/dist/types.d.cts +1 -2
  151. package/dist/types.d.cts.map +1 -0
  152. package/dist/types.d.ts +1 -2
  153. package/dist/types.d.ts.map +1 -0
  154. package/package.json +34 -36
  155. package/src/PrismicNextImage.tsx +113 -134
  156. package/src/PrismicNextLink.tsx +43 -45
  157. package/src/PrismicPreview.tsx +28 -29
  158. package/src/PrismicPreviewClient.tsx +42 -44
  159. package/src/SliceSimulator.tsx +38 -43
  160. package/src/SliceSimulatorWrapper.tsx +15 -25
  161. package/src/createLocaleRedirect.ts +3 -3
  162. package/src/enableAutoPreviews.ts +15 -16
  163. package/src/exitPreview.ts +12 -13
  164. package/src/getSlices.ts +6 -10
  165. package/src/imgixLoader.ts +10 -10
  166. package/src/index.ts +18 -21
  167. package/src/lib/devMsg.ts +9 -11
  168. package/src/lib/resolveDefaultExport.ts +9 -13
  169. package/src/pages/PrismicPreview.tsx +47 -51
  170. package/src/pages/SliceSimulator.tsx +35 -37
  171. package/src/pages/enableAutoPreviews.ts +17 -17
  172. package/src/pages/exitPreview.ts +17 -18
  173. package/src/pages/index.ts +20 -23
  174. package/src/pages/redirectToPreviewURL.ts +22 -33
  175. package/src/pages/setPreviewData.ts +7 -7
  176. package/src/pages/types.ts +16 -20
  177. package/src/redirectToPreviewURL.ts +21 -30
  178. package/src/types.ts +12 -13
@@ -1,33 +1,30 @@
1
- export { PrismicNextLink } from "../PrismicNextLink";
2
- export { type PrismicNextLinkProps } from "../PrismicNextLink";
1
+ export { PrismicNextLink } from "../PrismicNextLink"
2
+ export { type PrismicNextLinkProps } from "../PrismicNextLink"
3
3
 
4
- export { PrismicNextImage } from "../PrismicNextImage";
5
- export { type PrismicNextImageProps } from "../PrismicNextImage";
4
+ export { PrismicNextImage } from "../PrismicNextImage"
5
+ export { type PrismicNextImageProps } from "../PrismicNextImage"
6
6
 
7
- export { SliceSimulator } from "./SliceSimulator";
8
- export type {
9
- SliceSimulatorProps,
10
- SliceSimulatorSliceZoneProps,
11
- } from "./SliceSimulator";
7
+ export { SliceSimulator } from "./SliceSimulator"
8
+ export type { SliceSimulatorProps, SliceSimulatorSliceZoneProps } from "./SliceSimulator"
12
9
 
13
- export { imgixLoader } from "../imgixLoader";
10
+ export { imgixLoader } from "../imgixLoader"
14
11
 
15
- export { PrismicPreview } from "./PrismicPreview";
16
- export type { PrismicPreviewProps } from "./PrismicPreview";
12
+ export { PrismicPreview } from "./PrismicPreview"
13
+ export type { PrismicPreviewProps } from "./PrismicPreview"
17
14
 
18
- export { enableAutoPreviews } from "./enableAutoPreviews";
19
- export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
15
+ export { enableAutoPreviews } from "./enableAutoPreviews"
16
+ export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
20
17
 
21
- export { redirectToPreviewURL } from "./redirectToPreviewURL";
22
- export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
18
+ export { redirectToPreviewURL } from "./redirectToPreviewURL"
19
+ export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL"
23
20
 
24
- export { exitPreview } from "./exitPreview";
25
- export type { ExitPreviewAPIRouteConfig } from "./exitPreview";
21
+ export { exitPreview } from "./exitPreview"
22
+ export type { ExitPreviewAPIRouteConfig } from "./exitPreview"
26
23
 
27
- export { setPreviewData } from "./setPreviewData";
28
- export type { SetPreviewDataConfig } from "./setPreviewData";
24
+ export { setPreviewData } from "./setPreviewData"
25
+ export type { SetPreviewDataConfig } from "./setPreviewData"
29
26
 
30
- export type { CreateClientConfig } from "./types";
27
+ export type { CreateClientConfig } from "./types"
31
28
 
32
- export { createLocaleRedirect } from "../createLocaleRedirect";
33
- export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect";
29
+ export { createLocaleRedirect } from "../createLocaleRedirect"
30
+ export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect"
@@ -1,77 +1,66 @@
1
- import type { LinkResolverFunction, Client } from "@prismicio/client";
1
+ import type { LinkResolverFunction, Client } from "@prismicio/client"
2
2
 
3
- import type { NextApiRequestLike, NextApiResponseLike } from "./types";
3
+ import type { NextApiRequestLike, NextApiResponseLike } from "./types"
4
4
 
5
5
  export type RedirectToPreviewURLConfig = {
6
6
  /** The Prismic client configured for the preview session's repository. */
7
7
  // `Pick` is used to use the smallest possible subset of
8
8
  // `prismic.Client`. Doing this reduces the surface area for breaking
9
9
  // type changes.
10
- client: Pick<Client, "resolvePreviewURL">;
10
+ client: Pick<Client, "resolvePreviewURL">
11
11
 
12
12
  /**
13
13
  * The `req` object from a Next.js API route.
14
14
  *
15
15
  * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
16
16
  */
17
- req: NextApiRequestLike;
17
+ req: NextApiRequestLike
18
18
 
19
19
  /**
20
20
  * The `res` object from a Next.js API route.
21
21
  *
22
22
  * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
23
23
  */
24
- res: NextApiResponseLike;
24
+ res: NextApiResponseLike
25
25
 
26
26
  /**
27
27
  * A Link Resolver used to resolve the previewed document's URL.
28
28
  *
29
29
  * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
30
30
  */
31
- linkResolver?: LinkResolverFunction;
31
+ linkResolver?: LinkResolverFunction
32
32
 
33
33
  /**
34
- * The default redirect URL if a URL cannot be determined for the previewed
35
- * document.
34
+ * The default redirect URL if a URL cannot be determined for the previewed document.
36
35
  *
37
- * **Note**: If you `next.config.js` file contains a `basePath`, the
38
- * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
39
- * property using the `basePath` option.
36
+ * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
37
+ * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
40
38
  */
41
- defaultURL?: string;
39
+ defaultURL?: string
42
40
 
43
41
  /**
44
- * The `basePath` for the Next.js app as it is defined in `next.config.js`.
45
- * This option can be omitted if the app does not have a `basePath`.
42
+ * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be
43
+ * omitted if the app does not have a `basePath`.
46
44
  *
47
45
  * @remarks
48
- * The Router Handler or API route is unable to detect the app's `basePath`
49
- * automatically. It must be provided to `redirectToPreviewURL()` manually.
46
+ * The Router Handler or API route is unable to detect the app's `basePath` automatically. It
47
+ * must be provided to `redirectToPreviewURL()` manually.
50
48
  */
51
- basePath?: string;
52
- };
49
+ basePath?: string
50
+ }
53
51
 
54
- export async function redirectToPreviewURL(
55
- config: RedirectToPreviewURLConfig,
56
- ): Promise<void> {
57
- const {
58
- client,
59
- req,
60
- res,
61
- linkResolver,
62
- defaultURL = "/",
63
- basePath = "",
64
- } = config;
52
+ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {
53
+ const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config
65
54
 
66
- const previewToken = req.query.token?.toString();
55
+ const previewToken = req.query.token?.toString()
67
56
 
68
57
  const previewURL = await client.resolvePreviewURL({
69
58
  linkResolver,
70
59
  defaultURL,
71
60
  previewToken,
72
- });
61
+ })
73
62
 
74
- res.redirect(basePath + previewURL);
63
+ res.redirect(basePath + previewURL)
75
64
 
76
- return;
65
+ return
77
66
  }
@@ -1,6 +1,6 @@
1
- import { cookie } from "@prismicio/client";
1
+ import { cookie } from "@prismicio/client"
2
2
 
3
- import type { NextApiRequestLike, NextApiResponseLike } from "./types";
3
+ import type { NextApiRequestLike, NextApiResponseLike } from "./types"
4
4
 
5
5
  /** Configuration for `setPreviewData`. */
6
6
  export type SetPreviewDataConfig = {
@@ -9,21 +9,21 @@ export type SetPreviewDataConfig = {
9
9
  *
10
10
  * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
11
11
  */
12
- req: NextApiRequestLike;
12
+ req: NextApiRequestLike
13
13
 
14
14
  /**
15
15
  * The `res` object from a Next.js API route.
16
16
  *
17
17
  * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
18
18
  */
19
- res: NextApiResponseLike;
20
- };
19
+ res: NextApiResponseLike
20
+ }
21
21
 
22
22
  /** Set Prismic preview data for Next.js's Preview Mode. */
23
23
  export function setPreviewData({ req, res }: SetPreviewDataConfig): void {
24
- const ref = req.query.token || req.cookies[cookie.preview];
24
+ const ref = req.query.token || req.cookies[cookie.preview]
25
25
 
26
26
  if (ref) {
27
- res.setPreviewData({ ref });
27
+ res.setPreviewData({ ref })
28
28
  }
29
29
  }
@@ -1,35 +1,31 @@
1
- import type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
2
- import type { ClientConfig } from "@prismicio/client";
1
+ import type { ClientConfig } from "@prismicio/client"
3
2
 
4
- /**
5
- * Configuration for creating a Prismic client with automatic preview support in
6
- * Next.js apps.
7
- */
3
+ import type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
4
+
5
+ /** Configuration for creating a Prismic client with automatic preview support in Next.js apps. */
8
6
  export type CreateClientConfig = ClientConfig &
9
- Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
7
+ Pick<EnableAutoPreviewsConfig, "previewData" | "req">
10
8
 
11
9
  /**
12
10
  * The minimal set of properties needed from `next`'s `NextApiRequest` type.
13
11
  *
14
- * This request type is only compatible with API routes defined in the `pages`
15
- * directory.
12
+ * This request type is only compatible with API routes defined in the `pages` directory.
16
13
  */
17
14
  export type NextApiRequestLike = {
18
- query: Partial<Record<string, string | string[]>>;
19
- cookies: Partial<Record<string, string>>;
20
- };
15
+ query: Partial<Record<string, string | string[]>>
16
+ cookies: Partial<Record<string, string>>
17
+ }
21
18
 
22
19
  /**
23
20
  * The minimal set of properties needed from `next`'s `NextApiResponse` type.
24
21
  *
25
- * This request type is only compatible with API routes defined in the `pages`
26
- * directory.
22
+ * This request type is only compatible with API routes defined in the `pages` directory.
27
23
  */
28
24
  export type NextApiResponseLike = {
29
- redirect(url: string): NextApiResponseLike;
30
- clearPreviewData(): NextApiResponseLike;
31
- setHeader(name: string, value: string | string[]): NextApiResponseLike;
25
+ redirect(url: string): NextApiResponseLike
26
+ clearPreviewData(): NextApiResponseLike
27
+ setHeader(name: string, value: string | string[]): NextApiResponseLike
32
28
  // oxlint-disable-next-line no-explicit-any explicit-module-boundary-types
33
- json(body: any): void;
34
- setPreviewData(data: object | string): NextApiResponseLike;
35
- };
29
+ json(body: any): void
30
+ setPreviewData(data: object | string): NextApiResponseLike
31
+ }
@@ -1,65 +1,56 @@
1
- import { redirect } from "next/navigation";
2
- import {
3
- cookie as prismicCookie,
4
- type Client,
5
- type LinkResolverFunction,
6
- } from "@prismicio/client";
1
+ import { cookie as prismicCookie, type Client, type LinkResolverFunction } from "@prismicio/client"
2
+ import { redirect } from "next/navigation"
7
3
 
8
- import type { NextRequestLike } from "./types";
4
+ import type { NextRequestLike } from "./types"
9
5
 
10
6
  export type RedirectToPreviewURLConfig = {
11
7
  /** The Prismic client configured for the preview session's repository. */
12
8
  // `Pick` is used to use the smallest possible subset of
13
9
  // `prismic.Client`. Doing this reduces the surface area for breaking
14
10
  // type changes.
15
- client: Pick<Client, "resolvePreviewURL">;
11
+ client: Pick<Client, "resolvePreviewURL">
16
12
 
17
13
  /**
18
14
  * The `request` object from a Next.js Route Handler.
19
15
  *
20
16
  * @see Next.js Route Handler docs: \<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\>
21
17
  */
22
- request: NextRequestLike;
18
+ request: NextRequestLike
23
19
 
24
20
  /**
25
21
  * A Link Resolver used to resolve the previewed document's URL.
26
22
  *
27
23
  * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
28
24
  */
29
- linkResolver?: LinkResolverFunction;
25
+ linkResolver?: LinkResolverFunction
30
26
 
31
27
  /**
32
- * The default redirect URL if a URL cannot be determined for the previewed
33
- * document.
28
+ * The default redirect URL if a URL cannot be determined for the previewed document.
34
29
  *
35
- * **Note**: If you `next.config.js` file contains a `basePath`, the
36
- * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
37
- * property using the `basePath` option.
30
+ * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
31
+ * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
38
32
  */
39
- defaultURL?: string;
40
- };
33
+ defaultURL?: string
34
+ }
41
35
 
42
- export async function redirectToPreviewURL(
43
- config: RedirectToPreviewURLConfig,
44
- ): Promise<never> {
45
- const { client, request, linkResolver, defaultURL = "/" } = config;
36
+ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {
37
+ const { client, request, linkResolver, defaultURL = "/" } = config
46
38
 
47
39
  // Need this to avoid the following Next.js build-time error:
48
40
  // You're importing a component that needs next/headers. That only works
49
41
  // in a Server Component which is not supported in the pages/ directory.
50
- const { cookies, draftMode } = await import("next/headers");
42
+ const { cookies, draftMode } = await import("next/headers")
51
43
 
52
- const documentID =
53
- request.nextUrl.searchParams.get("documentId") ?? undefined;
44
+ const documentID = request.nextUrl.searchParams.get("documentId") ?? undefined
54
45
 
55
46
  // Set the initial preview cookie. Setting the cookie here is necessary
56
47
  // to support unpublished previews. Without setting it here, the page
57
48
  // will try to render without the preview cookie, leading to a
58
49
  // PrismicNotFound error.
59
- const previewToken = request.nextUrl.searchParams.get("token") ?? undefined;
50
+ const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
60
51
  if (previewToken) {
61
- const cookieJar = await cookies();
62
- cookieJar.set(prismicCookie.preview, previewToken);
52
+ const cookieJar = await cookies()
53
+ cookieJar.set(prismicCookie.preview, previewToken)
63
54
  }
64
55
 
65
56
  const previewURL = await client.resolvePreviewURL({
@@ -67,9 +58,9 @@ export async function redirectToPreviewURL(
67
58
  previewToken,
68
59
  defaultURL,
69
60
  linkResolver,
70
- });
61
+ })
71
62
 
72
- (await draftMode()).enable();
63
+ ;(await draftMode()).enable()
73
64
 
74
- redirect(previewURL);
65
+ redirect(previewURL)
75
66
  }
package/src/types.ts CHANGED
@@ -1,30 +1,29 @@
1
- import type { ClientConfig } from "@prismicio/client";
1
+ import type { ClientConfig } from "@prismicio/client"
2
2
 
3
3
  // Add Next.js-specific fetchOptions to `@prismicio/client`.
4
4
  declare module "@prismicio/client" {
5
5
  interface RequestInitLike {
6
- next?: RequestInit["next"];
6
+ next?: RequestInit["next"]
7
7
  }
8
8
  }
9
9
 
10
10
  /** @deprecated Use `@prismicio/client`'s `ClientConfig`. */
11
- export type CreateClientConfig = ClientConfig;
11
+ export type CreateClientConfig = ClientConfig
12
12
 
13
13
  /**
14
14
  * The minimal set of properties needed from `next`'s `NextRequest` type.
15
15
  *
16
- * This request type is only compatible with Route Handlers defined in the `app`
17
- * directory.
16
+ * This request type is only compatible with Route Handlers defined in the `app` directory.
18
17
  */
19
18
  export type NextRequestLike = {
20
19
  headers: {
21
- get(name: string): string | null;
22
- };
23
- url: string;
20
+ get(name: string): string | null
21
+ }
22
+ url: string
24
23
  nextUrl: {
25
- pathname: string;
24
+ pathname: string
26
25
  searchParams: {
27
- get(name: string): string | null;
28
- };
29
- };
30
- };
26
+ get(name: string): string | null
27
+ }
28
+ }
29
+ }