@prismicio/next 2.2.4 → 2.3.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 (60) hide show
  1. package/dist/PrismicNextLink.d.cts +3 -3
  2. package/dist/PrismicNextLink.d.ts +3 -3
  3. package/dist/cacheTagPrismicPages.cjs +23 -0
  4. package/dist/cacheTagPrismicPages.cjs.map +1 -0
  5. package/dist/cacheTagPrismicPages.d.cts +19 -0
  6. package/dist/cacheTagPrismicPages.d.cts.map +1 -0
  7. package/dist/cacheTagPrismicPages.d.ts +19 -0
  8. package/dist/cacheTagPrismicPages.d.ts.map +1 -0
  9. package/dist/cacheTagPrismicPages.js +22 -0
  10. package/dist/cacheTagPrismicPages.js.map +1 -0
  11. package/dist/enableAutoPreviews.cjs +2 -16
  12. package/dist/enableAutoPreviews.cjs.map +1 -1
  13. package/dist/enableAutoPreviews.d.cts.map +1 -1
  14. package/dist/enableAutoPreviews.d.ts.map +1 -1
  15. package/dist/enableAutoPreviews.js +2 -15
  16. package/dist/enableAutoPreviews.js.map +1 -1
  17. package/dist/exitPreview.cjs +4 -1
  18. package/dist/exitPreview.cjs.map +1 -1
  19. package/dist/exitPreview.d.cts.map +1 -1
  20. package/dist/exitPreview.d.ts.map +1 -1
  21. package/dist/exitPreview.js +3 -1
  22. package/dist/exitPreview.js.map +1 -1
  23. package/dist/getPreviewRef.cjs +38 -0
  24. package/dist/getPreviewRef.cjs.map +1 -0
  25. package/dist/getPreviewRef.d.cts +22 -0
  26. package/dist/getPreviewRef.d.cts.map +1 -0
  27. package/dist/getPreviewRef.d.ts +22 -0
  28. package/dist/getPreviewRef.d.ts.map +1 -0
  29. package/dist/getPreviewRef.js +37 -0
  30. package/dist/getPreviewRef.js.map +1 -0
  31. package/dist/getPrismicCacheTags.cjs +31 -0
  32. package/dist/getPrismicCacheTags.cjs.map +1 -0
  33. package/dist/getPrismicCacheTags.d.cts +16 -0
  34. package/dist/getPrismicCacheTags.d.cts.map +1 -0
  35. package/dist/getPrismicCacheTags.d.ts +16 -0
  36. package/dist/getPrismicCacheTags.d.ts.map +1 -0
  37. package/dist/getPrismicCacheTags.js +30 -0
  38. package/dist/getPrismicCacheTags.js.map +1 -0
  39. package/dist/index.cjs +8 -0
  40. package/dist/index.d.cts +5 -1
  41. package/dist/index.d.ts +5 -1
  42. package/dist/index.js +5 -1
  43. package/dist/package.cjs +1 -1
  44. package/dist/package.js +1 -1
  45. package/dist/revalidatePrismicPages.cjs +20 -0
  46. package/dist/revalidatePrismicPages.cjs.map +1 -0
  47. package/dist/revalidatePrismicPages.d.cts +14 -0
  48. package/dist/revalidatePrismicPages.d.cts.map +1 -0
  49. package/dist/revalidatePrismicPages.d.ts +14 -0
  50. package/dist/revalidatePrismicPages.d.ts.map +1 -0
  51. package/dist/revalidatePrismicPages.js +19 -0
  52. package/dist/revalidatePrismicPages.js.map +1 -0
  53. package/package.json +1 -1
  54. package/src/cacheTagPrismicPages.ts +20 -0
  55. package/src/enableAutoPreviews.ts +4 -33
  56. package/src/exitPreview.ts +7 -1
  57. package/src/getPreviewRef.ts +51 -0
  58. package/src/getPrismicCacheTags.ts +46 -0
  59. package/src/index.ts +8 -0
  60. package/src/revalidatePrismicPages.ts +19 -0
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -0,0 +1,23 @@
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_getPrismicCacheTags = require("./getPrismicCacheTags.cjs");
3
+ let next_cache_js = require("next/cache.js");
4
+ //#region src/cacheTagPrismicPages.ts
5
+ /**
6
+ * Tags the current cache entry with cache tags for a set of Prismic pages so they can be
7
+ * revalidated when their content changes.
8
+ *
9
+ * Linked documents (via content relationships) are tagged as well, so the cache entry is
10
+ * revalidated when any of its nested documents change.
11
+ *
12
+ * @param pages - A set of Prismic pages used to tag the cache entry.
13
+ * @experimental
14
+ *
15
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
16
+ */
17
+ function cacheTagPrismicPages(pages) {
18
+ (0, next_cache_js.cacheTag)(...require_getPrismicCacheTags.getPrismicCacheTags(pages));
19
+ }
20
+ //#endregion
21
+ exports.cacheTagPrismicPages = cacheTagPrismicPages;
22
+
23
+ //# sourceMappingURL=cacheTagPrismicPages.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTagPrismicPages.cjs","names":["getPrismicCacheTags"],"sources":["../src/cacheTagPrismicPages.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\nimport { cacheTag } from \"next/cache\"\n\nimport { getPrismicCacheTags } from \"./getPrismicCacheTags\"\n\n/**\n * Tags the current cache entry with cache tags for a set of Prismic pages so they can be\n * revalidated when their content changes.\n *\n * Linked documents (via content relationships) are tagged as well, so the cache entry is\n * revalidated when any of its nested documents change.\n *\n * @param pages - A set of Prismic pages used to tag the cache entry.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function cacheTagPrismicPages(pages: PrismicDocument[]): void {\n\tcacheTag(...getPrismicCacheTags(pages))\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,qBAAqB,OAAgC;AACpE,EAAA,GAAA,cAAA,UAAS,GAAGA,4BAAAA,oBAAoB,MAAM,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { PrismicDocument } from "@prismicio/client";
2
+
3
+ //#region src/cacheTagPrismicPages.d.ts
4
+ /**
5
+ * Tags the current cache entry with cache tags for a set of Prismic pages so they can be
6
+ * revalidated when their content changes.
7
+ *
8
+ * Linked documents (via content relationships) are tagged as well, so the cache entry is
9
+ * revalidated when any of its nested documents change.
10
+ *
11
+ * @param pages - A set of Prismic pages used to tag the cache entry.
12
+ * @experimental
13
+ *
14
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
15
+ */
16
+ declare function cacheTagPrismicPages(pages: PrismicDocument[]): void;
17
+ //#endregion
18
+ export { cacheTagPrismicPages };
19
+ //# sourceMappingURL=cacheTagPrismicPages.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTagPrismicPages.d.cts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;AAiBA;;;;;;;;;;iBAAgB,oBAAA,CAAqB,KAAA,EAAO,eAAA"}
@@ -0,0 +1,19 @@
1
+ import { PrismicDocument } from "@prismicio/client";
2
+
3
+ //#region src/cacheTagPrismicPages.d.ts
4
+ /**
5
+ * Tags the current cache entry with cache tags for a set of Prismic pages so they can be
6
+ * revalidated when their content changes.
7
+ *
8
+ * Linked documents (via content relationships) are tagged as well, so the cache entry is
9
+ * revalidated when any of its nested documents change.
10
+ *
11
+ * @param pages - A set of Prismic pages used to tag the cache entry.
12
+ * @experimental
13
+ *
14
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
15
+ */
16
+ declare function cacheTagPrismicPages(pages: PrismicDocument[]): void;
17
+ //#endregion
18
+ export { cacheTagPrismicPages };
19
+ //# sourceMappingURL=cacheTagPrismicPages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTagPrismicPages.d.ts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;AAiBA;;;;;;;;;;iBAAgB,oBAAA,CAAqB,KAAA,EAAO,eAAA"}
@@ -0,0 +1,22 @@
1
+ import { getPrismicCacheTags } from "./getPrismicCacheTags.js";
2
+ import { cacheTag } from "next/cache.js";
3
+ //#region src/cacheTagPrismicPages.ts
4
+ /**
5
+ * Tags the current cache entry with cache tags for a set of Prismic pages so they can be
6
+ * revalidated when their content changes.
7
+ *
8
+ * Linked documents (via content relationships) are tagged as well, so the cache entry is
9
+ * revalidated when any of its nested documents change.
10
+ *
11
+ * @param pages - A set of Prismic pages used to tag the cache entry.
12
+ * @experimental
13
+ *
14
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
15
+ */
16
+ function cacheTagPrismicPages(pages) {
17
+ cacheTag(...getPrismicCacheTags(pages));
18
+ }
19
+ //#endregion
20
+ export { cacheTagPrismicPages };
21
+
22
+ //# sourceMappingURL=cacheTagPrismicPages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheTagPrismicPages.js","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\nimport { cacheTag } from \"next/cache\"\n\nimport { getPrismicCacheTags } from \"./getPrismicCacheTags\"\n\n/**\n * Tags the current cache entry with cache tags for a set of Prismic pages so they can be\n * revalidated when their content changes.\n *\n * Linked documents (via content relationships) are tagged as well, so the cache entry is\n * revalidated when any of its nested documents change.\n *\n * @param pages - A set of Prismic pages used to tag the cache entry.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function cacheTagPrismicPages(pages: PrismicDocument[]): void {\n\tcacheTag(...getPrismicCacheTags(pages))\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAgB,qBAAqB,OAAgC;AACpE,UAAS,GAAG,oBAAoB,MAAM,CAAC"}
@@ -1,5 +1,4 @@
1
- require("./_virtual/_rolldown/runtime.cjs");
2
- let _prismicio_client = require("@prismicio/client");
1
+ const require_getPreviewRef = require("./getPreviewRef.cjs");
3
2
  //#region src/enableAutoPreviews.ts
