@prismicio/next 2.2.3-pr.136.19d76d2 → 2.2.3

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 (159) hide show
  1. package/dist/PrismicNextImage.cjs +11 -9
  2. package/dist/PrismicNextImage.cjs.map +1 -1
  3. package/dist/PrismicNextImage.d.cts +21 -13
  4. package/dist/PrismicNextImage.d.ts +21 -13
  5. package/dist/PrismicNextImage.js +11 -9
  6. package/dist/PrismicNextImage.js.map +1 -1
  7. package/dist/PrismicNextLink.cjs.map +1 -1
  8. package/dist/PrismicNextLink.js.map +1 -1
  9. package/dist/PrismicPreview.cjs +7 -6
  10. package/dist/PrismicPreview.cjs.map +1 -1
  11. package/dist/PrismicPreview.d.cts +12 -11
  12. package/dist/PrismicPreview.d.ts +12 -11
  13. package/dist/PrismicPreview.js +7 -6
  14. package/dist/PrismicPreview.js.map +1 -1
  15. package/dist/PrismicPreviewClient.cjs +3 -1
  16. package/dist/PrismicPreviewClient.cjs.map +1 -1
  17. package/dist/PrismicPreviewClient.js +3 -1
  18. package/dist/PrismicPreviewClient.js.map +1 -1
  19. package/dist/SliceSimulator.cjs +3 -3
  20. package/dist/SliceSimulator.cjs.map +1 -1
  21. package/dist/SliceSimulator.d.cts +5 -3
  22. package/dist/SliceSimulator.d.ts +5 -3
  23. package/dist/SliceSimulator.js +3 -3
  24. package/dist/SliceSimulator.js.map +1 -1
  25. package/dist/SliceSimulatorWrapper.cjs +4 -1
  26. package/dist/SliceSimulatorWrapper.cjs.map +1 -1
  27. package/dist/SliceSimulatorWrapper.js +4 -1
  28. package/dist/SliceSimulatorWrapper.js.map +1 -1
  29. package/dist/createLocaleRedirect.cjs.map +1 -1
  30. package/dist/createLocaleRedirect.js.map +1 -1
  31. package/dist/enableAutoPreviews.cjs +2 -1
  32. package/dist/enableAutoPreviews.cjs.map +1 -1
  33. package/dist/enableAutoPreviews.d.cts +2 -1
  34. package/dist/enableAutoPreviews.d.ts +2 -1
  35. package/dist/enableAutoPreviews.js +2 -1
  36. package/dist/enableAutoPreviews.js.map +1 -1
  37. package/dist/exitPreview.cjs +10 -9
  38. package/dist/exitPreview.cjs.map +1 -1
  39. package/dist/exitPreview.d.cts +10 -9
  40. package/dist/exitPreview.d.ts +10 -9
  41. package/dist/exitPreview.js +10 -9
  42. package/dist/exitPreview.js.map +1 -1
  43. package/dist/getSlices.cjs.map +1 -1
  44. package/dist/getSlices.js.map +1 -1
  45. package/dist/imgixLoader.cjs +2 -2
  46. package/dist/imgixLoader.cjs.map +1 -1
  47. package/dist/imgixLoader.d.cts +2 -2
  48. package/dist/imgixLoader.d.ts +2 -2
  49. package/dist/imgixLoader.js +2 -2
  50. package/dist/imgixLoader.js.map +1 -1
  51. package/dist/lib/devMsg.cjs +8 -6
  52. package/dist/lib/devMsg.cjs.map +1 -1
  53. package/dist/lib/devMsg.js +8 -6
  54. package/dist/lib/devMsg.js.map +1 -1
  55. package/dist/lib/resolveDefaultExport.cjs +12 -8
  56. package/dist/lib/resolveDefaultExport.cjs.map +1 -1
  57. package/dist/lib/resolveDefaultExport.js +12 -8
  58. package/dist/lib/resolveDefaultExport.js.map +1 -1
  59. package/dist/package.cjs +1 -1
  60. package/dist/package.js +1 -1
  61. package/dist/pages/PrismicPreview.cjs +7 -6
  62. package/dist/pages/PrismicPreview.cjs.map +1 -1
  63. package/dist/pages/PrismicPreview.d.cts +12 -11
  64. package/dist/pages/PrismicPreview.d.ts +12 -11
  65. package/dist/pages/PrismicPreview.js +7 -6
  66. package/dist/pages/PrismicPreview.js.map +1 -1
  67. package/dist/pages/SliceSimulator.cjs +2 -2
  68. package/dist/pages/SliceSimulator.cjs.map +1 -1
  69. package/dist/pages/SliceSimulator.d.cts +13 -10
  70. package/dist/pages/SliceSimulator.d.ts +13 -10
  71. package/dist/pages/SliceSimulator.js +2 -2
  72. package/dist/pages/SliceSimulator.js.map +1 -1
  73. package/dist/pages/enableAutoPreviews.cjs +3 -3
  74. package/dist/pages/enableAutoPreviews.cjs.map +1 -1
  75. package/dist/pages/enableAutoPreviews.d.cts +5 -5
  76. package/dist/pages/enableAutoPreviews.d.ts +5 -5
  77. package/dist/pages/enableAutoPreviews.js +3 -3
  78. package/dist/pages/enableAutoPreviews.js.map +1 -1
  79. package/dist/pages/exitPreview.cjs +10 -9
  80. package/dist/pages/exitPreview.cjs.map +1 -1
  81. package/dist/pages/exitPreview.d.cts +10 -9
  82. package/dist/pages/exitPreview.d.ts +10 -9
  83. package/dist/pages/exitPreview.js +10 -9
  84. package/dist/pages/exitPreview.js.map +1 -1
  85. package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
  86. package/dist/pages/redirectToPreviewURL.d.cts +9 -7
  87. package/dist/pages/redirectToPreviewURL.d.ts +9 -7
  88. package/dist/pages/redirectToPreviewURL.js.map +1 -1
  89. package/dist/pages/setPreviewData.cjs.map +1 -1
  90. package/dist/pages/setPreviewData.js.map +1 -1
  91. package/dist/pages/types.d.cts +8 -3
  92. package/dist/pages/types.d.ts +8 -3
  93. package/dist/redirectToPreviewURL.cjs.map +1 -1
  94. package/dist/redirectToPreviewURL.d.cts +5 -3
  95. package/dist/redirectToPreviewURL.d.ts +5 -3
  96. package/dist/redirectToPreviewURL.js.map +1 -1
  97. package/dist/types.d.cts +2 -1
  98. package/dist/types.d.ts +2 -1
  99. package/package.json +25 -23
  100. package/src/PrismicNextImage.tsx +134 -113
  101. package/src/PrismicNextLink.tsx +45 -43
  102. package/src/PrismicPreview.tsx +29 -28
  103. package/src/PrismicPreviewClient.tsx +44 -42
  104. package/src/SliceSimulator.tsx +43 -38
  105. package/src/SliceSimulatorWrapper.tsx +25 -15
  106. package/src/createLocaleRedirect.ts +3 -3
  107. package/src/enableAutoPreviews.ts +16 -15
  108. package/src/exitPreview.ts +13 -12
  109. package/src/getSlices.ts +10 -6
  110. package/src/imgixLoader.ts +10 -10
  111. package/src/index.ts +21 -18
  112. package/src/lib/devMsg.ts +11 -9
  113. package/src/lib/resolveDefaultExport.ts +13 -9
  114. package/src/pages/PrismicPreview.tsx +51 -47
  115. package/src/pages/SliceSimulator.tsx +37 -35
  116. package/src/pages/enableAutoPreviews.ts +17 -17
  117. package/src/pages/exitPreview.ts +18 -17
  118. package/src/pages/index.ts +23 -20
  119. package/src/pages/redirectToPreviewURL.ts +33 -22
  120. package/src/pages/setPreviewData.ts +7 -7
  121. package/src/pages/types.ts +20 -16
  122. package/src/redirectToPreviewURL.ts +30 -21
  123. package/src/types.ts +13 -12
  124. package/dist/PrismicNextImage.d.cts.map +0 -1
  125. package/dist/PrismicNextImage.d.ts.map +0 -1
  126. package/dist/PrismicNextLink.d.cts.map +0 -1
  127. package/dist/PrismicNextLink.d.ts.map +0 -1
  128. package/dist/PrismicPreview.d.cts.map +0 -1
  129. package/dist/PrismicPreview.d.ts.map +0 -1
  130. package/dist/SliceSimulator.d.cts.map +0 -1
  131. package/dist/SliceSimulator.d.ts.map +0 -1
  132. package/dist/createLocaleRedirect.d.cts.map +0 -1
  133. package/dist/createLocaleRedirect.d.ts.map +0 -1
  134. package/dist/enableAutoPreviews.d.cts.map +0 -1
  135. package/dist/enableAutoPreviews.d.ts.map +0 -1
  136. package/dist/exitPreview.d.cts.map +0 -1
  137. package/dist/exitPreview.d.ts.map +0 -1
  138. package/dist/getSlices.d.cts.map +0 -1
  139. package/dist/getSlices.d.ts.map +0 -1
  140. package/dist/imgixLoader.d.cts.map +0 -1
  141. package/dist/imgixLoader.d.ts.map +0 -1
  142. package/dist/pages/PrismicPreview.d.cts.map +0 -1
  143. package/dist/pages/PrismicPreview.d.ts.map +0 -1
  144. package/dist/pages/SliceSimulator.d.cts.map +0 -1
  145. package/dist/pages/SliceSimulator.d.ts.map +0 -1
  146. package/dist/pages/enableAutoPreviews.d.cts.map +0 -1
  147. package/dist/pages/enableAutoPreviews.d.ts.map +0 -1
  148. package/dist/pages/exitPreview.d.cts.map +0 -1
  149. package/dist/pages/exitPreview.d.ts.map +0 -1
  150. package/dist/pages/redirectToPreviewURL.d.cts.map +0 -1
  151. package/dist/pages/redirectToPreviewURL.d.ts.map +0 -1
  152. package/dist/pages/setPreviewData.d.cts.map +0 -1
  153. package/dist/pages/setPreviewData.d.ts.map +0 -1
  154. package/dist/pages/types.d.cts.map +0 -1
  155. package/dist/pages/types.d.ts.map +0 -1
  156. package/dist/redirectToPreviewURL.d.cts.map +0 -1
  157. package/dist/redirectToPreviewURL.d.ts.map +0 -1
  158. package/dist/types.d.cts.map +0 -1
  159. package/dist/types.d.ts.map +0 -1
