@prismicio/next 2.2.3 → 2.2.4
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.
- package/dist/PrismicNextImage.cjs +9 -11
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.cts +13 -21
- package/dist/PrismicNextImage.d.cts.map +1 -0
- package/dist/PrismicNextImage.d.ts +13 -21
- package/dist/PrismicNextImage.d.ts.map +1 -0
- package/dist/PrismicNextImage.js +9 -11
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.cts +3 -3
- package/dist/PrismicNextLink.d.cts.map +1 -0
- package/dist/PrismicNextLink.d.ts +3 -3
- package/dist/PrismicNextLink.d.ts.map +1 -0
- package/dist/PrismicNextLink.js.map +1 -1
- package/dist/PrismicPreview.cjs +6 -7
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts +11 -12
- package/dist/PrismicPreview.d.cts.map +1 -0
- package/dist/PrismicPreview.d.ts +11 -12
- package/dist/PrismicPreview.d.ts.map +1 -0
- package/dist/PrismicPreview.js +6 -7
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +1 -3
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js +1 -3
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/SliceSimulator.cjs +3 -3
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.d.cts +3 -5
- package/dist/SliceSimulator.d.cts.map +1 -0
- package/dist/SliceSimulator.d.ts +3 -5
- package/dist/SliceSimulator.d.ts.map +1 -0
- package/dist/SliceSimulator.js +3 -3
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/SliceSimulatorWrapper.cjs +1 -4
- package/dist/SliceSimulatorWrapper.cjs.map +1 -1
- package/dist/SliceSimulatorWrapper.js +1 -4
- package/dist/SliceSimulatorWrapper.js.map +1 -1
- package/dist/createLocaleRedirect.cjs.map +1 -1
- package/dist/createLocaleRedirect.d.cts.map +1 -0
- package/dist/createLocaleRedirect.d.ts.map +1 -0
- package/dist/createLocaleRedirect.js.map +1 -1
- package/dist/enableAutoPreviews.cjs +1 -2
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.cts +1 -2
- package/dist/enableAutoPreviews.d.cts.map +1 -0
- package/dist/enableAutoPreviews.d.ts +1 -2
- package/dist/enableAutoPreviews.d.ts.map +1 -0
- package/dist/enableAutoPreviews.js +1 -2
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs +9 -10
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.cts +9 -10
- package/dist/exitPreview.d.cts.map +1 -0
- package/dist/exitPreview.d.ts +9 -10
- package/dist/exitPreview.d.ts.map +1 -0
- package/dist/exitPreview.js +9 -10
- package/dist/exitPreview.js.map +1 -1
- package/dist/getSlices.cjs.map +1 -1
- package/dist/getSlices.d.cts.map +1 -0
- package/dist/getSlices.d.ts.map +1 -0
- package/dist/getSlices.js.map +1 -1
- package/dist/imgixLoader.cjs +2 -2
- package/dist/imgixLoader.cjs.map +1 -1
- package/dist/imgixLoader.d.cts +2 -2
- package/dist/imgixLoader.d.cts.map +1 -0
- package/dist/imgixLoader.d.ts +2 -2
- package/dist/imgixLoader.d.ts.map +1 -0
- package/dist/imgixLoader.js +2 -2
- package/dist/imgixLoader.js.map +1 -1
- package/dist/lib/devMsg.cjs +6 -8
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js +6 -8
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/resolveDefaultExport.cjs +8 -12
- package/dist/lib/resolveDefaultExport.cjs.map +1 -1
- package/dist/lib/resolveDefaultExport.js +8 -12
- package/dist/lib/resolveDefaultExport.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/PrismicPreview.cjs +6 -7
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts +11 -12
- package/dist/pages/PrismicPreview.d.cts.map +1 -0
- package/dist/pages/PrismicPreview.d.ts +11 -12
- package/dist/pages/PrismicPreview.d.ts.map +1 -0
- package/dist/pages/PrismicPreview.js +6 -7
- package/dist/pages/PrismicPreview.js.map +1 -1
- package/dist/pages/SliceSimulator.cjs +2 -2
- package/dist/pages/SliceSimulator.cjs.map +1 -1
- package/dist/pages/SliceSimulator.d.cts +10 -13
- package/dist/pages/SliceSimulator.d.cts.map +1 -0
- package/dist/pages/SliceSimulator.d.ts +10 -13
- package/dist/pages/SliceSimulator.d.ts.map +1 -0
- package/dist/pages/SliceSimulator.js +2 -2
- package/dist/pages/SliceSimulator.js.map +1 -1
- package/dist/pages/enableAutoPreviews.cjs +3 -3
- package/dist/pages/enableAutoPreviews.cjs.map +1 -1
- package/dist/pages/enableAutoPreviews.d.cts +5 -5
- package/dist/pages/enableAutoPreviews.d.cts.map +1 -0
- package/dist/pages/enableAutoPreviews.d.ts +5 -5
- package/dist/pages/enableAutoPreviews.d.ts.map +1 -0
- package/dist/pages/enableAutoPreviews.js +3 -3
- package/dist/pages/enableAutoPreviews.js.map +1 -1
- package/dist/pages/exitPreview.cjs +9 -10
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts +9 -10
- package/dist/pages/exitPreview.d.cts.map +1 -0
- package/dist/pages/exitPreview.d.ts +9 -10
- package/dist/pages/exitPreview.d.ts.map +1 -0
- package/dist/pages/exitPreview.js +9 -10
- package/dist/pages/exitPreview.js.map +1 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +7 -9
- package/dist/pages/redirectToPreviewURL.d.cts.map +1 -0
- package/dist/pages/redirectToPreviewURL.d.ts +7 -9
- package/dist/pages/redirectToPreviewURL.d.ts.map +1 -0
- package/dist/pages/redirectToPreviewURL.js.map +1 -1
- package/dist/pages/setPreviewData.cjs.map +1 -1
- package/dist/pages/setPreviewData.d.cts.map +1 -0
- package/dist/pages/setPreviewData.d.ts.map +1 -0
- package/dist/pages/setPreviewData.js.map +1 -1
- package/dist/pages/types.d.cts +3 -8
- package/dist/pages/types.d.cts.map +1 -0
- package/dist/pages/types.d.ts +3 -8
- package/dist/pages/types.d.ts.map +1 -0
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +3 -5
- package/dist/redirectToPreviewURL.d.cts.map +1 -0
- package/dist/redirectToPreviewURL.d.ts +3 -5
- package/dist/redirectToPreviewURL.d.ts.map +1 -0
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -0
- package/package.json +32 -34
- package/src/PrismicNextImage.tsx +113 -134
- package/src/PrismicNextLink.tsx +43 -45
- package/src/PrismicPreview.tsx +28 -29
- package/src/PrismicPreviewClient.tsx +42 -44
- package/src/SliceSimulator.tsx +38 -43
- package/src/SliceSimulatorWrapper.tsx +15 -25
- package/src/createLocaleRedirect.ts +3 -3
- package/src/enableAutoPreviews.ts +15 -16
- package/src/exitPreview.ts +12 -13
- package/src/getSlices.ts +6 -10
- package/src/imgixLoader.ts +10 -10
- package/src/index.ts +18 -21
- package/src/lib/devMsg.ts +9 -11
- package/src/lib/resolveDefaultExport.ts +9 -13
- package/src/pages/PrismicPreview.tsx +47 -51
- package/src/pages/SliceSimulator.tsx +35 -37
- package/src/pages/enableAutoPreviews.ts +17 -17
- package/src/pages/exitPreview.ts +17 -18
- package/src/pages/index.ts +20 -23
- package/src/pages/redirectToPreviewURL.ts +22 -33
- package/src/pages/setPreviewData.ts +7 -7
- package/src/pages/types.ts +16 -20
- package/src/redirectToPreviewURL.ts +21 -30
- package/src/types.ts +12 -13
|
@@ -11,8 +11,8 @@ import { PreviewData } from "next";
|
|
|
11
11
|
type EnableAutoPreviewsConfig = {
|
|
12
12
|
/** Prismic client with which automatic previews will be enabled. */client: Pick<Client, "queryContentFromRef" | "enableAutoPreviewsFromReq">;
|
|
13
13
|
/**
|
|
14
|
-
* The `previewData` object provided in the `getStaticProps()` or
|
|
15
|
-
*
|
|
14
|
+
* The `previewData` object provided in the `getStaticProps()` or `getServerSideProps()` context
|
|
15
|
+
* object.
|
|
16
16
|
*/
|
|
17
17
|
previewData?: PreviewData;
|
|
18
18
|
/**
|
|
@@ -23,9 +23,9 @@ type EnableAutoPreviewsConfig = {
|
|
|
23
23
|
req?: NextApiRequestLike;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* Configures a Prismic client to automatically query draft content during a
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* Configures a Prismic client to automatically query draft content during a preview session. It
|
|
27
|
+
* either takes in a Next.js `getStaticProps` context object or a Next.js API endpoint request
|
|
28
|
+
* object.
|
|
29
29
|
*
|
|
30
30
|
* @param config - Configuration for the function.
|
|
31
31
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.d.ts","names":[],"sources":["../../src/pages/enableAutoPreviews.ts"],"mappings":";;;;;;;AAUA;;;KAAY,wBAAA;EAKH,oEAAR,MAAA,EAAQ,IAAA,CAAK,MAAA;EAaP;;;;EAPN,WAAA,GAAc,WAAA;EAND;;;;;EAab,GAAA,GAAM,kBAAA;AAAA;AAUP;;;;;;;AAAA,iBAAgB,kBAAA,CAAmB,MAAA,EAAQ,wBAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
//#region src/pages/enableAutoPreviews.ts
|
|
2
2
|
/**
|
|
3
|
-
* Configures a Prismic client to automatically query draft content during a
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Configures a Prismic client to automatically query draft content during a preview session. It
|
|
4
|
+
* either takes in a Next.js `getStaticProps` context object or a Next.js API endpoint request
|
|
5
|
+
* object.
|
|
6
6
|
*
|
|
7
7
|
* @param config - Configuration for the function.
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.js","names":[],"sources":["../../src/pages/enableAutoPreviews.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.js","names":[],"sources":["../../src/pages/enableAutoPreviews.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\"\nimport type { PreviewData } from \"next\"\n\nimport type { NextApiRequestLike } from \"./types\"\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\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\t/**\n\t * The `previewData` object provided in the `getStaticProps()` or `getServerSideProps()` context\n\t * object.\n\t */\n\tpreviewData?: PreviewData\n\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike\n}\n\n/**\n * Configures a Prismic client to automatically query draft content during a preview session. It\n * either takes in a Next.js `getStaticProps` context object or a Next.js API endpoint request\n * object.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode.\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref)\n\t\t}\n\n\t\treturn\n\t}\n\n\tif (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route.\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req)\n\n\t\treturn\n\t}\n}\n\nfunction isPrismicPreviewData(input: unknown): input is { ref: string } {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input\n}\n"],"mappings":";;;;;;;;AAsCA,SAAgB,mBAAmB,QAAwC;AAC1E,KAAI,iBAAiB,UAAU,OAAO,aAAa;AAIlD,MAAI,qBAAqB,OAAO,YAAY,CAC3C,QAAO,OAAO,oBAAoB,OAAO,YAAY,IAAI;AAG1D;;AAGD,KAAI,SAAS,UAAU,OAAO,KAAK;AAGlC,SAAO,OAAO,0BAA0B,OAAO,IAAI;AAEnD;;;AAIF,SAAS,qBAAqB,OAA0C;AACvE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
//#region src/pages/exitPreview.ts
|
|
2
2
|
/**
|
|
3
|
-
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
4
|
-
*
|
|
3
|
+
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
4
|
+
* route.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
+
* ;```typescript
|
|
8
|
+
* // src/pages/api/exit-preview.js
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
* // src/pages/api/exit-preview.js
|
|
10
|
+
* import { exitPreview } from "@prismicio/next"
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
12
|
+
* export default function handler(_req, res) {
|
|
13
|
+
* return exitPreview({ res })
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
17
16
|
*/
|
|
18
17
|
function exitPreview(config) {
|
|
19
18
|
config.res.clearPreviewData();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\"
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in an API\n * route.\n *\n * @example\n * \t;```typescript\n * \t// src/pages/api/exit-preview.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport default function handler(_req, res) {\n * \t\treturn exitPreview({ res })\n * \t}\n * \t```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData()\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\")\n\n\tconfig.res.json({ success: true })\n\n\treturn\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;AAG7B,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
|
|
@@ -17,20 +17,19 @@ type ExitPreviewAPIRouteConfig = {
|
|
|
17
17
|
res: NextApiResponseLike;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
21
|
-
*
|
|
20
|
+
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
21
|
+
* route.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
|
+
* ;```typescript
|
|
25
|
+
* // src/pages/api/exit-preview.js
|
|
24
26
|
*
|
|
25
|
-
*
|
|
26
|
-
* // src/pages/api/exit-preview.js
|
|
27
|
+
* import { exitPreview } from "@prismicio/next"
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
29
|
+
* export default function handler(_req, res) {
|
|
30
|
+
* return exitPreview({ res })
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
34
33
|
*/
|
|
35
34
|
declare function exitPreview(config: ExitPreviewAPIRouteConfig): void;
|
|
36
35
|
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;KAGY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
|
|
@@ -17,20 +17,19 @@ type ExitPreviewAPIRouteConfig = {
|
|
|
17
17
|
res: NextApiResponseLike;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
21
|
-
*
|
|
20
|
+
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
21
|
+
* route.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
|
+
* ;```typescript
|
|
25
|
+
* // src/pages/api/exit-preview.js
|
|
24
26
|
*
|
|
25
|
-
*
|
|
26
|
-
* // src/pages/api/exit-preview.js
|
|
27
|
+
* import { exitPreview } from "@prismicio/next"
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
29
|
+
* export default function handler(_req, res) {
|
|
30
|
+
* return exitPreview({ res })
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
34
33
|
*/
|
|
35
34
|
declare function exitPreview(config: ExitPreviewAPIRouteConfig): void;
|
|
36
35
|
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;KAGY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
//#region src/pages/exitPreview.ts
|
|
2
2
|
/**
|
|
3
|
-
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
4
|
-
*
|
|
3
|
+
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
4
|
+
* route.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
+
* ;```typescript
|
|
8
|
+
* // src/pages/api/exit-preview.js
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
* // src/pages/api/exit-preview.js
|
|
10
|
+
* import { exitPreview } from "@prismicio/next"
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
12
|
+
* export default function handler(_req, res) {
|
|
13
|
+
* return exitPreview({ res })
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
17
16
|
*/
|
|
18
17
|
function exitPreview(config) {
|
|
19
18
|
config.res.clearPreviewData();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\"
|
|
1
|
+
{"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in an API\n * route.\n *\n * @example\n * \t;```typescript\n * \t// src/pages/api/exit-preview.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport default function handler(_req, res) {\n * \t\treturn exitPreview({ res })\n * \t}\n * \t```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData()\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\")\n\n\tconfig.res.json({ success: true })\n\n\treturn\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;AAG7B,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\"
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be\n\t * omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {\n\tconst { client, req, res, linkResolver, defaultURL = \"/\", basePath = \"\" } = config\n\n\tconst previewToken = req.query.token?.toString()\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t})\n\n\tres.redirect(basePath + previewURL)\n\n\treturn\n}\n"],"mappings":";AAmDA,eAAsB,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
|
|
@@ -23,21 +23,19 @@ type RedirectToPreviewURLConfig = {
|
|
|
23
23
|
*/
|
|
24
24
|
linkResolver?: LinkResolverFunction;
|
|
25
25
|
/**
|
|
26
|
-
* The default redirect URL if a URL cannot be determined for the previewed
|
|
27
|
-
* document.
|
|
26
|
+
* The default redirect URL if a URL cannot be determined for the previewed document.
|
|
28
27
|
*
|
|
29
|
-
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
30
|
-
*
|
|
31
|
-
* property using the `basePath` option.
|
|
28
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
|
|
29
|
+
* _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
|
|
32
30
|
*/
|
|
33
31
|
defaultURL?: string;
|
|
34
32
|
/**
|
|
35
|
-
* The `basePath` for the Next.js app as it is defined in `next.config.js`.
|
|
36
|
-
*
|
|
33
|
+
* The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be
|
|
34
|
+
* omitted if the app does not have a `basePath`.
|
|
37
35
|
*
|
|
38
36
|
* @remarks
|
|
39
|
-
*
|
|
40
|
-
*
|
|
37
|
+
* The Router Handler or API route is unable to detect the app's `basePath` automatically. It
|
|
38
|
+
* must be provided to `redirectToPreviewURL()` manually.
|
|
41
39
|
*/
|
|
42
40
|
basePath?: string;
|
|
43
41
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,GAAA,EAAK,kBAAA;EAcU;;;;;EAPf,GAAA,EAAK,mBAAA;EAPL;;;;;EAcA,YAAA,GAAe,oBAAA;EAQf;;;;AAaD;;EAbC,UAAA;EAasF;;;;;;;;EAHtF,QAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -23,21 +23,19 @@ type RedirectToPreviewURLConfig = {
|
|
|
23
23
|
*/
|
|
24
24
|
linkResolver?: LinkResolverFunction;
|
|
25
25
|
/**
|
|
26
|
-
* The default redirect URL if a URL cannot be determined for the previewed
|
|
27
|
-
* document.
|
|
26
|
+
* The default redirect URL if a URL cannot be determined for the previewed document.
|
|
28
27
|
*
|
|
29
|
-
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
30
|
-
*
|
|
31
|
-
* property using the `basePath` option.
|
|
28
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
|
|
29
|
+
* _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
|
|
32
30
|
*/
|
|
33
31
|
defaultURL?: string;
|
|
34
32
|
/**
|
|
35
|
-
* The `basePath` for the Next.js app as it is defined in `next.config.js`.
|
|
36
|
-
*
|
|
33
|
+
* The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be
|
|
34
|
+
* omitted if the app does not have a `basePath`.
|
|
37
35
|
*
|
|
38
36
|
* @remarks
|
|
39
|
-
*
|
|
40
|
-
*
|
|
37
|
+
* The Router Handler or API route is unable to detect the app's `basePath` automatically. It
|
|
38
|
+
* must be provided to `redirectToPreviewURL()` manually.
|
|
41
39
|
*/
|
|
42
40
|
basePath?: string;
|
|
43
41
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,GAAA,EAAK,kBAAA;EAcU;;;;;EAPf,GAAA,EAAK,mBAAA;EAPL;;;;;EAcA,YAAA,GAAe,oBAAA;EAQf;;;;AAaD;;EAbC,UAAA;EAasF;;;;;;;;EAHtF,QAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\"
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be\n\t * omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {\n\tconst { client, req, res, linkResolver, defaultURL = \"/\", basePath = \"\" } = config\n\n\tconst previewToken = req.query.token?.toString()\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t})\n\n\tres.redirect(basePath + previewURL)\n\n\treturn\n}\n"],"mappings":";AAmDA,eAAsB,qBAAqB,QAAmD;CAC7F,MAAM,EAAE,QAAQ,KAAK,KAAK,cAAc,aAAa,KAAK,WAAW,OAAO;CAE5E,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.cjs","names":["cookie"],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"
|
|
1
|
+
{"version":3,"file":"setPreviewData.cjs","names":["cookie"],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview]\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,kBAAAA,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setPreviewData.d.cts","names":[],"sources":["../../src/pages/setPreviewData.ts"],"mappings":";;;;KAKY,oBAAA;EAAA;;;;;EAMX,GAAA,EAAK,kBAAA;EAOL;;;;AAID;EAJC,GAAA,EAAK,mBAAA;AAAA;;iBAIU,cAAA,CAAA;EAAiB,GAAA;EAAK;AAAA,GAAO,oBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setPreviewData.d.ts","names":[],"sources":["../../src/pages/setPreviewData.ts"],"mappings":";;;;KAKY,oBAAA;EAAA;;;;;EAMX,GAAA,EAAK,kBAAA;EAOL;;;;AAID;EAJC,GAAA,EAAK,mBAAA;AAAA;;iBAIU,cAAA,CAAA;EAAiB,GAAA;EAAK;AAAA,GAAO,oBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"
|
|
1
|
+
{"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\"\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike\n}\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview]\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref })\n\t}\n}\n"],"mappings":";;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
|
package/dist/pages/types.d.cts
CHANGED
|
@@ -2,16 +2,12 @@ import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.cjs";
|
|
|
2
2
|
import { ClientConfig } from "@prismicio/client";
|
|
3
3
|
|
|
4
4
|
//#region src/pages/types.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for creating a Prismic client with automatic preview support in
|
|
7
|
-
* Next.js apps.
|
|
8
|
-
*/
|
|
5
|
+
/** Configuration for creating a Prismic client with automatic preview support in Next.js apps. */
|
|
9
6
|
type CreateClientConfig = ClientConfig & Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
|
|
10
7
|
/**
|
|
11
8
|
* The minimal set of properties needed from `next`'s `NextApiRequest` type.
|
|
12
9
|
*
|
|
13
|
-
* This request type is only compatible with API routes defined in the `pages`
|
|
14
|
-
* directory.
|
|
10
|
+
* This request type is only compatible with API routes defined in the `pages` directory.
|
|
15
11
|
*/
|
|
16
12
|
type NextApiRequestLike = {
|
|
17
13
|
query: Partial<Record<string, string | string[]>>;
|
|
@@ -20,8 +16,7 @@ type NextApiRequestLike = {
|
|
|
20
16
|
/**
|
|
21
17
|
* The minimal set of properties needed from `next`'s `NextApiResponse` type.
|
|
22
18
|
*
|
|
23
|
-
* This request type is only compatible with API routes defined in the `pages`
|
|
24
|
-
* directory.
|
|
19
|
+
* This request type is only compatible with API routes defined in the `pages` directory.
|
|
25
20
|
*/
|
|
26
21
|
type NextApiResponseLike = {
|
|
27
22
|
redirect(url: string): NextApiResponseLike;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
|
package/dist/pages/types.d.ts
CHANGED
|
@@ -2,16 +2,12 @@ import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.js";
|
|
|
2
2
|
import { ClientConfig } from "@prismicio/client";
|
|
3
3
|
|
|
4
4
|
//#region src/pages/types.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for creating a Prismic client with automatic preview support in
|
|
7
|
-
* Next.js apps.
|
|
8
|
-
*/
|
|
5
|
+
/** Configuration for creating a Prismic client with automatic preview support in Next.js apps. */
|
|
9
6
|
type CreateClientConfig = ClientConfig & Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
|
|
10
7
|
/**
|
|
11
8
|
* The minimal set of properties needed from `next`'s `NextApiRequest` type.
|
|
12
9
|
*
|
|
13
|
-
* This request type is only compatible with API routes defined in the `pages`
|
|
14
|
-
* directory.
|
|
10
|
+
* This request type is only compatible with API routes defined in the `pages` directory.
|
|
15
11
|
*/
|
|
16
12
|
type NextApiRequestLike = {
|
|
17
13
|
query: Partial<Record<string, string | string[]>>;
|
|
@@ -20,8 +16,7 @@ type NextApiRequestLike = {
|
|
|
20
16
|
/**
|
|
21
17
|
* The minimal set of properties needed from `next`'s `NextApiResponse` type.
|
|
22
18
|
*
|
|
23
|
-
* This request type is only compatible with API routes defined in the `pages`
|
|
24
|
-
* directory.
|
|
19
|
+
* This request type is only compatible with API routes defined in the `pages` directory.
|
|
25
20
|
*/
|
|
26
21
|
type NextApiResponseLike = {
|
|
27
22
|
redirect(url: string): NextApiResponseLike;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\nimport { redirect } from \"next/navigation\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies()\n\t\tcookieJar.set(prismicCookie.preview, previewToken)\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\tredirect(previewURL)\n}\n"],"mappings":";;;;AAmCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,kBAAAA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,EAAA,GAAA,gBAAA,UAAS,WAAW"}
|
|
@@ -17,12 +17,10 @@ type RedirectToPreviewURLConfig = {
|
|
|
17
17
|
*/
|
|
18
18
|
linkResolver?: LinkResolverFunction;
|
|
19
19
|
/**
|
|
20
|
-
* The default redirect URL if a URL cannot be determined for the previewed
|
|
21
|
-
* document.
|
|
20
|
+
* The default redirect URL if a URL cannot be determined for the previewed document.
|
|
22
21
|
*
|
|
23
|
-
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
24
|
-
*
|
|
25
|
-
* property using the `basePath` option.
|
|
22
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
|
|
23
|
+
* _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
|
|
26
24
|
*/
|
|
27
25
|
defaultURL?: string;
|
|
28
26
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAKY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -17,12 +17,10 @@ type RedirectToPreviewURLConfig = {
|
|
|
17
17
|
*/
|
|
18
18
|
linkResolver?: LinkResolverFunction;
|
|
19
19
|
/**
|
|
20
|
-
* The default redirect URL if a URL cannot be determined for the previewed
|
|
21
|
-
* document.
|
|
20
|
+
* The default redirect URL if a URL cannot be determined for the previewed document.
|
|
22
21
|
*
|
|
23
|
-
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
24
|
-
*
|
|
25
|
-
* property using the `basePath` option.
|
|
22
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
|
|
23
|
+
* _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
|
|
26
24
|
*/
|
|
27
25
|
defaultURL?: string;
|
|
28
26
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAKY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\nimport { redirect } from \"next/navigation\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies()\n\t\tcookieJar.set(prismicCookie.preview, previewToken)\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\tredirect(previewURL)\n}\n"],"mappings":";;;AAmCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,UAAS,WAAW"}
|
package/dist/types.d.cts
CHANGED
|
@@ -11,8 +11,7 @@ type CreateClientConfig = ClientConfig;
|
|
|
11
11
|
/**
|
|
12
12
|
* The minimal set of properties needed from `next`'s `NextRequest` type.
|
|
13
13
|
*
|
|
14
|
-
* This request type is only compatible with Route Handlers defined in the `app`
|
|
15
|
-
* directory.
|
|
14
|
+
* This request type is only compatible with Route Handlers defined in the `app` directory.
|
|
16
15
|
*/
|
|
17
16
|
type NextRequestLike = {
|
|
18
17
|
headers: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;YAIW,eAAA;IACT,IAAA,GAAO,WAAA;EAAA;AAAA;;KAKG,kBAAA,GAAqB,YAAA;;;;;;KAOrB,eAAA;EACX,OAAA;IACC,GAAA,CAAI,IAAA;EAAA;EAEL,GAAA;EACA,OAAA;IACC,QAAA;IACA,YAAA;MACC,GAAA,CAAI,IAAA;IAAA;EAAA;AAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -11,8 +11,7 @@ type CreateClientConfig = ClientConfig;
|
|
|
11
11
|
/**
|
|
12
12
|
* The minimal set of properties needed from `next`'s `NextRequest` type.
|
|
13
13
|
*
|
|
14
|
-
* This request type is only compatible with Route Handlers defined in the `app`
|
|
15
|
-
* directory.
|
|
14
|
+
* This request type is only compatible with Route Handlers defined in the `app` directory.
|
|
16
15
|
*/
|
|
17
16
|
type NextRequestLike = {
|
|
18
17
|
headers: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;YAIW,eAAA;IACT,IAAA,GAAO,WAAA;EAAA;AAAA;;KAKG,kBAAA,GAAqB,YAAA;;;;;;KAOrB,eAAA;EACX,OAAA;IACC,GAAA,CAAI,IAAA;EAAA;EAEL,GAAA;EACA,OAAA;IACC,QAAA;IACA,YAAA;MACC,GAAA,CAAI,IAAA;IAAA;EAAA;AAAA"}
|