4
3
  /**
5
4
  * Configures a Prismic client to automatically query draft content during a preview session.
@@ -7,20 +6,7 @@ let _prismicio_client = require("@prismicio/client");
7
6
  * @param config - Configuration for the function.
8
7
  */
9
8
  function enableAutoPreviews(config) {
10
- config.client.queryContentFromRef(async () => {
11
- const { cookies, draftMode } = await import("next/headers.js");
12
- let isDraftModeEnabled = false;
13
- try {
14
- isDraftModeEnabled = (await draftMode()).isEnabled;
15
- } catch {
16
- return;
17
- }
18
- if (!isDraftModeEnabled) return;
19
- const cookie = (await cookies()).get(_prismicio_client.cookie.preview)?.value;
20
- if (!cookie) return;
21
- if (!cookie.includes("websitePreviewId=")) return;
22
- return cookie;
23
- });
9
+ config.client.queryContentFromRef(() => require_getPreviewRef.getPreviewRef());
24
10
  }
25
11
  //#endregion
26
12
  exports.enableAutoPreviews = enableAutoPreviews;
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.cjs","names":["prismicCookie"],"sources":["../src/enableAutoPreviews.ts"],"sourcesContent":["import { type Client, cookie as prismicCookie } from \"@prismicio/client\"\n\n/** Configuration for `enableAutoPreviews`. */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\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, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">\n}\n\n/**\n * Configures a Prismic client to automatically query draft content during a preview session.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\t// We use a function value so the cookie is checked on every\n\t// request. We don't have a static value to read from.\n\tconfig.client.queryContentFromRef(async () => {\n\t\t// Need this to avoid the following Next.js build-time error:\n\t\t// You're importing a component that needs next/headers. That only works\n\t\t// in a Server Component which is not supported in the pages/ directory.\n\t\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t\tlet isDraftModeEnabled = false\n\t\ttry {\n\t\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t\t} catch {\n\t\t\t// `draftMode()` may have been called in a palce that\n\t\t\t// does not have access to its async storage. This\n\t\t\t// occurs in places like `generateStaticParams()`. We\n\t\t\t// can ignore this case.\n\t\t\treturn\n\t\t}\n\t\tif (!isDraftModeEnabled) {\n\t\t\treturn\n\t\t}\n\n\t\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\t\tif (!cookie) {\n\t\t\treturn\n\t\t}\n\n\t\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\t\tif (!isActiveCookie) {\n\t\t\treturn\n\t\t}\n\n\t\treturn cookie\n\t})\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,mBAAmB,QAAwC;AAG1E,QAAO,OAAO,oBAAoB,YAAY;EAI7C,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;EAE5C,IAAI,qBAAqB;AACzB,MAAI;AACH,yBAAsB,MAAM,WAAW,EAAE;UAClC;AAKP;;AAED,MAAI,CAAC,mBACJ;EAGD,MAAM,UAAU,MAAM,SAAS,EAAE,IAAIA,kBAAAA,OAAc,QAAQ,EAAE;AAC7D,MAAI,CAAC,OACJ;AAID,MAAI,CADmB,OAAO,SAAS,oBAAoB,CAE1D;AAGD,SAAO;GACN"}
1
+ {"version":3,"file":"enableAutoPreviews.cjs","names":["getPreviewRef"],"sources":["../src/enableAutoPreviews.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\"\n\nimport { getPreviewRef } from \"./getPreviewRef\"\n\n/** Configuration for `enableAutoPreviews`. */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\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, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">\n}\n\n/**\n * Configures a Prismic client to automatically query draft content during a preview session.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\t// We use a function value so the cookie is checked on every\n\t// request. We don't have a static value to read from.\n\tconfig.client.queryContentFromRef(() => getPreviewRef())\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,mBAAmB,QAAwC;AAG1E,QAAO,OAAO,0BAA0BA,sBAAAA,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.d.cts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;KAGY,wBAAA;EAAA,oEAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;AAAA;;;;;;iBAQE,kBAAA,CAAmB,MAAA,EAAQ,wBAAA"}
1
+ {"version":3,"file":"enableAutoPreviews.d.cts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;KAKY,wBAAA;EAAA,oEAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;AAAA;;;;;;iBAQE,kBAAA,CAAmB,MAAA,EAAQ,wBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.d.ts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;KAGY,wBAAA;EAAA,oEAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;AAAA;;;;;;iBAQE,kBAAA,CAAmB,MAAA,EAAQ,wBAAA"}
1
+ {"version":3,"file":"enableAutoPreviews.d.ts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;KAKY,wBAAA;EAAA,oEAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;AAAA;;;;;;iBAQE,kBAAA,CAAmB,MAAA,EAAQ,wBAAA"}
@@ -1,4 +1,4 @@
1
- import { cookie } from "@prismicio/client";
1
+ import { getPreviewRef } from "./getPreviewRef.js";
2
2
  //#region src/enableAutoPreviews.ts