@@ -17,19 +17,20 @@ type ExitPreviewAPIRouteConfig = {
17
17
  res: NextApiResponseLike;
18
18
  };
19
19
  /**
20
- * Ends a Prismic preview session within a Next.js app. This function should be used in an API
21
- * route.
20
+ * Ends a Prismic preview session within a Next.js app. This function should be
21
+ * used in an API route.
22
22
  *
23
23
  * @example
24
- * ```typescript
25
- * // src/pages/api/exit-preview.js
26
24
  *
27
- * import { exitPreview } from "@prismicio/next"
25
+ * ```typescript
26
+ * // src/pages/api/exit-preview.js
28
27
  *
29
- * export default function handler(_req, res) {
30
- * return exitPreview({ res })
31
- * }
32
- * ```
28
+ * import { exitPreview } from "@prismicio/next";
29
+ *
30
+ * export default function handler(_req, res) {
31
+ * return exitPreview({ res });
32
+ * }
33
+ * ```
33
34
  */
34
35
  declare function exitPreview(config: ExitPreviewAPIRouteConfig): void;
35
36
  //#endregion
@@ -1,18 +1,19 @@
1
1
  //#region src/pages/exitPreview.ts
2
2
  /**
3
- * Ends a Prismic preview session within a Next.js app. This function should be used in an API
4
- * route.
3
+ * Ends a Prismic preview session within a Next.js app. This function should be
4
+ * used in an API route.
5
5
  *
6
6
  * @example
7
- * ```typescript
8
- * // src/pages/api/exit-preview.js
9
7
  *
10
- * import { exitPreview } from "@prismicio/next"
8
+ * ```typescript
9
+ * // src/pages/api/exit-preview.js
11
10
  *
12
- * export default function handler(_req, res) {
13
- * return exitPreview({ res })
14
- * }
15
- * ```
11
+ * import { exitPreview } from "@prismicio/next";
12
+ *
13
+ * export default function handler(_req, res) {
14
+ * return exitPreview({ res });
15
+ * }
16
+ * ```
16
17
  */
