@prismicio/next 2.3.4-pr.175.5f9614e → 2.3.4-pr.175.88bf097

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 (65) hide show
  1. package/dist/PrismicPreview.cjs +22 -6
  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 +20 -6
  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 +1 -2
  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 +1 -2
  16. package/dist/exitPreview.js.map +1 -1
  17. package/dist/lib/getSafePath.cjs +21 -0
  18. package/dist/lib/getSafePath.cjs.map +1 -0
  19. package/dist/lib/getSafePath.js +21 -0
  20. package/dist/lib/getSafePath.js.map +1 -0
  21. package/dist/package.cjs +1 -1
  22. package/dist/package.js +1 -1
  23. package/dist/pages/PrismicPreview.cjs +4 -3
  24. package/dist/pages/PrismicPreview.cjs.map +1 -1
  25. package/dist/pages/PrismicPreview.d.cts.map +1 -1
  26. package/dist/pages/PrismicPreview.d.ts.map +1 -1
  27. package/dist/pages/PrismicPreview.js +5 -4
  28. package/dist/pages/PrismicPreview.js.map +1 -1
  29. package/dist/pages/appendCookie.cjs +2 -4
  30. package/dist/pages/appendCookie.cjs.map +1 -1
  31. package/dist/pages/appendCookie.js +2 -4
  32. package/dist/pages/appendCookie.js.map +1 -1
  33. package/dist/pages/exitPreview.cjs +2 -2
  34. package/dist/pages/exitPreview.cjs.map +1 -1
  35. package/dist/pages/exitPreview.d.cts.map +1 -1
  36. package/dist/pages/exitPreview.d.ts.map +1 -1
  37. package/dist/pages/exitPreview.js +2 -2
  38. package/dist/pages/exitPreview.js.map +1 -1
  39. package/dist/pages/redirectToPreviewURL.cjs +9 -13
  40. package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
  41. package/dist/pages/redirectToPreviewURL.d.cts +1 -1
  42. package/dist/pages/redirectToPreviewURL.d.ts +1 -1
  43. package/dist/pages/redirectToPreviewURL.js +9 -13
  44. package/dist/pages/redirectToPreviewURL.js.map +1 -1
  45. package/dist/redirectToPreviewURL.cjs +9 -13
  46. package/dist/redirectToPreviewURL.cjs.map +1 -1
  47. package/dist/redirectToPreviewURL.d.cts +1 -1
  48. package/dist/redirectToPreviewURL.d.ts +1 -1
  49. package/dist/redirectToPreviewURL.js +9 -13
  50. package/dist/redirectToPreviewURL.js.map +1 -1
  51. package/package.json +5 -2
  52. package/src/PrismicPreview.tsx +10 -1
  53. package/src/PrismicPreviewClient.tsx +1 -12
  54. package/src/exitPreview.ts +1 -3
  55. package/src/lib/getSafePath.ts +22 -0
  56. package/src/pages/PrismicPreview.tsx +5 -4
  57. package/src/pages/appendCookie.ts +5 -11
  58. package/src/pages/exitPreview.ts +5 -2
  59. package/src/pages/redirectToPreviewURL.ts +14 -15
  60. package/src/redirectToPreviewURL.ts +19 -15
  61. package/dist/lib/toolbarV5.cjs +0 -37
  62. package/dist/lib/toolbarV5.cjs.map +0 -1
  63. package/dist/lib/toolbarV5.js +0 -34
  64. package/dist/lib/toolbarV5.js.map +0 -1
  65. package/src/lib/toolbarV5.ts +0 -54
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;YAKY;;;;;;EAMX,MAAM;;;;;;EAON,KAAK;;;;;;;;;;;;;;;;;wBAkBU,YAAY,QAAQ"}
1
+ {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;YAMY;;;;;;EAMX,MAAM;;;;;;EAON,KAAK;;;;;;;;;;;;;;;;;wBAkBU,YAAY,QAAQ"}
@@ -1,5 +1,5 @@
1
- import { previewSessionCookie } from "../lib/toolbarV5.js";
2
1
  import { appendCookie } from "./appendCookie.js";
2
+ import { cookie } from "@prismicio/client";
3
3
  //#region src/pages/exitPreview.ts
4
4
  /**
5
5
  * Ends a Prismic preview session within a Next.js app. This function should be used in an API
@@ -18,7 +18,7 @@ import { appendCookie } from "./appendCookie.js";
18
18
  */
19
19
  function exitPreview(config) {
20
20
  config.res.clearPreviewData();
21
- appendCookie(config.res, previewSessionCookie, "", /* @__PURE__ */ new Date(0));
21
+ for (const name of [cookie.preview, cookie.previewSession]) appendCookie(config.res, `${name}=; Expires=${(/* @__PURE__ */ new Date(0)).toUTCString()}`);
22
22
  config.res.setHeader("Cache-Control", "no-store");
23
23
  config.res.json({ success: true });
24
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import { previewSessionCookie } from \"../lib/toolbarV5\"\nimport { appendCookie } from \"./appendCookie\"\nimport 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\tappendCookie(config.res, previewSessionCookie, \"\", new Date(0))\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":";;;;;;;;;;;;;;;;;;AAoCA,SAAgB,YAAY,QAAyC;CACpE,OAAO,IAAI,iBAAiB;CAC5B,aAAa,OAAO,KAAK,sBAAsB,oBAAI,IAAI,KAAK,CAAC,CAAC;CAG9D,OAAO,IAAI,UAAU,iBAAiB,UAAU;CAEhD,OAAO,IAAI,KAAK,EAAE,SAAS,KAAK,CAAC;AAGlC"}
1
+ {"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { appendCookie } from \"./appendCookie\"\nimport 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\tfor (const name of [prismicCookie.preview, prismicCookie.previewSession]) {\n\t\tappendCookie(config.res, `${name}=; Expires=${new Date(0).toUTCString()}`)\n\t}\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":";;;;;;;;;;;;;;;;;;AAqCA,SAAgB,YAAY,QAAyC;CACpE,OAAO,IAAI,iBAAiB;CAC5B,KAAK,MAAM,QAAQ,CAACA,OAAc,SAASA,OAAc,cAAc,GACtE,aAAa,OAAO,KAAK,GAAG,KAAK,8BAAa,IAAI,KAAK,CAAC,EAAA,CAAE,YAAY,GAAG;CAI1E,OAAO,IAAI,UAAU,iBAAiB,UAAU;CAEhD,OAAO,IAAI,KAAK,EAAE,SAAS,KAAK,CAAC;AAGlC"}
@@ -1,23 +1,19 @@
1
- const require_toolbarV5 = require("../lib/toolbarV5.cjs");
1
+ const require_getSafePath = require("../lib/getSafePath.cjs");
2
2
  const require_appendCookie = require("./appendCookie.cjs");
3
3
  let _prismicio_client = require("@prismicio/client");
4
4
  //#region src/pages/redirectToPreviewURL.ts
5
5
  async function redirectToPreviewURL(config) {
6
6
  const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config;
7
- let previewToken = req.query.token?.toString();
7
+ const previewToken = req.query.token?.toString();
8
8
  const session = req.query.session?.toString();
9
9
  if (session) {
10
- if (!previewToken) {
11
- previewToken = await require_toolbarV5.getPreviewSessionRef(client, session);
12
- res.setPreviewData({ ref: previewToken });
13
- }
14
- require_appendCookie.appendCookie(res, _prismicio_client.cookie.preview, previewToken);
15
- require_appendCookie.appendCookie(res, require_toolbarV5.previewSessionCookie, session);
16
- const path = require_toolbarV5.getSafePath(req.query.path?.toString());
17
- if (path) {
18
- res.redirect(path);
19
- return;
20
- }
10
+ require_appendCookie.appendCookie(res, `${_prismicio_client.cookie.previewSession}=${encodeURIComponent(session)}`);
11
+ if (previewToken) require_appendCookie.appendCookie(res, `${_prismicio_client.cookie.preview}=${encodeURIComponent(previewToken)}`);
12
+ }
13
+ const path = require_getSafePath.getSafePath(req.query.path?.toString());
14
+ if (path) {
15
+ res.redirect(path);
16
+ return;
21
17
  }
22
18
  const previewURL = await client.resolvePreviewURL({
23
19
  linkResolver,
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","names":["getPreviewSessionRef","prismicCookie","previewSessionCookie","getSafePath"],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type LinkResolverFunction, type Client } from \"@prismicio/client\"\n\nimport { getPreviewSessionRef, getSafePath, previewSessionCookie } from \"../lib/toolbarV5\"\nimport { appendCookie } from \"./appendCookie\"\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\" | \"documentAPIEndpoint\">\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\tlet previewToken = req.query.token?.toString()\n\n\t// The toolbar's v5 flow follows the session in the preview cookies. Share\n\t// links only carry the session, so `setPreviewData()` has no ref for them.\n\tconst session = req.query.session?.toString()\n\tif (session) {\n\t\tif (!previewToken) {\n\t\t\tpreviewToken = await getPreviewSessionRef(client, session)\n\t\t\tres.setPreviewData({ ref: previewToken })\n\t\t}\n\t\tappendCookie(res, prismicCookie.preview, previewToken)\n\t\tappendCookie(res, previewSessionCookie, session)\n\n\t\tconst path = getSafePath(req.query.path?.toString())\n\t\tif (path) {\n\t\t\tres.redirect(path)\n\n\t\t\treturn\n\t\t}\n\t}\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,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,IAAI,eAAe,IAAI,MAAM,OAAO,SAAS;CAI7C,MAAM,UAAU,IAAI,MAAM,SAAS,SAAS;CAC5C,IAAI,SAAS;EACZ,IAAI,CAAC,cAAc;GAClB,eAAe,MAAMA,kBAAAA,qBAAqB,QAAQ,OAAO;GACzD,IAAI,eAAe,EAAE,KAAK,aAAa,CAAC;EACzC;EACA,qBAAA,aAAa,KAAKC,kBAAAA,OAAc,SAAS,YAAY;EACrD,qBAAA,aAAa,KAAKC,kBAAAA,sBAAsB,OAAO;EAE/C,MAAM,OAAOC,kBAAAA,YAAY,IAAI,MAAM,MAAM,SAAS,CAAC;EACnD,IAAI,MAAM;GACT,IAAI,SAAS,IAAI;GAEjB;EACD;CACD;CAEA,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;CACD,CAAC;CAED,IAAI,SAAS,WAAW,UAAU;AAGnC"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie","getSafePath"],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type LinkResolverFunction, type Client } from \"@prismicio/client\"\n\nimport { getSafePath } from \"../lib/getSafePath\"\nimport { appendCookie } from \"./appendCookie\"\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\t// The toolbar's v5 flow follows this session from the ref the page shows. Without that ref, its\n\t// first ping would start the preview again, racing an early exit.\n\tconst session = req.query.session?.toString()\n\tif (session) {\n\t\tappendCookie(res, `${prismicCookie.previewSession}=${encodeURIComponent(session)}`)\n\t\tif (previewToken) {\n\t\t\tappendCookie(res, `${prismicCookie.preview}=${encodeURIComponent(previewToken)}`)\n\t\t}\n\t}\n\n\t// Share links return to the page they were opened from.\n\tconst path = getSafePath(req.query.path?.toString())\n\tif (path) {\n\t\tres.redirect(path)\n\n\t\treturn\n\t}\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,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,MAAM,eAAe,IAAI,MAAM,OAAO,SAAS;CAI/C,MAAM,UAAU,IAAI,MAAM,SAAS,SAAS;CAC5C,IAAI,SAAS;EACZ,qBAAA,aAAa,KAAK,GAAGA,kBAAAA,OAAc,eAAe,GAAG,mBAAmB,OAAO,GAAG;EAClF,IAAI,cACH,qBAAA,aAAa,KAAK,GAAGA,kBAAAA,OAAc,QAAQ,GAAG,mBAAmB,YAAY,GAAG;CAElF;CAGA,MAAM,OAAOC,oBAAAA,YAAY,IAAI,MAAM,MAAM,SAAS,CAAC;CACnD,IAAI,MAAM;EACT,IAAI,SAAS,IAAI;EAEjB;CACD;CAEA,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;CACD,CAAC;CAED,IAAI,SAAS,WAAW,UAAU;AAGnC"}
@@ -3,7 +3,7 @@ import { Client, LinkResolverFunction } from "@prismicio/client";
3
3
  //#region src/pages/redirectToPreviewURL.d.ts
4
4
  export type RedirectToPreviewURLConfig = {
5
5
  /** The Prismic client configured for the preview session's repository. */
6
- client: Pick<Client, "resolvePreviewURL" | "documentAPIEndpoint">;
6
+ client: Pick<Client, "resolvePreviewURL">;
7
7
  /**
8
8
  * The `req` object from a Next.js API route.
9
9
  *
@@ -3,7 +3,7 @@ import { Client, LinkResolverFunction } from "@prismicio/client";
3
3
  //#region src/pages/redirectToPreviewURL.d.ts
4
4
  export type RedirectToPreviewURLConfig = {
5
5
  /** The Prismic client configured for the preview session's repository. */
6
- client: Pick<Client, "resolvePreviewURL" | "documentAPIEndpoint">;
6
+ client: Pick<Client, "resolvePreviewURL">;
7
7
  /**
8
8
  * The `req` object from a Next.js API route.
9
9
  *
@@ -1,23 +1,19 @@
1
- import { getPreviewSessionRef, getSafePath, previewSessionCookie } from "../lib/toolbarV5.js";
1
+ import { getSafePath } from "../lib/getSafePath.js";
2
2
  import { appendCookie } from "./appendCookie.js";
3
3
  import { cookie } from "@prismicio/client";
4
4
  //#region src/pages/redirectToPreviewURL.ts
5
5
  async function redirectToPreviewURL(config) {
6
6
  const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config;
7
- let previewToken = req.query.token?.toString();
7
+ const previewToken = req.query.token?.toString();
8
8
  const session = req.query.session?.toString();
9
9
  if (session) {
10
- if (!previewToken) {
11
- previewToken = await getPreviewSessionRef(client, session);
12
- res.setPreviewData({ ref: previewToken });
13
- }
14
- appendCookie(res, cookie.preview, previewToken);
15
- appendCookie(res, previewSessionCookie, session);
16
- const path = getSafePath(req.query.path?.toString());
17
- if (path) {
18
- res.redirect(path);
19
- return;
20
- }
10
+ appendCookie(res, `${cookie.previewSession}=${encodeURIComponent(session)}`);
11
+ if (previewToken) appendCookie(res, `${cookie.preview}=${encodeURIComponent(previewToken)}`);
12
+ }
13
+ const path = getSafePath(req.query.path?.toString());
14
+ if (path) {
15
+ res.redirect(path);
16
+ return;
21
17
  }
22
18
  const previewURL = await client.resolvePreviewURL({
23
19
  linkResolver,
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type LinkResolverFunction, type Client } from \"@prismicio/client\"\n\nimport { getPreviewSessionRef, getSafePath, previewSessionCookie } from \"../lib/toolbarV5\"\nimport { appendCookie } from \"./appendCookie\"\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\" | \"documentAPIEndpoint\">\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\tlet previewToken = req.query.token?.toString()\n\n\t// The toolbar's v5 flow follows the session in the preview cookies. Share\n\t// links only carry the session, so `setPreviewData()` has no ref for them.\n\tconst session = req.query.session?.toString()\n\tif (session) {\n\t\tif (!previewToken) {\n\t\t\tpreviewToken = await getPreviewSessionRef(client, session)\n\t\t\tres.setPreviewData({ ref: previewToken })\n\t\t}\n\t\tappendCookie(res, prismicCookie.preview, previewToken)\n\t\tappendCookie(res, previewSessionCookie, session)\n\n\t\tconst path = getSafePath(req.query.path?.toString())\n\t\tif (path) {\n\t\t\tres.redirect(path)\n\n\t\t\treturn\n\t\t}\n\t}\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,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,IAAI,eAAe,IAAI,MAAM,OAAO,SAAS;CAI7C,MAAM,UAAU,IAAI,MAAM,SAAS,SAAS;CAC5C,IAAI,SAAS;EACZ,IAAI,CAAC,cAAc;GAClB,eAAe,MAAM,qBAAqB,QAAQ,OAAO;GACzD,IAAI,eAAe,EAAE,KAAK,aAAa,CAAC;EACzC;EACA,aAAa,KAAKA,OAAc,SAAS,YAAY;EACrD,aAAa,KAAK,sBAAsB,OAAO;EAE/C,MAAM,OAAO,YAAY,IAAI,MAAM,MAAM,SAAS,CAAC;EACnD,IAAI,MAAM;GACT,IAAI,SAAS,IAAI;GAEjB;EACD;CACD;CAEA,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;CACD,CAAC;CAED,IAAI,SAAS,WAAW,UAAU;AAGnC"}
1
+ {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type LinkResolverFunction, type Client } from \"@prismicio/client\"\n\nimport { getSafePath } from \"../lib/getSafePath\"\nimport { appendCookie } from \"./appendCookie\"\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\t// The toolbar's v5 flow follows this session from the ref the page shows. Without that ref, its\n\t// first ping would start the preview again, racing an early exit.\n\tconst session = req.query.session?.toString()\n\tif (session) {\n\t\tappendCookie(res, `${prismicCookie.previewSession}=${encodeURIComponent(session)}`)\n\t\tif (previewToken) {\n\t\t\tappendCookie(res, `${prismicCookie.preview}=${encodeURIComponent(previewToken)}`)\n\t\t}\n\t}\n\n\t// Share links return to the page they were opened from.\n\tconst path = getSafePath(req.query.path?.toString())\n\tif (path) {\n\t\tres.redirect(path)\n\n\t\treturn\n\t}\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,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,MAAM,eAAe,IAAI,MAAM,OAAO,SAAS;CAI/C,MAAM,UAAU,IAAI,MAAM,SAAS,SAAS;CAC5C,IAAI,SAAS;EACZ,aAAa,KAAK,GAAGA,OAAc,eAAe,GAAG,mBAAmB,OAAO,GAAG;EAClF,IAAI,cACH,aAAa,KAAK,GAAGA,OAAc,QAAQ,GAAG,mBAAmB,YAAY,GAAG;CAElF;CAGA,MAAM,OAAO,YAAY,IAAI,MAAM,MAAM,SAAS,CAAC;CACnD,IAAI,MAAM;EACT,IAAI,SAAS,IAAI;EAEjB;CACD;CAEA,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;CACD,CAAC;CAED,IAAI,SAAS,WAAW,UAAU;AAGnC"}
@@ -1,27 +1,23 @@
1
- const require_toolbarV5 = require("./lib/toolbarV5.cjs");
1
+ const require_getSafePath = require("./lib/getSafePath.cjs");
2
2
  let _prismicio_client = require("@prismicio/client");
3
3
  //#region src/redirectToPreviewURL.ts
4
4
  async function redirectToPreviewURL(config) {
5
5
  const { client, request, linkResolver, defaultURL = "/" } = config;
6
6
  const { cookies, draftMode } = await import("next/headers.js");
7
7
  const { redirect } = await import("next/navigation");
8
- const { searchParams } = request.nextUrl;
9
- const documentID = searchParams.get("documentId") ?? void 0;
10
- let previewToken = searchParams.get("token") ?? void 0;
8
+ const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
11
9
  const cookieJar = await cookies();
12
- const session = searchParams.get("session");
13
- if (session) {
14
- previewToken ??= await require_toolbarV5.getPreviewSessionRef(client, session);
15
- cookieJar.set(require_toolbarV5.previewSessionCookie, session, {
16
- sameSite: "none",
17
- secure: true
18
- });
19
- }
10
+ const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
20
11
  if (previewToken) cookieJar.set(_prismicio_client.cookie.preview, previewToken, {
21
12
  sameSite: "none",
22
13
  secure: true
23
14
  });
24
- const previewURL = session && require_toolbarV5.getSafePath(searchParams.get("path")) || await client.resolvePreviewURL({
15
+ const session = request.nextUrl.searchParams.get("session");
16
+ if (session) cookieJar.set(_prismicio_client.cookie.previewSession, session, {
17
+ sameSite: "none",
18
+ secure: true
19
+ });
20
+ const previewURL = require_getSafePath.getSafePath(request.nextUrl.searchParams.get("path")) ?? await client.resolvePreviewURL({
25
21
  documentID,
26
22
  previewToken,
27
23
  defaultURL,
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","names":["getPreviewSessionRef","previewSessionCookie","prismicCookie","getSafePath"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport { getPreviewSessionRef, getSafePath, previewSessionCookie } from \"./lib/toolbarV5\"\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\" | \"documentAPIEndpoint\">\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 { searchParams } = request.nextUrl\n\tconst documentID = searchParams.get(\"documentId\") ?? undefined\n\tlet previewToken = searchParams.get(\"token\") ?? undefined\n\tconst cookieJar = await cookies()\n\n\t// The toolbar's v5 flow follows the session. Share links only carry the session.\n\tconst session = searchParams.get(\"session\")\n\tif (session) {\n\t\tpreviewToken ??= await getPreviewSessionRef(client, session)\n\t\tcookieJar.set(previewSessionCookie, session, { sameSite: \"none\", secure: true })\n\t}\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\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL =\n\t\t(session && getSafePath(searchParams.get(\"path\"))) ||\n\t\t(await client.resolvePreviewURL({ documentID, previewToken, defaultURL, linkResolver }))\n\n\t;(await draftMode()).enable()\n\n\t// Next.js uses `SameSite=Lax` in development, which cross-site iframes drop.\n\tcookieJar.set({\n\t\t...cookieJar.get(\"__prerender_bypass\")!,\n\t\thttpOnly: true,\n\t\tsameSite: \"none\",\n\t\tsecure: true,\n\t})\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAmCA,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,EAAE,iBAAiB,QAAQ;CACjC,MAAM,aAAa,aAAa,IAAI,YAAY,KAAK,KAAA;CACrD,IAAI,eAAe,aAAa,IAAI,OAAO,KAAK,KAAA;CAChD,MAAM,YAAY,MAAM,QAAQ;CAGhC,MAAM,UAAU,aAAa,IAAI,SAAS;CAC1C,IAAI,SAAS;EACZ,iBAAiB,MAAMA,kBAAAA,qBAAqB,QAAQ,OAAO;EAC3D,UAAU,IAAIC,kBAAAA,sBAAsB,SAAS;GAAE,UAAU;GAAQ,QAAQ;EAAK,CAAC;CAChF;CAMA,IAAI,cACH,UAAU,IAAIC,kBAAAA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAGtF,MAAM,aACJ,WAAWC,kBAAAA,YAAY,aAAa,IAAI,MAAM,CAAC,KAC/C,MAAM,OAAO,kBAAkB;EAAE;EAAY;EAAc;EAAY;CAAa,CAAC;CAEtF,CAAC,MAAM,UAAU,EAAA,CAAG,OAAO;CAG5B,UAAU,IAAI;EACb,GAAG,UAAU,IAAI,oBAAoB;EACrC,UAAU;EACV,UAAU;EACV,QAAQ;CACT,CAAC;CAED,OAAO,SAAS,UAAU;AAC3B"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie","getSafePath"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport { getSafePath } from \"./lib/getSafePath\"\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\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\t// The toolbar's v5 flow follows this session.\n\tconst session = request.nextUrl.searchParams.get(\"session\")\n\tif (session) {\n\t\tcookieJar.set(prismicCookie.previewSession, session, { sameSite: \"none\", secure: true })\n\t}\n\n\t// Share links return to the page they were opened from.\n\tconst previewURL =\n\t\tgetSafePath(request.nextUrl.searchParams.get(\"path\")) ??\n\t\t(await client.resolvePreviewURL({\n\t\t\tdocumentID,\n\t\t\tpreviewToken,\n\t\t\tdefaultURL,\n\t\t\tlinkResolver,\n\t\t}))\n\n\t;(await draftMode()).enable()\n\n\t// Next.js uses `SameSite=Lax` in development, which cross-site iframes drop.\n\tcookieJar.set({\n\t\t...cookieJar.get(\"__prerender_bypass\")!,\n\t\thttpOnly: true,\n\t\tsameSite: \"none\",\n\t\tsecure: true,\n\t})\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAmCA,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,YAAY,KAAK,KAAA;CAMrE,MAAM,YAAY,MAAM,QAAQ;CAChC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,OAAO,KAAK,KAAA;CAClE,IAAI,cACH,UAAU,IAAIA,kBAAAA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAItF,MAAM,UAAU,QAAQ,QAAQ,aAAa,IAAI,SAAS;CAC1D,IAAI,SACH,UAAU,IAAIA,kBAAAA,OAAc,gBAAgB,SAAS;EAAE,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAIxF,MAAM,aACLC,oBAAAA,YAAY,QAAQ,QAAQ,aAAa,IAAI,MAAM,CAAC,KACnD,MAAM,OAAO,kBAAkB;EAC/B;EACA;EACA;EACA;CACD,CAAC;CAED,CAAC,MAAM,UAAU,EAAA,CAAG,OAAO;CAG5B,UAAU,IAAI;EACb,GAAG,UAAU,IAAI,oBAAoB;EACrC,UAAU;EACV,UAAU;EACV,QAAQ;CACT,CAAC;CAED,OAAO,SAAS,UAAU;AAC3B"}
@@ -3,7 +3,7 @@ import { Client, LinkResolverFunction } from "@prismicio/client";
3
3
  //#region src/redirectToPreviewURL.d.ts
4
4
  export type RedirectToPreviewURLConfig = {
5
5
  /** The Prismic client configured for the preview session's repository. */
6
- client: Pick<Client, "resolvePreviewURL" | "documentAPIEndpoint">;
6
+ client: Pick<Client, "resolvePreviewURL">;
7
7
  /**
8
8
  * The `request` object from a Next.js Route Handler.
9
9
  *
@@ -3,7 +3,7 @@ import { Client, LinkResolverFunction } from "@prismicio/client";
3
3
  //#region src/redirectToPreviewURL.d.ts
4
4
  export type RedirectToPreviewURLConfig = {
5
5
  /** The Prismic client configured for the preview session's repository. */
6
- client: Pick<Client, "resolvePreviewURL" | "documentAPIEndpoint">;
6
+ client: Pick<Client, "resolvePreviewURL">;
7
7
  /**
8
8
  * The `request` object from a Next.js Route Handler.
9
9
  *
@@ -1,27 +1,23 @@
1
- import { getPreviewSessionRef, getSafePath, previewSessionCookie } from "./lib/toolbarV5.js";
1
+ import { getSafePath } from "./lib/getSafePath.js";
2
2
  import { cookie } from "@prismicio/client";
3
3
  //#region src/redirectToPreviewURL.ts
4
4
  async function redirectToPreviewURL(config) {
5
5
  const { client, request, linkResolver, defaultURL = "/" } = config;
6
6
  const { cookies, draftMode } = await import("next/headers.js");
7
7
  const { redirect } = await import("next/navigation");
8
- const { searchParams } = request.nextUrl;
9
- const documentID = searchParams.get("documentId") ?? void 0;
10
- let previewToken = searchParams.get("token") ?? void 0;
8
+ const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
11
9
  const cookieJar = await cookies();
12
- const session = searchParams.get("session");
13
- if (session) {
14
- previewToken ??= await getPreviewSessionRef(client, session);
15
- cookieJar.set(previewSessionCookie, session, {
16
- sameSite: "none",
17
- secure: true
18
- });
19
- }
10
+ const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
20
11
  if (previewToken) cookieJar.set(cookie.preview, previewToken, {
21
12
  sameSite: "none",
22
13
  secure: true
23
14
  });
24
- const previewURL = session && getSafePath(searchParams.get("path")) || await client.resolvePreviewURL({
15
+ const session = request.nextUrl.searchParams.get("session");
16
+ if (session) cookieJar.set(cookie.previewSession, session, {
17
+ sameSite: "none",
18
+ secure: true
19
+ });
20
+ const previewURL = getSafePath(request.nextUrl.searchParams.get("path")) ?? await client.resolvePreviewURL({
25
21
  documentID,
26
22
  previewToken,
27
23
  defaultURL,
@@ -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 { getPreviewSessionRef, getSafePath, previewSessionCookie } from \"./lib/toolbarV5\"\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\" | \"documentAPIEndpoint\">\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 { searchParams } = request.nextUrl\n\tconst documentID = searchParams.get(\"documentId\") ?? undefined\n\tlet previewToken = searchParams.get(\"token\") ?? undefined\n\tconst cookieJar = await cookies()\n\n\t// The toolbar's v5 flow follows the session. Share links only carry the session.\n\tconst session = searchParams.get(\"session\")\n\tif (session) {\n\t\tpreviewToken ??= await getPreviewSessionRef(client, session)\n\t\tcookieJar.set(previewSessionCookie, session, { sameSite: \"none\", secure: true })\n\t}\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\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL =\n\t\t(session && getSafePath(searchParams.get(\"path\"))) ||\n\t\t(await client.resolvePreviewURL({ documentID, previewToken, defaultURL, linkResolver }))\n\n\t;(await draftMode()).enable()\n\n\t// Next.js uses `SameSite=Lax` in development, which cross-site iframes drop.\n\tcookieJar.set({\n\t\t...cookieJar.get(\"__prerender_bypass\")!,\n\t\thttpOnly: true,\n\t\tsameSite: \"none\",\n\t\tsecure: true,\n\t})\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAmCA,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,EAAE,iBAAiB,QAAQ;CACjC,MAAM,aAAa,aAAa,IAAI,YAAY,KAAK,KAAA;CACrD,IAAI,eAAe,aAAa,IAAI,OAAO,KAAK,KAAA;CAChD,MAAM,YAAY,MAAM,QAAQ;CAGhC,MAAM,UAAU,aAAa,IAAI,SAAS;CAC1C,IAAI,SAAS;EACZ,iBAAiB,MAAM,qBAAqB,QAAQ,OAAO;EAC3D,UAAU,IAAI,sBAAsB,SAAS;GAAE,UAAU;GAAQ,QAAQ;EAAK,CAAC;CAChF;CAMA,IAAI,cACH,UAAU,IAAIA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAGtF,MAAM,aACJ,WAAW,YAAY,aAAa,IAAI,MAAM,CAAC,KAC/C,MAAM,OAAO,kBAAkB;EAAE;EAAY;EAAc;EAAY;CAAa,CAAC;CAEtF,CAAC,MAAM,UAAU,EAAA,CAAG,OAAO;CAG5B,UAAU,IAAI;EACb,GAAG,UAAU,IAAI,oBAAoB;EACrC,UAAU;EACV,UAAU;EACV,QAAQ;CACT,CAAC;CAED,OAAO,SAAS,UAAU;AAC3B"}
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 { getSafePath } from \"./lib/getSafePath\"\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\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\t// The toolbar's v5 flow follows this session.\n\tconst session = request.nextUrl.searchParams.get(\"session\")\n\tif (session) {\n\t\tcookieJar.set(prismicCookie.previewSession, session, { sameSite: \"none\", secure: true })\n\t}\n\n\t// Share links return to the page they were opened from.\n\tconst previewURL =\n\t\tgetSafePath(request.nextUrl.searchParams.get(\"path\")) ??\n\t\t(await client.resolvePreviewURL({\n\t\t\tdocumentID,\n\t\t\tpreviewToken,\n\t\t\tdefaultURL,\n\t\t\tlinkResolver,\n\t\t}))\n\n\t;(await draftMode()).enable()\n\n\t// Next.js uses `SameSite=Lax` in development, which cross-site iframes drop.\n\tcookieJar.set({\n\t\t...cookieJar.get(\"__prerender_bypass\")!,\n\t\thttpOnly: true,\n\t\tsameSite: \"none\",\n\t\tsecure: true,\n\t})\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAmCA,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,YAAY,KAAK,KAAA;CAMrE,MAAM,YAAY,MAAM,QAAQ;CAChC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,OAAO,KAAK,KAAA;CAClE,IAAI,cACH,UAAU,IAAIA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAItF,MAAM,UAAU,QAAQ,QAAQ,aAAa,IAAI,SAAS;CAC1D,IAAI,SACH,UAAU,IAAIA,OAAc,gBAAgB,SAAS;EAAE,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAIxF,MAAM,aACL,YAAY,QAAQ,QAAQ,aAAa,IAAI,MAAM,CAAC,KACnD,MAAM,OAAO,kBAAkB;EAC/B;EACA;EACA;EACA;CACD,CAAC;CAED,CAAC,MAAM,UAAU,EAAA,CAAG,OAAO;CAG5B,UAAU,IAAI;EACb,GAAG,UAAU,IAAI,oBAAoB;EACrC,UAAU;EACV,UAAU;EACV,QAAQ;CACT,CAAC;CAED,OAAO,SAAS,UAAU;AAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.3.4-pr.175.5f9614e",
3
+ "version": "2.3.4-pr.175.88bf097",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "next",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@playwright/test": "^1.64.1",
64
- "@prismicio/client": "^7.22.3",
64
+ "@prismicio/client": "7.22.3-pr.477.5e5ad22",
65
65
  "@types/node": "^26.6.5",
66
66
  "@types/react": "^19.3.0",
67
67
  "next": "16.4.2",
@@ -73,6 +73,9 @@
73
73
  "tsdown": "^0.23.1",
74
74
  "typescript": "^7.0.2"
75
75
  },
76
+ "overrides": {
77
+ "@prismicio/client": "$@prismicio/client"
78
+ },
76
79
  "peerDependencies": {
77
80
  "@prismicio/client": "^7",
78
81
  "next": "^13.4.5 || ^14 || ^15 || ^16",
@@ -1,7 +1,12 @@
1
+ import { getToolbarSrc } from "@prismicio/client"
2
+ import Script from "next/script"
1
3
  import type { FC, ReactNode } from "react"
2
4
 
5
+ import { resolveDefaultExport } from "./lib/resolveDefaultExport"
3
6
  import { PrismicPreviewClient } from "./PrismicPreviewClient"
4
7
 
8
+ const ResolvedScript = resolveDefaultExport(Script)
9
+
5
10
  /** Props for `<PrismicPreview>`. */
6
11
  export type PrismicPreviewProps = {
7
12
  /**
@@ -35,13 +40,15 @@ export type PrismicPreviewProps = {
35
40
  * rendered on every page.
36
41
  */
37
42
  export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
38
- const { repositoryName, children, ...otherProps } = props
43
+ const { repositoryName, updatePreviewURL = "/api/preview", children, ...otherProps } = props
39
44
 
40
45
  // Need this to avoid the following Next.js build-time error:
41
46
  // You're importing a component that needs next/headers. That only works
42
47
  // in a Server Component which is not supported in the pages/ directory.
43
48
  const { draftMode } = await import("next/headers")
44
49
 
50
+ // TODO: Bump the `@prismicio/client` peer to `^7.23.0`, which adds `version`, and drop `overrides`.
51
+ const toolbarSrc = getToolbarSrc(repositoryName, { version: 5 })
45
52
  const isDraftMode = (await draftMode()).isEnabled
46
53
 
47
54
  return (
@@ -50,8 +57,10 @@ export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
50
57
  <PrismicPreviewClient
51
58
  repositoryName={repositoryName}
52
59
  isDraftMode={isDraftMode}
60
+ updatePreviewURL={updatePreviewURL}
53
61
  {...otherProps}
54
62
  />
63
+ <ResolvedScript src={toolbarSrc} strategy="lazyOnload" data-preview-url={updatePreviewURL} />
55
64
  </>
56
65
  )
57
66
  }
@@ -2,15 +2,9 @@
2
2
 
3
3
  import { cookie as prismicCookie } from "@prismicio/client"
4
4
  import { useRouter } from "next/navigation"
5
- import Script from "next/script"
6
5
  import type { FC } from "react"
7
6
  import { useEffect } from "react"
8
7
 
9
- import { resolveDefaultExport } from "./lib/resolveDefaultExport"
10
- import { getToolbarScriptProps } from "./lib/toolbarV5"
11
-
12
- const ResolvedScript = resolveDefaultExport(Script)
13
-
14
8
  type PrismicPreviewClientProps = {
15
9
  repositoryName: string
16
10
  isDraftMode: boolean
@@ -116,12 +110,7 @@ export const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {
116
110
  return () => controller.abort()
117
111
  }, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh])
118
112
 
119
- return (
120
- <ResolvedScript
121
- {...getToolbarScriptProps(repositoryName, updatePreviewURL)}
122
- strategy="lazyOnload"
123
- />
124
- )
113
+ return null
125
114
  }
126
115
 
127
116
  /**
@@ -1,7 +1,5 @@
1
1
  import { cookie as prismicCookie } from "@prismicio/client"
2
2
 
3
- import { previewSessionCookie } from "./lib/toolbarV5"
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.
@@ -26,7 +24,7 @@ export async function exitPreview(): Promise<Response> {
26
24
  const cookieJar = await cookies()
27
25
  cookieJar.delete({ name: "__prerender_bypass", sameSite: "none", secure: true })
28
26
  cookieJar.delete({ name: prismicCookie.preview, sameSite: "none", secure: true })
29
- cookieJar.delete({ name: previewSessionCookie, sameSite: "none", secure: true })
27
+ cookieJar.delete({ name: prismicCookie.previewSession, sameSite: "none", secure: true })
30
28
 
31
29
  // `Cache-Control` header is used to prevent CDN-level caching.
32
30
  return new Response(JSON.stringify({ success: true }), {
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from
3
+ * `location`, so it already includes `basePath`.
4
+ */
5
+ export function getSafePath(path: string | null | undefined): string | undefined {
6
+ if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) {
7
+ return
8
+ }
9
+
10
+ const origin = "https://placeholder.invalid"
11
+ let url: URL
12
+ try {
13
+ url = new URL(path, origin)
14
+ } catch {
15
+ return
16
+ }
17
+ const safePath = url.href.slice(origin.length)
18
+ // Normalizing can create `//`, like with `/.//example.com`.
19
+ if (url.origin === origin && !safePath.startsWith("//")) {
20
+ return safePath
21
+ }
22
+ }
@@ -1,11 +1,9 @@
1
- import { cookie as prismicCookie } from "@prismicio/client"
1
+ import { getToolbarSrc, cookie as prismicCookie } from "@prismicio/client"
2
2
  import { useRouter } from "next/router"
3
3
  import Script from "next/script"
4
4
  import type { FC } from "react"
5
5
  import { type ReactNode, useEffect } from "react"
6
6
 
7
- import { getToolbarScriptProps } from "../lib/toolbarV5"
8
-
9
7
  /** Props for `<PrismicPreview>`. */
10
8
  export type PrismicPreviewProps = {
11
9
  /**
@@ -48,6 +46,8 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
48
46
 
49
47
  const router = useRouter()
50
48
 
49
+ const toolbarSrc = getToolbarSrc(repositoryName, { version: 5 })
50
+
51
51
  useEffect(() => {
52
52
  const controller = new AbortController()
53
53
 
@@ -128,8 +128,9 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
128
128
  <>
129
129
  {children}
130
130
  <Script
131
- {...getToolbarScriptProps(repositoryName, router.basePath + updatePreviewURL)}
131
+ src={toolbarSrc}
132
132
  strategy="lazyOnload"
133
+ data-preview-url={router.basePath + updatePreviewURL}
133
134
  />
134
135
  </>
135
136
  )
@@ -1,16 +1,10 @@
1
1
  import type { NextApiResponseLike } from "./types"
2
2
 
3
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 {
4
+ export function appendCookie(res: NextApiResponseLike, cookie: string): void {
10
5
  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])
6
+ res.setHeader("Set-Cookie", [
7
+ ...[previous].flat().map(String),
8
+ `${cookie}; Path=/; SameSite=None; Secure`,
9
+ ])
16
10
  }
@@ -1,4 +1,5 @@
1
- import { previewSessionCookie } from "../lib/toolbarV5"
1
+ import { cookie as prismicCookie } from "@prismicio/client"
2
+
2
3
  import { appendCookie } from "./appendCookie"
3
4
  import type { NextApiRequestLike, NextApiResponseLike } from "./types"
4
5
 
@@ -36,7 +37,9 @@ export type ExitPreviewAPIRouteConfig = {
36
37
  */
37
38
  export function exitPreview(config: ExitPreviewAPIRouteConfig): void {
38
39
  config.res.clearPreviewData()
39
- appendCookie(config.res, previewSessionCookie, "", new Date(0))
40
+ for (const name of [prismicCookie.preview, prismicCookie.previewSession]) {
41
+ appendCookie(config.res, `${name}=; Expires=${new Date(0).toUTCString()}`)
42
+ }
40
43
 
41
44
  // `Cache-Control` header is used to prevent CDN-level caching.
42
45
  config.res.setHeader("Cache-Control", "no-store")
@@ -1,6 +1,6 @@
1
1
  import { cookie as prismicCookie, type LinkResolverFunction, type Client } from "@prismicio/client"
2
2
 
3
- import { getPreviewSessionRef, getSafePath, previewSessionCookie } from "../lib/toolbarV5"
3
+ import { getSafePath } from "../lib/getSafePath"
4
4
  import { appendCookie } from "./appendCookie"
5
5
  import type { NextApiRequestLike, NextApiResponseLike } from "./types"
6
6
 
@@ -9,7 +9,7 @@ export type RedirectToPreviewURLConfig = {
9
9
  // `Pick` is used to use the smallest possible subset of
10
10
  // `prismic.Client`. Doing this reduces the surface area for breaking
11
11
  // type changes.
12
- client: Pick<Client, "resolvePreviewURL" | "documentAPIEndpoint">
12
+ client: Pick<Client, "resolvePreviewURL">
13
13
 
14
14
  /**
15
15
  * The `req` object from a Next.js API route.
@@ -54,25 +54,24 @@ export type RedirectToPreviewURLConfig = {
54
54
  export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {
55
55
  const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config
56
56
 
57
- let previewToken = req.query.token?.toString()
57
+ const previewToken = req.query.token?.toString()
58
58
 
59
- // The toolbar's v5 flow follows the session in the preview cookies. Share
60
- // links only carry the session, so `setPreviewData()` has no ref for them.
59
+ // The toolbar's v5 flow follows this session from the ref the page shows. Without that ref, its
60
+ // first ping would start the preview again, racing an early exit.
61
61
  const session = req.query.session?.toString()
62
62
  if (session) {
63
- if (!previewToken) {
64
- previewToken = await getPreviewSessionRef(client, session)
65
- res.setPreviewData({ ref: previewToken })
63
+ appendCookie(res, `${prismicCookie.previewSession}=${encodeURIComponent(session)}`)
64
+ if (previewToken) {
65
+ appendCookie(res, `${prismicCookie.preview}=${encodeURIComponent(previewToken)}`)
66
66
  }
67
- appendCookie(res, prismicCookie.preview, previewToken)
68
- appendCookie(res, previewSessionCookie, session)
67
+ }
69
68
 
70
- const path = getSafePath(req.query.path?.toString())
71
- if (path) {
72
- res.redirect(path)
69
+ // Share links return to the page they were opened from.
70
+ const path = getSafePath(req.query.path?.toString())
71
+ if (path) {
72
+ res.redirect(path)
73
73
 
74
- return
75
- }
74
+ return
76
75
  }
77
76
 
78
77
  const previewURL = await client.resolvePreviewURL({