3
3
  /**
4
4
  * Configures a Prismic client to automatically query draft content during a preview session.
@@ -6,20 +6,7 @@ import { cookie } from "@prismicio/client";
6
6
  * @param config - Configuration for the function.
7
7
  */
8
8
  function enableAutoPreviews(config) {
9
- config.client.queryContentFromRef(async () => {
10
- const { cookies, draftMode } = await import("next/headers.js");
11
- let isDraftModeEnabled = false;
12
- try {
13
- isDraftModeEnabled = (await draftMode()).isEnabled;
14
- } catch {
15
- return;
16
- }
17
- if (!isDraftModeEnabled) return;
18
- const cookie$1 = (await cookies()).get(cookie.preview)?.value;
19
- if (!cookie$1) return;
20
- if (!cookie$1.includes("websitePreviewId=")) return;
21
- return cookie$1;
22
- });
9
+ config.client.queryContentFromRef(() => getPreviewRef());
23
10
  }
24
11
  //#endregion
25
12
  export { enableAutoPreviews };
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.js","names":["cookie","prismicCookie"],"sources":["../src/enableAutoPreviews.ts"],"sourcesContent":["import { type Client, cookie as prismicCookie } from \"@prismicio/client\"\n\n/** Configuration for `enableAutoPreviews`. */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\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, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">\n}\n\n/**\n * Configures a Prismic client to automatically query draft content during a preview session.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\t// We use a function value so the cookie is checked on every\n\t// request. We don't have a static value to read from.\n\tconfig.client.queryContentFromRef(async () => {\n\t\t// Need this to avoid the following Next.js build-time error:\n\t\t// You're importing a component that needs next/headers. That only works\n\t\t// in a Server Component which is not supported in the pages/ directory.\n\t\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t\tlet isDraftModeEnabled = false\n\t\ttry {\n\t\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t\t} catch {\n\t\t\t// `draftMode()` may have been called in a palce that\n\t\t\t// does not have access to its async storage. This\n\t\t\t// occurs in places like `generateStaticParams()`. We\n\t\t\t// can ignore this case.\n\t\t\treturn\n\t\t}\n\t\tif (!isDraftModeEnabled) {\n\t\t\treturn\n\t\t}\n\n\t\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\t\tif (!cookie) {\n\t\t\treturn\n\t\t}\n\n\t\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\t\tif (!isActiveCookie) {\n\t\t\treturn\n\t\t}\n\n\t\treturn cookie\n\t})\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,mBAAmB,QAAwC;AAG1E,QAAO,OAAO,oBAAoB,YAAY;EAI7C,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;EAE5C,IAAI,qBAAqB;AACzB,MAAI;AACH,yBAAsB,MAAM,WAAW,EAAE;UAClC;AAKP;;AAED,MAAI,CAAC,mBACJ;EAGD,MAAMA,YAAU,MAAM,SAAS,EAAE,IAAIC,OAAc,QAAQ,EAAE;AAC7D,MAAI,CAACD,SACJ;AAID,MAAI,CADmBA,SAAO,SAAS,oBAAoB,CAE1D;AAGD,SAAOA;GACN"}
1
+ {"version":3,"file":"enableAutoPreviews.js","names":[],"sources":["../src/enableAutoPreviews.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\"\n\nimport { getPreviewRef } from \"./getPreviewRef\"\n\n/** Configuration for `enableAutoPreviews`. */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\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, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">\n}\n\n/**\n * Configures a Prismic client to automatically query draft content during a preview session.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\t// We use a function value so the cookie is checked on every\n\t// request. We don't have a static value to read from.\n\tconfig.client.queryContentFromRef(() => getPreviewRef())\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,mBAAmB,QAAwC;AAG1E,QAAO,OAAO,0BAA0B,eAAe,CAAC"}
@@ -1,3 +1,5 @@
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
+ let _prismicio_client = require("@prismicio/client");
1
3
  //#region src/exitPreview.ts
2
4
  /**
3
5
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -15,8 +17,9 @@
15
17
  * ```
16
18
  */
17
19
  async function exitPreview() {
18
- const { draftMode } = await import("next/headers.js");
20
+ const { cookies, draftMode } = await import("next/headers.js");
19
21
  (await draftMode()).disable();
22
+ (await cookies()).delete(_prismicio_client.cookie.preview);
20
23
  return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
21
24
  }