17
18
  function exitPreview(config) {
18
19
  config.res.clearPreviewData();
@@ -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 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\n * used in an API route.\n *\n * @example\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(_req, res) {\n * \treturn exitPreview({ res });\n * }\n * ```\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":";;;;;;;;;;;;;;;;;AAmCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;AAG7B,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } 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 `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\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/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike\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\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be\n\t * omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {\n\tconst { client, req, res, linkResolver, defaultURL = \"/\", basePath = \"\" } = config\n\n\tconst previewToken = req.query.token?.toString()\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t})\n\n\tres.redirect(basePath + previewURL)\n\n\treturn\n}\n"],"mappings":";AAmDA,eAAsB,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } 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 `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\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/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike;\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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<void> {\n\tconst {\n\t\tclient,\n\t\treq,\n\t\tres,\n\t\tlinkResolver,\n\t\tdefaultURL = \"/\",\n\t\tbasePath = \"\",\n\t} = config;\n\n\tconst previewToken = req.query.token?.toString();\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t});\n\n\tres.redirect(basePath + previewURL);\n\n\treturn;\n}\n"],"mappings":";AAqDA,eAAsB,qBACrB,QACgB;CAChB,MAAM,EACL,QACA,KACA,KACA,cACA,aAAa,KACb,WAAW,OACR;CAEJ,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
@@ -23,19 +23,21 @@ type RedirectToPreviewURLConfig = {
23
23
  */
24
24
  linkResolver?: LinkResolverFunction;
25
25
  /**
26
- * The default redirect URL if a URL cannot be determined for the previewed document.
26
+ * The default redirect URL if a URL cannot be determined for the previewed
27
+ * document.
27
28
  *
28
- * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
29
- * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
29
+ * **Note**: If you `next.config.js` file contains a `basePath`, the
30
+ * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
31
+ * property using the `basePath` option.
30
32
  */
31
33
  defaultURL?: string;
32
34
  /**
33
- * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be
34
- * omitted if the app does not have a `basePath`.
35
+ * The `basePath` for the Next.js app as it is defined in `next.config.js`.
36
+ * This option can be omitted if the app does not have a `basePath`.
35
37
  *
36
38
  * @remarks
37
- * The Router Handler or API route is unable to detect the app's `basePath` automatically. It
38
- * must be provided to `redirectToPreviewURL()` manually.
39
+ * The Router Handler or API route is unable to detect the app's `basePath`
40
+ * automatically. It must be provided to `redirectToPreviewURL()` manually.
39
41
  */
40
42
  basePath?: string;
41
43
  };
@@ -23,19 +23,21 @@ type RedirectToPreviewURLConfig = {
23
23
  */
24
24
  linkResolver?: LinkResolverFunction;
25
25
  /**
26
- * The default redirect URL if a URL cannot be determined for the previewed document.
26
+ * The default redirect URL if a URL cannot be determined for the previewed
27
+ * document.
27
28
  *
28
- * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
29
- * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
29
+ * **Note**: If you `next.config.js` file contains a `basePath`, the
30
+ * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
31
+ * property using the `basePath` option.
30
32
  */
31
33
  defaultURL?: string;
32
34
  /**
33
- * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be
34
- * omitted if the app does not have a `basePath`.
35
+ * The `basePath` for the Next.js app as it is defined in `next.config.js`.
36
+ * This option can be omitted if the app does not have a `basePath`.
35
37
  *
36
38
  * @remarks
37
- * The Router Handler or API route is unable to detect the app's `basePath` automatically. It
38
- * must be provided to `redirectToPreviewURL()` manually.
39
+ * The Router Handler or API route is unable to detect the app's `basePath`
40
+ * automatically. It must be provided to `redirectToPreviewURL()` manually.
39
41
  */
40
42
  basePath?: string;
41
43
  };
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.js","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } 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 `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\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/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike\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\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be\n\t * omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {\n\tconst { client, req, res, linkResolver, defaultURL = \"/\", basePath = \"\" } = config\n\n\tconst previewToken = req.query.token?.toString()\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t})\n\n\tres.redirect(basePath + previewURL)\n\n\treturn\n}\n"],"mappings":";AAmDA,eAAsB,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.js","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } 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 `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\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/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike;\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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<void> {\n\tconst {\n\t\tclient,\n\t\treq,\n\t\tres,\n\t\tlinkResolver,\n\t\tdefaultURL = \"/\",\n\t\tbasePath = \"\",\n\t} = config;\n\n\tconst previewToken = req.query.token?.toString();\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t});\n\n\tres.redirect(basePath + previewURL);\n\n\treturn;\n}\n"],"mappings":";AAqDA,eAAsB,qBACrB,QACgB;CAChB,MAAM,EACL,QACA,KACA,KACA,cACA,aAAa,KACb,WAAW,OACR;CAEJ,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"setPreviewData.cjs","names":["cookie"],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\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/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview]\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,kBAAAA,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
1
+ {"version":3,"file":"setPreviewData.cjs","names":["cookie"],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\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/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"mappings":";;;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,kBAAAA,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\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/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview]\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
1
+ {"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\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/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"mappings":";;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
@@ -2,12 +2,16 @@ import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.cjs";
2
2
  import { ClientConfig } from "@prismicio/client";
3
3
 
4
4
  //#region src/pages/types.d.ts
5
- /** Configuration for creating a Prismic client with automatic preview support in Next.js apps. */
5
+ /**
6
+ * Configuration for creating a Prismic client with automatic preview support in
7
+ * Next.js apps.
8
+ */
6
9
  type CreateClientConfig = ClientConfig & Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
7
10
  /**
8
11
  * The minimal set of properties needed from `next`'s `NextApiRequest` type.
9
12
  *
10
- * This request type is only compatible with API routes defined in the `pages` directory.
13
+ * This request type is only compatible with API routes defined in the `pages`
14
+ * directory.
11
15
  */
12
16
  type NextApiRequestLike = {
13
17
  query: Partial<Record<string, string | string[]>>;
@@ -16,7 +20,8 @@ type NextApiRequestLike = {
16
20
  /**
17
21
  * The minimal set of properties needed from `next`'s `NextApiResponse` type.
18
22
  *
19
- * This request type is only compatible with API routes defined in the `pages` directory.
23
+ * This request type is only compatible with API routes defined in the `pages`
24
+ * directory.
20
25
  */
21
26
  type NextApiResponseLike = {
22
27
  redirect(url: string): NextApiResponseLike;
@@ -2,12 +2,16 @@ import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.js";
2
2
  import { ClientConfig } from "@prismicio/client";
3
3
 
4
4
  //#region src/pages/types.d.ts
5
- /** Configuration for creating a Prismic client with automatic preview support in Next.js apps. */
5
+ /**
6
+ * Configuration for creating a Prismic client with automatic preview support in
7
+ * Next.js apps.
8
+ */
6
9
  type CreateClientConfig = ClientConfig & Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
7
10
  /**
8
11
  * The minimal set of properties needed from `next`'s `NextApiRequest` type.
9
12
  *
10
- * This request type is only compatible with API routes defined in the `pages` directory.
13
+ * This request type is only compatible with API routes defined in the `pages`
14
+ * directory.
11
15
  */
12
16
  type NextApiRequestLike = {
13
17
  query: Partial<Record<string, string | string[]>>;
@@ -16,7 +20,8 @@ type NextApiRequestLike = {
16
20
  /**
17
21
  * The minimal set of properties needed from `next`'s `NextApiResponse` type.
18
22
  *
19
- * This request type is only compatible with API routes defined in the `pages` directory.
23
+ * This request type is only compatible with API routes defined in the `pages`
24
+ * directory.
20
25
  */
21
26
  type NextApiResponseLike = {
22
27
  redirect(url: string): NextApiResponseLike;
@@ -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\"\nimport { redirect } from \"next/navigation\"\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\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\tredirect(previewURL)\n}\n"],"mappings":";;;;AAmCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,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,EAAA,GAAA,gBAAA,UAAS,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} 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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): 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\tconst documentID =\n\t\trequest.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\tredirect(previewURL);\n}\n"],"mappings":";;;;AAyCA,eAAsB,qBACrB,QACiB;CACjB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMnD,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;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,EAAA,GAAA,gBAAA,UAAS,WAAW"}
@@ -17,10 +17,12 @@ type RedirectToPreviewURLConfig = {
17
17
  */
18
18
  linkResolver?: LinkResolverFunction;
19
19
  /**
20
- * The default redirect URL if a URL cannot be determined for the previewed document.
20
+ * The default redirect URL if a URL cannot be determined for the previewed
21
+ * document.
21
22
  *
22
- * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
23
- * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
23
+ * **Note**: If you `next.config.js` file contains a `basePath`, the
24
+ * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
25
+ * property using the `basePath` option.
24
26
  */
25
27
  defaultURL?: string;
26
28
  };
@@ -17,10 +17,12 @@ type RedirectToPreviewURLConfig = {
17
17
  */
18
18
  linkResolver?: LinkResolverFunction;
19
19
  /**
20
- * The default redirect URL if a URL cannot be determined for the previewed document.
20
+ * The default redirect URL if a URL cannot be determined for the previewed
21
+ * document.
21
22
  *
22
- * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
23
- * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
23
+ * **Note**: If you `next.config.js` file contains a `basePath`, the
24
+ * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
25
+ * property using the `basePath` option.
24
26
  */
25
27
  defaultURL?: string;
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\"\nimport { redirect } from \"next/navigation\"\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\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\tredirect(previewURL)\n}\n"],"mappings":";;;AAmCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,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,UAAS,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} 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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): 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\tconst documentID =\n\t\trequest.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\tredirect(previewURL);\n}\n"],"mappings":";;;AAyCA,eAAsB,qBACrB,QACiB;CACjB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMnD,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;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,UAAS,WAAW"}
package/dist/types.d.cts CHANGED
@@ -11,7 +11,8 @@ type CreateClientConfig = ClientConfig;
11
11
  /**
12
12
  * The minimal set of properties needed from `next`'s `NextRequest` type.
13
13
  *
14
- * This request type is only compatible with Route Handlers defined in the `app` directory.
14
+ * This request type is only compatible with Route Handlers defined in the `app`
15
+ * directory.
15
16
  */
16
17
  type NextRequestLike = {
17
18
  headers: {
package/dist/types.d.ts CHANGED
@@ -11,7 +11,8 @@ type CreateClientConfig = ClientConfig;
11
11
  /**
12
12
  * The minimal set of properties needed from `next`'s `NextRequest` type.
13
13
  *
14
- * This request type is only compatible with Route Handlers defined in the `app` directory.
14
+ * This request type is only compatible with Route Handlers defined in the `app`
15
+ * directory.
15
16
  */
16
17
  type NextRequestLike = {
17
18
  headers: {
package/package.json CHANGED
@@ -1,32 +1,22 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.2.3-pr.136.19d76d2",
3
+ "version": "2.2.3",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
- "next",
7
- "preview",
8
- "prismic",
9
6
  "typescript",
10
- "vercel"
7
+ "prismic",
8
+ "next",
9
+ "vercel",
10
+ "preview"
11
11
  ],
12
- "license": "Apache-2.0",
13
- "author": "Prismic <contact@prismic.io> (https://prismic.io)",
14
12
  "repository": {
15
13
  "type": "git",
16
14
  "url": "git+https://github.com/prismicio/prismic-next.git"
17
15
  },
18
- "workspaces": [
19
- ".",
20
- "e2e-projects/*"
21
- ],
22
- "files": [
23
- "dist",
24
- "src"
25
- ],
26
- "type": "module",
16
+ "license": "Apache-2.0",
17
+ "author": "Prismic <contact@prismic.io> (https://prismic.io)",
27
18
  "sideEffects": false,
28
- "main": "./dist/index.cjs",
29
- "types": "./dist/index.d.ts",
19
+ "type": "module",
30
20
  "exports": {
31
21
  ".": {
32
22
  "types": "./dist/index.d.ts",
@@ -38,15 +28,22 @@
38
28
  },
39
29
  "./package.json": "./package.json"
40
30
  },
41
- "publishConfig": {
42
- "access": "public"
43
- },
31
+ "main": "./dist/index.cjs",
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist",
35
+ "src"
36
+ ],
37
+ "workspaces": [
38
+ ".",
39
+ "e2e-projects/*"
40
+ ],
44
41
  "scripts": {
45
42
  "build": "tsdown",
46
43
  "dev": "tsdown --watch",
47
44
  "e2e": "playwright test",
48
45
  "e2e:ui": "npm run e2e -- --ui",
49
- "format": "oxfmt",
46
+ "format": "prettier --write .",
50
47
  "lint": "oxlint --deny-warnings",
51
48
  "prepare": "npm run build",
52
49
  "test": "npm run lint && npm run types && npm run build && npm run e2e",
@@ -60,12 +57,14 @@
60
57
  "devDependencies": {
61
58
  "@playwright/test": "^1.58.2",
62
59
  "@prismicio/client": "^7.12.0",
60
+ "@trivago/prettier-plugin-sort-imports": "^6.0.2",
63
61
  "@types/node": "^25.5.0",
64
62
  "@types/react": "^19.2.14",
65
63
  "next": "16.2.1",
66
- "oxfmt": "^0.43.0",
67
64
  "oxlint": "^1.58.0",
68
65
  "playwright": "^1.58.2",
66
+ "prettier": "^3.8.1",
67
+ "prettier-plugin-jsdoc": "^1.8.0",
69
68
  "react": "^19.2.4",
70
69
  "react-dom": "^19.2.4",
71
70
  "tsdown": "^0.21.7",
@@ -78,5 +77,8 @@
78
77
  },
79
78
  "engines": {
80
79
  "node": ">=20"
80
+ },
81
+ "publishConfig": {
82
+ "access": "public"
81
83
  }
82
84
  }