@prismicio/next 1.7.0 → 2.0.0-alpha.0

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 (150) hide show
  1. package/README.md +5 -3
  2. package/dist/PrismicNextImage.d.ts +7 -8
  3. package/dist/PrismicNextImage.js +8 -8
  4. package/dist/PrismicNextImage.js.map +1 -1
  5. package/dist/PrismicNextLink.d.ts +99 -100
  6. package/dist/PrismicNextLink.js +3 -5
  7. package/dist/PrismicNextLink.js.map +1 -1
  8. package/dist/PrismicPreview.d.ts +5 -13
  9. package/dist/PrismicPreview.js +6 -9
  10. package/dist/PrismicPreview.js.map +1 -1
  11. package/dist/PrismicPreviewClient.d.ts +5 -3
  12. package/dist/PrismicPreviewClient.js +58 -69
  13. package/dist/PrismicPreviewClient.js.map +1 -1
  14. package/dist/createLocaleRedirect.d.ts +8 -15
  15. package/dist/createLocaleRedirect.js +4 -28
  16. package/dist/createLocaleRedirect.js.map +1 -1
  17. package/dist/enableAutoPreviews.d.ts +7 -31
  18. package/dist/enableAutoPreviews.js +24 -35
  19. package/dist/enableAutoPreviews.js.map +1 -1
  20. package/dist/exitPreview.d.ts +5 -47
  21. package/dist/exitPreview.js +8 -15
  22. package/dist/exitPreview.js.map +1 -1
  23. package/dist/imgixLoader.js.map +1 -1
  24. package/dist/index.d.ts +15 -18
  25. package/dist/index.js +2 -4
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/devMsg.d.ts +1 -1
  28. package/dist/lib/devMsg.js.map +1 -1
  29. package/dist/package.json.js +1 -1
  30. package/dist/pages/PrismicPreview.d.ts +31 -0
  31. package/dist/pages/PrismicPreview.js +64 -0
  32. package/dist/pages/PrismicPreview.js.map +1 -0
  33. package/dist/pages/enableAutoPreviews.d.ts +31 -0
  34. package/dist/pages/enableAutoPreviews.js +19 -0
  35. package/dist/pages/enableAutoPreviews.js.map +1 -0
  36. package/dist/pages/exitPreview.d.ts +33 -0
  37. package/dist/pages/exitPreview.js +10 -0
  38. package/dist/pages/exitPreview.js.map +1 -0
  39. package/dist/pages/index.d.ts +18 -0
  40. package/dist/pages/redirectToPreviewURL.d.ts +43 -0
  41. package/dist/pages/redirectToPreviewURL.js +16 -0
  42. package/dist/pages/redirectToPreviewURL.js.map +1 -0
  43. package/dist/{setPreviewData.d.ts → pages/setPreviewData.d.ts} +3 -9
  44. package/dist/{setPreviewData.js → pages/setPreviewData.js} +2 -2
  45. package/dist/pages/setPreviewData.js.map +1 -0
  46. package/dist/pages/types.d.ts +30 -0
  47. package/dist/pages.js +21 -0
  48. package/dist/pages.js.map +1 -0
  49. package/dist/redirectToPreviewURL.d.ts +11 -41
  50. package/dist/redirectToPreviewURL.js +16 -22
  51. package/dist/redirectToPreviewURL.js.map +1 -1
  52. package/dist/types.d.ts +2 -51
  53. package/package.json +61 -54
  54. package/src/PrismicNextImage.tsx +19 -16
  55. package/src/PrismicNextLink.tsx +17 -13
  56. package/src/PrismicPreview.tsx +18 -30
  57. package/src/PrismicPreviewClient.tsx +111 -138
  58. package/src/createLocaleRedirect.ts +14 -56
  59. package/src/enableAutoPreviews.ts +38 -110
  60. package/src/exitPreview.ts +18 -79
  61. package/src/index.ts +15 -26
  62. package/src/lib/devMsg.ts +1 -1
  63. package/src/pages/PrismicPreview.tsx +145 -0
  64. package/src/pages/enableAutoPreviews.ts +62 -0
  65. package/src/pages/exitPreview.ts +45 -0
  66. package/src/pages/index.ts +27 -0
  67. package/src/pages/redirectToPreviewURL.ts +77 -0
  68. package/src/{setPreviewData.ts → pages/setPreviewData.ts} +5 -11
  69. package/src/pages/types.ts +36 -0
  70. package/src/redirectToPreviewURL.ts +44 -95
  71. package/src/types.ts +2 -56
  72. package/dist/PrismicNextImage.cjs +0 -64
  73. package/dist/PrismicNextImage.cjs.map +0 -1
  74. package/dist/PrismicNextLink.cjs +0 -40
  75. package/dist/PrismicNextLink.cjs.map +0 -1
  76. package/dist/PrismicPreview.cjs +0 -18
  77. package/dist/PrismicPreview.cjs.map +0 -1
  78. package/dist/PrismicPreviewClient.cjs +0 -81
  79. package/dist/PrismicPreviewClient.cjs.map +0 -1
  80. package/dist/_node_modules/@prismicio/client/dist/cookie.cjs +0 -5
  81. package/dist/_node_modules/@prismicio/client/dist/cookie.cjs.map +0 -1
  82. package/dist/_node_modules/@prismicio/client/dist/cookie.js +0 -5
  83. package/dist/_node_modules/@prismicio/client/dist/cookie.js.map +0 -1
  84. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +0 -16
  85. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +0 -1
  86. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +0 -16
  87. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +0 -1
  88. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +0 -13
  89. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +0 -1
  90. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +0 -13
  91. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +0 -1
  92. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +0 -47
  93. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +0 -1
  94. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +0 -47
  95. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +0 -1
  96. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +0 -28
  97. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +0 -1
  98. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +0 -28
  99. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +0 -1
  100. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +0 -27
  101. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +0 -1
  102. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +0 -27
  103. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +0 -1
  104. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +0 -14
  105. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +0 -1
  106. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +0 -14
  107. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +0 -1
  108. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +0 -7
  109. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +0 -1
  110. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +0 -7
  111. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +0 -1
  112. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +0 -9
  113. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +0 -1
  114. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +0 -9
  115. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +0 -1
  116. package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +0 -10
  117. package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +0 -1
  118. package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +0 -10
  119. package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +0 -1
  120. package/dist/createLocaleRedirect.cjs +0 -32
  121. package/dist/createLocaleRedirect.cjs.map +0 -1
  122. package/dist/enableAutoPreviews.cjs +0 -40
  123. package/dist/enableAutoPreviews.cjs.map +0 -1
  124. package/dist/exitPreview.cjs +0 -20
  125. package/dist/exitPreview.cjs.map +0 -1
  126. package/dist/imgixLoader.cjs +0 -17
  127. package/dist/imgixLoader.cjs.map +0 -1
  128. package/dist/index.cjs +0 -21
  129. package/dist/index.cjs.map +0 -1
  130. package/dist/lib/devMsg.cjs +0 -8
  131. package/dist/lib/devMsg.cjs.map +0 -1
  132. package/dist/lib/getPreviewCookieRepositoryName.cjs +0 -7
  133. package/dist/lib/getPreviewCookieRepositoryName.cjs.map +0 -1
  134. package/dist/lib/getPreviewCookieRepositoryName.d.ts +0 -9
  135. package/dist/lib/getPreviewCookieRepositoryName.js +0 -7
  136. package/dist/lib/getPreviewCookieRepositoryName.js.map +0 -1
  137. package/dist/lib/getPrismicPreviewCookie.cjs +0 -21
  138. package/dist/lib/getPrismicPreviewCookie.cjs.map +0 -1
  139. package/dist/lib/getPrismicPreviewCookie.d.ts +0 -9
  140. package/dist/lib/getPrismicPreviewCookie.js +0 -21
  141. package/dist/lib/getPrismicPreviewCookie.js.map +0 -1
  142. package/dist/package.json.cjs +0 -5
  143. package/dist/package.json.cjs.map +0 -1
  144. package/dist/redirectToPreviewURL.cjs +0 -30
  145. package/dist/redirectToPreviewURL.cjs.map +0 -1
  146. package/dist/setPreviewData.cjs +0 -11
  147. package/dist/setPreviewData.cjs.map +0 -1
  148. package/dist/setPreviewData.js.map +0 -1
  149. package/src/lib/getPreviewCookieRepositoryName.ts +0 -14
  150. package/src/lib/getPrismicPreviewCookie.ts +0 -33
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const headers = require("next/headers");
4
- function exitPreview(config) {
5
- if (config == null ? void 0 : config.res) {
6
- config.res.clearPreviewData();
7
- config.res.setHeader("Cache-Control", "no-store");
8
- config.res.json({ success: true });
9
- return;
10
- } else {
11
- headers.draftMode().disable();
12
- return new Response(JSON.stringify({ success: true }), {
13
- headers: {
14
- "Cache-Control": "no-store"
15
- }
16
- });
17
- }
18
- }
19
- exports.exitPreview = exitPreview;
20
- //# sourceMappingURL=exitPreview.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exitPreview.cjs","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is\n * used in a Pages Router API endpoint. `exitPreview()` does not require any\n * configuration when used in an App Router Route Handler.\n */\nexport type ExitPreviewConfig = ExitPreviewAPIRouteConfig;\n\n/**\n * Configuration for `exitPreview()` when used in a Pages Router API route.\n */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\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 * **Only use this parameter in the Pages Directory (/pages).**\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 a Router Handler or an API route, depending on whether you are using\n * the App Router or Pages Router.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export function GET() {\n * \treturn exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\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 * \texitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(): Response;\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void;\nexport function exitPreview(\n\tconfig?: ExitPreviewAPIRouteConfig,\n): Response | void {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\tdraftMode().disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["draftMode"],"mappings":";;;AAiEM,SAAU,YACf,QAAkC;AAElC,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGNA,YAAA,UAAA,EAAY;AAGL,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const imgixUrlBuilder = require("imgix-url-builder");
4
- const imgixLoader = (args) => {
5
- const url = new URL(args.src);
6
- const params = {
7
- fit: url.searchParams.get("fit") || "max",
8
- w: args.width,
9
- h: void 0
10
- };
11
- if (args.quality) {
12
- params.q = args.quality;
13
- }
14
- return imgixUrlBuilder.buildURL(args.src, params);
15
- };
16
- exports.imgixLoader = imgixLoader;
17
- //# sourceMappingURL=imgixLoader.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"imgixLoader.cjs","sources":["../../src/imgixLoader.ts"],"sourcesContent":["import { ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\n\n/**\n * A `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nexport const imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n"],"names":["buildURL"],"mappings":";;;AAUa,MAAA,cAAc,CAAC,SAAkC;AAC7D,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAChB;AAEM,SAAAA,yBAAS,KAAK,KAAK,MAAM;AACjC;;"}
package/dist/index.cjs DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const setPreviewData = require("./setPreviewData.cjs");
4
- const exitPreview = require("./exitPreview.cjs");
5
- const PrismicPreview = require("./PrismicPreview.cjs");
6
- const PrismicNextLink = require("./PrismicNextLink.cjs");
7
- const enableAutoPreviews = require("./enableAutoPreviews.cjs");
8
- const redirectToPreviewURL = require("./redirectToPreviewURL.cjs");
9
- const createLocaleRedirect = require("./createLocaleRedirect.cjs");
10
- const PrismicNextImage = require("./PrismicNextImage.cjs");
11
- const imgixLoader = require("./imgixLoader.cjs");
12
- exports.setPreviewData = setPreviewData.setPreviewData;
13
- exports.exitPreview = exitPreview.exitPreview;
14
- exports.PrismicPreview = PrismicPreview.PrismicPreview;
15
- exports.PrismicNextLink = PrismicNextLink.PrismicNextLink;
16
- exports.enableAutoPreviews = enableAutoPreviews.enableAutoPreviews;
17
- exports.redirectToPreviewURL = redirectToPreviewURL.redirectToPreviewURL;
18
- exports.createLocaleRedirect = createLocaleRedirect.createLocaleRedirect;
19
- exports.PrismicNextImage = PrismicNextImage.PrismicNextImage;
20
- exports.imgixLoader = imgixLoader.imgixLoader;
21
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const _package = require("../package.json.cjs");
4
- const devMsg = (slug) => {
5
- return `https://prismic.dev/msg/next/v${_package.version}/${slug}`;
6
- };
7
- exports.devMsg = devMsg;
8
- //# sourceMappingURL=devMsg.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devMsg.cjs","sources":["../../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param.md\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":["version"],"mappings":";;;AAiBa,MAAA,SAAS,CAAC,SAAgB;AAC/B,SAAA,iCAAiCA,SAAAA,OAAO,IAAI,IAAI;AACxD;;"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const getPreviewCookieRepositoryName = (previewCookie) => {
4
- return (decodeURIComponent(previewCookie).match(/"([^"]+)\.prismic\.io"/) || [])[1];
5
- };
6
- exports.getPreviewCookieRepositoryName = getPreviewCookieRepositoryName;
7
- //# sourceMappingURL=getPreviewCookieRepositoryName.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPreviewCookieRepositoryName.cjs","sources":["../../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/\"([^\"]+)\\.prismic\\.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":";;AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACf,UAAA,mBAAmB,aAAa,EAAE,MAAM,wBAAwB,KACvE,CAAA,GAAI,CAAC;AACP;;"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Extracts preview reference repo name from stringified Prismic preview cookie
3
- *
4
- * @param previewCookie - The Prismic preview cookie.
5
- *
6
- * @returns The repository name for the Prismic preview cookie. If the cookie
7
- * represents an inactive preview session, `undefined` will be returned.
8
- */
9
- export declare const getPreviewCookieRepositoryName: (previewCookie: string) => string | undefined;
@@ -1,7 +0,0 @@
1
- const getPreviewCookieRepositoryName = (previewCookie) => {
2
- return (decodeURIComponent(previewCookie).match(/"([^"]+)\.prismic\.io"/) || [])[1];
3
- };
4
- export {
5
- getPreviewCookieRepositoryName
6
- };
7
- //# sourceMappingURL=getPreviewCookieRepositoryName.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPreviewCookieRepositoryName.js","sources":["../../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/\"([^\"]+)\\.prismic\\.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":"AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACf,UAAA,mBAAmB,aAAa,EAAE,MAAM,wBAAwB,KACvE,CAAA,GAAI,CAAC;AACP;"}
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const cookie = require('./../_node_modules/@prismicio/client/dist/cookie.cjs');
4
- const readValue = (value) => {
5
- return value.replace(/%3B/g, ";");
6
- };
7
- const getPrismicPreviewCookie = (cookieJar) => {
8
- const cookies = cookieJar.split("; ");
9
- let value;
10
- for (const cookie$1 of cookies) {
11
- const parts = cookie$1.split("=");
12
- const name = readValue(parts[0]).replace(/%3D/g, "=");
13
- if (name === cookie.preview) {
14
- value = readValue(parts.slice(1).join("="));
15
- continue;
16
- }
17
- }
18
- return value;
19
- };
20
- exports.getPrismicPreviewCookie = getPrismicPreviewCookie;
21
- //# sourceMappingURL=getPrismicPreviewCookie.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPrismicPreviewCookie.cjs","sources":["../../../src/lib/getPrismicPreviewCookie.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\");\n};\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nexport const getPrismicPreviewCookie = (\n\tcookieJar: string,\n): string | undefined => {\n\tconst cookies = cookieJar.split(\"; \");\n\n\tlet value: string | undefined;\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\");\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\");\n\n\t\tif (name === prismic.cookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"));\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\treturn value;\n};\n"],"names":["cookie","prismic.cookie.preview"],"mappings":";;;AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,0BAA0B,CACtC,cACuB;AACjB,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAWA,YAAU,SAAS;AACvB,UAAA,QAAQA,SAAO,MAAM,GAAG;AACxB,UAAA,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAASC,OAAAA,SAAwB;AACpC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACA;AAAA,EACD;AAEM,SAAA;AACR;;"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Returns the value of a cookie from a given cookie store.
3
- *
4
- * @param cookieJar - The stringified cookie store from which to read the
5
- * cookie.
6
- *
7
- * @returns The value of the cookie, if it exists.
8
- */
9
- export declare const getPrismicPreviewCookie: (cookieJar: string) => string | undefined;
@@ -1,21 +0,0 @@
1
- import { preview } from './../_node_modules/@prismicio/client/dist/cookie.js';
2
- const readValue = (value) => {
3
- return value.replace(/%3B/g, ";");
4
- };
5
- const getPrismicPreviewCookie = (cookieJar) => {
6
- const cookies = cookieJar.split("; ");
7
- let value;
8
- for (const cookie of cookies) {
9
- const parts = cookie.split("=");
10
- const name = readValue(parts[0]).replace(/%3D/g, "=");
11
- if (name === preview) {
12
- value = readValue(parts.slice(1).join("="));
13
- continue;
14
- }
15
- }
16
- return value;
17
- };
18
- export {
19
- getPrismicPreviewCookie
20
- };
21
- //# sourceMappingURL=getPrismicPreviewCookie.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPrismicPreviewCookie.js","sources":["../../../src/lib/getPrismicPreviewCookie.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\");\n};\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nexport const getPrismicPreviewCookie = (\n\tcookieJar: string,\n): string | undefined => {\n\tconst cookies = cookieJar.split(\"; \");\n\n\tlet value: string | undefined;\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\");\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\");\n\n\t\tif (name === prismic.cookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"));\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\treturn value;\n};\n"],"names":["prismic.cookie.preview"],"mappings":";AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,0BAA0B,CACtC,cACuB;AACjB,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAW,UAAU,SAAS;AACvB,UAAA,QAAQ,OAAO,MAAM,GAAG;AACxB,UAAA,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAASA,SAAwB;AACpC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACA;AAAA,EACD;AAEM,SAAA;AACR;"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const version = "1.7.0";
4
- exports.version = version;
5
- //# sourceMappingURL=package.json.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package.json.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const navigation = require("next/navigation");
4
- const headers = require("next/headers");
5
- const cookie = require('./_node_modules/@prismicio/client/dist/cookie.cjs');
6
- async function redirectToPreviewURL(config) {
7
- const basePath = config.basePath || "";
8
- const request = "request" in config ? config.request : config.req;
9
- config.client.enableAutoPreviewsFromReq(request);
10
- const previewUrl = await config.client.resolvePreviewURL({
11
- linkResolver: config.linkResolver,
12
- defaultURL: config.defaultURL || "/"
13
- });
14
- if ("nextUrl" in request) {
15
- headers.draftMode().enable();
16
- const previewCookie = request.nextUrl.searchParams.get("token");
17
- if (previewCookie) {
18
- headers.cookies().set(cookie.preview, previewCookie);
19
- }
20
- navigation.redirect(basePath + previewUrl);
21
- } else {
22
- if (!("res" in config)) {
23
- throw new Error("[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.");
24
- }
25
- config.res.redirect(basePath + previewUrl);
26
- return;
27
- }
28
- }
29
- exports.redirectToPreviewURL = redirectToPreviewURL;
30
- //# sourceMappingURL=redirectToPreviewURL.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\ntype RedirectToPreviewURLConfigBase = {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\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<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\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?: prismic.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 type RedirectToPreviewURLRouteHandlerConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `request` object from a Next.js Route Handler.\n\t\t *\n\t\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t\t */\n\t\trequest: NextRequestLike;\n\t};\n\nexport type RedirectToPreviewURLAPIEndpointConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `req` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\treq: NextApiRequestLike;\n\n\t\t/**\n\t\t * The `res` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\tres: NextApiResponseLike;\n\t};\n\nexport type RedirectToPreviewURLConfig =\n\t| RedirectToPreviewURLRouteHandlerConfig\n\t| RedirectToPreviewURLAPIEndpointConfig;\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLRouteHandlerConfig,\n): Promise<never>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLAPIEndpointConfig,\n): Promise<void>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never | void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\tdraftMode().enable();\n\n\t\t// Set the initial preview cookie, if available.\n\t\t// Setting the cookie here is necessary to support unpublished\n\t\t// previews. Without setting it here, the page will try to\n\t\t// render without the preview cookie, leading to a\n\t\t// PrismicNotFound error.\n\t\tconst previewCookie = request.nextUrl.searchParams.get(\"token\");\n\t\tif (previewCookie) {\n\t\t\tcookies().set(prismic.cookie.preview, previewCookie);\n\t\t}\n\n\t\tredirect(basePath + previewUrl);\n\t} else {\n\t\tif (!(\"res\" in config)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.\",\n\t\t\t);\n\t\t}\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n}\n"],"names":["draftMode","cookies","prismic.cookie.preview","redirect"],"mappings":";;;;;AAuFA,eAAsB,qBACrB,QAAkC;AAE5B,QAAA,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,aAAa,SAAS,OAAO,UAAU,OAAO;AAEvD,SAAA,OAAO,0BAA0B,OAAO;AAE/C,QAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,IACxD,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO,cAAc;AAAA,EAAA,CACjC;AAED,MAAI,aAAa,SAAS;AACzBA,YAAA,UAAA,EAAY;AAOZ,UAAM,gBAAgB,QAAQ,QAAQ,aAAa,IAAI,OAAO;AAC9D,QAAI,eAAe;AAClBC,cAAAA,UAAU,IAAIC,gBAAwB,aAAa;AAAA,IACnD;AAEDC,wBAAS,WAAW,UAAU;AAAA,EAAA,OACxB;AACF,QAAA,EAAE,SAAS,SAAS;AACjB,YAAA,IAAI,MACT,0GAA0G;AAAA,IAE3G;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AACF;;"}
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const cookie = require('./_node_modules/@prismicio/client/dist/cookie.cjs');
4
- function setPreviewData({ req, res }) {
5
- const ref = req.query.token || req.cookies[cookie.preview];
6
- if (ref) {
7
- res.setPreviewData({ ref });
8
- }
9
- }
10
- exports.setPreviewData = setPreviewData;
11
- //# sourceMappingURL=setPreviewData.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setPreviewData.cjs","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * Configuration for `setPreviewData`.\n */\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/**\n * **Only use this function in the Pages Directory (/pages).**\n *\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":["prismic.cookie.preview"],"mappings":";;;SA4BgB,eAAe,EAAE,KAAK,OAA2B;AAC1D,QAAA,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,OAAAA,OAAsB;AAEjE,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"setPreviewData.js","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * Configuration for `setPreviewData`.\n */\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/**\n * **Only use this function in the Pages Directory (/pages).**\n *\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":["prismic.cookie.preview"],"mappings":";SA4BgB,eAAe,EAAE,KAAK,OAA2B;AAC1D,QAAA,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,OAAsB;AAEjE,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;"}
@@ -1,14 +0,0 @@
1
- /**
2
- * Extracts preview reference repo name from stringified Prismic preview cookie
3
- *
4
- * @param previewCookie - The Prismic preview cookie.
5
- *
6
- * @returns The repository name for the Prismic preview cookie. If the cookie
7
- * represents an inactive preview session, `undefined` will be returned.
8
- */
9
- export const getPreviewCookieRepositoryName = (
10
- previewCookie: string,
11
- ): string | undefined => {
12
- return (decodeURIComponent(previewCookie).match(/"([^"]+)\.prismic\.io"/) ||
13
- [])[1];
14
- };
@@ -1,33 +0,0 @@
1
- import * as prismic from "@prismicio/client";
2
-
3
- const readValue = (value: string): string => {
4
- return value.replace(/%3B/g, ";");
5
- };
6
-
7
- /**
8
- * Returns the value of a cookie from a given cookie store.
9
- *
10
- * @param cookieJar - The stringified cookie store from which to read the
11
- * cookie.
12
- *
13
- * @returns The value of the cookie, if it exists.
14
- */
15
- export const getPrismicPreviewCookie = (
16
- cookieJar: string,
17
- ): string | undefined => {
18
- const cookies = cookieJar.split("; ");
19
-
20
- let value: string | undefined;
21
-
22
- for (const cookie of cookies) {
23
- const parts = cookie.split("=");
24
- const name = readValue(parts[0]).replace(/%3D/g, "=");
25
-
26
- if (name === prismic.cookie.preview) {
27
- value = readValue(parts.slice(1).join("="));
28
- continue;
29
- }
30
- }
31
-
32
- return value;
33
- };