22
25
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.cjs","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\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 { draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,eAAsB,cAAiC;CAItD,MAAM,EAAE,cAAc,MAAM,OAAO;AAElC,EAAC,MAAM,WAAW,EAAE,SAAS;AAG9B,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
1
+ {"version":3,"file":"exitPreview.cjs","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\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;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes the preview cookie, so `exitPreview`\n\t// clears it to close the preview-cookie loop.\n\t;(await cookies()).delete(prismicCookie.preview)\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;AAI7B,EAAC,MAAM,SAAS,EAAE,OAAOA,kBAAAA,OAAc,QAAQ;AAGhD,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAeA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAeA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1,3 +1,4 @@
1
+ import { cookie } from "@prismicio/client";
1
2
  //#region src/exitPreview.ts
2
3
  /**
3
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -15,8 +16,9 @@
15
16
  * ```
16
17
  */
17
18
  async function exitPreview() {
18
- const { draftMode } = await import("next/headers.js");
19
+ const { cookies, draftMode } = await import("next/headers.js");
19
20
  (await draftMode()).disable();
21
+ (await cookies()).delete(cookie.preview);
20
22
  return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
21
23
  }
22
24
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\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 { draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,eAAsB,cAAiC;CAItD,MAAM,EAAE,cAAc,MAAM,OAAO;AAElC,EAAC,MAAM,WAAW,EAAE,SAAS;AAG9B,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
1
+ {"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\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;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes the preview cookie, so `exitPreview`\n\t// clears it to close the preview-cookie loop.\n\t;(await cookies()).delete(prismicCookie.preview)\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;AAI7B,EAAC,MAAM,SAAS,EAAE,OAAOA,OAAc,QAAQ;AAGhD,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
@@ -0,0 +1,38 @@
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
+ let _prismicio_client = require("@prismicio/client");
3
+ //#region src/getPreviewRef.ts
4
+ /**
5
+ * Reads the Prismic preview ref for the current request when an active preview session exists.
6
+ *
7
+ * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
8
+ * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
9
+ * an argument so it becomes part of the cache key:
10
+ *
11
+ * @example
12
+ * ;```typescript
13
+ * import { getPreviewRef } from "@prismicio/next"
14
+ *
15
+ * const page = await fetchPage(uid, await getPreviewRef())
16
+ * ```
17
+ *
18
+ * @returns The active preview ref, or `undefined` if no preview session is active.
19
+ * @experimental
20
+ */
21
+ async function getPreviewRef() {
22
+ const { cookies, draftMode } = await import("next/headers.js");
23
+ let isDraftModeEnabled = false;
24
+ try {
25
+ isDraftModeEnabled = (await draftMode()).isEnabled;
26
+ } catch {
27
+ return;
28
+ }
29
+ if (!isDraftModeEnabled) return;
30
+ const cookie = (await cookies()).get(_prismicio_client.cookie.preview)?.value;
31
+ if (!cookie) return;
32
+ if (!cookie.includes("websitePreviewId=")) return;
33
+ return cookie;
34
+ }
35
+ //#endregion
36
+ exports.getPreviewRef = getPreviewRef;
37
+
38
+ //# sourceMappingURL=getPreviewRef.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPreviewRef.cjs","names":["prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\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\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\tif (!isActiveCookie) {\n\t\treturn\n\t}\n\n\treturn cookie\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAM,UAAU,MAAM,SAAS,EAAE,IAAIA,kBAAAA,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAAC,OACJ;AAID,KAAI,CADmB,OAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAO"}
@@ -0,0 +1,22 @@
1
+ //#region src/getPreviewRef.d.ts
2
+ /**
3
+ * Reads the Prismic preview ref for the current request when an active preview session exists.
4
+ *
5
+ * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
6
+ * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
7
+ * an argument so it becomes part of the cache key:
8
+ *
9
+ * @example
10
+ * ;```typescript
11
+ * import { getPreviewRef } from "@prismicio/next"
12
+ *
13
+ * const page = await fetchPage(uid, await getPreviewRef())
14
+ * ```
15
+ *
16
+ * @returns The active preview ref, or `undefined` if no preview session is active.
17
+ * @experimental
18
+ */
19
+ declare function getPreviewRef(): Promise<string | undefined>;
20
+ //#endregion
21
+ export { getPreviewRef };
22
+ //# sourceMappingURL=getPreviewRef.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPreviewRef.d.cts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -0,0 +1,22 @@
1
+ //#region src/getPreviewRef.d.ts
2
+ /**
3
+ * Reads the Prismic preview ref for the current request when an active preview session exists.
4
+ *
5
+ * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
6
+ * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
7
+ * an argument so it becomes part of the cache key:
8
+ *
9
+ * @example
10
+ * ;```typescript
11
+ * import { getPreviewRef } from "@prismicio/next"
12
+ *
13
+ * const page = await fetchPage(uid, await getPreviewRef())
14
+ * ```
15
+ *
16
+ * @returns The active preview ref, or `undefined` if no preview session is active.
17
+ * @experimental
18
+ */
19
+ declare function getPreviewRef(): Promise<string | undefined>;
20
+ //#endregion
21
+ export { getPreviewRef };
22
+ //# sourceMappingURL=getPreviewRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPreviewRef.d.ts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -0,0 +1,37 @@
1
+ import { cookie } from "@prismicio/client";
2
+ //#region src/getPreviewRef.ts
3
+ /**
4
+ * Reads the Prismic preview ref for the current request when an active preview session exists.
5
+ *
6
+ * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
7
+ * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
8
+ * an argument so it becomes part of the cache key:
9
+ *
10
+ * @example
11
+ * ;```typescript
12
+ * import { getPreviewRef } from "@prismicio/next"
13
+ *
14
+ * const page = await fetchPage(uid, await getPreviewRef())
15
+ * ```
16
+ *
17
+ * @returns The active preview ref, or `undefined` if no preview session is active.
18
+ * @experimental
19
+ */
20
+ async function getPreviewRef() {
21
+ const { cookies, draftMode } = await import("next/headers.js");
22
+ let isDraftModeEnabled = false;
23
+ try {
24
+ isDraftModeEnabled = (await draftMode()).isEnabled;
25
+ } catch {
26
+ return;
27
+ }
28
+ if (!isDraftModeEnabled) return;
29
+ const cookie$1 = (await cookies()).get(cookie.preview)?.value;
30
+ if (!cookie$1) return;
31
+ if (!cookie$1.includes("websitePreviewId=")) return;
32
+ return cookie$1;
33
+ }
34
+ //#endregion
35
+ export { getPreviewRef };
36
+
37
+ //# sourceMappingURL=getPreviewRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPreviewRef.js","names":["cookie","prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\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\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\tif (!isActiveCookie) {\n\t\treturn\n\t}\n\n\treturn cookie\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAMA,YAAU,MAAM,SAAS,EAAE,IAAIC,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAACD,SACJ;AAID,KAAI,CADmBA,SAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAOA"}
@@ -0,0 +1,31 @@
1
+ //#region src/getPrismicCacheTags.ts
2
+ const CACHE_TAG_PREFIX = "prismic/";
3
+ /**
4
+ * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
5
+ * relationship) are included to ensure all related content can be revalidated.
6
+ *
7
+ * @param pages - A set of Prismic pages used to tag the function.
8
+ * @experimental
9
+ *
10
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
11
+ */
12
+ function getPrismicCacheTags(pages) {
13
+ return [...new Set(getPrismicDocumentIDs(pages))].map((id) => buildPrismicCacheTag(id));
14
+ }
15
+ function buildPrismicCacheTag(id) {
16
+ return `${CACHE_TAG_PREFIX}${id}`;
17
+ }
18
+ function getPrismicDocumentIDs(input) {
19
+ if (typeof input !== "object" || input == null) return [];
20
+ if (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item));
21
+ if ("id" in input && typeof input.id === "string") {
22
+ if ("href" in input && typeof input.href === "string" && input.href.includes("/api/v2/documents/search?") || "link_type" in input && input.link_type === "Document") if ("data" in input && typeof input.data === "object" && input.data !== null) return [input.id, ...getPrismicDocumentIDs(input.data)];
23
+ else return [input.id];
24
+ }
25
+ return Object.values(input).flatMap((input) => getPrismicDocumentIDs(input));
26
+ }
27
+ //#endregion
28
+ exports.buildPrismicCacheTag = buildPrismicCacheTag;
29
+ exports.getPrismicCacheTags = getPrismicCacheTags;
30
+
31
+ //# sourceMappingURL=getPrismicCacheTags.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPrismicCacheTags.cjs","names":[],"sources":["../src/getPrismicCacheTags.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\n\nconst CACHE_TAG_PREFIX = \"prismic/\"\n\n/**\n * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content\n * relationship) are included to ensure all related content can be revalidated.\n *\n * @param pages - A set of Prismic pages used to tag the function.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function getPrismicCacheTags(pages: PrismicDocument[]): string[] {\n\tconst ids = [...new Set(getPrismicDocumentIDs(pages))]\n\treturn ids.map((id) => buildPrismicCacheTag(id))\n}\n\nexport function buildPrismicCacheTag(id: string): string {\n\treturn `${CACHE_TAG_PREFIX}${id}`\n}\n\nfunction getPrismicDocumentIDs(input: unknown): string[] {\n\tif (typeof input !== \"object\" || input == null) return []\n\n\tif (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item))\n\n\tif (\"id\" in input && typeof input.id === \"string\") {\n\t\t// Document\n\t\t// Content relationship or link\n\t\tif (\n\t\t\t(\"href\" in input &&\n\t\t\t\ttypeof input.href === \"string\" &&\n\t\t\t\tinput.href.includes(\"/api/v2/documents/search?\")) ||\n\t\t\t(\"link_type\" in input && input.link_type === \"Document\")\n\t\t) {\n\t\t\tif (\"data\" in input && typeof input.data === \"object\" && input.data !== null) {\n\t\t\t\treturn [input.id, ...getPrismicDocumentIDs(input.data)]\n\t\t\t} else {\n\t\t\t\treturn [input.id]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Object.values(input).flatMap((input) => getPrismicDocumentIDs(input))\n}\n"],"mappings":";AAEA,MAAM,mBAAmB;;;;;;;;;;AAWzB,SAAgB,oBAAoB,OAAoC;AAEvE,QADY,CAAC,GAAG,IAAI,IAAI,sBAAsB,MAAM,CAAC,CAAC,CAC3C,KAAK,OAAO,qBAAqB,GAAG,CAAC;;AAGjD,SAAgB,qBAAqB,IAAoB;AACxD,QAAO,GAAG,mBAAmB;;AAG9B,SAAS,sBAAsB,OAA0B;AACxD,KAAI,OAAO,UAAU,YAAY,SAAS,KAAM,QAAO,EAAE;AAEzD,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,SAAS,SAAS,sBAAsB,KAAK,CAAC;AAErF,KAAI,QAAQ,SAAS,OAAO,MAAM,OAAO;MAItC,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,MAAM,KAAK,SAAS,4BAA4B,IAChD,eAAe,SAAS,MAAM,cAAc,WAE7C,KAAI,UAAU,SAAS,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,KACvE,QAAO,CAAC,MAAM,IAAI,GAAG,sBAAsB,MAAM,KAAK,CAAC;MAEvD,QAAO,CAAC,MAAM,GAAG;;AAKpB,QAAO,OAAO,OAAO,MAAM,CAAC,SAAS,UAAU,sBAAsB,MAAM,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { PrismicDocument } from "@prismicio/client";
2
+
3
+ //#region src/getPrismicCacheTags.d.ts
4
+ /**
5
+ * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
6
+ * relationship) are included to ensure all related content can be revalidated.
7
+ *
8
+ * @param pages - A set of Prismic pages used to tag the function.
9
+ * @experimental
10
+ *
11
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
12
+ */
13
+ declare function getPrismicCacheTags(pages: PrismicDocument[]): string[];
14
+ //#endregion
15
+ export { getPrismicCacheTags };
16
+ //# sourceMappingURL=getPrismicCacheTags.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPrismicCacheTags.d.cts","names":[],"sources":["../src/getPrismicCacheTags.ts"],"mappings":";;;;;AAaA;;;;;;;iBAAgB,mBAAA,CAAoB,KAAA,EAAO,eAAA"}
@@ -0,0 +1,16 @@
1
+ import { PrismicDocument } from "@prismicio/client";
2
+
3
+ //#region src/getPrismicCacheTags.d.ts
4
+ /**
5
+ * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
6
+ * relationship) are included to ensure all related content can be revalidated.
7
+ *
8
+ * @param pages - A set of Prismic pages used to tag the function.
9
+ * @experimental
10
+ *
11
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
12
+ */
13
+ declare function getPrismicCacheTags(pages: PrismicDocument[]): string[];
14
+ //#endregion
15
+ export { getPrismicCacheTags };
16
+ //# sourceMappingURL=getPrismicCacheTags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPrismicCacheTags.d.ts","names":[],"sources":["../src/getPrismicCacheTags.ts"],"mappings":";;;;;AAaA;;;;;;;iBAAgB,mBAAA,CAAoB,KAAA,EAAO,eAAA"}
@@ -0,0 +1,30 @@
1
+ //#region src/getPrismicCacheTags.ts
2
+ const CACHE_TAG_PREFIX = "prismic/";
3
+ /**
4
+ * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
5
+ * relationship) are included to ensure all related content can be revalidated.
6
+ *
7
+ * @param pages - A set of Prismic pages used to tag the function.
8
+ * @experimental
9
+ *
10
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
11
+ */
12
+ function getPrismicCacheTags(pages) {
13
+ return [...new Set(getPrismicDocumentIDs(pages))].map((id) => buildPrismicCacheTag(id));
14
+ }
15
+ function buildPrismicCacheTag(id) {
16
+ return `${CACHE_TAG_PREFIX}${id}`;
17
+ }
18
+ function getPrismicDocumentIDs(input) {
19
+ if (typeof input !== "object" || input == null) return [];
20
+ if (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item));
21
+ if ("id" in input && typeof input.id === "string") {
22
+ if ("href" in input && typeof input.href === "string" && input.href.includes("/api/v2/documents/search?") || "link_type" in input && input.link_type === "Document") if ("data" in input && typeof input.data === "object" && input.data !== null) return [input.id, ...getPrismicDocumentIDs(input.data)];
23
+ else return [input.id];
24
+ }
25
+ return Object.values(input).flatMap((input) => getPrismicDocumentIDs(input));
26
+ }
27
+ //#endregion
28
+ export { buildPrismicCacheTag, getPrismicCacheTags };
29
+
30
+ //# sourceMappingURL=getPrismicCacheTags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPrismicCacheTags.js","names":[],"sources":["../src/getPrismicCacheTags.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\n\nconst CACHE_TAG_PREFIX = \"prismic/\"\n\n/**\n * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content\n * relationship) are included to ensure all related content can be revalidated.\n *\n * @param pages - A set of Prismic pages used to tag the function.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function getPrismicCacheTags(pages: PrismicDocument[]): string[] {\n\tconst ids = [...new Set(getPrismicDocumentIDs(pages))]\n\treturn ids.map((id) => buildPrismicCacheTag(id))\n}\n\nexport function buildPrismicCacheTag(id: string): string {\n\treturn `${CACHE_TAG_PREFIX}${id}`\n}\n\nfunction getPrismicDocumentIDs(input: unknown): string[] {\n\tif (typeof input !== \"object\" || input == null) return []\n\n\tif (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item))\n\n\tif (\"id\" in input && typeof input.id === \"string\") {\n\t\t// Document\n\t\t// Content relationship or link\n\t\tif (\n\t\t\t(\"href\" in input &&\n\t\t\t\ttypeof input.href === \"string\" &&\n\t\t\t\tinput.href.includes(\"/api/v2/documents/search?\")) ||\n\t\t\t(\"link_type\" in input && input.link_type === \"Document\")\n\t\t) {\n\t\t\tif (\"data\" in input && typeof input.data === \"object\" && input.data !== null) {\n\t\t\t\treturn [input.id, ...getPrismicDocumentIDs(input.data)]\n\t\t\t} else {\n\t\t\t\treturn [input.id]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Object.values(input).flatMap((input) => getPrismicDocumentIDs(input))\n}\n"],"mappings":";AAEA,MAAM,mBAAmB;;;;;;;;;;AAWzB,SAAgB,oBAAoB,OAAoC;AAEvE,QADY,CAAC,GAAG,IAAI,IAAI,sBAAsB,MAAM,CAAC,CAAC,CAC3C,KAAK,OAAO,qBAAqB,GAAG,CAAC;;AAGjD,SAAgB,qBAAqB,IAAoB;AACxD,QAAO,GAAG,mBAAmB;;AAG9B,SAAS,sBAAsB,OAA0B;AACxD,KAAI,OAAO,UAAU,YAAY,SAAS,KAAM,QAAO,EAAE;AAEzD,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,SAAS,SAAS,sBAAsB,KAAK,CAAC;AAErF,KAAI,QAAQ,SAAS,OAAO,MAAM,OAAO;MAItC,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,MAAM,KAAK,SAAS,4BAA4B,IAChD,eAAe,SAAS,MAAM,cAAc,WAE7C,KAAI,UAAU,SAAS,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,KACvE,QAAO,CAAC,MAAM,IAAI,GAAG,sBAAsB,MAAM,KAAK,CAAC;MAEvD,QAAO,CAAC,MAAM,GAAG;;AAKpB,QAAO,OAAO,OAAO,MAAM,CAAC,SAAS,UAAU,sBAAsB,MAAM,CAAC"}
package/dist/index.cjs CHANGED
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_exitPreview = require("./exitPreview.cjs");
3
3
  const require_PrismicPreview = require("./PrismicPreview.cjs");
4
4
  const require_PrismicNextLink = require("./PrismicNextLink.cjs");
5
+ const require_getPreviewRef = require("./getPreviewRef.cjs");
5
6
  const require_enableAutoPreviews = require("./enableAutoPreviews.cjs");
6
7
  const require_redirectToPreviewURL = require("./redirectToPreviewURL.cjs");
7
8
  const require_imgixLoader = require("./imgixLoader.cjs");
@@ -9,13 +10,20 @@ const require_PrismicNextImage = require("./PrismicNextImage.cjs");
9
10
  const require_getSlices = require("./getSlices.cjs");
10
11
  const require_SliceSimulator = require("./SliceSimulator.cjs");
11
12
  const require_createLocaleRedirect = require("./createLocaleRedirect.cjs");
13
+ const require_getPrismicCacheTags = require("./getPrismicCacheTags.cjs");
14
+ const require_cacheTagPrismicPages = require("./cacheTagPrismicPages.cjs");
15
+ const require_revalidatePrismicPages = require("./revalidatePrismicPages.cjs");
12
16
  exports.PrismicNextImage = require_PrismicNextImage.PrismicNextImage;
13
17
  exports.PrismicNextLink = require_PrismicNextLink.PrismicNextLink;
14
18
  exports.PrismicPreview = require_PrismicPreview.PrismicPreview;
15
19
  exports.SliceSimulator = require_SliceSimulator.SliceSimulator;
20
+ exports.cacheTagPrismicPages = require_cacheTagPrismicPages.cacheTagPrismicPages;
16
21
  exports.createLocaleRedirect = require_createLocaleRedirect.createLocaleRedirect;
17
22
  exports.enableAutoPreviews = require_enableAutoPreviews.enableAutoPreviews;
18
23
  exports.exitPreview = require_exitPreview.exitPreview;
24
+ exports.getPreviewRef = require_getPreviewRef.getPreviewRef;
25
+ exports.getPrismicCacheTags = require_getPrismicCacheTags.getPrismicCacheTags;
19
26
  exports.getSlices = require_getSlices.getSlices;
20
27
  exports.imgixLoader = require_imgixLoader.imgixLoader;
21
28
  exports.redirectToPreviewURL = require_redirectToPreviewURL.redirectToPreviewURL;
29
+ exports.revalidatePrismicPages = require_revalidatePrismicPages.revalidatePrismicPages;
package/dist/index.d.cts CHANGED
@@ -2,6 +2,7 @@ import { exitPreview } from "./exitPreview.cjs";
2
2
  import { PrismicPreview, PrismicPreviewProps } from "./PrismicPreview.cjs";
3
3
  import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.cjs";
4
4
  import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./enableAutoPreviews.cjs";
5
+ import { getPreviewRef } from "./getPreviewRef.cjs";
5
6
  import { CreateClientConfig } from "./types.cjs";
6
7
  import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./redirectToPreviewURL.cjs";
7
8
  import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.cjs";
@@ -9,4 +10,7 @@ import { SliceSimulator, SliceSimulatorParams, SliceSimulatorProps } from "./Sli
9
10
  import { getSlices } from "./getSlices.cjs";
10
11
  import { imgixLoader } from "./imgixLoader.cjs";
11
12
  import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.cjs";
12
- export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, createLocaleRedirect, enableAutoPreviews, exitPreview, getSlices, imgixLoader, redirectToPreviewURL };
13
+ import { getPrismicCacheTags } from "./getPrismicCacheTags.cjs";
14
+ import { cacheTagPrismicPages } from "./cacheTagPrismicPages.cjs";
15
+ import { revalidatePrismicPages } from "./revalidatePrismicPages.cjs";
16
+ export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, cacheTagPrismicPages, createLocaleRedirect, enableAutoPreviews, exitPreview, getPreviewRef, getPrismicCacheTags, getSlices, imgixLoader, redirectToPreviewURL, revalidatePrismicPages };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { exitPreview } from "./exitPreview.js";
2
2
  import { PrismicPreview, PrismicPreviewProps } from "./PrismicPreview.js";
3
3
  import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.js";
4
4
  import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./enableAutoPreviews.js";
5
+ import { getPreviewRef } from "./getPreviewRef.js";
5
6
  import { CreateClientConfig } from "./types.js";
6
7
  import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./redirectToPreviewURL.js";
7
8
  import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.js";
@@ -9,4 +10,7 @@ import { SliceSimulator, SliceSimulatorParams, SliceSimulatorProps } from "./Sli
9
10
  import { getSlices } from "./getSlices.js";
10
11
  import { imgixLoader } from "./imgixLoader.js";
11
12
  import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.js";
12
- export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, createLocaleRedirect, enableAutoPreviews, exitPreview, getSlices, imgixLoader, redirectToPreviewURL };
13
+ import { getPrismicCacheTags } from "./getPrismicCacheTags.js";
14
+ import { cacheTagPrismicPages } from "./cacheTagPrismicPages.js";
15
+ import { revalidatePrismicPages } from "./revalidatePrismicPages.js";
16
+ export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, cacheTagPrismicPages, createLocaleRedirect, enableAutoPreviews, exitPreview, getPreviewRef, getPrismicCacheTags, getSlices, imgixLoader, redirectToPreviewURL, revalidatePrismicPages };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { exitPreview } from "./exitPreview.js";
2
2
  import { PrismicPreview } from "./PrismicPreview.js";
3
3
  import { PrismicNextLink } from "./PrismicNextLink.js";
4
+ import { getPreviewRef } from "./getPreviewRef.js";
4
5
  import { enableAutoPreviews } from "./enableAutoPreviews.js";
5
6
  import { redirectToPreviewURL } from "./redirectToPreviewURL.js";
6
7
  import { imgixLoader } from "./imgixLoader.js";
@@ -8,4 +9,7 @@ import { PrismicNextImage } from "./PrismicNextImage.js";
8
9
  import { getSlices } from "./getSlices.js";
9
10
  import { SliceSimulator } from "./SliceSimulator.js";
10
11
  import { createLocaleRedirect } from "./createLocaleRedirect.js";
11
- export { PrismicNextImage, PrismicNextLink, PrismicPreview, SliceSimulator, createLocaleRedirect, enableAutoPreviews, exitPreview, getSlices, imgixLoader, redirectToPreviewURL };
12
+ import { getPrismicCacheTags } from "./getPrismicCacheTags.js";
13
+ import { cacheTagPrismicPages } from "./cacheTagPrismicPages.js";
14
+ import { revalidatePrismicPages } from "./revalidatePrismicPages.js";
15
+ export { PrismicNextImage, PrismicNextLink, PrismicPreview, SliceSimulator, cacheTagPrismicPages, createLocaleRedirect, enableAutoPreviews, exitPreview, getPreviewRef, getPrismicCacheTags, getSlices, imgixLoader, redirectToPreviewURL, revalidatePrismicPages };
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.2.4";
2
+ var version = "2.3.0";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.2.4";
2
+ var version = "2.3.0";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -0,0 +1,20 @@
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_getPrismicCacheTags = require("./getPrismicCacheTags.cjs");
3
+ let next_cache_js = require("next/cache.js");
4
+ //#region src/revalidatePrismicPages.ts
5
+ /**
6
+ * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
7
+ * typically comes from a Prismic webhook triggered when publishing content.
8
+ *
9
+ * @param ids - A list of Prismic page IDs to revalidate.
10
+ * @experimental
11
+ *
12
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
13
+ */
14
+ function revalidatePrismicPages(ids) {
15
+ for (const id of ids) (0, next_cache_js.revalidateTag)(require_getPrismicCacheTags.buildPrismicCacheTag(id), { expire: 0 });
16
+ }
17
+ //#endregion
18
+ exports.revalidatePrismicPages = revalidatePrismicPages;
19
+
20
+ //# sourceMappingURL=revalidatePrismicPages.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revalidatePrismicPages.cjs","names":["buildPrismicCacheTag"],"sources":["../src/revalidatePrismicPages.ts"],"sourcesContent":["import { revalidateTag } from \"next/cache\"\n\nimport { buildPrismicCacheTag } from \"./getPrismicCacheTags\"\n\n/**\n * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs\n * typically comes from a Prismic webhook triggered when publishing content.\n *\n * @param ids - A list of Prismic page IDs to revalidate.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}\n */\nexport function revalidatePrismicPages(ids: string[]): void {\n\tfor (const id of ids) {\n\t\tconst tag = buildPrismicCacheTag(id)\n\t\trevalidateTag(tag, { expire: 0 })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,uBAAuB,KAAqB;AAC3D,MAAK,MAAM,MAAM,IAEhB,EAAA,GAAA,cAAA,eADYA,4BAAAA,qBAAqB,GAAG,EACjB,EAAE,QAAQ,GAAG,CAAC"}
@@ -0,0 +1,14 @@
1
+ //#region src/revalidatePrismicPages.d.ts
2
+ /**
3
+ * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
4
+ * typically comes from a Prismic webhook triggered when publishing content.
5
+ *
6
+ * @param ids - A list of Prismic page IDs to revalidate.
7
+ * @experimental
8
+ *
9
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
10
+ */
11
+ declare function revalidatePrismicPages(ids: string[]): void;
12
+ //#endregion
13
+ export { revalidatePrismicPages };
14
+ //# sourceMappingURL=revalidatePrismicPages.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revalidatePrismicPages.d.cts","names":[],"sources":["../src/revalidatePrismicPages.ts"],"mappings":";;AAaA;;;;;;;;iBAAgB,sBAAA,CAAuB,GAAA"}
@@ -0,0 +1,14 @@
1
+ //#region src/revalidatePrismicPages.d.ts
2
+ /**
3
+ * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
4
+ * typically comes from a Prismic webhook triggered when publishing content.
5
+ *
6
+ * @param ids - A list of Prismic page IDs to revalidate.
7
+ * @experimental
8
+ *
9
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
10
+ */
11
+ declare function revalidatePrismicPages(ids: string[]): void;
12
+ //#endregion
13
+ export { revalidatePrismicPages };
14
+ //# sourceMappingURL=revalidatePrismicPages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revalidatePrismicPages.d.ts","names":[],"sources":["../src/revalidatePrismicPages.ts"],"mappings":";;AAaA;;;;;;;;iBAAgB,sBAAA,CAAuB,GAAA"}
@@ -0,0 +1,19 @@
1
+ import { buildPrismicCacheTag } from "./getPrismicCacheTags.js";
2
+ import { revalidateTag } from "next/cache.js";
3
+ //#region src/revalidatePrismicPages.ts
4
+ /**
5
+ * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
6
+ * typically comes from a Prismic webhook triggered when publishing content.
7
+ *
8
+ * @param ids - A list of Prismic page IDs to revalidate.
9
+ * @experimental
10
+ *
11
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
12
+ */
13
+ function revalidatePrismicPages(ids) {
14
+ for (const id of ids) revalidateTag(buildPrismicCacheTag(id), { expire: 0 });
15
+ }
16
+ //#endregion
17
+ export { revalidatePrismicPages };
18
+
19
+ //# sourceMappingURL=revalidatePrismicPages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revalidatePrismicPages.js","names":[],"sources":["../src/revalidatePrismicPages.ts"],"sourcesContent":["import { revalidateTag } from \"next/cache\"\n\nimport { buildPrismicCacheTag } from \"./getPrismicCacheTags\"\n\n/**\n * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs\n * typically comes from a Prismic webhook triggered when publishing content.\n *\n * @param ids - A list of Prismic page IDs to revalidate.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}\n */\nexport function revalidatePrismicPages(ids: string[]): void {\n\tfor (const id of ids) {\n\t\tconst tag = buildPrismicCacheTag(id)\n\t\trevalidateTag(tag, { expire: 0 })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,uBAAuB,KAAqB;AAC3D,MAAK,MAAM,MAAM,IAEhB,eADY,qBAAqB,GAAG,EACjB,EAAE,QAAQ,GAAG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.2.4",
3
+ "version": "2.3.0",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "next",
@@ -0,0 +1,20 @@
1
+ import type { PrismicDocument } from "@prismicio/client"
2
+ import { cacheTag } from "next/cache"
3
+
4
+ import { getPrismicCacheTags } from "./getPrismicCacheTags"
5
+
6
+ /**
7
+ * Tags the current cache entry with cache tags for a set of Prismic pages so they can be
8
+ * revalidated when their content changes.
9
+ *
10
+ * Linked documents (via content relationships) are tagged as well, so the cache entry is
11
+ * revalidated when any of its nested documents change.
12
+ *
13
+ * @param pages - A set of Prismic pages used to tag the cache entry.
14
+ * @experimental
15
+ *
16
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
17
+ */
18
+ export function cacheTagPrismicPages(pages: PrismicDocument[]): void {
19
+ cacheTag(...getPrismicCacheTags(pages))
20
+ }
@@ -1,4 +1,6 @@
1
- import { type Client, cookie as prismicCookie } from "@prismicio/client"
1
+ import type { Client } from "@prismicio/client"
2
+
3
+ import { getPreviewRef } from "./getPreviewRef"
2
4
 
3
5
  /** Configuration for `enableAutoPreviews`. */
4
6
  export type EnableAutoPreviewsConfig = {
@@ -17,36 +19,5 @@ export type EnableAutoPreviewsConfig = {
17
19
  export function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {
18
20
  // We use a function value so the cookie is checked on every
19
21
  // request. We don't have a static value to read from.
20
- config.client.queryContentFromRef(async () => {
21
- // Need this to avoid the following Next.js build-time error:
22
- // You're importing a component that needs next/headers. That only works
23
- // in a Server Component which is not supported in the pages/ directory.
24
- const { cookies, draftMode } = await import("next/headers")
25
-
26
- let isDraftModeEnabled = false
27
- try {
28
- isDraftModeEnabled = (await draftMode()).isEnabled
29
- } catch {
30
- // `draftMode()` may have been called in a palce that
31
- // does not have access to its async storage. This
32
- // occurs in places like `generateStaticParams()`. We
33
- // can ignore this case.
34
- return
35
- }
36
- if (!isDraftModeEnabled) {
37
- return
38
- }
39
-
40
- const cookie = (await cookies()).get(prismicCookie.preview)?.value
41
- if (!cookie) {
42
- return
43
- }
44
-
45
- const isActiveCookie = cookie.includes("websitePreviewId=")
46
- if (!isActiveCookie) {
47
- return
48
- }
49
-
50
- return cookie
51
- })
22
+ config.client.queryContentFromRef(() => getPreviewRef())
52
23
  }
@@ -1,3 +1,5 @@
1
+ import { cookie as prismicCookie } from "@prismicio/client"
2
+
1
3
  /**
2
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
3
5
  * Handler.
@@ -17,10 +19,14 @@ export async function exitPreview(): Promise<Response> {
17
19
  // Need this to avoid the following Next.js build-time error:
18
20
  // You're importing a component that needs next/headers. That only works
19
21
  // in a Server Component which is not supported in the pages/ directory.
20
- const { draftMode } = await import("next/headers")
22
+ const { cookies, draftMode } = await import("next/headers")
21
23
 
22
24
  ;(await draftMode()).disable()
23
25
 
26
+ // `redirectToPreviewURL` writes the preview cookie, so `exitPreview`
27
+ // clears it to close the preview-cookie loop.
28
+ ;(await cookies()).delete(prismicCookie.preview)
29
+
24
30
  // `Cache-Control` header is used to prevent CDN-level caching.
25
31
  return new Response(JSON.stringify({ success: true }), {
26
32
  headers: {
@@ -0,0 +1,51 @@
1
+ import { cookie as prismicCookie } from "@prismicio/client"
2
+
3
+ /**
4
+ * Reads the Prismic preview ref for the current request when an active preview session exists.
5
+ *
6
+ * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
7
+ * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
8
+ * an argument so it becomes part of the cache key:
9
+ *
10
+ * @example
11
+ * ;```typescript
12
+ * import { getPreviewRef } from "@prismicio/next"
13
+ *
14
+ * const page = await fetchPage(uid, await getPreviewRef())
15
+ * ```
16
+ *
17
+ * @returns The active preview ref, or `undefined` if no preview session is active.
18
+ * @experimental
19
+ */
20
+ export async function getPreviewRef(): Promise<string | undefined> {
21
+ // Need this to avoid the following Next.js build-time error:
22
+ // You're importing a component that needs next/headers. That only works
23
+ // in a Server Component which is not supported in the pages/ directory.
24
+ const { cookies, draftMode } = await import("next/headers")
25
+
26
+ let isDraftModeEnabled = false
27
+ try {
28
+ isDraftModeEnabled = (await draftMode()).isEnabled
29
+ } catch {
30
+ // `draftMode()` may have been called in a place that
31
+ // does not have access to its async storage. This
32
+ // occurs in places like `generateStaticParams()`. We
33
+ // can ignore this case.
34
+ return
35
+ }
36
+ if (!isDraftModeEnabled) {
37
+ return
38
+ }
39
+
40
+ const cookie = (await cookies()).get(prismicCookie.preview)?.value
41
+ if (!cookie) {
42
+ return
43
+ }
44
+
45
+ const isActiveCookie = cookie.includes("websitePreviewId=")
46
+ if (!isActiveCookie) {
47
+ return
48
+ }
49
+
50
+ return cookie
51
+ }
@@ -0,0 +1,46 @@
1
+ import type { PrismicDocument } from "@prismicio/client"
2
+
3
+ const CACHE_TAG_PREFIX = "prismic/"
4
+
5
+ /**
6
+ * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
7
+ * relationship) are included to ensure all related content can be revalidated.
8
+ *
9
+ * @param pages - A set of Prismic pages used to tag the function.
10
+ * @experimental
11
+ *
12
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
13
+ */
14
+ export function getPrismicCacheTags(pages: PrismicDocument[]): string[] {
15
+ const ids = [...new Set(getPrismicDocumentIDs(pages))]
16
+ return ids.map((id) => buildPrismicCacheTag(id))
17
+ }
18
+
19
+ export function buildPrismicCacheTag(id: string): string {
20
+ return `${CACHE_TAG_PREFIX}${id}`
21
+ }
22
+
23
+ function getPrismicDocumentIDs(input: unknown): string[] {
24
+ if (typeof input !== "object" || input == null) return []
25
+
26
+ if (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item))
27
+
28
+ if ("id" in input && typeof input.id === "string") {
29
+ // Document
30
+ // Content relationship or link
31
+ if (
32
+ ("href" in input &&
33
+ typeof input.href === "string" &&
34
+ input.href.includes("/api/v2/documents/search?")) ||
35
+ ("link_type" in input && input.link_type === "Document")
36
+ ) {
37
+ if ("data" in input && typeof input.data === "object" && input.data !== null) {
38
+ return [input.id, ...getPrismicDocumentIDs(input.data)]
39
+ } else {
40
+ return [input.id]
41
+ }
42
+ }
43
+ }
44
+
45
+ return Object.values(input).flatMap((input) => getPrismicDocumentIDs(input))
46
+ }
package/src/index.ts CHANGED
@@ -9,6 +9,8 @@ export type { PrismicNextLinkProps } from "./PrismicNextLink"
9
9
  export { enableAutoPreviews } from "./enableAutoPreviews"
10
10
  export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
11
11
 
12
+ export { getPreviewRef } from "./getPreviewRef"
13
+
12
14
  export { redirectToPreviewURL } from "./redirectToPreviewURL"
13
15
  export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL"
14
16
 
@@ -26,3 +28,9 @@ export type { CreateClientConfig } from "./types"
26
28
 
27
29
  export { createLocaleRedirect } from "./createLocaleRedirect"
28
30
  export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect"
31
+
32
+ export { getPrismicCacheTags } from "./getPrismicCacheTags"
33
+
34
+ export { cacheTagPrismicPages } from "./cacheTagPrismicPages"
35
+
36
+ export { revalidatePrismicPages } from "./revalidatePrismicPages"
@@ -0,0 +1,19 @@
1
+ import { revalidateTag } from "next/cache"
2
+
3
+ import { buildPrismicCacheTag } from "./getPrismicCacheTags"
4
+
5
+ /**
6
+ * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
7
+ * typically comes from a Prismic webhook triggered when publishing content.
8
+ *
9
+ * @param ids - A list of Prismic page IDs to revalidate.
10
+ * @experimental
11
+ *
12
+ * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
13
+ */
14
+ export function revalidatePrismicPages(ids: string[]): void {
15
+ for (const id of ids) {
16
+ const tag = buildPrismicCacheTag(id)
17
+ revalidateTag(tag, { expire: 0 })
18
+ }
19
+ }